|
| 1 | +needsPackage "Probability" |
1 | 2 | needsPackage "GraphicalModels" |
2 | 3 |
|
3 | 4 |
|
@@ -112,16 +113,42 @@ BfsPathGen = (G, V) -> ( |
112 | 113 | return pathtable |
113 | 114 | ) |
114 | 115 |
|
115 | | ---- |
116 | 116 | -- 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}}} |
117 | 117 |
|
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 |
121 | 151 |
|
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 | | ---- |
125 | 152 |
|
126 | 153 |
|
127 | 154 |
|
|
0 commit comments