-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
94 lines (73 loc) · 3.36 KB
/
main.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
#include <iostream>
#include <fstream>
#include "Level.h"
#include "Simulator.h"
using namespace std;
int main(int argc, char **argv) {
// get input file name as a parameter of the program
string inputFilename = argv[1];
// get output file name
string delimiter = ".";
string outputFilename = inputFilename.substr(0, inputFilename.find(delimiter)) + ".output";
string outputRecordFilename = inputFilename.substr(0, inputFilename.find(delimiter)) + "_record.output";
string outputDetailedFilename = inputFilename.substr(0, inputFilename.find(delimiter)) + "_detailed.output";
// open output file
ofstream outputFile;
outputFile.open(outputFilename);
ofstream outputRecordFile;
outputRecordFile.open(outputRecordFilename);
ofstream outputDetailedFile;
outputDetailedFile.open(outputDetailedFilename);
vector<Flow> tmpFlows;
vector<Packet> tmpPackets;
readFile(inputFilename, tmpFlows, tmpPackets);
Simulator simulator(tmpFlows, tmpPackets);
outputFile << "Packet Num: " << simulator.numOfPackets() << endl;
// output file name
vector<vector<Packet>> flows(static_cast<unsigned long>(simulator.numOfFlows()));
for (int cycle = 0, packetNum = 0; packetNum < simulator.numOfPackets(); cycle++) {
vector<Packet> packets = simulator.runRound();
if (packets.empty()) continue;
for (auto packet: packets) {
// packet.setThryDepartureRound(cycle);
flows[packet.getFlowId() - 1].push_back(packet);
packetNum++;
}
}
//output to graph python program
for (int i = 0; i < simulator.numOfFlows(); i++) {
outputFile << "flow " << i + 1 << endl;
for (auto packet: flows[i]) {
outputFile << packet.getPacketOrder() << " ";
outputFile << packet.getThryDepartureRound() << " ";
outputFile << packet.getActlDepartureRound() << " ";
outputFile << packet.getDepartureCycle() << endl;
}
}
//output to detailed file
for (int i = 0; i < simulator.numOfFlows(); i++) {
outputDetailedFile << "flow " << i + 1 << endl;
outputDetailedFile << "Packet" << "\t" << "ArrCycle" << "\t";
outputDetailedFile << "ArrRound" << "\t";
outputDetailedFile << "ThryDepRnd" << "\t" << "ActlDepRnd" << "\t";
outputDetailedFile << "DepCycle" << "\t" << "InsLvl" << "\t";
outputDetailedFile << "InsFifo" << "\t" << "PosInFifo" << endl;
for (auto packet: flows[i]) {
outputDetailedFile << packet.getPacketOrder() << "\t\t";
outputDetailedFile << packet.getArriveCycle() << "\t\t\t";
outputDetailedFile << packet.getArriveRound() << "\t\t\t";
outputDetailedFile << packet.getThryDepartureRound() << "\t\t\t";
outputDetailedFile << packet.getActlDepartureRound() << "\t\t\t";
outputDetailedFile << packet.getDepartureCycle() << "\t\t\t";
outputDetailedFile << packet.getInsertLevel() << "\t\t";
outputDetailedFile << packet.getInsertFifo() << "\t\t";
outputDetailedFile << packet.getFifoPosition() << endl;
}
}
vector<int> packetNumRecord = simulator.getPacketNumRecord();
for (int i = 0; i < packetNumRecord.size(); i++) {
outputRecordFile << i << " ";
outputRecordFile << packetNumRecord[i] << endl;
}
return 0;
}