-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrouter.h
129 lines (122 loc) · 2.76 KB
/
router.h
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
// Author: Sean Davis
#ifndef ROUTER_H
#define ROUTER_H
#include "RouterRunner.h"
#include "BinaryHeap.h"
#include <cmath>
class PreviousVertex
{
public:
PreviousVertex(int x_, int y_) : x(x_), y(y_) {}
PreviousVertex() : x(-1), y(-1) {}
int x;
int y;
};
class Plot
{
public:
Plot(): previousVertex(-1, -1), weight(-1), x(-1), y(-1), isCity(false) {}
Plot(int x_, int y_, int change_in_elevation) : previousVertex(-1, -1), x(x_), y(y_), isCity(false)
{
weight = (int) pow(change_in_elevation, 2) + 10;
}
Plot(int x_, int y_) : previousVertex(-1, -1), weight(0), x(x_), y(y_), isCity(false) {} // for source vertex
bool operator<(const Plot& rhs) const
{
return weight < rhs.weight;
}
bool isLeftEdge(int width)
{
return (x == 0 && y > 0 && y < width - 1);
}
bool isRightEdge(int width)
{
return (x == width-1 && y > 0 && y < width - 1);
}
bool isTopEdge(int width)
{
return (y == width-1 && x > 0 && x < width - 1);
}
bool isBottomEdge(int width)
{
return (y == 0 && x > 0 && x < width - 1);
}
bool isUpperLeftCorner(int width)
{
return (x == 0 && y == width - 1);
}
bool isUpperRightCorner(int width)
{
return (x == width - 1 && y == width - 1);
}
bool isLowerLeftCorner(int width)
{
return (x == 0 && y == 0);
}
bool isLowerRightCorner(int width)
{
return (x == width - 1 && y == 0);
}
Plot getLeftVertex()
{
return Plot(x - 1, y);
}
Plot getRightVertex()
{
return Plot(x + 1, y);
}
Plot getTopVertex()
{
return Plot(x, y + 1);
}
Plot getBottomVertex()
{
return Plot(x, y - 1);
}
Plot getTopLeftVertex()
{
return Plot(x - 1, y + 1);
}
Plot getTopRightVertex()
{
return Plot(x + 1, y + 1);
}
Plot getBottomLeftVertex()
{
return Plot(x - 1, y - 1);
}
Plot getBottomRightVertex()
{
return Plot(x + 1, y - 1);
}
Plot getAdjacentPlot(int i, int width_);
PreviousVertex previousVertex;
int weight;
int x;
int y;
bool isCity;
};
// class AdjListNode
// {
// public:
// AdjListNode();
// bool operator<(const AdjListNode& rhs)
// {
// return (plot.x < rhs.plot.x) || ((plot.x == rhs.plot.x) && (plot.y < rhs.plot.y));
// }
// Plot plot;
// Plot adjacentPlots[4];
// };
class Router
{
public:
int width_;
BinaryHeap<Plot> heap;
// Map1000 map_; // has a double array of shorts called map1000
short** map_;
Router(const Map1000 *map, int width);
~Router();
void printMap();
void findRoutes(const CityPos *cityPos, int cityCount, Edge *paths, int &pathCount);
};
#endif