37 :MapAbstraction(_m), abstractUniformly(uniform)
40 #ifdef INSTRUMENT_REPAIR
42 hit.resize(abstractions.size());
53 cout <<
"VERIFY START" << endl;
54 for (
unsigned int x = 0; x < abstractions.size(); x++)
57 abstractions[x]->verifyGraph();
60 for (
node *n = abstractions[x]->nodeIterNext(ni); n; n = abstractions[x]->nodeIterNext(ni))
63 if (n->GetLabelL(
kParent) != -1)
65 Graph *g = abstractions[x+1];
71 { found =
true;
break; }
75 cout <<
"VERIFY: Graph doesn't verify; child:" << endl << *n << endl;
76 cout <<
"VERIFY: Graph doesn't verify; parent:" << endl << *parent << endl;
81 Graph *g = abstractions[x-1];
87 cout <<
"VERIFY: Graph doesn't verify; CHILD is null, parent:" << endl << *n << endl;
91 cout <<
"VERIFY: Graph doesn't verify; parent:" << endl << *n << endl;
92 cout <<
"VERIFY: Graph doesn't verify; child:" << endl << *child << endl;
98 cout <<
"VERIFY: Level 0 node listed as having more than 1 child!" << endl;
100 GetTileFromNode(n, x1, y1);
101 if (n != GetNodeFromMap(x1, y1))
102 cout <<
"VERIFY: node doesn't correspond to underlying map" << endl << *n << endl;
107 for (
edge *e = abstractions[x]->edgeIterNext(ei); e; e = abstractions[x]->edgeIterNext(ei))
114 if ((p1 == 0) || (p2 == 0))
116 cout <<
"VERIFY: One edge parent is null, and the other isn't " << *e << endl << *p1 << endl << *p2 << endl;
119 if (!abstractions[x+1]->FindEdge(p1->
GetNum(), p2->
GetNum()))
121 cout <<
"Didn't find parent edge of " << *e <<
" at abslevel " << x << endl;
122 cout << *p1 << endl << *p2 << endl;
124 p1 = abstractions[x]->GetNode(e->getFrom());
125 p2 = abstractions[x]->GetNode(e->getTo());
127 if (!
fequal(e->GetWeight(), h(p1, p2)))
129 cout <<
"VERIFY: Edge weight doesn't match heuristic cost. Level: " << x << endl;
130 cout << *p1 << endl << *p2 << endl << *e << endl;
139 cout <<
"weight: " << e->GetWeight() <<
" heuristic " << h(p1, p2) << endl;
142 cout <<
"VERIFY: Edge capacity is 0?!? " << e << endl;
147 p1 = abstractions[x]->GetNode(e->getFrom());
148 p2 = abstractions[x]->GetNode(e->getTo());
162 cout <<
"VERIFY: Edge capactiy of " << *e <<
" is "
164 <<
" edges below that abstract into it." << endl;
169 cout <<
"VERIFY END" << endl;
194 Graph *g = abstractions[0];
199 printf(
"Base Graph (0) has %d nodes\n", g->
GetNumNodes());
201 for (
int x = 1; ; x++)
281 if (e->getFrom() == n->
GetNum())
301 std::vector<node *> remainingNodes;
309 for (
int x = 0; x < GetMap()->GetMapWidth()-1; x+=(2<<abLevel))
311 for (
int y = 0; y < GetMap()->GetMapHeight()-1; y+=(2<<abLevel))
315 a = GetNthParent(GetNodeFromMap(x, y), abLevel);
317 b = GetNthParent(GetNodeFromMap(x+(1<<abLevel), y), abLevel);
319 c = GetNthParent(GetNodeFromMap(x, y+(1<<abLevel)), abLevel);
321 d = GetNthParent(GetNodeFromMap(x+(1<<abLevel), y+(1<<abLevel)), abLevel);
328 int nnum = aGraph->
AddNode(newNode =
new node(
"4c"));
377 if (n->GetLabelL(
kParent) != -1)
continue;
378 int numEdges = n->GetNumEdges();
395 remainingNodes.push_back(n);
399 std::vector<int>
neighbor(numEdges);
402 for (
int x = 0; x < numEdges; x++)
404 e = n->edgeIterNext(ei);
407 cout <<
"That's impossible; we were told we had "
408 << numEdges <<
":(" << n->getNumOutgoingEdges()
409 <<
"+" << n->getNumIncomingEdges()
410 <<
") edges, we're on #" << x <<
" and we got nil!"
420 for (
int x = 0; x < numEdges-2; x++)
423 for (
int y = x+1; y < numEdges-1; y++)
426 for (
int z = y+1; z < numEdges; z++)
439 int nnum = aGraph->
AddNode(newNode =
new node(
"4c"));
463 if (n->GetLabelL(
kParent) == -1)
465 for (
int x = 0; x < numEdges-1; x++)
468 for (
int y = x+1; y < numEdges; y++)
477 int nnum = aGraph->
AddNode(newNode =
new node(
"3c"));
522 if (n->GetLabelL(
kParent) == -1) remainingNodes.push_back(n);
525 while (remainingNodes.size() > 0)
527 node *orphan = (
node*)remainingNodes.back();
529 remainingNodes.pop_back();
532 if (numEdges == 0)
continue;
537 int neighbor = (e->getFrom() == orphan->
GetNum())?e->getTo():e->getFrom();
560 int neighbor = (e->getFrom() == orphan->
GetNum())?e->getTo():e->getFrom();
616 if ((from != to) && (!(f = aGraph->
FindEdge(to, from))))
623 f =
new edge(from, to, weight);
627 printf(
"Adding edge from %d (%d) to %d (%d) weight %1.2f\n", from, e->getFrom(), to, e->getTo(), weight);
946 return Pathable(abstractions[0]->GetNode(from), abstractions[0]->GetNode(to));
954 if ((!from) || (!to) ||
963 if ((from == 0) || (to == 0))
988 abstractions[absLevel]->RemoveEdge(e);
994 if (absLevel+1 < abstractions.size())
996 node *pNode = abstractions[absLevel+1]->GetNode(abstractions[absLevel]->GetNode(e->
getFrom())->GetLabelL(
kParent));
1001 abstractions[absLevel]->RemoveEdge(e);
1018 cout <<
"REM: Adding " << *n <<
" to modified queue" << endl;
1041 cout <<
"REM: Removing " << *n << endl;
1052 #ifdef INSTRUMENT_REPAIR
1053 hit[absLevel+1] += 1;
1055 if (!pNode)
continue;
1078 printf(
"Removing parent!\n");
1098 node *changed = abstractions[absLevel]->RemoveNode(n, oldID);
1099 #ifdef INSTRUMENT_REPAIR
1130 cout <<
"REM: Choosing to repair: " << *changed << endl;
1135 cout <<
"REM: We got " << count <<
" groups out of " << *changed << endl;
1148 std::vector<node *> seenStack;
1153 Graph *g = abstractions[absLevel-1];
1154 #ifdef INSTRUMENT_REPAIR
1155 hit[absLevel-1] += 1;
1174 cout << *nextChild <<
" now assigned to group " << currGroup << endl;
1176 if (seenStack.size() > 0)
1178 nextChild = seenStack.back();
1179 seenStack.pop_back();
1185 (e->getTo()):(e->getFrom());
1191 cout << *g->
GetNode(
neighbor) <<
" now added to group " << currGroup << endl;
1195 }
while (seenStack.size() > 0);
1207 std::vector<node *> children;
1213 #ifdef INSTRUMENT_REPAIR
1223 cout <<
"REM: parent has no neighbors, just splitting and ending" << endl;
1224 for (
int x = 1; x < numGroups; x++)
1229 std::vector<int> groupSize(numGroups);
1230 for (
int x = 0; x < numGroups; x++) groupSize[x] =
getGroupSize(parent, x);
1236 for (
int x = 0; x < numGroups; x++)
1238 if (reassigned == numGroups-1)
1240 if (groupSize[x] == 1)
1246 cout <<
"REM: Reassigning group " << reassigned <<
" by splitting off group " << x << endl;
1253 cout <<
"REM: Reassigning group " << reassigned <<
" by (neighbor) merging group " << x << endl;
1262 cout <<
"REM: Reassigning group " << reassigned <<
" by (neighbor) merging " << x << endl;
1267 cout <<
"REM: Reassigning group " << reassigned <<
" by extraction " << x << endl;
1278 for (
int x = 0; x < numGroups; x++)
1280 if (reassigned == numGroups-1)
1285 cout <<
"REM: Reassigning (big) group " << reassigned <<
" by extracting " << x << endl;
1298 #ifdef INSTRUMENT_REPAIR
1317 #ifdef INSTRUMENT_REPAIR
1339 #ifdef INSTRUMENT_REPAIR
1363 #ifdef INSTRUMENT_REPAIR
1369 node *nextNode = g->
GetNode((e->getFrom() == child->
GetNum())?(e->getTo()):(e->getFrom()));
1384 #ifdef INSTRUMENT_REPAIR
1387 if (neighborParent == 0)
1390 #ifdef INSTRUMENT_REPAIR
1406 if (matches)
return true;
1421 #ifdef INSTRUMENT_REPAIR
1441 cout <<
"Merging group " << group <<
" into " << *
neighbor << endl;
1443 #ifdef INSTRUMENT_REPAIR
1448 cout <<
"(Child of " << *newParent <<
")" << endl;
1452 printf(
"GOTTA HANDLE THE NO PARENT CASE IN mergeGroupIntoNeighbor --- but logic says we shouldn't hit this unless we add edges\n");
1455 if (newParent == parent)
1457 printf(
"HOW DID THAT HAPPEN? oldParent = newParent\n");
1474 #ifdef INSTRUMENT_REPAIR
1504 #ifdef INSTRUMENT_REPAIR
1511 #ifdef INSTRUMENT_REPAIR
1522 printf(
"Collapsing node into neighbor: ");
1523 printf(
"New parent (%d) now has %ld abstracted nodes\n", newParent->
GetNum(),
1532 #ifdef INSTRUMENT_REPAIR
1542 printf(
"Cliquing node into neighbor: ");
1543 printf(
"New parent (%d) now has %ld abstracted nodes\n", parent->
GetNum(),
1556 cout <<
"We stay lonely: " << *newNode << endl;
1566 Graph *g = abstractions[absLevel+1];
1567 #ifdef INSTRUMENT_REPAIR
1568 hit[absLevel+1] += 1;
1583 if (absLevel+1 == abstractions.size())
1585 abstractions.push_back(
new Graph());
1586 #ifdef INSTRUMENT_REPAIR
1591 unsigned int id = abstractions[absLevel+1]->AddNode(parent =
new node(
"created"));
1592 #ifdef INSTRUMENT_REPAIR
1593 hit[absLevel+1] += 1;
1609 std::vector<node *> groupies;
1615 #ifdef INSTRUMENT_REPAIR
1623 groupies.push_back(nextNode);
1658 for (
unsigned int x = 0; x < groupies.size(); x++)
1660 node *which = groupies[x];
1666 cout <<
"Group member: " << *which <<
" has edge " << *e <<
" which we want to abstract up" << endl;
1685 Graph *g = abstractions[absLevel];
1686 Graph *pg = abstractions[absLevel+1];
1687 #ifdef INSTRUMENT_REPAIR
1689 hit[absLevel+1] += 1;
1700 " edge(s), but no parent: " << endl << *g->
GetNode(e->
getFrom()) << endl;
1707 " edge(s), but no parent: " << endl << *g->
GetNode(e->
getTo()) << endl;
1718 pg->
AddEdge(pe =
new edge(par1, par2, edgeWeight));
1721 cout <<
"*** Abstracting " << *e <<
" with edge " << *pe << endl;
1742 p1 = g->
GetNode(e->getFrom());
1744 double edgeWeight = h(p1, p2);
1745 e->setWeight(edgeWeight);
1752 n = abstractions[absLevel]->GetNode(parent);
1762 if (absLevel < abstractions.size()-1)
1764 #ifdef INSTRUMENT_REPAIR
1765 hit[absLevel+1] += 1;
1778 if (absLevel >= abstractions.size()-1)
return 0;
1780 Graph *g = abstractions[absLevel];
1781 #ifdef INSTRUMENT_REPAIR
1783 hit[absLevel+1] += 1;
1789 g = abstractions[absLevel+1];
1793 if (from == to)
return 0;
1811 #ifdef INSTRUMENT_REPAIR
1812 hit[absLevel-1] += 1;
1818 if (absLevel < abstractions.size()-1)
1821 #ifdef INSTRUMENT_REPAIR
1822 hit[absLevel+1] += 1;
1845 #ifdef INSTRUMENT_REPAIR
1846 for (
unsigned int x = 0; x < hit.size(); x++)
1850 printf(
"Level %d hit %d times\n", x, hit[x]);
1853 hit.resize(abstractions.size());