Skip to content

Commit b9fbae5

Browse files
authored
Merge pull request #26 from JuliaDecisionFocusedLearning/deterministic-vsp-solver
Implement the deterministic vsp as a possible solver
2 parents ff93d7a + 25e9ac8 commit b9fbae5

File tree

4 files changed

+63
-7
lines changed

4 files changed

+63
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DecisionFocusedLearningBenchmarks"
22
uuid = "2fbe496a-299b-4c81-bab5-c44dfc55cf20"
33
authors = ["Members of JuliaDecisionFocusedLearning"]
4-
version = "0.2.1"
4+
version = "0.2.2"
55

66
[deps]
77
ConstrainedShortestPaths = "b3798467-87dc-4d99-943d-35a1bd39e395"

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: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@
33
using DecisionFocusedLearningBenchmarks.StochasticVehicleScheduling
44
using Graphs
55
using Plots
6+
using StableRNGs: StableRNG
67

78
b = StochasticVehicleSchedulingBenchmark(; nb_tasks=25, nb_scenarios=10)
89

910
N = 5
10-
dataset = generate_dataset(b, N; seed=0)
11-
mip_dataset = generate_dataset(b, N; seed=0, algorithm=compact_mip)
12-
mipl_dataset = generate_dataset(b, N; seed=0, algorithm=compact_linearized_mip)
13-
local_search_dataset = generate_dataset(b, N; seed=0, algorithm=local_search)
11+
dataset = generate_dataset(b, N; seed=0, rng=StableRNG(0))
12+
mip_dataset = generate_dataset(b, N; seed=0, rng=StableRNG(0), algorithm=compact_mip)
13+
mipl_dataset = generate_dataset(
14+
b, N; seed=0, rng=StableRNG(0), algorithm=compact_linearized_mip
15+
)
16+
local_search_dataset = generate_dataset(
17+
b, N; seed=0, rng=StableRNG(0), algorithm=local_search
18+
)
19+
deterministic_dataset = generate_dataset(
20+
b, N; seed=0, rng=StableRNG(0), algorithm=deterministic_mip
21+
)
1422
@test length(dataset) == N
1523

1624
figure_1 = plot_instance(b, dataset[1])
@@ -25,11 +33,12 @@
2533
gap_mip = compute_gap(b, mip_dataset, model, maximizer)
2634
gap_mipl = compute_gap(b, mipl_dataset, model, maximizer)
2735
gap_local_search = compute_gap(b, local_search_dataset, model, maximizer)
36+
gap_deterministic = compute_gap(b, deterministic_dataset, model, maximizer)
2837

29-
@test gap >= 0 && gap_mip >= 0 && gap_mipl >= 0 && gap_local_search >= 0
3038
@test gap_mip gap_mipl rtol = 1e-2
3139
@test gap_mip >= gap_local_search
3240
@test gap_mip >= gap
41+
@test gap_local_search >= gap_deterministic
3342

3443
for sample in dataset
3544
x = sample.x

0 commit comments

Comments
 (0)