-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
265 lines (213 loc) · 6.69 KB
/
Copy pathmain.cpp
File metadata and controls
265 lines (213 loc) · 6.69 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#define DEBUG_DESTRUCTOR
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include "Headers/Device.h"
#include "Headers/Schedule.h"
#include "Headers/DynamicScheduler.h"
#include "Headers/LeveledDag.h"
#include "DagGen/Headers/DagGen.h"
using namespace std;
void GenerateFullDAGList(vector<DagGen*>& dags, int number);
void InitalizeDAGs(vector<DagGen*>& dags, int number);
void GenerateGraphic(Schedule*, string = "",bool colorOP = false);
string GetDagName(string N);
int main()
{
srand(time(NULL));
vector<DagGen*> startingPoint;
vector<DagGen*> FullDagList;
DMFB* board = new DMFB();
Schedule* CritscheduleStatic = new Schedule(board);
Schedule* CritscheduleDynamic = new Schedule(board);
Schedule* FIFOschedule = new Schedule(board);
DynamicScheduler Scheduler;
vector<LeveledDag*> CritPathStaticLEVELDAGS;
vector<LeveledDag*> CritPathDynamicLEVELDAGS;
vector<LeveledDag*> lg2;
InitalizeDAGs(startingPoint,256);
GenerateFullDAGList(FullDagList,256);
int dagCounter=0;
for(unsigned int i=0; i < startingPoint.size(); ++i)
{
char buffer[20];
sprintf(buffer,"%i",i);
// cout<<i<<endl;
LeveledDag* LDag= new LeveledDag(startingPoint[i],buffer,i,i,dagCounter,true);
LeveledDag* LDag2= new LeveledDag(startingPoint[i],buffer,i,i,dagCounter,true);
CritPathStaticLEVELDAGS.push_back(LDag);
CritPathDynamicLEVELDAGS.push_back(LDag2);
dagCounter++;
}
//static
Scheduler.schedule(CriticalPath, CritscheduleStatic,CritPathStaticLEVELDAGS);
Scheduler.schedule(CriticalPath,CritscheduleDynamic,CritPathDynamicLEVELDAGS);
GenerateGraphic(CritscheduleDynamic, "CritDagDynamicRd1.html");
GenerateGraphic(CritscheduleStatic, "CritDagStaticRd1.html");
vector<LeveledDag*> FullList;
vector<LeveledDag*> FullListDup;
for(unsigned int i=0; i < FullDagList.size(); ++i)
{
char buffer[20];
sprintf(buffer,"%i",i);
LeveledDag* LDag= new LeveledDag(FullDagList[i],buffer,i,i,dagCounter,true);
LeveledDag* LDagDup= new LeveledDag(FullDagList[i],buffer,i,i,dagCounter,true);
FullList.push_back(LDag);
FullListDup.push_back(LDagDup);
dagCounter++;
}
unsigned int timeLimit = CritscheduleDynamic->schduledNodes.size();
vector<int> dagstoberun;
unsigned int StaticEndtime;
//add dag dynamically.
for(unsigned int timestep = 1; timestep<timeLimit; ++timestep )
{
double prob = (double)rand()/(double)RAND_MAX;
// cout<<prob <<endl;
if ( prob >= .85){
int dagNum = rand() % FullDagList.size();
cout<< "Adding Dag at time: "<< timestep<<endl;
Scheduler.ScheduleDag(CritscheduleDynamic,FullList[dagNum],timestep);
dagstoberun.push_back(dagNum);
}
}
// secondRoundofStaticDags
unsigned int StartingPoint = timeLimit;
for(unsigned int i = 0 ; i < dagstoberun.size(); ++i)
{
cout<<dagstoberun[i]<<endl;
Scheduler.ScheduleDag(CritscheduleStatic,FullListDup[dagstoberun[i]],StartingPoint);
}
GenerateGraphic(CritscheduleDynamic, "CritDagDynamicRd2.html");
GenerateGraphic(CritscheduleStatic, "CritDagStaticRd2.html");
if(CritscheduleStatic->isValid())
cout<<"Valid"<<endl;
else
cout<<"INVALID"<<endl;
if(CritscheduleDynamic->isValid())
cout<<"Valid"<<endl;
else
cout<<"INVALID"<<endl;
cout<<"IT IS FINISHED!"<<endl;
return 0;
}
void GenerateFullDAGList(vector<DagGen*>& dags, int number)
{
string PathPrefix = "Inputs\\Remia";
string PathPosFix = "_256.dag";
char buffer[50];
for(int i =1; i< number; ++i) {
sprintf(buffer,"Inputs\\Remia%i_256.dag",i);
dags.push_back(new DagGen(buffer));
}
}
void InitalizeDAGs(vector<DagGen*>& dags, int number)
{
string PathPrefix = "Inputs\\Remia";
string PathPosFix = "_256.dag";
char buffer[50];
//int i=62;
//for(int i =1; i< number; ++i) {
// sprintf(buffer,"Inputs\\Remia%i_256.dag",i);
//dags.push_back(new DagGen(buffer));
dags.push_back(new DagGen("Inputs\\Remia1_256.dag"));
dags.push_back(new DagGen("Inputs\\Remia62_256.dag"));
dags.push_back(new DagGen("Inputs\\Remia128_256.dag"));
dags.push_back(new DagGen("Inputs\\Remia8_256.dag"));
dags.push_back(new DagGen("Inputs\\Remia16_256.dag"));
dags.push_back(new DagGen("Inputs\\Remia32_256.dag"));
dags.push_back(new DagGen("Inputs\\Remia13_256.dag"));
dags.push_back(new DagGen("Inputs\\Remia71_256.dag"));
dags.push_back(new DagGen("Inputs\\Remia205_256.dag"));
// }
}
string GetDagName(string N)
{
if (N.find("N") ==-1)
{
cerr<<"Need to run schedul through rename Labels."<<endl;
return "error";
}
int d = N.find('D');
int n = N.find('N');
return N.substr(d,n-d);
}
string GetFriendlyName( string N)
{
if (N.find("N") ==-1)
{
cerr<<"Need to run schedul through rename Labels."<<endl;
return "error";
}
return "Node_" + N.substr(N.find("N")+2);
}
string GetOpName(VertexType type)
{
switch (type) {
case DETECT:
case HEAT:
case MIX:
case SPLIT:
return "SPLIT";
case STORE:
return "STORE";
case OUTPUT:
case WASTE:
case DISPENSE:
return "OUTPUT";
default:
return "UNKNOWN";
}
}
void GenerateGraphic(Schedule* schedule, string fileName,bool colorOP)
{
map<string,string> dagColors;
string colors[] = {"0099FF","9933CC","FF9933","FF6699","FFCCFF","CCFF66", "66CC00", "CC6600","B35F5F","60C1D9", "99DD22", "F69C42","F642DB","AC52E9","A2E16A"};
int maxColors=15;
int nextColor=0;
if(schedule == NULL)
return;
std:: ostream& out = (fileName != "") ? *(new std::ofstream(fileName.c_str())) : std::cout;
out<<"\t<TABLE ALIGN=\"LEFT\">"<<endl;
for(unsigned int timeStep = 0; timeStep< schedule->schduledNodes.size(); ++timeStep) {
out<<"\t\t<TR>"<<endl;
out <<"\t\t\t<TD>"<<timeStep<< "</TD>"<<endl;
for(unsigned int nodeIndex =0 ; nodeIndex < schedule->schduledNodes[timeStep].size(); ++nodeIndex ) {
out<<"\t\t\t<TD";
string label = schedule->schduledNodes[timeStep][nodeIndex]->label;
string dagName = GetDagName(label);
//cout<<dagName<<endl;
string friendlyName = GetFriendlyName(label);
string dagColor = "";
if(!colorOP)
{
if (dagColors.find(dagName) != dagColors.end()) {
map<string,string>::iterator mycolor = dagColors.find(dagName);
dagColor = mycolor->second;
}
else{
dagColor = colors[(nextColor++ % maxColors)];
dagColors.insert(pair<string,string>(dagName, dagColor));
}
}
else{
string opName = GetOpName (schedule->schduledNodes[timeStep][nodeIndex]->type);
if (dagColors.find(opName) != dagColors.end()) {
map<string,string>::iterator mycolor = dagColors.find(opName);
dagColor = mycolor->second;
}
else{
dagColor = colors[(nextColor++ % maxColors)];
dagColors.insert(pair<string,string>(opName, dagColor));
}
}
out<<" BGCOLOR=\""<< dagColor << "\">" << label << "</TD>"<<endl;
}
out<<"\t\t</TR>"<<endl;
}
out<<"\t</TABLE>"<<endl;
if (&out!=&std::cout)
delete(&out);
}