-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouteData.cpp
More file actions
126 lines (114 loc) · 2.16 KB
/
Copy pathRouteData.cpp
File metadata and controls
126 lines (114 loc) · 2.16 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
#include"RouteData.h"
void AllRoute::add_line(int from, int to, int dis)
{
add(from, to, dis);
add(to, from, dis);
all_line.push_back(new RouteLine(from,to,p[from].x, p[from].y, p[to].x, p[to].y, dis));
}
AllRoute::AllRoute()
{
p[0] = { 298, 525 };
p[1] = { 298, 430 };
p[2] = { 298, 735 };
p[3] = { 365, 716 };
p[4] = { 454, 655 };
p[5] = { 82, 709 };
p[6] = { 98, 386 };
p[7] = { 463, 420 };
p[8] = { 498, 524 };
p[9] = { 292, 221 };
add_line(0, 1, 30);
add_line(0, 2, 50);
add_line(5, 0, 60);
add_line(7, 1, 70);
add_line(2, 3, 80);
add_line(3, 4, 20);
add_line(1, 6, 60);
add_line(2, 5, 90);
add_line(6, 5, 10);
add_line(9, 6, 60);
add_line(7, 8, 20);
add_line(9, 7, 30);
add_line(8, 0, 90);
add_line(4, 8, 30);
}
void AllRoute:: dij(int s, int end)
{
int pre[N];
memset(dis, 0x3f, sizeof dis);
memset(vis, 0, sizeof(vis));
dis[s] = 0;
q.push({ -1, s, 0 });//(dis , s)
while (!q.empty())
{
combine cur = q.top();
q.pop();
int x = cur.from;
int y = cur.to;
if (vis[y])continue;
vis[y] = 1;
pre[y] = x;
for (int i = hd[y]; i; i = e[i].nx)
{
int z = e[i].to;
if (dis[y] + e[i].w < dis[z])
{
dis[z] = dis[y] + e[i].w;
q.push({ y, z, dis[z] });
}
}
}
int cur = end, cnt = 0;
while (cur >= 0)
{
pick_path[++cnt] = cur;
//printf("%d->%d\n", cur, pre[cur]);
cur = pre[cur];
}
pick_path[0] = cnt;
pick_dis = dis[end];
//printf("%d\n", dis[end]);
}
bool AllRoute::show(int from, int to)
{
for (auto cur : all_line)
{
if (cur->pick(from, to))
{
setlinecolor((202, 211, 195));
setlinestyle(PS_DASH, 5);
cur->show();
setlinecolor(WHITE);
setlinestyle(PS_SOLID, 0);
return true;
}
}
printf("Path Not exist\n");
return false;
}
void AllRoute::show_all()
{
setlinecolor((202,211,195));
setlinestyle(PS_DASH, 5);
for (auto cur : all_line)
{
cur->show();
}
setlinecolor(WHITE);
setlinestyle(PS_SOLID, 0);
}
bool AllRoute::findRoute(int s, int e)
{
if (s == e)
{
printf("起点和终点不可选同一个\n");
return false;
}
dij(s,e);
for (int i = 1; i <= pick_path[0]-1; i++)
{
printf("%d->%d\n", pick_path[i], pick_path[i+1]);
show(pick_path[i], pick_path[i + 1]);
}
return true;
}