Go to the documentation of this file.
9 #ifndef hog2_glut_MPLRTAStar_h
10 #define hog2_glut_MPLRTAStar_h
17 #include <unordered_map>
38 virtual const char *
GetName() {
if (
doKilling)
return "MPLRTAStar[kill]";
return "MPLRTAStar[]"; }
47 if (val !=
heur.end())
49 return val->second.theHeuristic+env->
HCost(from, to);
51 return env->
HCost(from, to);
101 static const bool benefitRule =
true;
104 double minF = DBL_MAX;
117 std::vector<xyLoc> neighbors;
119 for (
unsigned int x = 0; x < neighbors.size(); x++)
124 if (
IsDead(env, neighbors[x]))
132 double g = env->
GCost(from, neighbors[x]);
135 double h =
HCost(env, neighbors[x], to);
164 double oldH =
HCost(env, from, to);
165 double deltaH = newH - oldH;
168 if (benefitRule &&
fless(deltaH, 0.0))
171 deltaH = fabs(deltaH);
190 for (
int x = 0; x < 8; x++)
201 if (passable <= 4 && changes <= 2 && !(from ==
startState))
205 thePath.push_back(neighbors[minC]);
206 thePath.push_back(from);
213 for (LearnedHeuristic::const_iterator it =
heur.begin(); it !=
heur.end(); it++)
215 double thisState = (*it).second.theHeuristic;
216 if (learned < thisState)
219 for (LearnedHeuristic::const_iterator it =
heur.begin(); it !=
heur.end(); it++)
221 double r = (*it).second.theHeuristic;
222 if ((*it).second.dead)
229 e->
SetColor(0.5+0.5*r/learned, 0, 0, 0.1+0.8*r/learned);
virtual const char * GetName()
bool IsDead(MapEnvironment *env, const xyLoc &from)
virtual uint64_t GetNodesExpanded() const
double HCost(MapEnvironment *env, const xyLoc &from, const xyLoc &to) const
void SetHCost(MapEnvironment *env, const xyLoc &where, const xyLoc &to, double val)
virtual double GCost(const xyLoc &node1, const xyLoc &node2) const
void GetPath(MapEnvironment *, const xyLoc &, const xyLoc &, std::vector< tDirection > &)
virtual void OpenGLDraw() const
virtual void ApplyAction(xyLoc &s, tDirection dir) const
virtual void SetColor(const rgbColor &r) const
double GetAmountLearned()
virtual uint64_t GetNodesTouched() const
bool fless(double a, double b)
virtual double HCost(const xyLoc &) const
Heuristic value between node and the stored goal.
bool fgreater(double a, double b)
virtual void GetSuccessors(const xyLoc &nodeID, std::vector< xyLoc > &neighbors) const
uint64_t GetStateHash(const xyLoc &node) const
The StatCollection class is for collecting stats across different parts of the simulation.
MPLRTAStar(bool kill=true)
bool CanStep(long x1, long y1, long x2, long y2) const
std::unordered_map< uint64_t, learnedData, Hash64 > LearnedHeuristic
virtual void LogFinalStats(StatCollection *s)
void AddStat(const char *category, const char *owner, double value)
Add a new stat entry for the given category, owner and value.
void Kill(MapEnvironment *env, const xyLoc &s)
virtual ~MPLRTAStar(void)
bool fequal(double a, double b, double tolerance=TOLERANCE)
void GetPath(MapEnvironment *env, const xyLoc &from, const xyLoc &to, std::vector< xyLoc > &thePath)
The core routine of MPLRTAStar – computes at most one-move path.