|
lab_ml
Lazy Machine Learning
|
Represents a graph; used by the GraphTools class. More...
#include "graph.h"
Collaboration diagram for Graph:Public Member Functions | |
| Graph (bool weighted) | |
| Constructor to create an empty graph. More... | |
| Graph (bool weighted, bool directed) | |
| Constructor to create an empty graph. More... | |
| Graph (bool weighted, int numVertices, unsigned long seed) | |
| Constructor to create a random, connected graph. More... | |
| vector< Vertex > | getAdjacent (Vertex source) const |
| Gets all adjacent vertices to the parameter vertex. More... | |
| Vertex | getStartingVertex () const |
| Returns one vertex in the graph. More... | |
| vector< Vertex > | getVertices () const |
| Gets all vertices in the graph. More... | |
| Edge | getEdge (Vertex source, Vertex destination) const |
| Gets an edge between two vertices. More... | |
| vector< Edge > | getEdges () const |
| Gets all the edges in the graph. More... | |
| Vertex | setVertexLabel (Vertex v, string label) |
| Set label to Vertex v. More... | |
| string | getVertexLabel (Vertex v) const |
| Set label to Vertex v. More... | |
| Edge | setEdgeLabel (Vertex source, Vertex destination, string label) |
| Sets the edge label of the edge between vertices u and v. More... | |
| string | getEdgeLabel (Vertex source, Vertex destination) const |
| Gets the edge label of the edge between vertices u and v. More... | |
| int | getEdgeWeight (Vertex source, Vertex destination) const |
| Gets the weight of the edge between two vertices. More... | |
| void | insertVertex (Vertex v) |
| Inserts a new vertex into the graph and initializes its label as "". More... | |
| Vertex | removeVertex (Vertex v) |
| Removes a given vertex from the graph. More... | |
| bool | insertEdge (Vertex source, Vertex destination) |
| Inserts an edge between two vertices. More... | |
| Edge | removeEdge (Vertex source, Vertex destination) |
| Removes the edge between two vertices. More... | |
| Edge | setEdgeWeight (Vertex source, Vertex destination, int weight) |
| Sets the weight of the edge between two vertices. More... | |
| void | initSnapshot (string title) |
| Creates a name for snapshots of the graph. More... | |
| void | snapshot () |
| Saves a snapshot of the graph to file. More... | |
| void | print () const |
| Prints the graph to stdout. More... | |
| void | savePNG (string title) const |
| Saves the graph as a PNG image. More... | |
| Vertex | insertVertexByLabel (string label) |
| Untilities for lab_ml. More... | |
| Vertex | getVertexByLabel (string label) const |
| Gets a vertex based on the label of a vertex. More... | |
Private Member Functions | |
| bool | assertVertexExists (Vertex v, string functionName) const |
| Returns whether a given vertex exists in the graph. More... | |
| bool | assertEdgeExists (Vertex source, Vertex destination, string functionName) const |
| Returns whether thee edge exists in the graph. More... | |
| void | error (string message) const |
| Prints a graph error and quits the program. More... | |
Represents a graph; used by the GraphTools class.
| Graph::Graph | ( | bool | weighted | ) |
Constructor to create an empty graph.
| weighted | - specifies whether the graph is a weighted graph or not |
| Graph::Graph | ( | bool | weighted, |
| bool | directed | ||
| ) |
Constructor to create an empty graph.
| weighted | - specifies whether the graph is a weighted graph or not |
| directed | - specifies whether the graph is directed |
| Graph::Graph | ( | bool | weighted, |
| int | numVertices, | ||
| unsigned long | seed | ||
| ) |
Constructor to create a random, connected graph.
| weighted | - specifies whether the graph is a weighted graph or not |
| numVertices | - the number of vertices the graph will have |
| seed | - a random seed to create the graph with |
Gets all adjacent vertices to the parameter vertex.
| source | - vertex to get neighbors from |
| Vertex Graph::getStartingVertex | ( | ) | const |
Returns one vertex in the graph.
This function can be used to find a random vertex with which to start a traversal.
Gets all vertices in the graph.
Gets an edge between two vertices.
| source | - one vertex the edge is connected to |
| destination | - the other vertex the edge is connected to |
Gets all the edges in the graph.
Set label to Vertex v.
Set label to Vertex v.
Sets the edge label of the edge between vertices u and v.
| source | - one vertex the edge is connected to |
| destination | - the other vertex the edge is connected to |
Gets the edge label of the edge between vertices u and v.
| source | - one vertex the edge is connected to |
| destination | - the other vertex the edge is connected to |
Gets the weight of the edge between two vertices.
| source | - one vertex the edge is connected to |
| destination | - the other vertex the edge is connected to |
| void Graph::insertVertex | ( | Vertex | v | ) |
Inserts a new vertex into the graph and initializes its label as "".
| v | - the name for the vertex |
Removes a given vertex from the graph.
| v | - the vertex to remove |
Inserts an edge between two vertices.
A boolean is returned for use with the random graph generation. Hence, an error is not thrown when it fails to insert an edge.
| source | - one vertex the edge is connected to |
| destination | - the other vertex the edge is connected to |
Removes the edge between two vertices.
| source | - one vertex the edge is connected to |
| destination | - the other vertex the edge is connected to |
Sets the weight of the edge between two vertices.
| source | - one vertex the edge is connected to |
| destination | - the other vertex the edge is connected to |
| weight | - the weight to set to the edge |
| void Graph::initSnapshot | ( | string | title | ) |
Creates a name for snapshots of the graph.
| title | - the name to save the snapshots as |
| void Graph::snapshot | ( | ) |
Saves a snapshot of the graph to file.
initSnapshot() must be run first.
| void Graph::print | ( | ) | const |
Prints the graph to stdout.
| void Graph::savePNG | ( | string | title | ) | const |
Saves the graph as a PNG image.
| title | - the filename of the PNG image |
Gets a vertex based on the label of a vertex.
Returns whether a given vertex exists in the graph.
| v | - the vertex to check |
| functionName | - the name of the calling function to return in the event of an error |
|
private |
Returns whether thee edge exists in the graph.
| source | - one vertex |
| destination | - another vertex |
| functionName | - the name of the calling function to return in the event of an error |
|
private |
Prints a graph error and quits the program.
The program is exited with a segfault to provide a stack trace.
| message | - the error message that is printed |