-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouter.cpp
More file actions
824 lines (729 loc) · 24.9 KB
/
Copy pathRouter.cpp
File metadata and controls
824 lines (729 loc) · 24.9 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <set>
#include <utility>
#include <string>
#include <queue>
#include <algorithm>
#ifdef LIN
#include "display.h"
#include "tester.h"
#endif
#include "common.h"
#include "Router.h"
//#include "tester.h"
using namespace std;
bool final;
int main(int argc, char **argv)
{
int gridx, gridy;
int numCells;
int numWires;
int algorithm;
if (argc < 3)
{
cout << "Invalid number of arguments\n";
exit(-1);
}
ifstream infile;
infile.open(argv[1]);
if (!infile)
{
cerr << "Unable to open file";
exit(1);
}
infile >> gridx;
infile >> gridy;
infile >> numCells;
string algo = argv[2];
if (algo.compare("LM") == 0 || algo.compare("Lee Moore") == 0)
{
algorithm = 0;
}
else if (algo.compare("A") == 0 || algo.compare("A*") == 0)
{
algorithm = 1;
}
else
{
cout << "Invalid Algorithm\n";
exit(-1);
}
//Read in cell information
vector<vector<int>> cells(numCells);
for (int i = 0; i < numCells; i++)
{
cells[i] = vector<int>(2);
infile >> cells[i][0];
infile >> cells[i][1];
}
infile >> numWires;
vector<Wire> W(numWires);
vector<vector<Point>> points(gridx);
//Read in wire information
for (int i = 0; i < numWires; i++)
{
infile >> W[i].numPins;
W[i].colour = i + 4; //Colour offset to start colours form blue
W[i].pins = vector<vector<int>>(W[i].numPins);
W[i].found = vector<bool>(W[i].numPins);
for (int j = 0; j < W[i].numPins; j++)
{
W[i].pins[j] = vector<int>(2);
infile >> W[i].pins[j][0];
infile >> W[i].pins[j][1];
}
}
init(points, W, gridx, gridy, numWires, numCells, cells);
priority_queue<wPair, vector<wPair>, greater<wPair>> PQ; //min heap queue ordered by wire weight
//Determine weights and insert into priority queue
for (int i = 0; i < numWires; i++)
{
W[i].weight = calculateWeight(W[i], numWires);
PQ.push(make_pair(W[i].weight, i));
}
int index;
int ret;
pair<int, int> top;
int success = 0;
int attempts = 0;
vector<int> bestWeights(numWires);
queue<int> unrouted;
queue<int> backup;
final = true;
for (int i = 0; i < numWires; i++)
{
top = PQ.top();
index = top.second;
if (algorithm == 0)
{
ret = LM(index, gridx, gridy, W, points);
}
else if (algorithm == 1)
{
ret = aStar(index, gridx, gridy, W, points);
}
else
{
cout << "Error\n";
}
if (ret == 0)
{
W[index].routed = true;
success++;
}
else
{
W[index].routed = false;
unrouted.push(index);
}
reset(points, gridx, gridy);
PQ.pop();
}
if (success != numWires)
{
//Keep ripping up and re-routing while there are unrouted nets
while(!unrouted.empty())
{
reset(points, gridx, gridy);
index = unrouted.front();
//Expand from the source
expand(index, gridx, gridy, 0, W[index], points);
//Expand from each unreached pin
for (int j = 1; j < W[index].numPins; j++)
{
if (W[index].found[j] == false)
{
expand(index, gridx, gridy, j, W[index], points);
}
}
//Find the wire that causes the most obstructions
int maxC = 0;
int maxJ = 0;
for (int j = 0; j < numWires; j++)
{
//Don't include the current wire when searching for the maximum
auto it = find( W[index].rippedBy.begin(), W[index].rippedBy.end(), j ); //Check if wire(index) was previously ripped by wire(j)
//If it hasn't been ripped, consider wire(j) for ripping, prevents a loop of 2 wires ripping each other up
if(it == W[index].rippedBy.end())
{
if (W[index].counter[j] > maxC && j != index)
{
maxC = W[index].counter[j];
maxJ = j;
}
}
}
cout << "Rip up: " << maxJ << endl;
ripUp(W[maxJ], gridx, gridy); //Rip up the blocking wire
W[maxJ].rippedBy.push_back(index);
//If blocking wire was previously routed, it now isn't, add it to the queue
if(W[maxJ].routed == true)
{
W[maxJ].routed = false;
unrouted.push(maxJ);
}
cout << "For: " << index << endl;
ripUp(W[index], gridx, gridy); //We need to also disard the path for this wire
//reroute this net
cout << "Reroute: " << index << endl;
if (algorithm == 0)
{
ret = LM(index, gridx, gridy, W, points);
}
else if (algorithm == 1)
{
ret = aStar(index, gridx, gridy, W, points);
}
if(ret == 0)
{
W[index].routed = true;
unrouted.pop();
}
//unrouted.pop();
//Now attempt ot re-route any other un-routed (including the ripped up) nets
backup = unrouted; //First backup our queue
while(!unrouted.empty())
{
reset(points, gridx, gridy);
int ind = unrouted.front();
cout << "RR: " << ind << endl;
if (algorithm == 0)
{
ret = LM(ind, gridx, gridy, W, points);
}
else if (algorithm == 1)
{
ret = aStar(ind, gridx, gridy, W, points);
}
if(ret == 0)
{
backup.pop();
W[ind].routed = true;
}
unrouted.pop();
}
unrouted = backup; //Any that are successfully routed are removed, and those which weren't are still in the queue
//We don't want to immediately reroute this wire after attempting to reroute earlier
if(W[index].routed == false)
{
//unrouted.push(index);
}
}
/*for (int i = 0; i < numWires; i++)
{
if (W[i].routed == false)
{
//Expand from the source
expand(i, gridx, gridy, 0, W[i], points);
//Expand from each unreached pin
for (int j = 1; j < W[i].numPins; j++)
{
if (W[i].found[j] == false)
{
expand(i, gridx, gridy, j, W[i], points);
}
}
//Find the wire that causes the most obstructions
int maxC = 0;
int maxJ = 0;
for (int j = 0; j < numWires; j++)
{
if (W[i].counter[j] > maxC && j != i)
{
maxC = W[i].counter[j];
maxJ = j;
}
}
cout << "Rip up: " << maxJ << endl;
ripUp(W[maxJ], gridx, gridy); //Rip up the blocking wire
W[maxJ].routed = false;
cout << "Rip up: " << i << endl;
ripUp(W[i], gridx, gridy); // We need to also disard the path for this wire
//reroute this net
cout << "Reroute: " << i << endl;
if (algorithm == 0)
{
ret = LM(i, gridx, gridy, W, points);
}
else if (algorithm == 1)
{
ret = aStar(i, gridx, gridy, W, points);
}
reset(points, gridx, gridy);
//reroute the ripped up net
cout << "Reroute: " << maxJ << endl;
if (algorithm == 0)
{
ret = LM(maxJ, gridx, gridy, W, points);
}
else if (algorithm == 1)
{
ret = aStar(maxJ, gridx, gridy, W, points);
}
}
}*/
}
success = 0;
for(int i = 0; i < numWires; i++)
{
if(W[i].routed == true)
{
success ++;
}
}
cout << success << "/" << numWires << "\n";
cout << "Routing done\n";
return 0;
}
//Initialises the search space
void init(vector<vector<Point>> &points, vector<Wire> &W, int gridx, int gridy, int numWires, int numCells, vector<vector<int>> cells)
{
for (int i = 0; i < gridx; i++)
{
points[i] = vector<Point>(gridy);
for (int j = 0; j < gridy; j++)
{
points[i][j].x = i;
points[i][j].y = j;
points[i][j].dist = 0;
points[i][j].target = false;
points[i][j].expanded = false;
points[i][j].obstructed = false;
points[i][j].obstructedBy = -2;
points[i][j].prev = NULL;
points[i][j].f = 1E06;
}
}
int x, y, np;
//Set sinks and pins as obstructions
for (int i = 0; i < numWires; i++)
{
np = W[i].numPins;
W[i].counter = vector<int>(numWires);
for (int j = 0; j < np; j++)
{
x = W[i].pins[j][0];
y = W[i].pins[j][1];
points[x][y].obstructed = true;
points[x][y].obstructedBy = i;
}
for (int j = 0; j < numWires; j++)
{
W[i].counter[j] = 0;
}
}
for (int i = 0; i < numCells; i++)
{
x = cells[i][0];
y = cells[i][1];
points[x][y].obstructed = true;
points[x][y].obstructedBy = -1;
}
}
/*Calculates the weight for net ordering, less dispersed nets with a small
number of pins are routed before very scattered nets with a large number of pins*/
int calculateWeight(Wire W, int nw)
{
int np = W.numPins;
int d = 0;
for (int i = 1; i < np; i++)
{
d += distanceTo(W.pins[0], W.pins[i]);
}
return -d;
}
//Calculates the nearest target pin to a point in the grid
Point nearest(Point a, vector<Point> dests, vector<bool> skip)
{
int d = 1E06;
Point near;
for (unsigned int i = 0; i < dests.size(); i++)
{
if (skip[i] == true)
{
continue;
}
if (d > distanceTo(a, dests[i]))
{
d = distanceTo(a, dests[i]);
near = dests[i];
}
}
return near;
}
//Routes the wire specified by 'index' using the Lee Moore Algorithm
int LM(int index, int gx, int gy, vector<Wire> &W, vector<vector<Point>> &points)
{
int n = W[index].numPins;
int targets = n - 1;
int found = 0;
int sx = W[index].pins[0][0];
int sy = W[index].pins[0][1];
queue<Point> Q;
Q.push(points[sx][sy]); //FIFO queue
points[sx][sy].expanded = true;
Point current;
bool stop = false;
int x, y, np;
np = W[index].numPins;
for (int i = 0; i < np; i++)
{
x = W[index].pins[i][0];
y = W[index].pins[i][1];
points[x][y].obstructed = false;
}
while (!Q.empty())
{
current = Q.front();
for (int i = 1; i < n; i++)
{
if (W[index].pins[i][0] == current.x && W[index].pins[i][1] == current.y)
{
found++;
W[index].found[i] = true;
trace(points, W[index], targets, current.x, current.y, gx, gy, index);
if (found == targets)
{
stop = true;
}
break;
}
}
if (stop)
{
break;
}
if (current.y > 0)
{
if (points[current.x][current.y - 1].obstructed == false && points[current.x][current.y - 1].expanded == false)
{
points[current.x][current.y - 1].dist = points[current.x][current.y].dist + 1;
points[current.x][current.y - 1].expanded = true;
points[current.x][current.y - 1].prev = &points[current.x][current.y];
Q.push(points[current.x][current.y - 1]);
}
}
if (current.y < gy - 1)
{
if (points[current.x][current.y + 1].obstructed == false && points[current.x][current.y + 1].expanded == false)
{
points[current.x][current.y + 1].dist += points[current.x][current.y].dist + 1;
points[current.x][current.y + 1].expanded = true;
points[current.x][current.y + 1].prev = &points[current.x][current.y];
Q.push(points[current.x][current.y + 1]);
}
}
if (current.x < gx - 1)
{
if (points[current.x + 1][current.y].obstructed == false && points[current.x + 1][current.y].expanded == false)
{
points[current.x + 1][current.y].dist += points[current.x][current.y].dist + 1;
points[current.x + 1][current.y].expanded = true;
points[current.x + 1][current.y].prev = &points[current.x][current.y];
Q.push(points[current.x + 1][current.y]);
}
}
if (current.x > 0)
{
if (points[current.x - 1][current.y].obstructed == false && points[current.x - 1][current.y].expanded == false)
{
points[current.x - 1][current.y].dist += points[current.x][current.y].dist + 1;
points[current.x - 1][current.y].expanded = true;
points[current.x - 1][current.y].prev = &points[current.x][current.y];
Q.push(points[current.x - 1][current.y]);
}
}
Q.pop();
}
if (found != targets)
{
return 1;
}
else
{
return 0;
}
}
//Routes the wire specified by 'index' using the A* algorithm
int aStar(int index, int gx, int gy, vector<Wire> &W, vector<vector<Point>> &points)
{
int n = W[index].numPins;
int targets = n - 1;
int found = 0;
int sx = W[index].pins[0][0];
int sy = W[index].pins[0][1];
Point current;
int nT = W[index].numPins - 1;
vector<Point> dests(nT); //Holds each target pin for the current wire
int x, y, h, f, g;
for (int i = 0; i < nT; i++)
{
x = W[index].pins[i + 1][0];
y = W[index].pins[i + 1][1];
dests[i] = points[x][y];
}
int np = W[index].numPins;
//Set the source and sinks of this pin as not obstructed to allow for expansion
for (int i = 0; i < np; i++)
{
x = W[index].pins[i][0];
y = W[index].pins[i][1];
points[x][y].obstructed = false;
}
bool stop = false;
priority_queue<Point, vector<Point>, CompareF> PQ; //min heap priority queue, sorted by f
vector<bool> skip(targets);
for (int i = 1; i < n; i++)
{
skip[i] = false;
}
/*while (!PQ.empty())
{
PQ.pop();
}*/
points[sx][sy].f = 0;
points[sx][sy].expanded = true;
PQ.push(points[sx][sy]);
Point near;
while (!PQ.empty())
{
current = PQ.top();
//Determine if this point is a target
for (int i = 1; i < n; i++)
{
if (W[index].pins[i][0] == current.x && W[index].pins[i][1] == current.y)
{
found++;
W[index].found[i] = true;
skip[i - 1] = true; //Skip this destination in 'nearest' function
trace(points, W[index], targets, current.x, current.y, gx, gy, index);
if (found == targets)
{
stop = true;
}
break;
}
}
if (stop)
{
break;
}
if (current.y > 0) //Boundary Check
{
//Determine if the point is obstructed by a cell or another wire
if ((points[current.x][current.y - 1].obstructedBy == -2 || points[current.x][current.y - 1].obstructedBy == index) && points[current.x][current.y - 1].expanded == false)
{
g = points[current.x][current.y].dist + 1;
near = nearest(points[current.x][current.y - 1], dests, skip);
h = distanceTo(points[current.x][current.y - 1], near);
f = h + g;
points[current.x][current.y - 1].dist = g;
points[current.x][current.y - 1].f = f;
points[current.x][current.y - 1].expanded = true;
points[current.x][current.y - 1].prev = &points[current.x][current.y];
PQ.push(points[current.x][current.y - 1]);
}
}
if (current.y < gy - 1)
{
if ((points[current.x][current.y + 1].obstructedBy == -2 || points[current.x][current.y + 1].obstructedBy == index) && points[current.x][current.y + 1].expanded == false)
{
g = points[current.x][current.y].dist + 1;
h = distanceTo(points[current.x][current.y + 1], nearest(points[current.x][current.y + 1], dests, skip));
f = h + g;
points[current.x][current.y + 1].dist = g;
points[current.x][current.y + 1].f = f;
points[current.x][current.y + 1].expanded = true;
points[current.x][current.y + 1].prev = &points[current.x][current.y];
PQ.push(points[current.x][current.y + 1]);
}
}
if (current.x < gx - 1)
{
if ((points[current.x + 1][current.y].obstructedBy == -2 || points[current.x + 1][current.y].obstructedBy == index) && points[current.x + 1][current.y].expanded == false)
{
g = points[current.x][current.y].dist + 1;
h = distanceTo(points[current.x + 1][current.y], nearest(points[current.x + 1][current.y], dests, skip));
f = h + g;
points[current.x + 1][current.y].dist = g;
points[current.x + 1][current.y].f = f;
points[current.x + 1][current.y].expanded = true;
points[current.x + 1][current.y].prev = &points[current.x][current.y];
PQ.push(points[current.x + 1][current.y]);
}
}
if (current.x > 0)
{
if ((points[current.x - 1][current.y].obstructedBy == -2 || points[current.x - 1][current.y].obstructedBy == index) && points[current.x - 1][current.y].expanded == false)
{
g = points[current.x][current.y].dist + 1;
h = distanceTo(points[current.x - 1][current.y], nearest(points[current.x - 1][current.y], dests, skip));
f = h + g;
points[current.x - 1][current.y].dist = g;
points[current.x - 1][current.y].f = f;
points[current.x - 1][current.y].expanded = true;
points[current.x - 1][current.y].prev = &points[current.x][current.y];
PQ.push(points[current.x - 1][current.y]);
}
}
PQ.pop();
}
if (found != targets)
{
return 1;
}
else
{
return 0;
}
}
//Calculates the manhattan distance between 2 points
int distanceTo(Point a, Point b)
{
int d = abs(a.x - b.x) + abs(a.y - b.y);
return d;
}
//Calculates the manhattan distance between 2 pins
int distanceTo(vector<int> a, vector<int> b)
{
int d = abs(a[0] - b[0]) + abs(a[1] - b[1]);
return d;
}
/*Traces the route back from the target sink to the source. If this is the final
run, displays the trace on the GUI */
void trace(vector<vector<Point>> &points, Wire &W, int targets, int x, int y, int gx, int gy, int index)
{
int d;
vector<Point> R;
Point current;
current = points[x][y];
d = current.dist;
R = vector<Point>(d);
vector<Point *> route(d);
int i = 0;
points[current.x][current.y].obstructed = true;
points[current.x][current.y].obstructedBy = index;
while (1)
{
current = *points[current.x][current.y].prev;
R[i] = points[current.x][current.y];
route[i] = &points[current.x][current.y];
points[current.x][current.y].obstructed = true; //This wire is now an obstruction
points[current.x][current.y].obstructedBy = index;
if (current.prev == NULL)
{
break;
}
i++;
}
//W.route = vector<Point *>(d);
W.route.insert(W.route.end(), route.begin(), route.end());
#ifdef LIN
if (final)
{
drawRoute(R, gx, gy, index);
}
#endif
}
//Resets the grid in preparation for another search by a different wire
void reset(vector<vector<Point>> &points, int gx, int gy)
{
for (int i = 0; i < gx; i++)
{
for (int j = 0; j < gy; j++)
{
points[i][j].expanded = false;
points[i][j].dist = 0;
points[i][j].f = 0;
points[i][j].prev = NULL;
}
}
}
/*Performs an expansion of the wire specified by 'index' from the point
specified by 'pin' using the Lee Moore algorithm until the queue is empty.
Keeps track of which wires are encountered during the expansion*/
void expand(int index, int gx, int gy, int pin, Wire &W, vector<vector<Point>> points)
{
int sx = W.pins[pin][0];
int sy = W.pins[pin][1];
Point current;
queue<Point> Q;
Q.push(points[sx][sy]);
points[sx][sy].expanded = true;
while (!Q.empty())
{
current = Q.front();
if (current.y > 0)
{
if ((points[current.x][current.y - 1].obstructedBy == -2 || points[current.x][current.y - 1].obstructedBy == index) && points[current.x][current.y - 1].expanded == false)
{
points[current.x][current.y - 1].dist = points[current.x][current.y].dist + 1;
points[current.x][current.y - 1].expanded = true;
points[current.x][current.y - 1].prev = &points[current.x][current.y];
Q.push(points[current.x][current.y - 1]);
}
else if (points[current.x][current.y - 1].obstructedBy >= 0 && points[current.x][current.y - 1].obstructedBy != index)
{
W.counter[points[current.x][current.y - 1].obstructedBy]++;
}
}
if (current.y < gy - 1)
{
if ((points[current.x][current.y + 1].obstructedBy == -2 || points[current.x][current.y + 1].obstructedBy == index) && points[current.x][current.y + 1].expanded == false)
{
points[current.x][current.y + 1].expanded = true;
points[current.x][current.y + 1].prev = &points[current.x][current.y];
Q.push(points[current.x][current.y + 1]);
}
else if (points[current.x][current.y + 1].obstructedBy >= 0 && points[current.x][current.y + 1].obstructedBy != index)
{
W.counter[points[current.x][current.y + 1].obstructedBy]++;
}
}
if (current.x < gx - 1)
{
if ((points[current.x + 1][current.y].obstructedBy == -2 || points[current.x + 1][current.y].obstructedBy == index) && points[current.x + 1][current.y].expanded == false)
{
points[current.x + 1][current.y].expanded = true;
points[current.x + 1][current.y].prev = &points[current.x][current.y];
Q.push(points[current.x + 1][current.y]);
}
else if (points[current.x + 1][current.y].obstructedBy >= 0 && points[current.x + 1][current.y].obstructedBy != index)
{
W.counter[points[current.x + 1][current.y].obstructedBy]++;
}
}
if (current.x > 0)
{
if ((points[current.x - 1][current.y].obstructedBy == -2 || points[current.x - 1][current.y].obstructedBy == index) && points[current.x - 1][current.y].expanded == false)
{
points[current.x - 1][current.y].expanded = true;
points[current.x - 1][current.y].prev = &points[current.x][current.y];
Q.push(points[current.x - 1][current.y]);
}
else if (points[current.x - 1][current.y].obstructedBy >= 0 && points[current.x - 1][current.y].obstructedBy != index)
{
W.counter[points[current.x - 1][current.y].obstructedBy]++;
}
}
Q.pop();
}
}
//Follow the route for this wire and remove its obstrucitons from the grid
void ripUp(Wire &W, int gx, int gy)
{
Point *current;
//cout << "Rip up: " << W. << endl;
for (unsigned int i = 0; i < W.route.size(); i++)
{
current = W.route[i];
current->obstructed = false;
current->obstructedBy = -2;
}
#ifdef LIN
removeRoute(W.route, gx, gy);
#endif
W.route.clear();
}