My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* AnnotatedHierarchicalAStar.cpp
* hog
*
* Created by Daniel Harabor on 7/04/08.
* Copyright 2008 __MyCompanyName__. All rights reserved.
*
*/

#include "AnnotatedHierarchicalAStar.h"
#include "AnnotatedClusterAbstraction.h"

bool AnnotatedHierarchicalAStar::evaluate(node* n, node* target)
{
if(!n || !target)
return false;

/* only evaluate nodes connected by the edge currently being traversed */
edge* e = this->traversing();
if(!e)
return false;

int to = e->getTo();
int from = e->getFrom();
if(n->getNum() != to && n->getNum() != from)
return false;
if(target->getNum() != to && target->getNum() != from)
return false;

int capability = this->getCapability();
int clearance = this->getClearance();

if(e->getClearance(capability) >= clearance)
return true;

return false;
}

/*
Find an abstract path and refine it using the path cache

NB: sometimes we may require a cached path which was obtained by planning in the reverse direction to current requirements
ie. we store the path from n1 -> n2, but we may require the path from n2 -> n1.
In such cases, we specify the id of the node that should be at the head of the path. if the cached path doesn't meet those
requirements, we reverse it.
*/
path* AnnotatedHierarchicalAStar::getPath(graphAbstraction* aMap, node* from, node* to, reservationProvider *rp)
{
AnnotatedClusterAbstraction* aca = dynamic_cast<AnnotatedClusterAbstraction*>(aMap);
assert(aca != 0);

insertNodesExpanded = insertNodesTouched = insertPeakMemory =0;
insertSearchTime = 0;

path* thepath=0;

if(from->getParentCluster() == to->getParentCluster())
{
AnnotatedAStar aastar;
aastar.setGraphAbstraction(aMap);
aastar.setCapability(this->getCapability());
aastar.setClearance(this->getClearance());
aastar.limitSearchToClusterCorridor(true);
thepath = aastar.getPath(aMap, from, to, rp);
this->nodesExpanded += aastar.getNodesExpanded();
this->nodesTouched += aastar.getNodesTouched();
if(this->peakmemory < aastar.getPeakMemory())
this->peakmemory = aastar.getPeakMemory();
this->searchtime += aastar.getSearchTime();
}

if(thepath==0)
{
aca->insertStartAndGoalNodesIntoAbstractGraph(from, to);
graph *absg = aca->getAbstractGraph(1);
node* absstart = absg->getNode(from->getLabelL(kParent));
node* absgoal = absg->getNode(to->getLabelL(kParent));

/* edge_iterator ei = absg->getEdgeIter();
edge* e = absg->edgeIterNext(ei);
while(e)
{
node* f = absg->getNode(e->getFrom());
node* t = absg->getNode(e->getTo());
std::cout << "\n edge connects "<<f->getLabelL(kFirstData)<<","<<f->getLabelL(kFirstData+1)<< " and "<<t->getLabelL(kFirstData)<<","<<t->getLabelL(kFirstData+1);
std::cout <<"(weight: "<<e->getWeight()<<" caps: "<<e->getCapability() << " clearance: "<<e->getClearance(e->getCapability())<<")";
e = absg->edgeIterNext(ei);
}
*/

path* abspath = getAbstractPath(aMap, absstart, absgoal);

if(abspath)
{
// debugging
/* std::cout << "\n abstract path: ";
path* tmpptr = abspath;
while(tmpptr)
{
node* n = tmpptr->n;
std::cout << "\n id: "<<n->getUniqueID()<<" node @ "<<n->getLabelL(kFirstData) << ","<<n->getLabelL(kFirstData+1);
tmpptr = tmpptr->next;
}

*/
AnnotatedAStar aastar;
int capability = this->getCapability();
int clearance = this->getClearance();
path* tail;
path* tmp = abspath;//->next;
while(tmp->next)
{
edge* e = tmp->n->findAnnotatedEdge(tmp->next->n,capability,clearance,MAXINT);
if(e == NULL)
{
std::cout << "\n AHA::getPath -- something went horribly wrong; I couldn't find any cached paths. Search params: ";
std::cout << "from: "<<from->getLabelL(kFirstData)<<","<<from->getLabelL(kFirstData+1);
std::cout << " to: "<<to->getLabelL(kFirstData)<<","<<to->getLabelL(kFirstData+1);
std::cout << " caps: "<<capability<<" clearance: "<<clearance;
exit(-1);
}

// path refinement. enable this and comment out section below to turn off caching (one or the other)
// [refine]
node* llstart = aca->getNodeFromMap(tmp->n->getLabelL(kFirstData), tmp->n->getLabelL(kFirstData+1));
node* llgoal = aca->getNodeFromMap(tmp->next->n->getLabelL(kFirstData), tmp->next->n->getLabelL(kFirstData+1));
aastar.setCapability(this->getCapability());
aastar.setClearance(this->getClearance());
path* cachedpath = aastar.getPath(aMap,llstart, llgoal);
this->nodesExpanded += aastar.getNodesExpanded();
this->nodesTouched += aastar.getNodesTouched();
if(this->peakmemory < aastar.getPeakMemory())
this->peakmemory = aastar.getPeakMemory();
this->searchtime += aastar.getSearchTime();
// [/refine]

/* // [cache]
path* cachedpath = aca->getPathFromCache(e)->clone();
if(e->getFrom() != tmp->n->getNum()) // fix segments if necessary
cachedpath = cachedpath->reverse();
// [/cache]
*/
if(thepath == 0)
thepath = cachedpath;
tail = thepath->tail();

/* // debugging
node* n1 = absg->getNode(e->getFrom());
node* n2 = absg->getNode(e->getTo());
std::cout << "\n expanding abstract edge between nodes: "<<n1->getUniqueID()<<" and "<<n2->getUniqueID();
path* meh = cachedpath;
std::cout << "\n expanding cached path: ";
while(meh)
{
std::cout << "\n id: "<<meh->n->getUniqueID()<<" node @ "<<meh->n->getLabelL(kFirstData) << ","<<meh->n->getLabelL(kFirstData+1);
meh = meh->next;
}
*/

if(tail->n->getNum() == cachedpath->n->getNum()) // avoid overlap where the cached path segments overlap (one ends where another begins)
tail->next = cachedpath->next;

tmp = tmp->next;
}
}
insertNodesExpanded = aca->getNodesExpanded();
insertNodesTouched = aca->getNodesTouched();
insertPeakMemory = aca->getPeakMemory();
insertSearchTime = aca->getSearchTime();

aca->removeStartAndGoalNodesFromAbstractGraph();
delete abspath;
}

this->nodesExpanded += insertNodesExpanded;
this->nodesTouched += insertNodesTouched;
this->searchtime += insertSearchTime;

if(this->peakmemory < insertPeakMemory)
this->peakmemory = insertPeakMemory;

//std::cout << "\n thepath distance: "<<aMap->distance(thepath);
return thepath;
}

void AnnotatedHierarchicalAStar::logFinalStats(statCollection* stats)
{
AnnotatedAStar::logFinalStats(stats);

stats->addStat("insNodesExpanded",getName(),getInsertNodesExpanded());
stats->addStat("insNodesTouched",getName(),getInsertNodesTouched());
stats->addStat("insPeakMemory",getName(),getInsertPeakMemory());
stats->addStat("insSearchTime",getName(),getInsertSearchTime());
}
Show details Hide details

Change log

r194 by dharabor on Jul 30, 2008   Diff
KEPS release
Go to: 
Project members, sign in to write a code review

Older revisions

r136 by dharabor on Jun 04, 2008   Diff
Added new results for improved low-
quality abstraction.
Fixed some wrongly commented out code
in AHA required for refinement.
Updated scripts to produce refinement
...
r135 by dharabor on Jun 03, 2008   Diff
enable caching by default
r130 by dharabor on May 29, 2008   Diff
Refactored: moved findAnnotatedEdge
from graph to node class (where it
makes more sense since we only use it
to find nodes between immediate
neighbours)
All revisions of this file

File info

Size: 6662 bytes, 194 lines
Hosted by Google Code