Quad-SDK
Loading...
Searching...
No Matches
graph_class.h
1#ifndef GRAPHCLASS_H
2#define GRAPHCLASS_H
3
4#include <algorithm>
5#include <iostream>
6#include <unordered_map>
7#include <unordered_set>
8#include <vector>
9
10#include "global_body_planner/planning_utils.h"
11
12using namespace planning_utils;
13
15
25 public:
30 GraphClass();
31
37 void addVertex(int index, State s);
38
44 State getVertex(int index);
45
51 int getNumVertices();
52
58 virtual void addEdge(int idx1, int idx2);
59
66 virtual void addEdge(int idx1, int idx2, double edge_cost);
67
73 void removeEdge(int idx1, int idx2);
74
80 virtual int getPredecessor(int idx);
81
87 std::vector<int> getSuccessors(int idx);
88
95 void addAction(int idx, Action a);
96
102 Action getAction(int idx);
103
109 void updateGValue(int idx, double val);
110
116 double getGValue(int idx);
117
124 double computeEdgeCost(int idx1, int idx2);
125
130 void printVertex(State s);
131
135 void printVertices();
136
141 void printIncomingEdges(int idx);
142
146 virtual void printEdges();
147
153 virtual void init(State s);
154
155 protected:
157 std::unordered_map<int, State> vertices;
158
160 std::unordered_map<int, Action> actions;
161
163 std::unordered_map<int, std::vector<int>> edges;
164
166 std::unordered_map<int, std::vector<int>> successors;
167
169 std::unordered_map<int, double> g_values;
170};
171
172#endif
A general directed graph class.
Definition graph_class.h:24
void addVertex(int index, State s)
Add a new vertex to the graph along with its state data.
Definition graph_class.cpp:18
void printVertices()
Print the all vertices in the graph via stdout.
Definition graph_class.cpp:69
double computeEdgeCost(int idx1, int idx2)
Compute the cost of an edge between two vertices.
Definition graph_class.cpp:100
std::unordered_map< int, std::vector< int > > successors
Map from vertex indices to their children.
Definition graph_class.h:166
GraphClass()
Constructor for GraphClass.
Definition graph_class.cpp:12
Action getAction(int idx)
Get the action of a vertex.
Definition graph_class.cpp:65
virtual void printEdges()
Print the all edges in the graph via stdout.
Definition graph_class.cpp:91
int getNumVertices()
Retrieve the total number of vertices in the graph, computed as the size of the vertices vector.
Definition graph_class.cpp:16
void printIncomingEdges(int idx)
Print the edges leading to a vertex via stdout.
Definition graph_class.cpp:79
virtual void init(State s)
Initialize the graph by adding the root vertex (idx = 0) and setting g(idx) = 0.
Definition graph_class.cpp:111
double getGValue(int idx)
Get the g-value of a vertex.
Definition graph_class.cpp:98
std::unordered_map< int, double > g_values
Map from vertex indices to their costs (g-values)
Definition graph_class.h:169
std::vector< int > getSuccessors(int idx)
Get the children of a vertex.
Definition graph_class.cpp:61
virtual int getPredecessor(int idx)
Get the parent of a vertex.
Definition graph_class.cpp:54
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...
Definition graph_class.cpp:63
void printVertex(State s)
Print the state information via stdout.
Definition graph_class.cpp:67
std::unordered_map< int, std::vector< int > > edges
Map from vertex indices to their parent(s)
Definition graph_class.h:163
void removeEdge(int idx1, int idx2)
Remove an edge of the graph.
Definition graph_class.cpp:37
virtual void addEdge(int idx1, int idx2)
Add a new edge to the graph.
Definition graph_class.cpp:23
State getVertex(int index)
Retrieve the state stored at a particular index in the graph.
Definition graph_class.cpp:14
void updateGValue(int idx, double val)
Update the g-value of a vertex and propogate to all its successors.
Definition graph_class.cpp:104
std::unordered_map< int, State > vertices
Map from vertex indices to corresponding states.
Definition graph_class.h:157
std::unordered_map< int, Action > actions
Map from vertex indices to the actions leading to those vertices.
Definition graph_class.h:160
Define action with Eigen data.
Definition planning_utils.h:218
Define state with Eigen data.
Definition planning_utils.h:184