Quad-SDK
|
A general directed graph class. More...
#include <graph_class.h>
Public Member Functions | |
GraphClass () | |
Constructor for GraphClass. | |
void | addVertex (int index, State s) |
Add a new vertex to the graph along with its state data. | |
State | getVertex (int index) |
Retrieve the state stored at a particular index in the graph. | |
int | getNumVertices () |
Retrieve the total number of vertices in the graph, computed as the size of the vertices vector. | |
virtual void | addEdge (int idx1, int idx2) |
Add a new edge to the graph. | |
virtual void | addEdge (int idx1, int idx2, double edge_cost) |
Add a new edge to the graph. | |
void | removeEdge (int idx1, int idx2) |
Remove an edge of the graph. | |
virtual int | getPredecessor (int idx) |
Get the parent of a vertex. | |
std::vector< int > | getSuccessors (int idx) |
Get the children of a vertex. | |
void | addAction (int idx, Action a) |
Add an action to a particular vertex. This is the action that lead to this particular vertex from its parent. | |
Action | getAction (int idx) |
Get the action of a vertex. | |
void | updateGValue (int idx, double val) |
Update the g-value of a vertex and propogate to all its successors. | |
double | getGValue (int idx) |
Get the g-value of a vertex. | |
double | computeEdgeCost (int idx1, int idx2) |
Compute the cost of an edge between two vertices. | |
void | printVertex (State s) |
Print the state information via stdout. | |
void | printVertices () |
Print the all vertices in the graph via stdout. | |
void | printIncomingEdges (int idx) |
Print the edges leading to a vertex via stdout. | |
virtual void | printEdges () |
Print the all edges in the graph via stdout. | |
virtual void | init (State s) |
Initialize the graph by adding the root vertex (idx = 0) and setting g(idx) = 0. | |
Protected Attributes | |
std::unordered_map< int, State > | vertices |
Map from vertex indices to corresponding states. | |
std::unordered_map< int, Action > | actions |
Map from vertex indices to the actions leading to those vertices. | |
std::unordered_map< int, std::vector< int > > | edges |
Map from vertex indices to their parent(s) | |
std::unordered_map< int, std::vector< int > > | successors |
Map from vertex indices to their children. | |
std::unordered_map< int, double > | g_values |
Map from vertex indices to their costs (g-values) | |
A general directed graph class.
This class implements a directed graph data structure with methods for adding and deleting vertices and edges, as well storing information at each vertex and providing print statements for debugging. Vertices are indexed with ints, and edges as unordered maps that map a vertex's index to the indices of its parents. If the graph is a tree there should only be one parent per vertex. Other unordered maps store information about each vertex, such as the associated state, action, or distance from the root vertex (g-value).
GraphClass::GraphClass | ( | ) |
Constructor for GraphClass.
void GraphClass::addAction | ( | int | idx, |
Action | a | ||
) |
Add an action to a particular vertex. This is the action that lead to this particular vertex from its parent.
[in] | idx | Index of the desired vertex |
[in] | a | Action corresponding to the desired vertex |
|
virtual |
Add a new edge to the graph.
[in] | idx1 | Index of the outgoing vertex of the edge |
[in] | idx2 | Index of the incoming vertex of the edge |
|
virtual |
Add a new edge to the graph.
[in] | idx1 | Index of the outgoing vertex of the edge |
[in] | idx2 | Index of the incoming vertex of the edge |
[in] | edge_code | Cost of the new edge |
void GraphClass::addVertex | ( | int | index, |
State | s | ||
) |
Add a new vertex to the graph along with its state data.
[in] | index | Index of the new vertex |
[in] | s | State information corresponding to the specified index |
double GraphClass::computeEdgeCost | ( | int | idx1, |
int | idx2 | ||
) |
Compute the cost of an edge between two vertices.
[in] | idx1 | Index of vertex 1 |
[in] | idx2 | Index of vertex 2 |
Action GraphClass::getAction | ( | int | idx | ) |
Get the action of a vertex.
[in] | idx | Index of the desired vertex |
double GraphClass::getGValue | ( | int | idx | ) |
Get the g-value of a vertex.
[in] | idx | Index of the desired vertex |
int GraphClass::getNumVertices | ( | ) |
Retrieve the total number of vertices in the graph, computed as the size of the vertices vector.
|
virtual |
Get the parent of a vertex.
[in] | idx | Index of the desired vertex |
std::vector< int > GraphClass::getSuccessors | ( | int | idx | ) |
Get the children of a vertex.
[in] | idx | Index of the desired vertex |
State GraphClass::getVertex | ( | int | index | ) |
Retrieve the state stored at a particular index in the graph.
[in] | index | Index of the desired vertex |
|
virtual |
Initialize the graph by adding the root vertex (idx = 0) and setting g(idx) = 0.
[in] | s | State for the root vertex |
void GraphClass::printIncomingEdges | ( | int | idx | ) |
Print the edges leading to a vertex via stdout.
[in] | idx | Index of the desired vertex |
void GraphClass::printVertex | ( | State | s | ) |
Print the state information via stdout.
[in] | s | The state information to print |
void GraphClass::removeEdge | ( | int | idx1, |
int | idx2 | ||
) |
Remove an edge of the graph.
[in] | idx1 | Index of the outgoing vertex of the edge |
[in] | idx2 | Index of the incoming vertex of the edge |
void GraphClass::updateGValue | ( | int | idx, |
double | val | ||
) |
Update the g-value of a vertex and propogate to all its successors.
[in] | idx | Index of the desired vertex |
[in] | val | New g-value corresponding to the desired vertex |