-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeterministic_mip.jl
More file actions
45 lines (38 loc) · 1.16 KB
/
deterministic_mip.jl
File metadata and controls
45 lines (38 loc) · 1.16 KB
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
"""
$TYPEDSIGNATURES
Solves the deterministic version of the vehicle scheduling problem using a MIP model.
Does not take into account the stochastic nature of the problem.
"""
function deterministic_mip(instance::Instance; model_builder=highs_model, silent=true)
(; graph, vehicle_cost) = instance
nb_nodes = nv(graph)
job_indices = 2:(nb_nodes - 1)
nodes = 1:nb_nodes
# Model definition
model = model_builder()
silent && set_silent(model)
# Variables and objective function
@variable(model, y[u in nodes, v in nodes; has_edge(graph, u, v)], Bin)
@objective(
model,
Min,
vehicle_cost * sum(y[1, v] for v in job_indices) # nb_vehicles
)
# Flow contraints
@constraint(
model,
flow[i in job_indices],
sum(y[j, i] for j in inneighbors(graph, i)) ==
sum(y[i, j] for j in outneighbors(graph, i))
)
@constraint(
model,
unit_demand[i in job_indices],
sum(y[j, i] for j in inneighbors(graph, i)) == 1
)
# Solve model
optimize!(model)
solution = value.(y)
sol = solution_from_JuMP_array(solution, graph)
return sol
end