Skip to content

Commit 82d31df

Browse files
committed
Implement the deterministic vsp as a possible solver
1 parent ff93d7a commit 82d31df

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

src/StochasticVehicleScheduling/StochasticVehicleScheduling.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module StochasticVehicleScheduling
33
export StochasticVehicleSchedulingBenchmark
44
export generate_dataset, generate_maximizer, generate_statistical_model
55
export plot_instance, plot_solution
6-
export compact_linearized_mip, compact_mip, column_generation_algorithm, local_search
6+
export compact_linearized_mip,
7+
compact_mip, column_generation_algorithm, local_search, deterministic_mip
78
export evaluate_solution, is_feasible
89

910
using ..Utils
@@ -44,6 +45,7 @@ include("solution/solution.jl")
4445
include("solution/algorithms/mip.jl")
4546
include("solution/algorithms/column_generation.jl")
4647
include("solution/algorithms/local_search.jl")
48+
include("solution/algorithms/deterministic_mip.jl")
4749

4850
include("maximizer.jl")
4951

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
$TYPEDSIGNATURES
3+
4+
Solves the deterministic version of the vehicle scheduling problem using a MIP model.
5+
Does not take into account the stochastic nature of the problem.
6+
"""
7+
function deterministic_mip(instance::Instance; model_builder=highs_model, silent=true)
8+
(; graph, vehicle_cost) = instance
9+
nb_nodes = nv(graph)
10+
job_indices = 2:(nb_nodes - 1)
11+
nodes = 1:nb_nodes
12+
13+
# Model definition
14+
model = model_builder()
15+
silent && set_silent(model)
16+
17+
# Variables and objective function
18+
@variable(model, y[u in nodes, v in nodes; has_edge(graph, u, v)], Bin)
19+
20+
@objective(
21+
model,
22+
Min,
23+
vehicle_cost * sum(y[1, v] for v in job_indices) # nb_vehicles
24+
)
25+
26+
# Flow contraints
27+
@constraint(
28+
model,
29+
flow[i in job_indices],
30+
sum(y[j, i] for j in inneighbors(graph, i)) ==
31+
sum(y[i, j] for j in outneighbors(graph, i))
32+
)
33+
@constraint(
34+
model,
35+
unit_demand[i in job_indices],
36+
sum(y[j, i] for j in inneighbors(graph, i)) == 1
37+
)
38+
39+
# Solve model
40+
optimize!(model)
41+
solution = value.(y)
42+
43+
sol = solution_from_JuMP_array(solution, graph)
44+
return sol
45+
end

test/vsp.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
mip_dataset = generate_dataset(b, N; seed=0, algorithm=compact_mip)
1212
mipl_dataset = generate_dataset(b, N; seed=0, algorithm=compact_linearized_mip)
1313
local_search_dataset = generate_dataset(b, N; seed=0, algorithm=local_search)
14+
deterministic_dataset = generate_dataset(b, N; seed=0, algorithm=deterministic_mip)
1415
@test length(dataset) == N
1516

1617
figure_1 = plot_instance(b, dataset[1])
@@ -25,11 +26,17 @@
2526
gap_mip = compute_gap(b, mip_dataset, model, maximizer)
2627
gap_mipl = compute_gap(b, mipl_dataset, model, maximizer)
2728
gap_local_search = compute_gap(b, local_search_dataset, model, maximizer)
29+
gap_deterministic = compute_gap(b, deterministic_dataset, model, maximizer)
2830

29-
@test gap >= 0 && gap_mip >= 0 && gap_mipl >= 0 && gap_local_search >= 0
31+
@test gap >= 0 &&
32+
gap_mip >= 0 &&
33+
gap_mipl >= 0 &&
34+
gap_local_search >= 0 &&
35+
gap_deterministic >= 0
3036
@test gap_mip gap_mipl rtol = 1e-2
3137
@test gap_mip >= gap_local_search
3238
@test gap_mip >= gap
39+
@test gap__local_search >= gap_deterministic
3340

3441
for sample in dataset
3542
x = sample.x

0 commit comments

Comments
 (0)