Go to the documentation of this file.
27 #ifndef ABSTRACTWEIGHTEDSEARCHALGORITHM_H
28 #define ABSTRACTWEIGHTEDSEARCHALGORITHM_H
109 return (state == goal);
123 if (nParent == goalParent)
141 return h->
HCost(state1,state2);
151 regenv->GetMapAbstraction()->GetTileUnderLoc(parx,pary,
regenv->GetMapAbstraction()->GetNodeLoc(par));
161 return sqrt(pow(st1.
x-parx,2) + pow(st1.
y-pary,2));
236 fprintf(stderr,
"ERROR: Single State HCost not implemented for AbsGraphEnvironment\n");
237 exit(1);
return -1.0;}
240 fprintf(stderr,
"ERROR: Single State Goal Test not implemented for AbsGraphEnvironment\n");
241 exit(1);
return false;}
284 return sqrt(pow(x1-x2,2) + pow(y1-y2,2));
304 double a = ((x1>x2)?(x1-x2):(x2-x1));
305 double b = ((y1>y2)?(y1-y2):(y2-y1));
319 template <
class state,
class action,
class environment>
326 bool InitializeSearch(environment *env,
const state& from,
const state& to, std::vector<state> &thePath);
327 virtual void GetPath(environment *env,
const state& from,
const state& to, std::vector<state> &thePath);
328 virtual void GetPath(environment *,
const state &,
const state &, std::vector<action> &) {}
329 virtual const char *
GetName() {
return "AbstractWeightedSearchAlgorihm";}
354 template<
class state,
class action,
class environment>
360 template<
class state,
class action,
class environment>
366 template<
class state,
class action,
class environment>
374 template<
class state,
class action,
class environment>
382 InitializeSearch(theEnv, from, to, thePath);
386 MapAbstraction* ma = theEnv->GetMapAbstraction();
387 Graph *abs = ma->GetAbstractGraph(1);
388 Graph *g = ma->GetAbstractGraph(0);
391 node* fromnode = ma->GetNodeFromMap(from.x, from.y);
396 node* tonode = theEnv->GetMapAbstraction()->GetNodeFromMap(to.x,to.y);
401 if (fromPar == toPar)
405 std::vector<graphState> refpath;
414 astar.
GetPath(graphenv,fromGs,toGs,refpath);
421 for (
unsigned int j=0; j<refpath.size(); j++)
427 thePath.push_back(newloc);
442 std::vector<graphState> abspath;
450 astar.DoAbstractSearch();
451 astar.
GetPath(graphenv,fromPar,toPar,abspath);
480 astar2.SetRadiusEnvironment(agebla);
484 std::vector<graphState> refpath;
485 assert(abspath.size() != 0);
491 thePath.push_back(nl);
499 if (abspath.size()==2)
504 std::vector<graphState> refPath;
513 AStar.
GetPath(graphEnv,fromGs,toGs,refPath);
519 for (
unsigned int j=1; j<refPath.size(); j++)
525 thePath.push_back(newloc);
547 astar2.
GetPath(age,start,end,refpath);
551 if (refpath.size()>0)
553 for (
unsigned int j=1; j<refpath.size(); j++)
560 thePath.push_back(newloc);
591 int desiredLength = (int)(refinePart * thePath.size());
594 thePath.resize(desiredLength);
621 for (
unsigned int i=1; i<abspath.size()-1; i++)
625 std::vector<graphState> nb;
629 for (
unsigned int k=0; k<nb.size(); k++)
667 astar2.
GetPath(age,start,end,refpath);
675 if (refpath.size()>0)
677 for (
unsigned int j=1; j<refpath.size(); j++)
685 thePath.push_back(newloc);
689 start = refpath[refpath.size()-1];
705 astar3.
GetPath(absgraphenv2,start,toGs,refpath);
711 for (
unsigned int j=1; j<refpath.size(); j++)
718 thePath.push_back(newloc);
void SetWeightedEnvironment(WeightedMap2DEnvironment *w)
Set the weighted environment This must be set for the algorithm to work.
GraphOccupancyInterface * GetOccupancyInfo()
GraphStraightLineHeuristic(Map *map, Graph *graph, Graph *mg)
virtual void SetStateOccupied(const graphState &gs, bool b)
bool GoalTest(const graphState &)
virtual bool CanMove(const graphState &gs1, const graphState &gs2)
GraphOccupancyInterface * goi
virtual double GCost(const xyLoc &node1, const xyLoc &node2) const
virtual bool GetStateOccupied(const xyLoc &)
Returns the occupancy of a state.
double HCost(const graphState &state1, const graphState &state2) const
bool InitializeSearch(environment *env, const state &from, const state &to, std::vector< state > &thePath)
uint64_t GetNodesExpanded() const
virtual void LogFinalStats(StatCollection *)
void Print(graphState &s)
A search algorithm which combines direction maps with abstraction.
void SetWeightedEnvironment(WeightedMap2DEnvironment *w)
WeightedMap2DEnvironment * wenv
bool GoalTest(const graphState &state, const graphState &goal)
If exactGoal is set, GoalTest returns true when state is the same as goal.
double HCost(const graphState &state1, const graphState &state2) const
Heuristic value between two arbitrary nodes.
virtual void GetSuccessors(const graphState &stateID, std::vector< graphState > &neighbors) const
Occupancy interface which works with graphState and graphMove A wrapper to use with an exisitng BaseM...
virtual void MoveUnitOccupancy(const xyLoc &, const xyLoc &)
Updates the occupancy interface when a unit moves.
long CalculateIndex(uint16_t x, uint16_t y)
WeightedMap2DEnvironment * wenv
GraphOccupancyInterface(BaseMapOccupancyInterface *b, Graph *_g)
virtual void GetPath(environment *, const state &, const state &, std::vector< action > &)
xyLoc Convert(const graphState &gs)
virtual const char * GetName()
node * GetNode(unsigned long num)
double HCost(const graphState &state1, const graphState &state2) const
void GetPath(environment *env, const state &from, const state &to, std::vector< state > &thePath)
Perform an A* search between two states.
virtual void StoreGoal(graphState &)
Stores the goal for use by single-state HCost.
virtual ~AbstractWeightedSearchAlgorithm()
AbsGraphEnvironment(Graph *_g, GraphHeuristic *gh, AbsMapEnvironment *me, BaseMapOccupancyInterface *bmoi)
virtual void MoveUnitOccupancy(const graphState &gs1, const graphState &gs2)
uint64_t GetNodesTouched() const
static const double ROOT_TWO
A templated version of A*, based on HOG genericAStar.
virtual bool GetStateOccupied(const graphState &gs)
virtual double HCost(const graphState &) const
Heuristic value between node and the stored goal.
AbstractWeightedSearchAlgorithm()
void SetSkipAbsNode(double pathPerc)
Set skip abstract nodes, and partial path refinement If set to 'true', the algorithm plans to the one...
OctileHeuristic(Map *map, Graph *graph)
A graph environment to use with the a graph abstraction.
virtual double GCost(const graphState &state1, const graphMove &state2)
void SetNoDummyGoal(bool b)
void SetAbsGraph(Graph *_g)
The StatCollection class is for collecting stats across different parts of the simulation.
AbsMapEnvironment * regenv
virtual bool IsGoalStored() const
virtual uint64_t GetNodesTouched() const
unsigned int GetNum() const
virtual void SetStateOccupied(const xyLoc &, bool)
Sets the occupancy of a state.
double GCost(const graphState &state1, const graphState &state2)
GCost returns a weighted GCost from the WeightedMap2DEnvironment.
virtual uint64_t GetNodesExpanded() const
long GetLabelL(unsigned int index) const
virtual double HCost(const graphState &state1, const graphState &state2) const =0
virtual void ClearGoal()
Clears the goal from memory.
void SetFindExactGoal(bool b)
Set to true when we want to find the exact goal rather than any child of the parent of the goal.
BaseMapOccupancyInterface * boi
virtual ~GraphOccupancyInterface()
Nodes to be stored within a Graph.
A tile-based representation of the world.
virtual void GetPath(environment *env, const state &from, const state &to, std::vector< state > &thePath)
virtual bool CanMove(const xyLoc &, const xyLoc &)