1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#include "stdafx.h"
#include "Dijkstra.h"
Graph::Graph(): dest(NULL)
{
}
void Graph::SelectGraph(int i)
{
if(i==1)
DoGraph1();
else
DoGraph2();
}
void Graph::DoGraph1()
{
cout << "Graph 1 Analysis: " << endl;
nodes.clear();
edges.clear();
Node* a = new Node('a', nodes);
Node* b = new Node('b', nodes);
Node* c = new Node('c', nodes);
Node* d = new Node('d', nodes);
Node* e = new Node('e', nodes);
Node* f = new Node('f', nodes);
Node* g = new Node('g', nodes);
Edge* e1 = new Edge(a,c,1,edges);
Edge* e2 = new Edge(a,d,2,edges);
Edge* e3 = new Edge(b,c,2,edges);
Edge* e4 = new Edge(c,d,1,edges);
Edge* e5 = new Edge(b,f,3,edges);
Edge* e6 = new Edge(c,e,3,edges);
Edge* e7 = new Edge(e,f,2,edges);
Edge* e8 = new Edge(d,g,1,edges);
Edge* e9 = new Edge(g,f,1,edges);
a->distanceFromStart = 0; //Set start node
dest = f;
}
void Graph::DoGraph2()
{
cout << "Graph 2 Analysis: " << endl;
nodes.clear();
edges.clear();
Node* a = new Node('a', nodes);
Node* b = new Node('b', nodes);
Node* c = new Node('c', nodes);
Node* d = new Node('d', nodes);
Node* e = new Node('e', nodes);
Node* f = new Node('f', nodes);
Node* g = new Node('g', nodes);
Edge* e1 = new Edge(a,c,1,edges);
Edge* e2 = new Edge(a,d,3,edges);
Edge* e3 = new Edge(b,c,2,edges);
Edge* e4 = new Edge(c,d,1,edges);
Edge* e5 = new Edge(b,f,3,edges);
Edge* e6 = new Edge(c,e,3,edges);
Edge* e7 = new Edge(e,f,2,edges);
Edge* e8 = new Edge(d,g,1,edges);
Edge* e9 = new Edge(g,f,1,edges);
a->distanceFromStart = 0; //Set start node
dest = f;
}
void Graph::DoGraph3()
{
cout << "Graph 3 Analysis: " << endl;
nodes.clear();
edges.clear();
Node* a = new Node('a', nodes);
Node* b = new Node('b', nodes);
Node* c = new Node('c', nodes);
Node* d = new Node('d', nodes);
Node* e = new Node('e', nodes);
Node* f = new Node('f', nodes);
Node* g = new Node('g', nodes);
Node* h = new Node('h', nodes);
Node* i = new Node('i', nodes);
Node* j = new Node('j', nodes);
Node* l = new Node('l', nodes);
Node* m = new Node('m', nodes);
Node* n = new Node('n', nodes);
Node* o = new Node('o', nodes);
Node* p = new Node('p', nodes);
Edge* e1 = new Edge(a,c,1,edges);
Edge* e2 = new Edge(a,d,3,edges);
Edge* e3 = new Edge(b,c,2,edges);
Edge* e4 = new Edge(c,d,1,edges);
Edge* e5 = new Edge(b,f,3,edges);
Edge* e6 = new Edge(c,e,3,edges);
Edge* e7 = new Edge(e,f,2,edges);
Edge* e8 = new Edge(d,g,1,edges);
Edge* e9 = new Edge(g,f,1,edges);
Edge* e10 = new Edge(f,h,1,edges);
Edge* e11 = new Edge(f,i,4,edges);
Edge* e12 = new Edge(h,i,2,edges);
Edge* e13 = new Edge(i,j,3,edges);
Edge* e14 = new Edge(h,m,10,edges);
Edge* e15 = new Edge(j,m,1,edges);
Edge* e16 = new Edge(j,l,1,edges);
Edge* e17 = new Edge(m,n,2,edges);
Edge* e18 = new Edge(l,p,7,edges);
Edge* e19 = new Edge(n,o,1,edges);
Edge* e20 = new Edge(o,p,1,edges);
a->distanceFromStart = 0; //Set start node
dest = o;
}
//Testing
void Graph::PrintNodes()
{
cout << "Size of Nodes: " << nodes.size() << endl;
cout << "Size of Edges: " << edges.size() << endl;
cout << "Nodes of Graph: " << endl;
for(int i=0; i<nodes.size(); ++i)
{
cout << nodes.at(i)->id << " ";
}
cout << endl;
}
|