forked from aashish157/cbse-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperators.cpp
More file actions
108 lines (82 loc) · 3.61 KB
/
operators.cpp
File metadata and controls
108 lines (82 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// operators.cpp
// helloworld
//
// Created by Kunal bhatia on 25/09/18.
// Copyright © 2018 Kunal bhatia. All rights reserved.
//
//
// main.cpp
// XcodeTest
//
// A sample SNAP program which uses Xcode.
//
// For more detailed examples, see the snap/examples directory.
#include "Snap.h"
using namespace TSnap;
int main(int argc, char* argv[]) {
// Demos Breadth First Search functions on a full graph.
const int NNodes = 500;
PNGraph G = GenFull<PNGraph>(NNodes);
PNGraph GOut;
int TreeSz, TreeDepth;
// Get BFS tree from first node without following links (demos different options)
GOut = GetBfsTree(G, 1, false, false);
GetSubTreeSz(G, 1, false, false, TreeSz, TreeDepth);
printf("FollowOut=false, FollowIn=false, GOut->GetNodes() == %d, GOut->GetEdges() = %d\n",
GOut->GetNodes(), G->GetEdges());
printf("TreeSz == %d, TreeDepth = %d\n", TreeSz, TreeDepth);
GOut = GetBfsTree(G, NNodes-1, true, true);
GetSubTreeSz(G, 1, true, true, TreeSz, TreeDepth);
printf("FollowOut=true, FollowIn=true, GOut->GetNodes() == %d, GOut->GetEdges() = %d\n",
GOut->GetNodes(), G->GetEdges());
printf("TreeSz == %d, TreeDepth = %d\n", TreeSz, TreeDepth);
GOut = GetBfsTree(G, NNodes/2, true, false);
GetSubTreeSz(G, 1, true, false, TreeSz, TreeDepth);
printf("FollowOut=true, FollowIn=false, GOut->GetNodes() == %d, GOut->GetEdges() = %d\n",
GOut->GetNodes(), G->GetEdges());
printf("TreeSz == %d, TreeDepth = %d\n", TreeSz, TreeDepth);
GOut = GetBfsTree(G, 1, false, true);
GetSubTreeSz(G, 1, false, true, TreeSz, TreeDepth);
printf("FollowOut=false, FollowIn=true, GOut->GetNodes() == %d, GOut->GetEdges() = %d\n",
GOut->GetNodes(), G->GetEdges());
printf("TreeSz == %d, TreeDepth = %d\n", TreeSz, TreeDepth);
TIntV NIdV;
int StartNId, Hop, Nodes;
StartNId = 1;
Hop = 1;
Nodes = GetNodesAtHop(G, StartNId, Hop, NIdV, true);
printf("StartNId = %d, Nodes = %d, GetNodesAtHop NIdV.Len() = %d\n", StartNId, Nodes, NIdV.Len());
TIntPrV HopCntV;
Nodes = GetNodesAtHops(G, StartNId, HopCntV, true);
printf("StartNId = %d, Nodes = %d, GetNodesAtHops HopCntV.Len() = %d\n", StartNId, Nodes, HopCntV.Len());
int Length, SrcNId, DstNId;
SrcNId = 1;
DstNId = NNodes-1;
Length = GetShortPath(G, SrcNId, DstNId, true);
printf("SPL Length = %d\n", Length);
TIntH NIdToDistH;
int MaxDist = 9;
Length = GetShortPath(G, SrcNId, NIdToDistH, true, MaxDist);
int FullDiam;
double EffDiam, AvgDiam;
int NTestNodes = 10;
for (int IsDir = 0; IsDir < 2; IsDir++) {
printf("IsDir = %d:\n", IsDir);
FullDiam = GetBfsFullDiam(G, NTestNodes, IsDir);
printf("FullDiam = %d\n", FullDiam);
EffDiam = GetBfsEffDiam (G, NTestNodes, IsDir);
printf("EffDiam = %.3f\n", EffDiam);
EffDiam = GetBfsEffDiam (G, NTestNodes, IsDir, EffDiam, FullDiam);
printf("EffDiam = %.3f, FullDiam = %d\n", EffDiam, FullDiam);
EffDiam = GetBfsEffDiam (G, NTestNodes, IsDir, EffDiam, FullDiam, AvgDiam);
printf("EffDiam = %.3f, FullDiam = %d, AvgDiam = %.3f\n", EffDiam, FullDiam, AvgDiam);
TIntV SubGraphNIdV;
for (int i = 0; i < NTestNodes; i++) {
SubGraphNIdV.Add(G->GetRndNId());
}
EffDiam = GetBfsEffDiam(G, NTestNodes, SubGraphNIdV, IsDir, EffDiam, FullDiam);
printf("For subgraph: EffDiam = %.3f, FullDiam = %d\n", EffDiam, FullDiam);
}
return 0;
}