forked from makrell38/CPSC8380
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
193 lines (164 loc) · 5.55 KB
/
test.cpp
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <fstream>
#include <vector>
#include <string>
#include <sstream>
#include "graph.h"
#include "testAlgorithms.h"
#include "edd_ip.h"
#include "edd_app.h"
#include "approximate.h"
#include <chrono>
using namespace std;
void printData(vector<vector<string> > data){
vector<string> row;
for(std::vector<vector<string> >::size_type it = 0; it != data.size(); ++it){
row.clear();
row = data[it];
for(std::vector<string>::size_type it = 0; it != row.size(); ++it)
cout<<row[it]<<" ";
cout<<endl;
}
}
int main(){
/*
// read in data
vector<vector<string> > data;
data = readInData("dataSet/aws_edge_locations_na.csv");
vector<vector<string> > cacheLocations;
cacheLocations = readInData("dataSet/aws_cache_locations_na.csv");
// create graph
// cloud node = 0
// cacheLocations start at 1
// data locations are after cacheLocations to end of graph
int size = data.size() + cacheLocations.size();
Graph *g = new Graph(size);
g->dLimit = 2;
g->delta = 9;
cout<<g->v<<endl;
// add edges from cachelocations to edge servers in the same region
for(int i=0; i < cacheLocations.size(); i++){
for(int j=0; j < data.size(); j++){
if(cacheLocations[i][8] == data[j][8]){
g->addEdge(i+1, cacheLocations.size()+j+1, 1);
}
}
}
// add cloud node edge to each edge server with weight delta
for(int i=1; i<=size; i++){
g->addEdge(0, i, g->delta);
}
// initialize all S to be 0
g->S = new int[g->v];
for(int i=0; i<g->v; i++){
g->S[i] = 0;
}
// set target nodes
// done randomly here
int num_dest_servers = 10;
int count = 0;
while(count < num_dest_servers){
int loc = rand() % size +1;
if(g->S[loc] == 0)
g->S[loc] = 1;
count++;
}
g->setR(num_dest_servers);
cout<<num_dest_servers<<endl;
//g->printGraph();
*/
Graph *g = new Graph(10);
g->delta = 9;
g->dLimit = 2;
g->addEdge(1,2,1);
g->addEdge(1,5,1);
g->addEdge(3,5,1);
g->addEdge(2,3,1);
g->addEdge(3,4,1);
g->addEdge(3,6,1);
g->addEdge(8,5,1);
g->addEdge(9,5,1);
g->addEdge(4,6,1);
g->addEdge(6,7,1);
g->addEdge(9,10,1);
g->addEdge(7,10,1);
for(int i=0;i<=g->v; i++){
g->addEdge(0,i,g->delta);
}
g->S[0] = 1;
g->S[3] = 1;
g->S[4] = 1;
g->S[5] = 1;
g->S[8] = 1;
g->S[9] = 1;
g->setR(6);
ofstream myfile;
cout<<"Fandom algorithm output:"<<endl;
myfile.open("randomOutputTime.txt", fstream::app);
auto startRand = std::chrono::high_resolution_clock::now();
int costRand = random(g);
auto stopRand = std::chrono::high_resolution_clock::now();
auto durationRand = std::chrono::duration_cast<std::chrono::microseconds>(stopRand - startRand);
//cout<<costRand<<endl;
myfile<<g->v<<" "<<durationRand.count()<<"\n";
myfile.close();
cout<<endl<<endl;
cout<<"Greedy algorithm output:"<<endl;
myfile.open("greedyOutputTime.txt", fstream::app);
auto startGreedy = std::chrono::high_resolution_clock::now();
int costGreedy = greedy(g);
auto stopGreedy = std::chrono::high_resolution_clock::now();
auto durationGreedy = std::chrono::duration_cast<std::chrono::microseconds>(stopGreedy - startGreedy);
myfile<<g->v<<" "<<durationGreedy.count()<<"\n";
myfile.close();
cout<<endl<<endl;
myfile.open("fullOutputTime.txt", fstream::app);
auto startFull = std::chrono::high_resolution_clock::now();
cout<<"Full optimal algorithm output:"<<endl;
full(g);
auto stopFull = std::chrono::high_resolution_clock::now();
auto durationFull = std::chrono::duration_cast<std::chrono::microseconds>(stopFull - startFull);
myfile<<g->v<<" "<<durationFull.count()<<"\n";
myfile.close();
cout<<endl<<endl;
cout<<"CMST algorithm output:"<<endl;
Graph *Tms = new Graph(g->v);
auto startEdda = std::chrono::high_resolution_clock::now();
Tms->graph = CMST(g);
//Tms->printGraph();
Tms->printPath();
cout<<endl<<endl;
cout<<"EDDA algorithm output:"<<endl;
Graph *Tedda = new Graph(g->v);
Tedda->graph = EDDA(g, Tms->graph);
//Tedda->printGraph();
Tedda->printPath();
int costTedda = Tedda->computeCost();
auto stopEdda = std::chrono::high_resolution_clock::now();
auto durationEdda = std::chrono::duration_cast<std::chrono::microseconds>(stopEdda - startEdda);
//cout<<costTedda<<endl;
myfile.open("TeddaOutput.txt", fstream::app);
myfile<<g->v<<" "<<costTedda<<"\n";
myfile.close();
cout<<endl<<endl;
cout<<"k-LCA algorithm output:"<<endl;
myfile.open("klcaOutput.txt", fstream::app);
auto startKlca = std::chrono::high_resolution_clock::now();
vector<edge> klca = kLCA(g, g->numDestServers);
printEdges(klca);
cout<<endl<<endl;
Graph *g2 = new Graph(g->v);
for(std::vector<edge>::size_type it = 0; it != klca.size(); ++it){
g2->graph[klca[it].v1][klca[it].v2] = klca[it].weight;
}
Graph *something = new Graph(g->v);
cout<<"EDDA on k-LCA algorithm output:"<<endl;
something->graph = EDDA(g, g2->graph);
something->printPath();
int costklca = something->computeCost();
auto stopKlca = std::chrono::high_resolution_clock::now();
auto durationKlca = std::chrono::duration_cast<std::chrono::microseconds>(stopKlca - startKlca);
myfile<<g->v<<" "<<costklca<<"\n";
myfile.close();
cout<<endl<<endl;
return 0;
}