Skip to content

Commit be418bd

Browse files
committed
update plotting methods
1 parent b3505c2 commit be418bd

2 files changed

Lines changed: 38 additions & 15 deletions

File tree

src/StochasticVehicleScheduling/StochasticVehicleScheduling.jl

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,53 +134,64 @@ function plot_instance(
134134
(; tasks, district_width, width) = sample.instance.city
135135
ticks = 0:district_width:width
136136
max_time = maximum(t.end_time for t in sample.instance.city.tasks[1:(end - 1)])
137-
pp = floor(Int, max(max_time))
138-
palette = Plots.palette(color_scheme, pp)
139137
fig = plot(;
140138
xlabel="x",
141139
ylabel="y",
142-
legend=false,
143140
gridlinewidth=3,
144141
aspect_ratio=:equal,
145142
size=(500, 500),
146143
xticks=ticks,
147144
yticks=ticks,
148145
xlims=(-1, width + 1),
149146
ylims=(-1, width + 1),
147+
clim=(0.0, max_time),
148+
label=nothing,
149+
colorbar_title="Time",
150+
)
151+
scatter!(
152+
fig,
153+
[tasks[1].start_point.x],
154+
[tasks[1].start_point.y];
155+
label=nothing,
156+
marker=:rect,
157+
markersize=10,
150158
)
151-
for (i_task, task) in enumerate(tasks[1:(end - 1)])
159+
annotate!(fig, (tasks[1].start_point.x, tasks[1].start_point.y, text("0", 10)))
160+
for (i_task, task) in enumerate(tasks[2:(end - 1)])
152161
(; start_point, end_point) = task
153162
points = [(start_point.x, start_point.y), (end_point.x, end_point.y)]
154-
plot!(fig, points; color=:black)
163+
plot!(fig, points; color=:black, label=nothing)
155164
scatter!(
156165
fig,
157166
points[1];
158167
markersize=10,
159168
marker=:rect,
160-
color=palette[max(floor(Int, task.start_time), 1)],
169+
marker_z=task.start_time,
170+
colormap=:turbo,
171+
label=nothing,
161172
)
162173
scatter!(
163174
fig,
164175
points[2];
165176
markersize=10,
166177
marker=:rect,
167-
color=palette[max(floor(Int, task.end_time), 1)],
178+
marker_z=task.end_time,
179+
colormap=:turbo,
180+
label=nothing,
181+
# color=palette[max(floor(Int, task.end_time), 1)],
168182
)
169-
annotate!(fig, (points[1]..., text("$(i_task-1)", 10)))
183+
annotate!(fig, (points[1]..., text("$(i_task)", 10)))
170184
end
171-
p2 = Plots.heatmap(
172-
rand(2, 2); clims=(0, pp), framestyle=:none, c=palette, cbar=true, lims=(-1, -1)
173-
)
174-
l = Plots.@layout [a{0.99w} b]
175-
return plot(fig, p2; layout=l)
185+
return fig
176186
end
177187

178188
function plot_solution(
179189
::StochasticVehicleSchedulingBenchmark, sample::DataSample{<:Instance{City}}; kwargs...
180190
)
181191
(; tasks, district_width, width) = sample.instance.city
182192
ticks = 0:district_width:width
183-
path_list = compute_path_list(sample.y_true)
193+
solution = Solution(sample.y_true, sample.instance)
194+
path_list = compute_path_list(solution)
184195
fig = plot(;
185196
xlabel="x",
186197
ylabel="y",

src/Utils/interface.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,25 @@ It's usually a Flux model, that takes a feature matrix x as input, and returns a
4040
function generate_statistical_model end
4141

4242
"""
43-
plot_data(::AbstractBenchmark, args...)
43+
plot_data(::AbstractBenchmark, ::DataSample; kwargs...)
4444
4545
Plot a data sample from the dataset created by [`generate_dataset`](@ref).
4646
Check the specific benchmark documentation of `plot_data` for more details on the arguments.
4747
"""
4848
function plot_data end
49+
50+
"""
51+
plot_instance(::AbstractBenchmark, instance; kwargs...)
52+
53+
Plot the instance object of the sample.
54+
"""
4955
function plot_instance end
56+
57+
"""
58+
plot_solution(::AbstractBenchmark, sample::DataSample, [solution]; kwargs...)
59+
60+
Plot `solution` if given, else plot the target solution in the sample.
61+
"""
5062
function plot_solution end
5163

5264
"""

0 commit comments

Comments
 (0)