Skip to content

Commit 09e619b

Browse files
committed
simple plot tests
1 parent 3499195 commit 09e619b

File tree

2 files changed

+36
-38
lines changed

2 files changed

+36
-38
lines changed

src/DynamicVehicleScheduling/anticipative_solver.jl

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -130,44 +130,7 @@ function anticipative_solver(
130130

131131
optimize!(model)
132132

133-
# Debug infeasibility
134-
if termination_status(model) == JuMP.MOI.INFEASIBLE
135-
@warn "Model is infeasible! Let's debug..."
136-
@info "Number of nodes: $nb_nodes"
137-
@info "Number of job indices: $(length(job_indices))"
138-
@info "Epoch indices: $epoch_indices"
139-
@info "Request epochs: $request_epoch"
140-
@info "Start times: $start_time"
141-
@info "Service times: $service_time"
142-
@info "Epoch duration: $epoch_duration, Δ_dispatch: $Δ_dispatch"
143-
144-
# Check if any job can be scheduled in any epoch
145-
for i in job_indices
146-
can_schedule = false
147-
for t in epoch_indices
148-
# Check release constraint
149-
if t >= request_epoch[i]
150-
# Check time limit constraint
151-
travel_time = duration[1, i]
152-
arrival_time = (t - 1) * epoch_duration + Δ_dispatch + travel_time
153-
if arrival_time <= start_time[i]
154-
can_schedule = true
155-
@info "Job $i can be scheduled in epoch $t (arrival: $arrival_time <= deadline: $(start_time[i]))"
156-
break
157-
else
158-
@info "Job $i cannot be scheduled in epoch $t: arrival $arrival_time > deadline $(start_time[i])"
159-
end
160-
else
161-
@info "Job $i cannot be scheduled in epoch $t: request epoch $(request_epoch[i]) > epoch $t"
162-
end
163-
end
164-
if !can_schedule
165-
@warn "Job $i cannot be scheduled in any epoch! Request epoch: $(request_epoch[i]), start time: $(start_time[i]), travel time: $(duration[1, i]), release index $(customer_index[i])"
166-
@warn " Epochs available: $epoch_indices"
167-
@warn " Epoch duration: $epoch_duration, Δ_dispatch: $Δ_dispatch"
168-
end
169-
end
170-
end
133+
@assert termination_status(model) == JuMP.MOI.OPTIMAL "Anticipative MIP did not solve to optimality! (status: $(termination_status(model)))"
171134
obj = JuMP.objective_value(model)
172135
epoch_routes = retrieve_routes_anticipative(
173136
value.(y), env, customer_index, epoch_indices

test/dynamic_vsp_plots.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@testitem "Dynamic VSP Plots" begin
2+
using DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling
3+
const DVSP = DecisionFocusedLearningBenchmarks.DynamicVehicleScheduling
4+
using Plots
5+
6+
# Create test benchmark and data (similar to scripts/a.jl)
7+
b = DynamicVehicleSchedulingBenchmark(; two_dimensional_features=true)
8+
dataset = generate_dataset(b, 3)
9+
environments = generate_environments(b, dataset; seed=0)
10+
env = environments[1]
11+
12+
# Test basic plotting functions
13+
fig1 = DVSP.plot_instancee(env)
14+
@test fig1 isa Plots.Plot
15+
16+
# Test with anticipative solution and plot_epochs (like in the script)
17+
instance = dataset[1].instance
18+
scenario = generate_scenario(b, instance; seed=0)
19+
v, y = generate_anticipative_solution(b, env, scenario; nb_epochs=3, reset_env=true)
20+
21+
fig2 = DVSP.plot_epochs(y)
22+
@test fig2 isa Plots.Plot
23+
24+
# Test animation
25+
temp_filename = tempname() * ".gif"
26+
try
27+
anim = DVSP.animate_epochs(y; filename=temp_filename, fps=1)
28+
@test anim isa Plots.AnimatedGif || anim isa Plots.Animation
29+
@test isfile(temp_filename)
30+
finally
31+
if isfile(temp_filename)
32+
rm(temp_filename)
33+
end
34+
end
35+
end

0 commit comments

Comments
 (0)