Quad-SDK
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
GraphClass Class Reference

A general directed graph class. More...

#include <graph_class.h>

Inheritance diagram for GraphClass:
Inheritance graph
[legend]

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, Statevertices
 Map from vertex indices to corresponding states.
 
std::unordered_map< int, Actionactions
 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)
 

Detailed Description

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).

Constructor & Destructor Documentation

◆ GraphClass()

GraphClass::GraphClass ( )

Constructor for GraphClass.

Returns
Constructed object of type GraphClass

Member Function Documentation

◆ addAction()

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.

Parameters
[in]idxIndex of the desired vertex
[in]aAction corresponding to the desired vertex

◆ addEdge() [1/2]

void GraphClass::addEdge ( int  idx1,
int  idx2 
)
virtual

Add a new edge to the graph.

Parameters
[in]idx1Index of the outgoing vertex of the edge
[in]idx2Index of the incoming vertex of the edge

◆ addEdge() [2/2]

void GraphClass::addEdge ( int  idx1,
int  idx2,
double  edge_cost 
)
virtual

Add a new edge to the graph.

Parameters
[in]idx1Index of the outgoing vertex of the edge
[in]idx2Index of the incoming vertex of the edge
[in]edge_codeCost of the new edge

◆ addVertex()

void GraphClass::addVertex ( int  index,
State  s 
)

Add a new vertex to the graph along with its state data.

Parameters
[in]indexIndex of the new vertex
[in]sState information corresponding to the specified index

◆ computeEdgeCost()

double GraphClass::computeEdgeCost ( int  idx1,
int  idx2 
)

Compute the cost of an edge between two vertices.

Parameters
[in]idx1Index of vertex 1
[in]idx2Index of vertex 2
Returns
Cost of the edge between idx1 and idx2

◆ getAction()

Action GraphClass::getAction ( int  idx)

Get the action of a vertex.

Parameters
[in]idxIndex of the desired vertex
Returns
Action corresponding to the desired vertex

◆ getGValue()

double GraphClass::getGValue ( int  idx)

Get the g-value of a vertex.

Parameters
[in]idxIndex of the desired vertex
Returns
G-value corresponding to the desired vertex

◆ getNumVertices()

int GraphClass::getNumVertices ( )

Retrieve the total number of vertices in the graph, computed as the size of the vertices vector.

Returns
Number of vertices in the graph

◆ getPredecessor()

int GraphClass::getPredecessor ( int  idx)
virtual

Get the parent of a vertex.

Parameters
[in]idxIndex of the desired vertex
Returns
Index of the parent of the specified vertex

◆ getSuccessors()

std::vector< int > GraphClass::getSuccessors ( int  idx)

Get the children of a vertex.

Parameters
[in]idxIndex of the desired vertex
Returns
Indices of the children of the specified vertex

◆ getVertex()

State GraphClass::getVertex ( int  index)

Retrieve the state stored at a particular index in the graph.

Parameters
[in]indexIndex of the desired vertex
Returns
State information corresponding to the requested index

◆ init()

void GraphClass::init ( State  s)
virtual

Initialize the graph by adding the root vertex (idx = 0) and setting g(idx) = 0.

Parameters
[in]sState for the root vertex

◆ printIncomingEdges()

void GraphClass::printIncomingEdges ( int  idx)

Print the edges leading to a vertex via stdout.

Parameters
[in]idxIndex of the desired vertex

◆ printVertex()

void GraphClass::printVertex ( State  s)

Print the state information via stdout.

Parameters
[in]sThe state information to print

◆ removeEdge()

void GraphClass::removeEdge ( int  idx1,
int  idx2 
)

Remove an edge of the graph.

Parameters
[in]idx1Index of the outgoing vertex of the edge
[in]idx2Index of the incoming vertex of the edge

◆ updateGValue()

void GraphClass::updateGValue ( int  idx,
double  val 
)

Update the g-value of a vertex and propogate to all its successors.

Parameters
[in]idxIndex of the desired vertex
[in]valNew g-value corresponding to the desired vertex

The documentation for this class was generated from the following files: