24 #include <unordered_map>
28 #include "lab_graphs_random.h"
31 typedef std::unordered_map<Vertex, Edge> EdgeMap;
32 typedef std::unordered_map<Vertex, EdgeMap> VertexMap;
33 typedef std::unordered_map<Vertex, std::string> VertexLabelMap;
34 typedef std::unordered_map<Vertex, std::string> VertexNameMap;
56 Graph(
bool isWeighted);
64 Graph(
bool isWeighted,
int numVertices,
unsigned long seed);
216 void savePNG(
string title)
const;
224 VertexLabelMap vertexLabels;
227 VertexNameMap vertexNames;
235 size_t vertexCounter;
249 void assertExists(Vertex v,
string functionName)
const;
258 void assertConnected(Vertex u, Vertex v,
string functionName)
const;
265 void error(
string message)
const;
bool insertEdge(Vertex u, Vertex v)
Inserts an edge between two vertices.
Definition: graph.cpp:277
Represents a graph of vertices and edges and allows basic operations to be performed on it...
Definition: graph.h:49
int getEdgeWeight(Vertex u, Vertex v) const
Gets the weight of an edge between two vertices.
Definition: graph.cpp:224
vector< Vertex > getVertices() const
Gets all vertices in the graph.
Definition: graph.cpp:158
void setVertexLabel(Vertex v, string label)
Labels a vertex with a string.
Definition: graph.cpp:173
void removeVertex(Vertex v)
Removes a given vertex from the graph.
Definition: graph.cpp:252
Represents an edge in a graph; used by the Graph class.
Definition: edge.h:22
Vertex insertVertex(string label="")
Inserts a new vertex into the graph and labels it.
Definition: graph.cpp:240
Provides random functionality per a given seed.
Definition: lab_graphs_random.h:22
string getVertexName(Vertex v) const
Gets the name of a vertex.
Definition: graph.cpp:514
void snapshot()
Saves a snapshot of the graph to file.
Definition: graph.cpp:398
void setEdgeLabel(Vertex u, Vertex v, string label)
Sets the edge label of an edge between vertices u and v.
Definition: graph.cpp:195
vector< Vertex > getAdjacent(Vertex v) const
Gets all adjacent vertices to the parameter vertex.
Definition: graph.cpp:85
void setEdgeWeight(Vertex u, Vertex v, int weight)
Sets the weight of an edge between two vertices.
Definition: graph.cpp:317
void print() const
Prints the graph to stdout.
Definition: graph.cpp:410
Vertex getStartingVertex() const
Returns one vertex in the graph.
Definition: graph.cpp:103
string getEdgeLabel(Vertex u, Vertex v) const
Gets the edge label of an edge between vertices u and v.
Definition: graph.cpp:210
void removeEdge(Vertex u, Vertex v)
Removes an edge between two vertices.
Definition: graph.cpp:302
void setVertexName(Vertex v, string name)
Creates a name for a vertex.
Definition: graph.cpp:502
void savePNG(string title) const
Saves the graph as a PNG image.
Definition: graph.cpp:440
Graph(bool isWeighted)
Constructor to create an empty graph.
Definition: graph.cpp:15
Edge getEdge(Vertex u, Vertex v) const
Gets an edge between two vertices.
Definition: graph.cpp:146
vector< Edge > getEdges() const
Gets all the edges in the graph.
Definition: graph.cpp:112
string getVertexLabel(Vertex v) const
Gets the label of a vertex.
Definition: graph.cpp:184
Definition and (minimal) implementation of an edge class.
void initSnapshot(string title)
Creates a name for snapshots of the graph.
Definition: graph.cpp:388