Go to the documentation of this file.
90 neighbors.push_back(e->getTo());
97 if (stateID != e->getTo())
98 neighbors.push_back(e->getTo());
100 neighbors.push_back(e->getFrom());
120 actions.push_back(
graphMove(e->getFrom(),e->getTo()));
127 if (stateID != e->getTo())
128 actions.push_back(
graphMove(e->getFrom(),e->getTo()));
130 actions.push_back(
graphMove(e->getTo(),e->getFrom()));
149 uint32_t tmp = a.
from;
160 return h->
HCost(state1, state2);
161 if (state1 == state2)
184 return state == goal;
217 glBegin(GL_TRIANGLE_FAN);
218 glColor4f(0, 0, 0, 0.01);
219 glVertex3f(-1, -1, 0.01);
220 glVertex3f(1, -1, 0.01);
221 glVertex3f(1, 1, 0.01);
222 glVertex3f(-1, 1, 0.01);
240 glColor4f(r,
g, b, t);
244 glColor3f(1.0, 0.0, 0.0);
255 glVertex3f(x, y, z+off);
263 glVertex3f(x, y, z+off);
271 glColor4f(0.0, 0.0, 0.0, 1.0);
276 sprintf(label,
"%d",
int(e->GetWeight()));
278 sprintf(label,
"%1.2f", e->GetWeight());
292 DrawText(x/2, y/2, z/2-0.003, 0.2, label);
299 glColor4f(0.0, 0.0, 0.0, 1.0);
317 GLdouble xx, yy, zz, rad;
329 glVertex3d(xx+rad, yy+rad, zz-rad);
330 glVertex3d(xx-rad, yy+rad, zz-rad);
331 glVertex3d(xx-rad, yy-rad, zz-rad);
332 glVertex3d(xx+rad, yy-rad, zz-rad);
342 glColor4f(r, gr, b, t);
345 GLdouble x, y, z, rad;
356 glColor4f(0, 0, 0, t);
371 glColor4f(r, gr, b, t);
401 glColor4f(0.0, 0.0, 0.0, 1.0);
424 glColor4f(r,
g, b, t);
451 s =
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width = \""+std::to_string(610)+
"\" height = \""+std::to_string(610)+
"\" ";
452 s +=
"viewBox=\""+std::to_string(-5)+
" "+std::to_string(-5)+
" ";
453 s += std::to_string(610)+
" "+std::to_string(610)+
"\" ";
454 s +=
"preserveAspectRatio = \"none\" ";
465 x1 = int((x1+1.0)*300.0+12.0);
466 y1 = int((y1+1.0)*300.0+20.0);
478 x1 = int((x1+1.0)*300.0);
479 y1 = int((y1+1.0)*300.0);
486 std::string s =
"<path d=\"";
490 int minx = 600, miny=600, maxx = 0, maxy= 0;
493 if (e->getFrom() >= e->getTo())
510 float x1, y1, x2, y2;
518 int fx1, fx2, fy1, fy2;
519 fx1 = int((x1+1.0)*300.0);
520 fx2 = int((x2+1.0)*300.0);
521 fy1 = int((y1+1.0)*300.0);
522 fy2 = int((y2+1.0)*300.0);
523 if (fx1 == fx2 && fy1 == fy2)
537 s +=
"M "+std::to_string(fx1)+
" "+std::to_string(fy1)+
" ";
538 s +=
"L "+std::to_string(fx2)+
" "+std::to_string(fy2)+
" ";
540 if (0 == ++count%200)
542 s +=
"\" stroke=\"black\" stroke-width=\"0.1\" fill=\"none\" />\n";
547 s +=
"\" stroke=\"black\" stroke-width=\"0.1\" fill=\"none\" />\n";
562 [](
float a,
float b,
float mix) {
return (1-mix)*a+mix*b;},
563 [](
float a,
float b,
float mix) {
return (1-mix)*a+mix*b;});
567 std::function<
float(
float,
float,
float)> l1,
568 std::function<
float(
float,
float,
float)> l2)
const
611 std::function<
float(
float,
float,
float)> l1,
612 std::function<
float(
float,
float,
float)> l2)
const
672 GLdouble len = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
673 GLdouble ratio = (rad+0.1*rad)/len;
674 DrawLine(disp, x1, y1, (x2*(1-ratio)+ratio*x1), (y2*(1-ratio)+ratio*y1), 1);
687 glColor4f(0.0, 0.0, 0.0, 1.0);
692 sprintf(label,
"%d",
int(e->GetWeight()));
694 sprintf(label,
"%1.2f", e->GetWeight());
783 GLdouble x, y, z, rad;
877 AddEdges(m, g, x, y, directed, 1.0, 0.0, 100, 0);
898 GLdouble xx, yy, zz, rr;
902 sprintf(name,
"(%d, %d)", x, y);
913 GLdouble xx, yy, zz, rr;
917 sprintf(name,
"(%d, %d)", x, y);
932 GLdouble xx, yy, zz, rr;
936 sprintf(name,
"(%d, %d)", x, y);
962 double straigtEdgeCost,
964 int straightEdgeProb,
978 if ((random()%100) < straightEdgeProb)
991 if ((random()%100) < straightEdgeProb)
1015 if ((random()%100) < straightEdgeProb)
1029 if ((random()%100) < straightEdgeProb)
1047 if ((random()%100) < straightEdgeProb)
1061 if ((random()%100) < straightEdgeProb)
1092 if ((random()%100) < diagEdgeProb)
1106 if ((random()%100) < diagEdgeProb)
1137 if ((random()%100) < diagEdgeProb)
1151 if ((random()%100) < diagEdgeProb)
1206 double a = ((x1>x2)?(x1-x2):(x2-x1));
1207 double b = ((y1>y2)?(y1-y2):(y2-y1));
1222 if (hval < 0) hval = -hval;
1240 if ( (x1+x2) % 4 == 0 && (y1+y2) % 4 == 0)
1242 for (
unsigned int i=0;i<
heuristics.size();i++)
1257 static std::vector<double> vals;
1258 static std::vector<double> errors;
1261 if (lastGoal != state2)
1269 for (
unsigned int x = 0; x <
heuristics.size(); x++)
1301 for (
unsigned int state1 = 0; state1 <
heuristics[0].size(); state1++)
1313 std::vector<double> &errors,
1319 assert(!
"No heuristics being used");
1332 vals.resize(unused);
1333 errors.resize(unused);
1335 for (
unsigned int x = 0; x < vals.size(); x++)
1336 vals[x] = errors[x] = -1;
1354 for (
unsigned int x = 0; x <
heuristics.size(); x++)
1362 while ((unused > 0) && (!h.
Empty()))
1374 for (
unsigned int x = 0; x <
heuristics.size(); x++)
1391 errors[x] = cost+edgeCost;
1420 printf(
"No heuristics\n");
1432 for (
unsigned int a = 0; a <
heuristics.back().size(); a++)
1438 for (
unsigned int a = 0; a <
heuristics.back().size(); a++)
1485 for (
unsigned int a = 0; a <
locations.size(); a++)
1495 glColor3f(0.0, 0.0, 1.0);
1498 double maxWeight = 0;
1499 for (
unsigned int a = 0; a <
weight.size(); a++)
1500 if (
weight[a] > maxWeight)
1504 for (
unsigned int a = 0; a <
sizes.size(); a++)
1505 if (
sizes[a] > maxSize)
1508 for (
unsigned int a = 0; a <
weight.size(); a++)
1518 glColor3f(0.0,
sizes[a]/maxSize, 0.0);
1529 for (
unsigned int i = 0; i <
heuristics.size(); i++)
1544 double minStart=-1, minGoal=-1;
1548 for (
unsigned int x = 1; x <
heuristics.size(); x++)
1555 if (minStart < minGoal)
1573 std::vector<double> values;
1590 for (
unsigned int x = 0; x < values.size(); x++)
1606 if (values[tmp] == -1)
1640 for (
unsigned int x = 0; x <
heuristics[0].size(); x+=1)
1646 for (
unsigned int y = 0; y <
heuristics.size(); y++)
1650 for (
unsigned int y = 0; y <
heuristics.size(); y++)
1673 for (
unsigned int x = 0; x <
dist.size(); x++)
1688 for (
unsigned int x = 1; x <
sizes.size(); x++)
1696 std::vector<double> &weight, std::vector<double> &sizes)
1714 else if (nodeSize == -1)
1718 else if (nodeSize != 0) {
1729 else if (nodeSize != 0) {
1736 for (
unsigned int x = 0; x <
locations.size(); x++)
1744 std::vector<double> &sizes)
1746 int nextChild = best;
1761 if (nextChild == -1)
1765 nextChild = nb->
GetNum();
1771 nextChild = nb->
GetNum();
1775 }
while (nextChild != -1);
1780 std::vector<double> values;
1782 for (
unsigned int x = 0; x < values.size(); x++)
1786 for (
unsigned int x = 0; x <
locations.size(); x++)
1800 for (
int x = 0; x < 10; x++)
1819 if (values[tmp] == -1)
void DrawLine(point start, point end, float lineWidth, rgbColor c)
void SetLabelL(unsigned int index, long val) const
void OutlineRect(GLdouble left, GLdouble top, GLdouble right, GLdouble bottom, double zz)
void SetMode(tHeuristicCombination mode)
void AddHeuristic(node *n=0)
Graphics::point GetLocation(const graphState &s) const
void DrawSquare(GLdouble xx, GLdouble yy, GLdouble zz, GLdouble rad)
void SetLabelF(unsigned int index, double val) const
std::vector< std::vector< double > > heuristics
virtual void OpenGLDraw() const
A color; r/g/b are between 0...1.
edge * FindEdge(unsigned int from, unsigned int to)
Finds an edge between nodes with ids from and to, no matter which direction.
unsigned int neighbor_iterator
double min(double a, double b)
void OpenGLDraw(tDisplay how=kPolygons) const
Does actual OpenGL drawing of the map.
edge_iterator getOutgoingEdgeIter() const
void AddNodesToGraph(Map *m, Graph *g)
std::vector< double > dist
Graph * GetEightConnectedGraph(Map *m, bool directed)
std::vector< double > sizes
void ComputeSizes(node *n, std::vector< double > &dist, std::vector< double > &weight, std::vector< double > &sizes)
std::string SVGDrawText(float x1, float y1, const char *txt, rgbColor c, double size, const char *typeface, SVG::svgAlignment align, SVG::svgBaseline base)
virtual void GetSuccessors(const graphState &stateID, std::vector< graphState > &neighbors) const
std::vector< edge * >::const_iterator edge_iterator
void DrawSphere(GLdouble _x, GLdouble _y, GLdouble _z, GLdouble tRadius)
virtual ~GraphEnvironment()
edge * edgeIterNextOutgoing(edge_iterator &) const
tHeuristicCombination hmode
Tile & GetTile(long x, long y)
Return the tile at location x, y.
GraphMapInconsistentHeuristic(Map *map, Graph *graph)
void SetNumUsedHeuristics(int count)
void DecreaseKey(graph_object *val)
Indicate that the key for a particular object has decreased.
std::string SVGDrawCircle(double x, double y, double radius, rgbColor c)
void DrawLERP(Graphics::Display &disp, Graph *a, Graph *b, float mix) const
node * GetNode(unsigned long num)
virtual bool GoalTest(const graphState &state, const graphState &goal) const
virtual void DrawStateLabel(Graphics::Display &disp, const graphState &l1, const char *txt) const
edge * edgeIterNext(edge_iterator &) const
virtual uint64_t GetStateHash(const graphState &state) const
virtual double HCost(const graphState &state1, const graphState &state2) const
edge_iterator getEdgeIter() const
virtual void SetColor(const rgbColor &r) const
node * FindAvoidNode(node *n)
virtual bool InvertAction(graphMove &a) const
void SetKeyLabel(int which)
edge_iterator getEdgeIter() const
std::vector< graphState > locations
void DrawTextCentered(double x, double y, double z, double scale, const char *str)
virtual void ApplyAction(graphState &s, graphMove a) const
bool Empty()
Returns true if no items are in the Heap.
bool fless(double a, double b)
double HCost(const graphState &state1, const graphState &state2) const
void DrawText(double x, double y, double z, double scale, const char *str)
static const double ROOT_TWO
virtual void GetStateFromHash(uint64_t parent, graphState &s) const
Graph * GetFourConnectedGraph(Map *m, bool directed)
long GetMapWidth() const
return the width of the map
virtual void Draw(Graphics::Display &disp) const
virtual rgbColor GetColor() const
virtual double GCost(const graphState &state1, const graphState &state2) const
long GetTerrainType(long x, long y, tSplitSide split=kWholeTile) const
Get the terrain type of the (split) tile at x, y.
virtual void DrawLine(Graphics::Display &disp, const graphState &x, const graphState &y, double width=1.0) const
std::string SVGLabelState(const graphState &s, const char *) const
void ChooseStartGoal(graphState &start, graphState &goal)
graph_object * Remove()
Remove the item with the lowest key from the Heap & re-heapify.
void FrameCircle(rect r, rgbColor c, float lineWidth)
virtual int GetNumSuccessors(const graphState &stateID) const
bool fgreater(double a, double b)
void GetOptimalDistances(node *n, std::vector< double > &values)
virtual double HCost(const graphState &state1, const graphState &state2) const
Heuristic value between two arbitrary nodes.
int nodeNeighborNext(neighbor_iterator &) const
void Add(graph_object *val)
Add object into Heap.
void DrawArrow(point start, point end, float lineWidth, rgbColor c)
std::vector< double > weight
void AddEdges(Map *m, Graph *g, int x, int y, bool directed, double straigtEdgeCost, double diagEdgeCost, int straightEdgeProb, int diagEdgeProb)
AddEdges(map, Graph, x, y)
node * FindBestChild(int best, std::vector< double > &dist, std::vector< double > &weight)
virtual void GLDrawLine(const graphState &x, const graphState &y) const
void FillInCache(std::vector< double > &vals, std::vector< double > &errors, graphState state2) const
double GetLabelF(unsigned int index) const
void FillCircle(rect r, rgbColor c)
virtual uint64_t GetActionHash(graphMove act) const
A simple & efficient Heap class which uses Graph objects.
placementScheme placement
unsigned int GetNum() const
long GetMapHeight() const
return the height of the map
Graph * GetUndirectedGraph(Map *m)
GetMapGraph(map)
std::string SVGDraw() const
virtual graphMove GetAction(const graphState &s1, const graphState &s2) const
tSplit GetSplit(long x, long y) const
Return the split of the tile at x, y.
virtual void GLLabelState(const graphState &, const char *) const
node * FindFarNode(node *n)
static const double ONE_OVER_ROOT_TWO
bool AdjacentEdges(long x, long y, tEdge edge) const
Is the tile at x, y adjacent across the edge?
virtual void GetActions(const graphState &stateID, std::vector< graphMove > &actions) const
bool GetOpenGLCoord(int _x, int _y, GLdouble &x, GLdouble &y, GLdouble &z, GLdouble &radius) const
Get the openGL coordinates of a given tile.
long GetLabelL(unsigned int index) const
neighbor_iterator getNeighborIter() const
virtual double HCost(const graphState &state1, const graphState &state2) const =0
void DrawText(const char *text, point location, rgbColor c, float height, const char *typeface=0)
edge * findDirectedEdge(unsigned int from, unsigned int to)
bool fequal(double a, double b, double tolerance=TOLERANCE)
edge * edgeIterNext(edge_iterator &) const
std::string SVGHeader() const
GraphEnvironment(Graph *g, GraphHeuristic *gh=0)
virtual void OpenGLDraw() const
Nodes to be stored within a Graph.
A tile-based representation of the world.
int getNumOutgoingEdges()
virtual void OpenGLDraw() const
bool IsIn(graph_object *val)
Returns true if the object is in the Heap.
Edge class for connections between node in a Graph.
const char * GetName() const