HOG2
GraphAbstraction.h
Go to the documentation of this file.
1 /*
2  * $Id: GraphAbstraction.h
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 1/11/05.
6  * Modified by Nathan Sturtevant on 02/29/20.
7  *
8  * This file is part of HOG2. See https://github.com/nathansttt/hog2 for licensing information.
9  *
10  */
11 
12 #include "Graph.h"
13 #include "Path.h"
14 #include "GLUtil.h"
15 #include <stdlib.h>
16 #include <stdio.h>
17 
18 #ifndef GRAPHABSTRACTION_H
19 #define GRAPHABSTRACTION_H
20 #include <vector>
21 
24  enum {
25  kAbstractionLevel = 0, // this is a LONG label
26  kNumAbstractedNodes = 1, // nodes that we abstract; this is a LONG label
27  kParent = 2, // node that abstracts us; this is a LONG label
28  kNodeWidth = 3, // the maximum size object that can completely traverse this node; this is a LONG label
29  kTemporaryLabel = 4, // for any temporary usage; this label can be LONG or FLOATING point
30  kXCoordinate = 5, // cache for opengl drawing; this is a FLOATING POINT label
31  kYCoordinate = 6, // this is a FLOATING POINT label
32  kZCoordinate = 7, // this is a FLOATING POINT label
33  kNodeBlocked = 8, // this is a LONG label
35  };
36 
38  enum {
40  };
41 
42 
52  enum {
54  };
55 
56  const double kUnknownPosition = -50.0;
57 }
58 
64 public:
66  virtual ~GraphAbstraction();
67 
68  // basic Graph functions
70  virtual bool Pathable(node *from, node *to) = 0;
72  void GetNumAbstractGraphs(node *from, node *to, std::vector<node *> &fromChain, std::vector<node *> &toChain);
74  Graph* GetAbstractGraph(int level) { return abstractions[level]; }
76  unsigned int getNumAbstractGraphs() { return (unsigned int)abstractions.size(); }
78  virtual double h(node *a, node *b) = 0;
80  double distance(path *p);
82  node *GetNthParent(node *which, int n);
84  bool IsParentOf(node *parent, node *child);
85 
86  inline node *GetParent(node *which) { return abstractions[GetAbstractionLevel(which)+1]->GetNode(which->GetLabelL(GraphAbstractionConstants::kParent)); }
88  inline node *GetNthChild(node *which, int n) { return abstractions[GetAbstractionLevel(which)-1]->GetNode(which->GetLabelL(GraphAbstractionConstants::kFirstData+n)); }
89 
91 
94  // utility functions
96  virtual void VerifyHierarchy() = 0;
98  // virtual void rebuild() = 0;
100  //virtual int GetRevision() = 0;
101  void ClearMarkedNodes();
102 
103  // hierarchical modifications
105  virtual void RemoveNode(node *n) = 0;
107  virtual void RemoveEdge(edge *e, unsigned int absLevel) = 0;
109  virtual void AddNode(node *n) = 0;
111  virtual void AddEdge(edge *e, unsigned int absLevel) = 0;
114  virtual void RepairAbstraction() = 0;
115  virtual int MeasureRepairHits() { return 0; }
116  void MeasureAbstractionValues(int level, double &n, double &n_dev, double &c, double &c_dev);
117  double MeasureAverageNodeWidth(int level);
118 
119  virtual void OpenGLDraw() const {}
120  virtual recVec GetNodeLoc(node *) const { recVec v; v.x = v.y = v.z = 0; return v; }
121 protected:
122  std::vector<Graph *> abstractions;
123 private:
124  int ComputeWidth(node *n);
125  int WidthBFS(node *child, node *parent);
126  double MeasureExpectedNodeWidth(node *n);
127  int GetNumExternalEdges(node *n, node *p);
128  int CountEdgesAtDistance(node *child, node *parent, std::vector<int> &dists);
129 };
130 
131 // this class can be defined if you want to solve multiple domains...
132 //
133 // class domainAbstraction : public GraphAbstraction {
134 // void domainAbstraction(abstractableDomain *) = 0;
135 // };
136 
137 #endif
GraphAbstraction
A generic class for basic operations on Graph abstractions.
Definition: GraphAbstraction.h:63
GraphAbstractionConstants
Definition: GraphAbstraction.h:22
Graph.h
GraphAbstraction::distance
double distance(path *p)
length in distance of a path
Definition: GraphAbstraction.cpp:102
GraphAbstraction::~GraphAbstraction
virtual ~GraphAbstraction()
Definition: GraphAbstraction.cpp:29
recVec
A generic vector (essentially the same as a point, but offers normalization)
Definition: GLUtil.h:78
GraphAbstraction::GetAbstractGraph
Graph * GetAbstractGraph(int level)
return the abstract Graph at the given level
Definition: GraphAbstraction.h:74
recVec::z
GLdouble z
Definition: GLUtil.h:98
GraphAbstraction::OpenGLDraw
virtual void OpenGLDraw() const
Definition: GraphAbstraction.h:119
Path.h
GraphAbstraction::MeasureRepairHits
virtual int MeasureRepairHits()
Definition: GraphAbstraction.h:115
GraphAbstraction::RepairAbstraction
virtual void RepairAbstraction()=0
This must be called after any of the above add/remove operations.
GraphAbstraction::AddEdge
virtual void AddEdge(edge *e, unsigned int absLevel)=0
add edge to abstraction
GraphAbstraction::VerifyHierarchy
virtual void VerifyHierarchy()=0
verify that the hierarchy is consistent
GraphAbstractionConstants::kEdgeCapacity
@ kEdgeCapacity
Definition: GraphAbstraction.h:53
GraphAbstractionConstants::kNodeWidth
@ kNodeWidth
Definition: GraphAbstraction.h:28
GraphAbstraction::ClearMarkedNodes
void ClearMarkedNodes()
rebuild hierarchy from original domain *‍/
Definition: GraphAbstraction.cpp:89
GraphAbstraction::GetNthChild
node * GetNthChild(node *which, int n)
Definition: GraphAbstraction.h:88
Graph
A generic Graph class.
Definition: Graph.h:66
GraphAbstraction::GetAbstractGraph
Graph * GetAbstractGraph(node *which)
Definition: GraphAbstraction.h:93
GraphAbstraction::CountEdgesAtDistance
int CountEdgesAtDistance(node *child, node *parent, std::vector< int > &dists)
Definition: GraphAbstraction.cpp:291
GraphAbstractionConstants::kZCoordinate
@ kZCoordinate
Definition: GraphAbstraction.h:32
GraphAbstractionConstants::kNumAbstractedNodes
@ kNumAbstractedNodes
Definition: GraphAbstraction.h:26
GraphAbstraction::GetAbstractionLevel
long GetAbstractionLevel(node *which)
Definition: GraphAbstraction.h:92
GraphAbstraction::h
virtual double h(node *a, node *b)=0
heuristic cost between any two nodes
GraphAbstraction::Pathable
virtual bool Pathable(node *from, node *to)=0
is there a legal path between these 2 nodes?
GraphAbstractionConstants::kFirstData
@ kFirstData
Definition: GraphAbstraction.h:34
GraphAbstraction::WidthBFS
int WidthBFS(node *child, node *parent)
Definition: GraphAbstraction.cpp:152
GraphAbstraction::GetNumChildren
long GetNumChildren(node *which)
Definition: GraphAbstraction.h:87
GraphAbstractionConstants::kAbstractionLevel
@ kAbstractionLevel
Definition: GraphAbstraction.h:25
GraphAbstraction::RemoveNode
virtual void RemoveNode(node *n)=0
remove node from abstraction
GraphAbstraction::GetRandomGroundNodeFromNode
node * GetRandomGroundNodeFromNode(node *n)
Definition: GraphAbstraction.cpp:331
GraphAbstractionConstants::kEdgeWidth
@ kEdgeWidth
Definition: GraphAbstraction.h:39
GraphAbstractionConstants::kYCoordinate
@ kYCoordinate
Definition: GraphAbstraction.h:31
GLUtil.h
GraphAbstraction::getNumAbstractGraphs
unsigned int getNumAbstractGraphs()
return the total number of graphs in the hierarchy
Definition: GraphAbstraction.h:76
GraphAbstraction::AddNode
virtual void AddNode(node *n)=0
add node to abstraction
GraphAbstraction::abstractions
std::vector< Graph * > abstractions
Definition: GraphAbstraction.h:122
GraphAbstractionConstants::kXCoordinate
@ kXCoordinate
Definition: GraphAbstraction.h:30
GraphAbstraction::GetNumAbstractGraphs
void GetNumAbstractGraphs(node *from, node *to, std::vector< node * > &fromChain, std::vector< node * > &toChain)
given 2 nodes, find as much of their hierarchy that exists in the Graph
Definition: GraphAbstraction.cpp:39
GraphAbstraction::ComputeWidth
int ComputeWidth(node *n)
Definition: GraphAbstraction.cpp:141
GraphAbstraction::MeasureExpectedNodeWidth
double MeasureExpectedNodeWidth(node *n)
Definition: GraphAbstraction.cpp:212
GraphAbstractionConstants::kNodeBlocked
@ kNodeBlocked
Definition: GraphAbstraction.h:33
GraphAbstractionConstants::kTemporaryLabel
@ kTemporaryLabel
Definition: GraphAbstraction.h:29
GraphAbstraction::IsParentOf
bool IsParentOf(node *parent, node *child)
return true if the first node is a parent of or is equal two the second node
Definition: GraphAbstraction.cpp:78
GraphAbstraction::MeasureAverageNodeWidth
double MeasureAverageNodeWidth(int level)
Definition: GraphAbstraction.cpp:186
GraphAbstraction::GetNodeLoc
virtual recVec GetNodeLoc(node *) const
Definition: GraphAbstraction.h:120
GraphAbstractionConstants::kParent
@ kParent
Definition: GraphAbstraction.h:27
node::GetLabelL
long GetLabelL(unsigned int index) const
Definition: Graph.h:220
path
A linked list of nodes which form a continuous path.
Definition: Path.h:20
GraphAbstraction::RemoveEdge
virtual void RemoveEdge(edge *e, unsigned int absLevel)=0
remove edge from abstraction
GraphAbstractionConstants::kUnknownPosition
const double kUnknownPosition
Definition: GraphAbstraction.h:56
recVec::y
GLdouble y
Definition: GLUtil.h:98
GraphAbstraction::GraphAbstraction
GraphAbstraction()
Definition: GraphAbstraction.h:65
GraphAbstraction::GetParent
node * GetParent(node *which)
Definition: GraphAbstraction.h:86
recVec::x
GLdouble x
Definition: GLUtil.h:98
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
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
GraphAbstraction::GetNumExternalEdges
int GetNumExternalEdges(node *n, node *p)
Definition: GraphAbstraction.cpp:275
GraphAbstraction::MeasureAbstractionValues
void MeasureAbstractionValues(int level, double &n, double &n_dev, double &c, double &c_dev)
Definition: GraphAbstraction.cpp:109
edge
Edge class for connections between node in a Graph.
Definition: Graph.h:129