Skip to content

Commit ebb91cd

Browse files
author
xinoip
committed
critical path founding
1 parent a273556 commit ebb91cd

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"environment": [],
1616
"externalConsole": false,
1717
"MIMode": "gdb",
18-
"preLaunchTask": "build debug",
18+
//"preLaunchTask": "build debug",
1919
"setupCommands": [
2020
{
2121
"description": "Enable pretty-printing for gdb",

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
"cinttypes": "cpp",
6666
"typeinfo": "cpp",
6767
"variant": "cpp",
68-
"qstyleoptiongraphicsitem": "cpp"
68+
"qstyleoptiongraphicsitem": "cpp",
69+
"optional": "cpp",
70+
"shared_mutex": "cpp"
6971
}
7072
}

currentcircuit.cpp

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ void CurrentCircuit::topological_sort() {
5959
if (visited[i] == false)
6060
topological_sort_helper(circ.elements[i].elementName, visited, stack);
6161

62+
std::vector<std::pair<std::string, int>> top_list {};
63+
6264
while (stack.empty() == false) {
6365
int vertex = stack.top();
6466
auto& element = circ.elements[vertex];
@@ -89,8 +91,74 @@ void CurrentCircuit::topological_sort() {
8991

9092
element.arrivalTime += max_arrival + element.delay;
9193

92-
printf("%s(d:%d)(a:%d)\n", element.elementName.c_str(), element.delay, element.arrivalTime);
94+
// if(element.isGate()) {
95+
top_list.push_back({element.elementName, element.arrivalTime});
96+
// }
97+
// printf("%s(d:%d)(a:%d)\n", element.elementName.c_str(), element.delay, element.arrivalTime);
9398
stack.pop();
9499
}
100+
101+
printf("Topological order: ");
102+
for(auto& element : top_list) {
103+
printf("%s[%d], ", element.first.c_str(), element.second);
104+
}
105+
printf("\n");
106+
107+
printf("Critical path:\n");
108+
int slowest_output_index = 0;
109+
for(int i = 0, current_max = 0; i < top_list.size(); i++) {
110+
auto& element = top_list[i];
111+
if(element.second > current_max) {
112+
current_max = element.second;
113+
slowest_output_index = i;
114+
}
115+
}
116+
printf("%s[%d]\n", top_list[slowest_output_index].first.c_str(), top_list[slowest_output_index].second);
117+
while(true) {
118+
std::vector<CircuitElement> predecessor_elements;
119+
// get pred elements
120+
for(auto& pair : adj) {
121+
auto& second = pair.second;
122+
for(auto& connection : second) {
123+
if(connection.elementName == top_list[slowest_output_index].first) {
124+
predecessor_elements.push_back(pair.first);
125+
}
126+
}
127+
}
128+
if(predecessor_elements.empty()) {
129+
break;
130+
}
131+
// hack for dirty ugly datastructure to get arrival times..
132+
for(auto& pred : predecessor_elements) {
133+
for(auto& el : circ.elements) {
134+
if(el.elementName == pred.elementName) {
135+
pred.arrivalTime = el.arrivalTime;
136+
break;
137+
}
138+
}
139+
}
140+
// determine slowest pred
141+
int slowest_pred_index = 0;
142+
int slowest_pred_arrival_time = 0;
143+
for(int i = 0; i < predecessor_elements.size(); i++) {
144+
auto& pred = predecessor_elements[i];
145+
if(pred.arrivalTime > slowest_pred_arrival_time) {
146+
slowest_pred_arrival_time = pred.arrivalTime;
147+
slowest_pred_index = i;
148+
}
149+
}
150+
// find slowest pred in topological sorted list
151+
CircuitElement& slowest_pred = predecessor_elements[slowest_pred_index];
152+
int found_index = -1;
153+
for(int i = 0; i < top_list.size(); i++) {
154+
if(top_list[i].first == slowest_pred.elementName) {
155+
found_index = i;
156+
break;
157+
}
158+
}
159+
printf("%s[%d] \n", slowest_pred.elementName.c_str(), slowest_pred.arrivalTime);
160+
slowest_output_index = found_index;
161+
}
162+
// printf("DEBUG slowest output index %d\n", slowest_output_index);
95163
printf("\n");
96164
}

0 commit comments

Comments
 (0)