-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.jl
275 lines (254 loc) · 8.48 KB
/
plot.jl
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
using Plots
pyplot()
include("Bus.jl")
Plots.scalefontsizes()
Plots.scalefontsizes(1)
colors = palette(:tab20)
#colors = ["tomato1","mediumpurple", "springgreen2", "royalblue4", "lightskyblue", "yellow", "teal", "goldenrod1", "brown2", "brown2", "brown2", "brown2", "brown2", "brown2" ]
"Ajoute un cluster à un graphique (points reliés par des lignes)"
function add_cluster_to_plot!(cluster::Cluster, localisations::Vector{Bus_stop}, pl::Plots.Plot, index::Int = 0)
loc_depot = localisations[cluster.depot.start_point]
latitude_list = [loc_depot.latitude]
longitude_list = [loc_depot.longitude]
for i in 1:length(cluster.points)
bus_stop = localisations[cluster.points[i]]
push!(latitude_list, bus_stop.latitude)
push!(longitude_list, bus_stop.longitude)
end
loc_gare = loc[cluster.gare.start_point]
push!(latitude_list, loc_gare.latitude)
push!(longitude_list, loc_gare.longitude)
if index == 0
label = "cluster"
else
label = "cluster n°" * string(index)
end
plot!(
pl, latitude_list, longitude_list,
linewidth = 1,
label = label,
legend=:outertopleft
)
end
"Ajoute un cluster à un graphique"
function scatter_cluster_to_plot!(cluster::Cluster, localisations::Vector{Bus_stop}, pl::Plots.Plot, index::Int = 0)
latitude_list = []
longitude_list = []
for i in 1:length(cluster.points)
bus_stop = localisations[cluster.points[i]]
push!(latitude_list, bus_stop.latitude)
push!(longitude_list, bus_stop.longitude)
end
if index == 0
label = "cluster"
else
label = "cluster n°" * string(index)
end
scatter!(
pl, latitude_list, longitude_list,
markersize = 4,
markeralpha = 1,
markerstrokealpha = 0,
label = label,
legend = :outertopleft
)
end
"Ajoute un cluster à un graphique"
function scatter_cluster_to_plot!(cluster::Cluster, localisations::Vector{Bus_stop}, pl::Plots.Plot, colors, index::Int = 0)
latitude_list = []
longitude_list = []
for i in 1:length(cluster.points)
bus_stop = localisations[cluster.points[i]]
push!(latitude_list, bus_stop.latitude)
push!(longitude_list, bus_stop.longitude)
end
if index == 0
label = "cluster"
else
label = "cluster n°" * string(index)
end
scatter!(
pl, latitude_list, longitude_list,
markersize = 4,
markeralpha = 1,
color = colors,
markerstrokealpha = 0,
label = label,
legend = false,# :outertopleft
)
end
"Affiche le graphique des clusters présents dans une solution"
function plot_clusters(solution::Solution, localisations::Vector{Bus_stop}, pl::Plots.Plot, scatter = true)::Plots.Plot
for (index, cluster) in enumerate(solution.clusters)
if scatter
scatter_cluster_to_plot!(cluster, localisations, pl, index)
else
add_cluster_to_plot!(cluster, localisations, pl, index)
end
end
plot!(title = "Carte des clusters")
return pl
end
"Affiche le graphique des clusters présents dans une solution sans modifier le graphe initial"
function plot_clusters_copy(solution::Solution, localisations::Vector{Bus_stop}, pl::Plots.Plot, scatter = true)::Plots.Plot
pl_copy = deepcopy(pl)
for (index, cluster) in enumerate(solution.clusters)
if scatter
scatter_cluster_to_plot!(cluster, localisations, pl_copy, index)
else
add_cluster_to_plot!(cluster, localisations, pl_copy, index)
end
end
plot!(title = "Carte des clusters")
return pl_copy
end
"Affiche les dépots et la gare"
function plot_terminus(loc::Vector{Bus_stop}, drivers::Vector{Person}, gare::Person, pl = nothing)::Plots.Plot
index_gare = gare.start_point
if pl == nothing
pl = plot()
end
#On affiche les dépots
latitude_list = []
longitude_list = []
for driver in drivers
loc_depot = loc[driver.start_point]
push!(latitude_list, loc_depot.latitude)
push!(longitude_list, loc_depot.longitude)
end
scatter!(
pl, latitude_list, longitude_list,
markershape = :diamond,
markersize = 5,
markeralpha = 1,
markercolor = :green,
markerstrokealpha = 0,
label = "depots",
legend=:outertopleft
)
#On affiche la gare
loc_gare = loc[index_gare]
scatter!(
pl, [loc_gare.latitude], [loc_gare.longitude],
markershape = :rect,
markersize = 5,
markeralpha = 1,
markercolor = :red,
markerstrokealpha = 0,
label = "gare",
legend = :outertopleft
)
plot!(title = "Carte des arrets de bus")
return pl
end
"""
Inputs :
- localisations un vecteur d'éléments de type Bus_stop qui contient les localisations de tous les arrets de bus
- drivers la liste des drivers (de type Person)
- index_gare l'indice de la gare
Affiche le graphique des arrets de bus, des dépots et de la gare
Output : le graphe
"""
function plot_bus_stops(localisations::Vector{Bus_stop}, drivers::Vector{Person}, gare::Person)::Plots.Plot
pl = plot()
#On affiche les arrets de bus
latitude_list = []
longitude_list = []
for i in 1:length(localisations)
bus_stop = localisations[i]
push!(latitude_list, bus_stop.latitude)
push!(longitude_list, bus_stop.longitude)
end
scatter!(
pl, latitude_list, longitude_list,
marker = (:circle, 3, 0.7, "black"),
label = "arrets de bus",
legend=:outertopleft
)
plot_terminus(localisations, drivers, gare, pl)
plot!(title = "Carte des arrets de bus")
return pl
end
function add_bus_route_to_plot!(bus::Bus, localisations::Vector{Bus_stop}, pl::Plots.Plot, index::Int = 0)
latitude_list = []
longitude_list = []
for i in 1:length(bus.stops)
bus_stop = localisations[bus.stops[i]]
push!(latitude_list, bus_stop.latitude)
push!(longitude_list, bus_stop.longitude)
end
if index == 0
label = "bus"
else
label = "bus n°" * string(index)
end
plot!(
pl, latitude_list, longitude_list,
linewidth = 1,
label = label,
legend =:outertopleft,
)
end
function add_bus_route_to_plot!(bus::Bus, localisations::Vector{Bus_stop}, pl::Plots.Plot, color,index::Int = 0)
latitude_list = []
longitude_list = []
for i in 1:length(bus.stops)
bus_stop = localisations[bus.stops[i]]
push!(latitude_list, bus_stop.latitude)
push!(longitude_list, bus_stop.longitude)
end
if index == 0
label = "bus"
else
label = "bus n°" * string(index)
end
plot!(
pl, latitude_list, longitude_list,
linewidth = 1,
label = label,
legend = false,#:outertopleft,
color=color,
)
end
function plot_bus_routes(buses::Vector{Bus},localisations::Vector{Bus_stop}, pl::Plots.Plot)
for (index, bus) in enumerate(buses)
add_bus_route_to_plot!(bus, localisations, pl, index)
end
plot!(title = "Carte des bus")
return pl
end
function plot_bus_routes_copy(buses::Vector{Bus},localisations::Vector{Bus_stop}, pl::Plots.Plot)
pl_copy = deepcopy(pl)
for (index, bus) in enumerate(buses)
add_bus_route_to_plot!(bus, localisations, pl_copy, index)
end
plot!(title = "Carte des bus")
return pl_copy
end
function plot_points_bus_routes_copy(depots, gare, clients_refuses, solution, buses::Vector{Bus},localisations::Vector{Bus_stop})
pl_new = plot_terminus(localisations, depots, gare)
for (index, cluster) in enumerate(solution.clusters)
color = colors[index]
scatter_cluster_to_plot!(cluster, localisations, pl_new, color, index)
end
for (index, bus) in enumerate(buses)
color = colors[index]
add_bus_route_to_plot!(bus, localisations, pl_new, color, index)
end
latitude_list = []
longitude_list = []
for (index, person) in enumerate(clients_refuses)
push!(latitude_list, localisations[person.start_point].latitude)
push!(longitude_list, localisations[person.start_point].longitude)
end
if length(clients_refuses) != 0
scatter!(
pl_new, latitude_list, longitude_list,
marker = (:circle, 3, 0.7, "black"),
label = "clients refusés",
legend=false#:outertopleft
)
end
plot!(title = "Carte des clusters et des bus")
return pl_new
end