Adaptive Traffic Simulator
Loading...
Searching...
No Matches
Header1.h
Go to the documentation of this file.
1
2#pragma once
3#include <cmath>
4#include <iostream>
5#include <list>
6#include <queue>
7#include <stack>
8#include <string>
9
10using namespace std;
11
13
18 float redtimer;
19 float pa, pb;
21 greentimer = 0;
22 minGreenTime = 2; // Default Tg = 2 steps
24 maxGreenTime = 8; // Default Tmax = 10 steps
25 pa = 10;
26 pb = 7; // Default threshold
27 redtimer = 0;
28 }
29
30 void Timer(bool state, float time) {
31 if (state == true) {
32 greentimer += time;
33 redtimer = 0;
34 } else {
35 redtimer += time;
36 }
37 }
38 float starvationCost() const { return redtimer * 3.5f; }
39 void turnGreen(bool &state) {
40 state = true;
41 greentimer = 0;
42 }
43 void turnRed(bool &state) {
44 state = false;
45 redtimer = 0;
46 }
47
48 bool canSwitch(int currentQueue, int maxOtherQueue) const {
50 return false;
51
52 if (mustSwitch())
53 return true;
54
55 return (currentQueue < maxOtherQueue) || (starvationCost() > 12.0f);
56 }
57 bool mustSwitch() const { return greentimer >= maxGreenTime; }
58};
59
66 float a, b;
68
70 bool operator<(const RoadDetails &other) const {
71 return this->calculateWeight() < other.calculateWeight();
72 }
73
74 float calculateWeight() const {
75 float best = length / max_speed;
76 if (capacity <= 0)
77 return 1000000; // Safety for division
78 return best * (1.0f + a * pow((float)currentVehicles / capacity, b));
79 }
80 RoadDetails(float ab, float bc, float c, float aplha = 0.5, float beta = 4,
81 int discharge = 5)
82 : a(aplha), b(beta), dischargeCapcity(discharge) {
84 length = ab;
85 max_speed = bc;
86 capacity = c;
87 queueCount = 0;
88 signalState = true;
89 }
90 float DischargeAllowed(int capacity_ofnext_road, int pop_of_next_road) {
91 float allowed = queueCount;
92 float avail = capacity_ofnext_road - pop_of_next_road;
93 if (avail > allowed) {
94 if (dischargeCapcity <= allowed) {
96 } else {
97 return signalState * queueCount;
98 }
99 } else if (dischargeCapcity > avail) {
100 return avail * signalState;
101 } else {
103 }
104 }
105 float TimeCal() {
106 if (capacity <= 0) {
107 return bestTime();
108 }
109
111 return NonIdealWeight;
112 }
113
114 float bestTime() { return length / max_speed; }
115
116 float NonIdealtime() {
117 if (capacity <= 0) {
118 return bestTime();
119 }
122 NonIdealWeight * (1 + a * pow((float)currentVehicles / capacity, b));
123 return NonIdealWeight;
124 }
128 NonIdealtime();
129 }
130 }
132 if (currentVehicles > 0) {
134 NonIdealtime();
135 }
136 }
137
139 if (queueCount < capacity) // FIX: added capacity check to prevent overflow
140 queueCount++;
141 }
142
144 queueCount++; // FIX: removed capacity cap — queue is a waiting area
145 // (stoplight), not the road; capping caused phantom members
146 // that drifted queueCount to 0 and deadlocked vehicles
147 NonIdealtime();
148 }
150 if (queueCount > 0) {
151 queueCount--;
152 }
153 }
154 void decVehicles() {
155 if (queueCount >
156 0) // FIX: added bounds check to prevent negative queueCount
157 queueCount--;
158 }
159
160 float Congestion() {
161 if (capacity <= 0) {
162 return 0;
163 }
164 return (float)currentVehicles / capacity;
165 }
166
167 void Time(int time) { light.Timer(signalState, time); }
168
169 void changeState() {
170 if (signalState) {
171 light.turnRed(signalState);
172 } else {
173 light.turnGreen(signalState);
174 }
175 }
176 void change_to_red() { light.turnRed(signalState); }
177 // bool switching (int maxWaitingQueue) {
178 // return light.canSwitch(queueCount, maxWaitingQueue);
179 // }
180 void increment(int time) { light.Timer(signalState, time); }
181
182 float choosing() { // computes per-road cost used for signal selection.
183 float currentCost =
184 (light.pa * queueCount) + (light.pb * pow(Congestion(), 2));
185 return currentCost;
186 }
187};
188
189struct weighted {
190 int index;
192 bool operator==(const weighted &other) const { return index == other.index; }
193};
194template <class t> struct Gnode {
196 list<weighted> Neighbors;
197 bool operator==(t v) { return vertex == v; }
198};
199
200template <class t, int size> class Graph {
201
202 Gnode<t> array[size];
203 bool directed;
204
205public:
208 Vcount = 0;
209 directed = false;
210 }
211 Graph(bool x) {
212 Vcount = 0;
213 directed = x;
214 }
215
216 void bfs(int levels[size]) {
217 if (Vcount <= 0) {
218 return;
219 }
220 int visited[size] = {0};
221 queue<int> adjacent;
222 int starting = getIndex(array[0].vertex);
223 adjacent.push(starting);
224 visited[starting] = 1;
225
226 levels[starting] = 0;
227
228 while (!adjacent.empty()) {
229 int top = adjacent.front();
230 cout << array[top].vertex << "\t";
231 adjacent.pop();
232
233 typename list<weighted>::iterator temp = array[top].Neighbors.begin();
234 while (temp != array[top].Neighbors.end()) {
235 int neighborIndex = temp->index;
236 if (visited[neighborIndex] != 1) {
237 visited[neighborIndex] = 1;
238 adjacent.push(neighborIndex);
239 levels[neighborIndex] = levels[top] + 1;
240 }
241 temp++;
242 }
243 }
244
245 cout << endl;
246 }
247
248 void PrintLevels() {
249 int levels[size];
250 for (int i = 0; i < size; i++) {
251 levels[i] = -1;
252 }
253 bfs(levels);
254 int max = 0;
255
256 for (int i = 0; i < Vcount; i++) {
257 if (max < levels[i]) {
258 max = levels[i];
259 }
260 }
261
262 for (int i = 0; i <= max; i++) {
263 cout << "\nLevel = " << i << endl;
264 for (int j = 0; j < Vcount; j++) {
265 if (levels[j] == i) {
266 cout << "\t" << array[j].vertex << "\t";
267 }
268 }
269 }
270 }
271
272 void insertVertex(t vertex) {
273 if (Vcount < size) {
274 array[Vcount].vertex = vertex;
275 Vcount++;
276 } else {
277 return;
278 }
279 }
280
281 void makeEdge(int a, int b, float len, float speed, float cap) {
282 RoadDetails road(len, speed, cap);
283 if (!directed) {
284 if (a < size && b < size && a >= 0 && b >= 0) {
285 weighted tempA = {b, road};
286 weighted tempB = {a, road};
287 array[a].Neighbors.push_back(tempA);
288 array[b].Neighbors.push_back(tempB);
289 }
290 } else {
291 if (a < size && b < size && a >= 0 && b >= 0) {
292 weighted tempA = {b, road};
293 array[a].Neighbors.push_back(tempA);
294 }
295 }
296 }
297 void makeEdge(int a, int b, float len, float speed, float cap,
298 float alpha = 0.5, float beta = 4.0) {
299 RoadDetails road(len, speed, cap, alpha, beta);
300
301 if (!directed) {
302 if (a < size && b < size && a >= 0 && b >= 0) {
303 weighted tempA = {b, road};
304 weighted tempB = {a, road};
305 array[a].Neighbors.push_back(tempA);
306 array[b].Neighbors.push_back(tempB);
307 }
308 } else {
309 if (a < size && b < size && a >= 0 && b >= 0) {
310 weighted tempA = {b, road};
311 array[a].Neighbors.push_back(tempA);
312 }
313 }
314 }
315 int getIndex(t label) {
316 for (int i = 0; i < Vcount; i++) {
317 if (array[i].vertex == label)
318 return i;
319 }
320 return -1; // Not found
321 }
322
323 int getVertex() { return Vcount; }
324
325 bool isEmpty() { return Vcount <= 0; }
326
327 int No_of_edges_btw_2_vertices(t data, t data2) {
328 int a = getIndex(data);
329 int b = getIndex(data2);
330 int links = 0;
331 if (a == -1 || b == -1) {
332 return 0;
333 }
334
335 typename list<weighted>::iterator temp = array[a].Neighbors.begin();
336 typename list<weighted>::iterator temp1 = array[b].Neighbors.begin();
337 while (temp != array[a].Neighbors.end()) {
338 if (temp->index == b) {
339 links++;
340 }
341 temp++;
342 }
343 while (temp1 != array[b].Neighbors.end()) {
344 if (temp1->index == a) {
345 links++;
346 }
347 temp1++;
348 }
349 if (!directed) {
350 return links / 2;
351 } else {
352 return links;
353 }
354 }
355 void DeleteEdge(t data1, t data2) {
356 int a = getIndex(data1);
357 int b = getIndex(data2);
358 if (a == -1 || b == -1)
359 return;
360
361 weighted B = {b,
362 RoadDetails(0, 1, 1)}; // FIX: used aggregate init — weighted
363 // has no default constructor
364 weighted A = {a,
365 RoadDetails(0, 1, 1)}; // FIX: used aggregate init — weighted
366 // has no default constructor
367
368 if (!directed) {
369 array[a].Neighbors.remove(B);
370 array[b].Neighbors.remove(A);
371 } else {
372 array[a].Neighbors.remove(B);
373 }
374
375 cout << "\t\t\t\t\t\tDeleted\n";
376 }
377 void DeleteVertex(t data) {
378 int index = getIndex(data);
379 if (index == -1)
380 return;
381 weighted d = {index,
382 RoadDetails(0, 1, 1)}; // FIX: was {index, 0} which is invalid
383 // — RoadDetails needs 3 args
384
385 for (int i = 0; i < Vcount; i++) {
386 array[i].Neighbors.remove(d);
387 }
388
389 for (int i = index; i < Vcount - 1; i++) {
390 array[i] = array[i + 1];
391 }
392
393 Vcount--;
394
395 for (int i = 0; i < Vcount; i++) {
396 typename list<weighted>::iterator it = array[i].Neighbors.begin();
397 while (it != array[i].Neighbors.end()) {
398 if (it->index > index) {
399 it->index = it->index - 1;
400 }
401 it++;
402 }
403 }
404 }
405
406 void dfs() {
407 stack<int> holder;
408 bool visited[size] = {false};
409 t data = array[0].vertex;
410 int start = getIndex(data);
411 holder.push(start);
412 visited[start] = true;
413
414 while (!holder.empty()) {
415 int index = holder.top();
416 cout << array[index].vertex << "\t";
417 holder.pop();
418 typename list<weighted>::iterator temp = array[index].Neighbors.begin();
419 while (temp != array[index].Neighbors.end()) {
420 if (visited[temp->index] == false) {
421 holder.push(temp->index);
422 visited[temp->index] = true;
423 }
424 temp++;
425 }
426 }
427 }
428
429 bool edgeExist(t data1, t data2) {
430 int a = getIndex(data1);
431 int b = getIndex(data2);
432 if (a == -1 || b == -1) {
433 return false;
434 }
435
436 typename list<weighted>::iterator temp = array[a].Neighbors.begin();
437 while (temp != array[a].Neighbors.end()) {
438 if (b == temp->index) {
439 return true;
440 }
441 temp++;
442 }
443 return false;
444 }
445
447 int edges = 0;
448 for (int i = 0; i < Vcount; i++) {
449 typename list<weighted>::iterator temp = array[i].Neighbors.begin();
450 while (temp != array[i].Neighbors.end()) {
451 edges++;
452 temp++;
453 }
454 }
455 if (!directed) {
456 return edges / 2;
457 } else {
458 return edges;
459 }
460 }
461
463 Graph<t, size> result;
464 for (int i = 0; i < Vcount; i++) {
465 result.insertVertex(array[i].vertex);
466 }
467 bool visited[size] = {false};
468 visited[0] = true;
469 for (int edges = 0; edges < Vcount - 1; edges++) {
470
471 float minimum = 100000;
472 int start = -1;
473 int end = -1;
474
475 for (int i = 0; i < Vcount; i++) {
476 if (visited[i] == true) {
477
478 typename list<weighted>::iterator temp = array[i].Neighbors.begin();
479 while (temp != array[i].Neighbors.end()) {
480
481 if (temp->weight.calculateWeight() < minimum &&
482 visited[temp->index] == false) {
483 minimum = temp->weight.calculateWeight();
484 start = i;
485 end = temp->index;
486 }
487 temp++;
488 }
489 }
490 }
491
492 if (end != -1) {
493 visited[end] = true;
494
495 RoadDetails *w = nullptr;
496
497 typename list<weighted>::iterator temp = array[start].Neighbors.begin();
498 while (temp != array[start].Neighbors.end()) {
499 if (temp->index == end) {
500 w = &(temp->weight);
501 break;
502 }
503 temp++;
504 }
505
506 if (w != nullptr) {
507 result.makeEdge(start, end, w->length, w->max_speed, w->capacity);
508 }
509
510 cout << "Inserting link btw " << start << "\t" << end
511 << "\t for a weight of " << minimum << endl;
512 }
513 }
514
515 return result;
516 }
517
518 void Shortest_Link_btw_two_vertices(t data, t data1) {
519 int a = getIndex(data);
520 int b = getIndex(data1);
521 if (a == -1 || b == -1) {
522 cout << "Vertex not found";
523 return;
524 } // FIX: added index validation to prevent UB
525 bool direct = false;
526 typename list<weighted>::iterator temp = array[a].Neighbors.begin();
527 float min =
528 100000.0f; // FIX: was int — caused type mismatch with RoadDetails
529 int index = -1;
530 while (temp != array[a].Neighbors.end()) {
531 if (b == temp->index) {
532 float w =
533 temp->weight
534 .calculateWeight(); // FIX: extract weight as float instead of
535 // comparing RoadDetails < int
536 if (w < min) {
537 min =
538 w; // FIX: was `min = temp->weight` — assigning RoadDetails to int
539 index = temp->index;
540 direct = true;
541 }
542 }
543 temp++;
544 }
545 if (direct) {
546 cout << "The minimum distance between the vertices " << data << "\t"
547 << data1 << "\t" << "is \t" << min;
548 } else {
549 cout << "No direct link";
550 }
551 }
552
554 list<t> temp;
555 int a = getIndex(data); // starting index
556 int b = getIndex(data2); // target
557 float distance[size];
558 bool visited[size];
559 int indexes[size];
560 for (int i = 0; i < size; i++) {
561
562 distance[i] = 1000000000;
563 visited[i] = false;
564 indexes[i] = -1;
565 }
566
567 distance[a] = 0;
568 for (int i = 0; i < Vcount; i++) {
569 int nextNode = -1;
570 float min = 1000000000;
571 for (int j = 0; j < Vcount; j++) {
572 if (distance[j] < min && visited[j] == false) {
573 min = distance[j];
574 nextNode = j;
575 }
576 }
577 if (nextNode == -1) {
578 break;
579 }
580
581 else {
582 visited[nextNode] = true;
583 }
584
585 for (auto it = array[nextNode].Neighbors.begin();
586 it != array[nextNode].Neighbors.end(); ++it) {
587 int v = it->index;
588 float weight = it->weight.NonIdealtime();
589
590 if (!visited[v] && distance[nextNode] + weight < distance[v]) {
591 distance[v] = distance[nextNode] + weight;
592 indexes[v] = nextNode;
593 }
594 }
595 }
596 if (distance[b] == 1000000000) {
597
598 return temp;
599 }
600
601 int current = b;
602 int path[size];
603 int count = 0;
604 while (current != -1) {
605 path[count] = current;
606 count++;
607 current = indexes[current];
608 }
609
610 for (int i = count - 1; i >= 0; i--) {
611 int nodeIndex = path[i];
612 temp.push_back(array[nodeIndex].vertex);
613 }
614 return temp;
615 }
616
617 void shortest_Path_btw2_vericex(t data, t data2) {
618
619 int a = getIndex(data); // starting index
620 int b = getIndex(data2); // target
621 float distance[size];
622 bool visited[size];
623 int indexes[size];
624 for (int i = 0; i < size; i++) {
625
626 distance[i] = 1000000000;
627 visited[i] = false;
628 indexes[i] = -1;
629 }
630
631 distance[a] = 0;
632 for (int i = 0; i < Vcount; i++) {
633 int nextNode = -1;
634 float min = 1000000000;
635 for (int j = 0; j < Vcount; j++) {
636 if (distance[j] < min && visited[j] == false) {
637 min = distance[j];
638 nextNode = j;
639 }
640 }
641 if (nextNode == -1) {
642 cout << "Path does not exist";
643 break;
644 }
645
646 else {
647 visited[nextNode] = true;
648 }
649
650 for (auto it = array[nextNode].Neighbors.begin();
651 it != array[nextNode].Neighbors.end(); ++it) {
652 int v = it->index;
653 float weight = it->weight.NonIdealtime();
654
655 if (!visited[v] && distance[nextNode] + weight < distance[v]) {
656 distance[v] = distance[nextNode] + weight;
657 indexes[v] = nextNode;
658 }
659 }
660 }
661 if (distance[b] == 1000000000) {
662 cout << "No path exists\n";
663 return; // FIX: was missing — code fell through to print garbage path
664 }
665
666 int current = b;
667 int path[size];
668 int count = 0;
669 while (current != -1) {
670 path[count] = current;
671 count++;
672 current = indexes[current];
673 }
674 for (int i = count - 1; i >= 0; i--) {
675 int nodeIndex = path[i];
676 cout << array[nodeIndex].vertex << "\t";
677 }
678 cout << "\nTotal Travel Cost: " << distance[b] << " units" << endl;
679 }
680
681 bool searchVertex(t data) { return getIndex(data) != -1; }
682
683 int getDegree(t data) {
684 int a = getIndex(data);
685 if (a == -1) {
686 cout << "\nVertex does not exist \n";
687 return -1;
688 } // FIX: moved check before array access to prevent UB
689 int degree =
690 0; // FIX: removed unused iterator that was dereferencing array[-1]
691 degree = array[a].Neighbors.size();
692 cout << "\nThe degree of the vertex " << data << " is " << degree << endl;
693 return degree;
694 }
695
696 void Type() {
697 if (directed) {
698 cout << "\nThe graph is Directed\n";
699 } else {
700 cout << "\nThe graph is Undirected\n";
701 }
702 }
703
704 string display_edge_of_index(string s) {
705 string x = "";
706 int index = getIndex(s);
707 if (index == -1) {
708 cout << "\nCity not found.\n";
709 return x;
710 } // Safety
711 typename list<weighted>::iterator temp = array[index].Neighbors.begin();
712 x += "\nThe vertex ";
713 x += array[index].vertex + " has links to \n";
714 while (temp != array[index].Neighbors.end()) {
715 x += array[temp->index].vertex + "\t";
716 x += "length = " + to_string(temp->weight.length) + "\n";
717 x += "Current Vehicles = " + to_string(temp->weight.currentVehicles) +
718 "\n";
719 x += "Signal State = " + to_string(temp->weight.signalState) + "\n";
720 x += "Congestion = " + to_string(temp->weight.Congestion()) + "\n";
721 temp++;
722 }
723 return x;
724 }
725 void Incoming(t target) {
726 if (!directed) {
727 return;
728 }
729 int targetIdx = getIndex(target);
730 if (targetIdx == -1)
731 return;
732
733 cout << "Incoming flights to " << target << ":" << endl;
734 for (int i = 0; i < Vcount; i++) {
735 typename list<weighted>::iterator temp = array[i].Neighbors.begin();
736 while (temp != array[i].Neighbors.end()) {
737 if (temp->index == targetIdx) {
738 cout << array[i].vertex << "\t";
739 }
740 temp++;
741 }
742 }
743 }
744
745 RoadDetails &getEdgeDetails(t data, t data1) {
746 int a = getIndex(data);
747 int b = getIndex(data1);
748 if (a == -1 || b == -1) { // FIX: added validation — accessing array[-1] was
749 // undefined behavior
750 throw std::runtime_error("Edge not found: invalid vertex");
751 }
752
753 typename list<weighted>::iterator temp = array[a].Neighbors.begin();
754 while (temp != array[a].Neighbors.end()) {
755 if (temp->index == b) {
756 return temp->weight;
757 }
758 temp++;
759 }
760 throw std::runtime_error("Edge not found");
761 }
762
763 list<RoadDetails *> getEdges(t data, list<RoadDetails *> edges) {
764
765 int index = getIndex(data);
766 if (index == -1) {
767 return edges;
768 }
769 for (int i = 0; i < Vcount; i++) {
770 typename list<weighted>::iterator temp = array[i].Neighbors.begin();
771 while (temp != array[i].Neighbors.end()) {
772 if (temp->index == index) {
773 edges.push_back(&(temp->weight));
774 }
775 temp++;
776 }
777 }
778 return edges;
779 }
780
781 float AverageRush() {
782 float sum = 0;
783 int count = 0;
784
785 for (int i = 0; i < Vcount; i++) {
786 typename list<weighted>::iterator temp = array[i].Neighbors.begin();
787 while (temp != array[i].Neighbors.end()) {
788
789 sum += temp->weight.Congestion();
790 count++;
791 temp++;
792 }
793 }
794
795 if (count == 0)
796 return 0.0f; // FIX: prevent division by zero when graph has no edges
797 return sum / count;
798 }
799
800 t getVertexAt(int i) { return array[i].vertex; }
801
802 string printGrapgh() {
803 string result = "";
804 for (int i = 0; i < Vcount; i++) {
805 result += display_edge_of_index(array[i].vertex);
806 }
807 return result;
808 }
809
811 double totalCost = 0;
812 for (int i = 0; i < Vcount;
813 i++) { // FIX: was `i < size` — iterated over uninitialized array slots
814 typename list<weighted>::iterator temp = array[i].Neighbors.begin();
815 while (temp != array[i].Neighbors.end()) {
816
817 totalCost += temp->weight.choosing();
818 temp++;
819 }
820 }
821 return totalCost;
822 }
823
824 // METRICS UPGRADE: per-road congestion snapshot for active roads
826 string result = "";
827 for (int i = 0; i < Vcount; i++) {
828 typename list<weighted>::iterator temp = array[i].Neighbors.begin();
829 while (temp != array[i].Neighbors.end()) {
830 if (temp->weight.currentVehicles > 0 || temp->weight.queueCount > 0) {
831 result += " " + array[i].vertex + " -> " + array[temp->index].vertex;
832 result += " | Vehicles: " + to_string(temp->weight.currentVehicles);
833 result += "/" + to_string((int)temp->weight.capacity);
834 result += " | Queue: " + to_string(temp->weight.queueCount);
835 result += " | Congestion: " +
836 to_string((int)(temp->weight.Congestion() * 100)) + "%";
837 result += " | Signal: " +
838 string(temp->weight.signalState ? "GREEN" : "RED");
839 result += "\n";
840 }
841 temp++;
842 }
843 }
844 return result;
845 }
846};
int Vcount
Definition Header1.h:206
string display_edge_of_index(string s)
Definition Header1.h:704
void insertVertex(t vertex)
Definition Header1.h:272
bool isEmpty()
Definition Header1.h:325
float AverageRush()
Definition Header1.h:781
int No_Of_Edges()
Definition Header1.h:446
string printRoadSnapshot()
Definition Header1.h:825
string printGrapgh()
Definition Header1.h:802
void DeleteVertex(t data)
Definition Header1.h:377
void shortest_Path_btw2_vericex(t data, t data2)
Definition Header1.h:617
void dfs()
Definition Header1.h:406
int getVertex()
Definition Header1.h:323
RoadDetails & getEdgeDetails(t data, t data1)
Definition Header1.h:745
void Incoming(t target)
Definition Header1.h:725
void makeEdge(int a, int b, float len, float speed, float cap, float alpha=0.5, float beta=4.0)
Definition Header1.h:297
void Type()
Definition Header1.h:696
Graph minimumSpanningtree()
Definition Header1.h:462
int getIndex(t label)
Definition Header1.h:315
list< RoadDetails * > getEdges(t data, list< RoadDetails * > edges)
Definition Header1.h:763
t getVertexAt(int i)
Definition Header1.h:800
void Shortest_Link_btw_two_vertices(t data, t data1)
Definition Header1.h:518
int getDegree(t data)
Definition Header1.h:683
void PrintLevels()
Definition Header1.h:248
bool edgeExist(t data1, t data2)
Definition Header1.h:429
bool searchVertex(t data)
Definition Header1.h:681
void DeleteEdge(t data1, t data2)
Definition Header1.h:355
double total_System_Cost()
Definition Header1.h:810
int No_of_edges_btw_2_vertices(t data, t data2)
Definition Header1.h:327
list< t > shortest_Path_btw2_vericex_returing_list(t data, t data2)
Definition Header1.h:553
void makeEdge(int a, int b, float len, float speed, float cap)
Definition Header1.h:281
Graph(bool x)
Definition Header1.h:211
Graph()
Definition Header1.h:207
void bfs(int levels[size])
Definition Header1.h:216
Definition Header1.h:194
t vertex
Definition Header1.h:195
bool operator==(t v)
Definition Header1.h:197
list< weighted > Neighbors
Definition Header1.h:196
Definition Header1.h:60
RoadDetails(float ab, float bc, float c, float aplha=0.5, float beta=4, int discharge=5)
Definition Header1.h:80
float a
Definition Header1.h:66
float calculateWeight() const
Definition Header1.h:74
float NonIdealWeight
Definition Header1.h:65
void changeState()
Definition Header1.h:169
float Congestion()
Definition Header1.h:160
void decVehicles()
Definition Header1.h:154
float capacity
Definition Header1.h:61
int dischargeCapcity
Definition Header1.h:69
TrafficSignal light
Definition Header1.h:67
float bestTime()
Definition Header1.h:114
int queueCount
Definition Header1.h:63
float max_speed
Definition Header1.h:61
float DischargeAllowed(int capacity_ofnext_road, int pop_of_next_road)
Definition Header1.h:90
void updateVehicles()
Definition Header1.h:138
int currentVehicles
Definition Header1.h:62
float NonIdealtime()
Definition Header1.h:116
bool operator<(const RoadDetails &other) const
Definition Header1.h:70
float b
Definition Header1.h:66
void increment(int time)
Definition Header1.h:180
void vehicleJoinsQueue()
Definition Header1.h:143
void change_to_red()
Definition Header1.h:176
void vehicleExitsRoad()
Definition Header1.h:131
bool signalState
Definition Header1.h:64
float length
Definition Header1.h:61
float choosing()
Definition Header1.h:182
void vehicleEntersRoad()
Definition Header1.h:125
void Time(int time)
Definition Header1.h:167
float TimeCal()
Definition Header1.h:105
void vehicleExitsQueue()
Definition Header1.h:149
Definition Header1.h:12
bool canSwitch(int currentQueue, int maxOtherQueue) const
Definition Header1.h:48
float maxGreenTime
Definition Header1.h:17
float starvationCost() const
Definition Header1.h:38
float minGreenTime
Definition Header1.h:15
float pb
Definition Header1.h:19
float pa
Definition Header1.h:19
void turnGreen(bool &state)
Definition Header1.h:39
TrafficSignal()
Definition Header1.h:20
float redtimer
Definition Header1.h:18
float greentimer
Definition Header1.h:14
void Timer(bool state, float time)
Definition Header1.h:30
bool mustSwitch() const
Definition Header1.h:57
float queueThreshold
Definition Header1.h:16
void turnRed(bool &state)
Definition Header1.h:43
Definition Header1.h:189
int index
Definition Header1.h:190
bool operator==(const weighted &other) const
Definition Header1.h:192
RoadDetails weight
Definition Header1.h:191