77 return sqrt(d1*d1+d2*d2+d3*d3);
91 glDisable(GL_LIGHTING);
98 glEnable(GL_LIGHTING);
116 if (e->GetLabelL(
kEdgeCapacity) == 0) glColor4f(.5, .5, .5, 1);
117 else if (e->GetLabelL(
kEdgeCapacity) <= 0) glColor4f(.2, .2, .2, 1);
118 else if (e->getMarked()) glColor4f(1, 1, 1, 1);
120 glColor4f(1-((GLfloat)(abLevel%15)/15.0), ((GLfloat)(abLevel%15)/15.0), 0, 1);
121 else glColor4f(((GLfloat)(abLevel%15)/15.0), 1-((GLfloat)(abLevel%15)/15.0), 0, 1);
123 glVertex3f(rv.
x, rv.
y, rv.
z);
128 glVertex3f(rv.
x, rv.
y, rv.
z);
146 glColor4f(.6, .6, .6, .6);
151 glVertex3f(v.
x, v.
y, v.
z);
152 glVertex3f(v1.
x, v1.
y, v1.
z);
172 ans.
x = ans.
y = ans.
z = 0;
180 ans.
x += weight*tmp.
x;
181 ans.
y += weight*tmp.
y;
182 ans.
z += weight*tmp.
z;
197 FILE *f = fopen(fname,
"r");
200 printf(
"Error opening %s for loading\n", fname);
204 std::vector<unsigned int> IDS;
207 fgets(nextLine, 255, f);
210 sscanf(nextLine,
"VERSION %lf", &version);
213 printf(
"Got %lf; code can only handle version 1.0\n", version);
217 while ((!feof(f)) && fgets(nextLine, 255, f))
219 if (nextLine[0] ==
'#')
221 if (strncmp(
"edges", nextLine, 5) == 0)
231 sscanf(nextLine,
"%d %lf %lf %lf", &ID, &x, &y, &z);
233 if (IDS.size() <= (
unsigned int)ID)
247 sscanf(nextLine,
"%d %d", &ID1, &ID2);
257 cout <<
"VERIFY START" << endl;
267 if (n->GetLabelL(
kParent) != -1)
275 { found =
true;
break; }
279 cout <<
"VERIFY: Graph doesn't verify; child:" << endl << *n << endl;
280 cout <<
"VERIFY: Graph doesn't verify; parent:" << endl << *parent << endl;
291 cout <<
"VERIFY: Graph doesn't verify; CHILD is null, parent:" << endl << *n << endl;
295 cout <<
"VERIFY: Graph doesn't verify; parent:" << endl << *n << endl;
296 cout <<
"VERIFY: Graph doesn't verify; child:" << endl << *child << endl;
316 if ((p1 == 0) || (p2 == 0))
318 cout <<
"VERIFY: One edge parent is null, and the other isn't " << *e << endl << *p1 << endl << *p2 << endl;
323 cout <<
"Didn't find parent edge of " << *e <<
" at abslevel " << x << endl;
324 cout << *p1 << endl << *p2 << endl;
329 if (!
fequal(e->GetWeight(),
h(p1, p2)))
331 cout <<
"VERIFY: Edge weight doesn't match heuristic cost. Level: " << x << endl;
332 cout << *p1 << endl << *p2 << endl << *e << endl;
341 cout <<
"weight: " << e->GetWeight() <<
" heuristic " <<
h(p1, p2) << endl;
345 cout <<
"VERIFY: Edge capacity is 0?!? " << e << endl;
365 cout <<
"VERIFY: Edge capactiy of " << *e <<
" is "
366 << e->GetLabelL(
kEdgeCapacity) <<
" but we only found " << count
367 <<
" edges below that abstract into it." << endl;
372 cout <<
"VERIFY END" << endl;
405 printf(
"Base Graph (0) has %d nodes\n", g->
GetNumNodes());
408 for (
int x = 1; ; x++)
416 printf(
"Abstract Graph #%2d has %d nodes\n", x, g->
GetNumNodes());
432 std::vector<node *> remainingNodes;
441 if (n->GetLabelL(
kParent) != -1)
continue;
442 newNode =
new node(
"");
461 if ((from != to) && (!(f = aGraph->
FindEdge(to, from))))
464 f =
new edge(from, to, weight);
492 if (e->getFrom() == n->
GetNum())
512 std::vector<node *> remainingNodes;
520 if (n->GetLabelL(
kParent) != -1)
continue;
521 int numEdges = n->GetNumEdges();
526 remainingNodes.push_back(n);
530 std::vector<int>
neighbor(numEdges);
533 for (
int x = 0; x < numEdges; x++)
535 e = n->edgeIterNext(ei);
538 cout <<
"That's impossible; we were told we had "
539 << numEdges <<
":(" << n->getNumOutgoingEdges()
540 <<
"+" << n->getNumIncomingEdges()
541 <<
") edges, we're on #" << x <<
" and we got nil!"
551 for (
int x = 0; x < numEdges-2; x++)
554 for (
int y = x+1; y < numEdges-1; y++)
557 for (
int z = y+1; z < numEdges; z++)
570 int nnum = aGraph->
AddNode(newNode =
new node(
"4c"));
594 if (n->GetLabelL(
kParent) == -1)
596 for (
int x = 0; x < numEdges-1; x++)
599 for (
int y = x+1; y < numEdges; y++)
608 int nnum = aGraph->
AddNode(newNode =
new node(
"3c"));
653 if (n->GetLabelL(
kParent) == -1) remainingNodes.push_back(n);
656 while (remainingNodes.size() > 0)
658 node *orphan = (
node*)remainingNodes.back();
660 remainingNodes.pop_back();
663 if (numEdges == 0)
continue;
668 int neighbor = (e->getFrom() == orphan->
GetNum())?e->getTo():e->getFrom();
691 int neighbor = (e->getFrom() == orphan->
GetNum())?e->getTo():e->getFrom();
722 if ((from != to) && (!(f = aGraph->
FindEdge(to, from))))
729 f =
new edge(from, to, weight);
733 printf(
"Adding edge from %d (%d) to %d (%d) weight %1.2f\n", from, e->getFrom(), to, e->getTo(), weight);
1060 if ((!from) || (!to) ||
1069 if ((from == 0) || (to == 0))
1150 cout <<
"REM: Adding " << *n <<
" to modified queue" << endl;
1173 cout <<
"REM: Removing " << *n << endl;
1184 if (!pNode)
continue;
1207 printf(
"Removing parent!\n");
1256 cout <<
"REM: Choosing to repair: " << *changed << endl;
1261 cout <<
"REM: We got " << count <<
" groups out of " << *changed << endl;
1274 std::vector<node *> seenStack;
1296 cout << *nextChild <<
" now assigned to group " << currGroup << endl;
1298 if (seenStack.size() > 0)
1300 nextChild = seenStack.back();
1301 seenStack.pop_back();
1307 (e->getTo()):(e->getFrom());
1313 cout << *g->
GetNode(
neighbor) <<
" now added to group " << currGroup << endl;
1317 }
while (seenStack.size() > 0);
1329 std::vector<node *> children;
1342 cout <<
"REM: parent has no neighbors, just splitting and ending" << endl;
1343 for (
int x = 1; x < numGroups; x++)
1348 std::vector<int> groupSize(numGroups);
1349 for (
int x = 0; x < numGroups; x++) groupSize[x] =
getGroupSize(parent, x);
1355 for (
int x = 0; x < numGroups; x++)
1357 if (reassigned == numGroups-1)
1359 if (groupSize[x] == 1)
1365 cout <<
"REM: Reassigning group " << reassigned <<
" by splitting off group " << x << endl;
1372 cout <<
"REM: Reassigning group " << reassigned <<
" by (neighbor) merging group " << x << endl;
1381 cout <<
"REM: Reassigning group " << reassigned <<
" by (neighbor) merging " << x << endl;
1386 cout <<
"REM: Reassigning group " << reassigned <<
" by extraction " << x << endl;
1397 for (
int x = 0; x < numGroups; x++)
1399 if (reassigned == numGroups-1)
1404 cout <<
"REM: Reassigning (big) group " << reassigned <<
" by extracting " << x << endl;
1476 node *nextNode = g->
GetNode((e->getFrom() == child->
GetNum())?(e->getTo()):(e->getFrom()));
1491 if (neighborParent == 0)
1506 if (matches)
return true;
1538 cout <<
"Merging group " << group <<
" into " << *
neighbor << endl;
1542 cout <<
"(Child of " << *newParent <<
")" << endl;
1546 printf(
"GOTTA HANDLE THE NO PARENT CASE IN mergeGroupIntoNeighbor --- but logic says we shouldn't hit this unless we add edges\n");
1549 if (newParent == parent)
1551 printf(
"HOW DID THAT HAPPEN? oldParent = newParent\n");
1606 printf(
"Collapsing node into neighbor: ");
1607 printf(
"New parent (%d) now has %ld abstracted nodes\n", newParent->
GetNum(),
1623 printf(
"Cliquing node into neighbor: ");
1624 printf(
"New parent (%d) now has %ld abstracted nodes\n", parent->
GetNum(),
1637 cout <<
"We stay lonely: " << *newNode << endl;
1666 unsigned int id =
abstractions[absLevel+1]->AddNode(parent =
new node(
"created"));
1681 std::vector<node *> groupies;
1692 groupies.push_back(nextNode);
1727 for (
unsigned int x = 0; x < groupies.size(); x++)
1729 node *which = groupies[x];
1735 cout <<
"Group member: " << *which <<
" has edge " << *e <<
" which we want to abstract up" << endl;
1765 " edge(s), but no parent: " << endl << *g->
GetNode(e->
getFrom()) << endl;
1772 " edge(s), but no parent: " << endl << *g->
GetNode(e->
getTo()) << endl;
1785 cout <<
"*** Abstracting " << *e <<
" with edge " << *pe << endl;
1829 if (from == to)
return 0;