Go to the documentation of this file.
37 #ifndef GENERICSEARCHUNIT_H
38 #define GENERICSEARCHUNIT_H
45 template <
class state,
class action,
class environment>
89 template <
class state,
class action,
class environment>
104 _r = (double)rand() / RAND_MAX;
105 _g = (double)rand() / RAND_MAX;
106 _b = (double)rand() / RAND_MAX;
107 this->SetColor(_r,_g,_b);
111 template <
class state,
class action,
class environment>
115 targ->getLocation(goal);
126 template <
class state,
class action,
class environment>
131 template <
class state,
class action,
class environment>
134 if (getCachedMove(a))
142 target->GetLocation(targpos);
143 if (~(targpos == goal))
170 std::vector<state>
path;
172 algorithm->GetPath(theEnv,from, to,
path);
174 nodesExpanded+=algorithm->GetNodesExpanded();
175 nodesTouched+=algorithm->GetNodesTouched();
190 AddPathToCache(theEnv,
path);
192 assert(moves.size() > 0);
197 moves.erase(moves.begin());
201 template <
class state,
class action,
class environment>
213 theEnv->SetColor(_r, _g, _b);
220 theEnv->SetColor(1.0, 0.25, 0.25, 0.25);
224 theEnv->SetColor(_r, _g, _b, 0.5);
225 theEnv->OpenGLDraw(goal);
232 for (
unsigned int i=0; i<moves.size(); i++)
234 theEnv->SetColor(1.0, 0.0, 0.0, 0.5);
235 theEnv->OpenGLDraw(current);
238 theEnv->ApplyAction(current, moves[i]);
243 template <
class state,
class action,
class environment>
246 if (((nodesExpanded == 0) && (nodesTouched != 0)) ||
247 ((nodesExpanded != 0) && (nodesTouched == 0)))
249 printf(
"Error; somehow nodes touched/expanded are inconsistent. t:%d e:%d\n",
250 nodesTouched, nodesExpanded);
253 if (nodesExpanded != 0)
254 stats->
AddStat(
"nodesExpanded", GetName(), (
long)nodesExpanded);
255 if (nodesTouched != 0)
256 stats->
AddStat(
"nodesTouched", GetName(), (
long)nodesTouched);
257 nodesExpanded = nodesTouched = 0;
260 template <
class state,
class action,
class environment>
263 algorithm->LogFinalStats(stats);
270 template<
class state,
class action,
class environment>
273 for (
unsigned int i=0; i<
path.size()-1; i++)
275 moves.push_back(theEnv->GetAction(
path[i],
path[i+1]));
279 template<
class state,
class action,
class environment>
282 if (moves.size() > 0)
285 moves.erase(moves.begin());
293 template<
class state,
class action,
class environment>
301 if ((!success) || (l ==
loc))
rgbColor GetColor(float v, float vmin, float vmax, int type)
Given min/max values, get a color from a color schema.
An interface for generic search algorithms.
virtual void AddPathToCache(environment *env, std::vector< state > &path)
Store path as a vector of actions.
virtual double GetSimulationTime() const =0
virtual bool MakeMove(environment *env, OccupancyInterface< state, action > *oi, SimulationInfo< state, action, environment > *si, action &a)
A general unit which collects path information from a GenericSearchAlgorithm and incrementally execut...
bool getCachedMove(action &a)
virtual void GetGoal(state &s)
virtual ~GenericSearchUnit()
virtual void GetLocation(state &s)
void LogStats(StatCollection *stats)
log an stats that may have been computed during the last run
Unit< state, action, environment > * target
virtual Unit< state, action, environment > * GetTarget()
void LogFinalStats(StatCollection *stats)
log any final one-time stats before a simulation is ended
bool fgreater(double a, double b)
virtual void GetPublicUnitInfo(unsigned int unitnum, PublicUnitInfo< state, action, environment > &) const =0
std::vector< xyLoc > path
The StatCollection class is for collecting stats across different parts of the simulation.
virtual void OpenGLDraw(const environment *, const SimulationInfo< state, action, environment > *) const
std::vector< action > moves
virtual const char * GetName()
GenericSearchUnit(state &start, state &goal, GenericSearchAlgorithm< state, action, environment > *alg)
virtual void SetTarget(Unit< state, action, environment > *u)
void AddStat(const char *category, const char *owner, double value)
Add a new stat entry for the given category, owner and value.
virtual GenericSearchAlgorithm< state, action, environment > * getAlgorithm()
virtual unsigned int GetCurrentUnit() const =0
A linked list of nodes which form a continuous path.
virtual void UpdateLocation(environment *env, state &l, bool success, SimulationInfo< state, action, environment > *si)
GenericSearchAlgorithm< state, action, environment > * algorithm