32 while (abstractions.size() > 0)
34 delete abstractions.back();
35 abstractions.pop_back();
40 std::vector<node *> &fromChain,
41 std::vector<node *> &toChain)
49 fromChain.push_back(from);
50 toChain.push_back(to);
59 printf(
"GetNumAbstractGraphs: Moving to nodes #%d and %d\n",
62 fromChain.push_back(from);
63 toChain.push_back(to);
72 Graph *g = abstractions[nextLevel];
80 if (GetAbstractionLevel(child) > GetAbstractionLevel(parent))
82 while (GetAbstractionLevel(child) < GetAbstractionLevel(parent))
84 child = GetParent(child);
86 return (parent == child);
91 for (
unsigned int x = 0; x < abstractions.size(); x++)
93 Graph *g = abstractions[x];
104 if ((p == 0) || (p->
next == 0) || (p->
n == 0) || (p->
next->
n == 0))
111 assert((level > 0) && (level < (
int)abstractions.size()));
112 Graph *g = abstractions[level];
122 cs.push_back(ComputeWidth(nd));
130 for (
unsigned int x = 0; x < ns.size(); x++)
132 n_dev += (ns[x]-n)*(ns[x]-n);
133 c_dev += (cs[x]-c)*(cs[x]-c);
137 n_dev = sqrtf(n_dev);
138 c_dev = sqrtf(c_dev);
154 std::vector<int> depth;
155 std::vector<node *> q;
156 Graph *g = GetAbstractGraph(child);
162 for (
unsigned int x = 0; x < q.size(); x++)
166 for (
int next = q[x]->nodeNeighborNext(ni); next != -1; next = q[x]->nodeNeighborNext(ni))
179 depth.push_back(depth[x]+1);
188 if ((level > (
int)abstractions.size()) || (level <= 0))
190 Graph *g = abstractions[level];
192 std::vector<double> widths;
198 double val = MeasureExpectedNodeWidth(nd);
202 widths.push_back(val);
207 if (widths.size() > 0)
208 return sum/widths.size();
215 std::vector<std::vector<int> > edgeInfo;
217 std::vector<int> sums;
218 std::vector<double> value;
223 double expectedWidth = 0;
224 int totalExternalEdges = 0;
227 node *c = GetNthChild(n, child);
228 CountEdgesAtDistance(c, n, edgeInfo[child]);
230 for (
unsigned int x = 0; x < edgeInfo[child].size(); x++)
232 sums.back() += edgeInfo[child][x];
244 if ((edgeInfo[child][0] != 0) && sums[child] > 1)
246 totalExternalEdges += edgeInfo[child][0];
247 for (
unsigned int x = 0; x < edgeInfo[child].size(); x++)
249 if (edgeInfo[child][x] > 0)
252 dist += (edgeInfo[child][x]-1.0)*(x+1);
254 dist += (edgeInfo[child][x])*(x+1);
257 dist /= (sums[child]-1);
263 if (totalExternalEdges != 0)
267 expectedWidth += (value[child]*edgeInfo[child][0])/(
double)totalExternalEdges;
271 return expectedWidth;
279 Graph *g = GetAbstractGraph(n);
283 if (GetParent(nb) != p)
295 std::vector<unsigned int> depth;
296 std::vector<node *> q;
297 Graph *g = GetAbstractGraph(child);
303 for (
unsigned int x = 0; x < q.size(); x++)
307 if (depth[x]+1 > dists.size())
308 dists.resize(depth[x]+1);
309 dists[depth[x]] += GetNumExternalEdges(q[x], parent);
311 for (
int next = q[x]->nodeNeighborNext(ni); next != -1; next = q[x]->nodeNeighborNext(ni))
324 depth.push_back(depth[x]+1);
333 while (GetAbstractionLevel(n) != 0)
334 n = GetNthChild(n, random()%GetNumChildren(n));