HOG2
GraphRefinementEnvironment.cpp
Go to the documentation of this file.
1 /*
2  * GraphRefinementEnvironment.cpp
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 4/15/10.
6  * Copyright 2010 NS Software. All rights reserved.
7  *
8  */
9 
11 
12 //GraphAbstraction *ga;
13 //int planLevel, corridorLevel;
14 // CorridorCheck corridorTable;
15 
17 :GraphEnvironment(ma, ga->GetAbstractGraph(planLevel), gh)
18 {
19  this->planLevel = planLevel;
20  this->ga = ga;
21  corridorLevel = 0;
22  useAbstractGoal = false;
23 }
24 
26 {
27 }
28 
29 //void GraphRefinementEnvironment::SetPlanningLevel(int planLevel)
30 //{
31 //}
32 //
33 //int GraphRefinementEnvironment::GetPlanningLevel()
34 //{
35 //}
36 
37 void GraphRefinementEnvironment::GetSuccessors(const graphState &stateID, std::vector<graphState> &neighbors) const
38 {
39  GraphEnvironment::GetSuccessors(stateID, neighbors);
40  //printf("%d initial successors\n", (int)neighbors.size());
41  if (corridorTable.size() > 0)
42  {
43  for (unsigned int x = 0; x < neighbors.size(); x++)
44  {
45  //graphState parent =
46  //Graph *g = ga->GetAbstractGraph(planLevel);
47  if (corridorTable.find(ga->GetNthParent(g->GetNode(neighbors[x]),
48  corridorLevel)->GetNum()) == corridorTable.end())
49  {
50 // printf("Excluding %d from expansion due to corridor\n", neighbors[x]);
51  neighbors[x] = neighbors.back();
52  neighbors.pop_back();
53  x--;
54  }
55  }
56  }
57  //printf("%d final successors\n", (int)neighbors.size());
58 }
59 
60 void GraphRefinementEnvironment::GetActions(const graphState &stateID, std::vector<graphMove> &actions) const
61 {
62  GraphEnvironment::GetActions(stateID, actions);
63  assert(false);
64 }
65 
66 bool GraphRefinementEnvironment::GoalTest(const graphState &state, const graphState &goal) const
67 {
68  if (useAbstractGoal)
69  {
70  return (ga->GetNthParent(g->GetNode(state), abstractGoalLevel)->GetNum() == goal);
71  }
72  return (state == goal);
73 }
74 
75 void GraphRefinementEnvironment::SetPlanningCorridor(std::vector<graphState> &corridor, int level, int start)
76 {
77  corridorTable.clear();
78  corridorLevel = level;
79  for (unsigned int x = start; x < corridor.size(); x++)
80  corridorTable[corridor[x]] = true;
81 }
82 
83 double GraphRefinementEnvironment::HCost(const graphState &state1, const graphState &state2) const
84 {
85  if (useAbstractGoal)
86  {
87  return ga->h(ga->GetAbstractGraph(planLevel)->GetNode(state1),
89  }
90  if (h)
91  return max(h->HCost(state1, state2), ga->h(ga->GetAbstractGraph(planLevel)->GetNode(state1),
92  ga->GetAbstractGraph(planLevel)->GetNode(state2)));
93  return ga->h(ga->GetAbstractGraph(planLevel)->GetNode(state1),
95 }
GraphAbstraction
A generic class for basic operations on Graph abstractions.
Definition: GraphAbstraction.h:63
GraphRefinementEnvironment::corridorLevel
int corridorLevel
Definition: GraphRefinementEnvironment.h:40
GraphRefinementEnvironment::ga
GraphAbstraction * ga
Definition: GraphRefinementEnvironment.h:38
GraphAbstraction::GetAbstractGraph
Graph * GetAbstractGraph(int level)
return the abstract Graph at the given level
Definition: GraphAbstraction.h:74
graphState
unsigned long graphState
Definition: GraphEnvironment.h:32
GraphRefinementEnvironment::HCost
double HCost(const graphState &state1, const graphState &state2) const
Heuristic value between two arbitrary nodes.
Definition: GraphRefinementEnvironment.cpp:83
GraphRefinementEnvironment::GraphRefinementEnvironment
GraphRefinementEnvironment(GraphAbstraction *ga, int planLevel, GraphHeuristic *gh, Map *m=0)
Definition: GraphRefinementEnvironment.cpp:16
GraphRefinementEnvironment::GetSuccessors
virtual void GetSuccessors(const graphState &stateID, std::vector< graphState > &neighbors) const
Definition: GraphRefinementEnvironment.cpp:37
GraphEnvironment::GetSuccessors
virtual void GetSuccessors(const graphState &stateID, std::vector< graphState > &neighbors) const
Definition: GraphEnvironment.cpp:75
GraphRefinementEnvironment::planLevel
int planLevel
Definition: GraphRefinementEnvironment.h:40
Graph::GetNode
node * GetNode(unsigned long num)
Definition: Graph.cpp:152
GraphRefinementEnvironment.h
GraphEnvironment::g
Graph * g
Definition: GraphEnvironment.h:360
GraphRefinementEnvironment::corridorTable
CorridorCheck corridorTable
Definition: GraphRefinementEnvironment.h:42
GraphAbstraction::h
virtual double h(node *a, node *b)=0
heuristic cost between any two nodes
GraphRefinementEnvironment::GetActions
virtual void GetActions(const graphState &stateID, std::vector< graphMove > &actions) const
Definition: GraphRefinementEnvironment.cpp:60
GraphRefinementEnvironment::~GraphRefinementEnvironment
~GraphRefinementEnvironment()
Definition: GraphRefinementEnvironment.cpp:25
GraphRefinementEnvironment::SetPlanningCorridor
void SetPlanningCorridor(std::vector< graphState > &corridor, int level, int start=0)
Definition: GraphRefinementEnvironment.cpp:75
max
#define max(a, b)
Definition: MinimalSectorAbstraction.cpp:40
GraphRefinementEnvironment::useAbstractGoal
bool useAbstractGoal
Definition: GraphRefinementEnvironment.h:41
GraphEnvironment::h
GraphHeuristic * h
Definition: GraphEnvironment.h:361
node::GetNum
unsigned int GetNum() const
Definition: Graph.h:176
GraphRefinementEnvironment::GoalTest
virtual bool GoalTest(const graphState &state, const graphState &goal) const
Definition: GraphRefinementEnvironment.cpp:66
GraphEnvironment::GetActions
virtual void GetActions(const graphState &stateID, std::vector< graphMove > &actions) const
Definition: GraphEnvironment.cpp:105
GraphHeuristic::HCost
virtual double HCost(const graphState &state1, const graphState &state2) const =0
GraphRefinementEnvironment::abstractGoalLevel
int abstractGoalLevel
Definition: GraphRefinementEnvironment.h:40
GraphEnvironment
Definition: GraphEnvironment.h:291
GraphAbstraction::GetNthParent
node * GetNthParent(node *which, int n)
return nth level parent of which or null if it doesn't exist
Definition: GraphAbstraction.cpp:67
Map
A tile-based representation of the world.
Definition: Map.h:142
GraphHeuristic
Definition: GraphEnvironment.h:77