Skip to content

Commit 8bc7c27

Browse files
committed
Update treksDynamic.m2
added runtime comparison of BfsPathGen vs PathGen for ER random graphs
1 parent a3c2f39 commit 8bc7c27

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

treksDynamic.m2

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
needsPackage "Probability"
12
needsPackage "GraphicalModels"
23

34

@@ -112,16 +113,42 @@ BfsPathGen = (G, V) -> (
112113
return pathtable
113114
)
114115

115-
---
116116
-- G = digraph {{1, {2,3,4,5,6,7,8,9}}, {2, {3,4,5,6,7,8,9}}, {3, {4,5,6,7,8,9}}, {4,{5,6,7,8,9}}, {5, {6,7,8,9}}, {6, {7,8,9}}, {7, {8,9}}, {8, {9}}}
117117

118-
-- sum(apply(1000, x -> (elapsedTiming(pathGen(G)))#0))
119-
-- sum(apply(1000, x -> (elapsedTiming(BfsPathGen(G)))#0))
120-
-- how about testing when each of the pathgen is faster and allTreks calls the programs accordingly=
118+
-- sum(apply(1000, x -> (elapsedTiming(pathGen(G, V)))#0))
119+
-- sum(apply(1000, x -> (elapsedTiming(BfsPathGen(G, V)))#0))
120+
121+
122+
123+
-- testfunction when each of the pathgens is faster; aim: allTreks calls the programs accordingly
124+
pathgenruntime = (n) -> (
125+
probs = apply(11, i -> i/10);
126+
timelist = new MutableList from {};
127+
for p in probs do(
128+
P := bernoulliDistribution(p);
129+
E := for e in subsets(1..n, 2) list if random(P) == 1 then e else continue;
130+
G = digraph(toList(1..n), E);
131+
V = vertices(G);
132+
tmatrix = sum(apply(5, x -> (elapsedTiming(pathGen(G, V)))#0));
133+
tbfs = sum(apply(5, x -> (elapsedTiming(BfsPathGen(G, V)))#0));
134+
if tbfs < tmatrix then timelist##timelist = p;
135+
);
136+
X = toList(timelist)
137+
)
138+
139+
-- n = 15;
140+
-- pathgenruntime(n)
141+
142+
-- n = 15 then timelist = {3/10, 5/10, 6/10, 7/10, 8/10, 9/10, 1}
143+
-- n = 16 then timelist = {2/10, 3/10, 5/10, 6/10, 7/10, 8/10, 9/10, 1}
144+
-- n = 17 then timelist = {2/10, 3/10, 5/10, 6/10, 7/10, 8/10, 9/10, 1}
145+
-- n = 18 then timelist = {2/10, 4/10, 5/10, 6/10, 7/10, 8/10, 9/10, 1} (takes 1-2 minutes)
146+
147+
148+
-- from this testing, Bfs is faster for all p >= 1/2 (i.e. Bfs is faster in non-sparse situations while normal is faster in sparse graphs)
149+
-- thus if E >= 1/2 * V(V-1)/2 = V(V-1)/4 BfsPathGen is faster
150+
-- so if E >= V(V-1)/4 call Bfs, otherwise pathgen
121151

122-
-- from my testting Bfs is better in non-sparse situations while normal is faster in sparse graphs
123-
-- none of them have propper loop protection (for cyclic graphs) at the moment
124-
---
125152

126153

127154

0 commit comments

Comments
 (0)