Skip to content

Commit 07d00ab

Browse files
committed
option to restrict scenarios
1 parent 91482b8 commit 07d00ab

File tree

3 files changed

+64
-181
lines changed

3 files changed

+64
-181
lines changed

docs/src/warcraft.md

Lines changed: 0 additions & 155 deletions
This file was deleted.

src/StochasticVehicleScheduling/solution/exact_algorithms/column_generation.jl

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,17 @@ function column_generation(
2727
model_builder=highs_model,
2828
bounding,
2929
use_convex_resources,
30+
scenario_range=nothing,
31+
silent=true,
3032
)
31-
(; graph, slacks, intrinsic_delays, vehicle_cost, delay_cost) = instance
33+
(; graph, vehicle_cost, delay_cost) = instance
34+
35+
Ω = isnothing(scenario_range) ? (1:get_nb_scenarios(instance)) : scenario_range
36+
intrinsic_delays = instance.intrinsic_delays[:, Ω]
37+
slacks = deepcopy(instance.slacks)
38+
for edge in edges(graph)
39+
slacks[src(edge), dst(edge)] = slacks[src(edge), dst(edge)][Ω]
40+
end
3241

3342
nb_nodes = nv(graph)
3443
job_indices = 2:(nb_nodes - 1)
@@ -66,6 +75,7 @@ function column_generation(
6675
)
6776
λ_sum = sum(λ_val[v] for v in job_indices if v in p_star)
6877
path_cost = delay_cost * c_star + λ_sum + vehicle_cost
78+
silent || @info path_cost - λ_sum
6979
if path_cost - λ_sum > -1e-10
7080
break
7181
end
@@ -89,23 +99,24 @@ function column_generation(
8999
dual.(cons)
90100
end
91101

92-
# else, try to close the gap
93-
threshold = (c_upp - c_low - vehicle_cost) / delay_cost
94-
λ_val = value.(λ)
95-
additional_paths, costs = stochastic_routing_shortest_path_with_threshold(
96-
graph,
97-
slacks,
98-
intrinsic_delays,
99-
λ_val ./ delay_cost;
100-
threshold,
101-
bounding=true,
102-
use_convex_resources=false,
103-
)
102+
# @info "hello"
103+
# # else, try to close the gap
104+
# threshold = (c_upp - c_low - vehicle_cost) / delay_cost
105+
# λ_val = value.(λ)
106+
# @info "" size(intrinsic_delays) threshold
107+
# additional_paths, costs = stochastic_routing_shortest_path_with_threshold(
108+
# graph,
109+
# slacks,
110+
# intrinsic_delays,
111+
# λ_val ./ delay_cost;
112+
# threshold,
113+
# bounding,
114+
# use_convex_resources,
115+
# )
116+
# @info "done"
104117

105118
return value.(λ),
106-
objective_value(model),
107-
unique(cat(initial_paths, new_paths, additional_paths; dims=1)),
108-
dual.(con),
119+
objective_value(model), unique(cat(initial_paths, new_paths; dims=1)), dual.(con),
109120
dual.(cons)
110121
end
111122

@@ -115,15 +126,27 @@ end
115126
Note: If you have Gurobi, use `grb_model` as `model_builder` instead od `glpk_model`.
116127
"""
117128
function compute_solution_from_selected_columns(
118-
instance::Instance, paths; bin=true, model_builder=highs_model
129+
instance::Instance,
130+
paths;
131+
bin=true,
132+
model_builder=highs_model,
133+
scenario_range=nothing,
134+
silent=true,
119135
)
120-
(; graph, slacks, intrinsic_delays, vehicle_cost, delay_cost) = instance
136+
(; graph, vehicle_cost, delay_cost) = instance
121137

122138
nb_nodes = nv(graph)
123139
job_indices = 2:(nb_nodes - 1)
124140

141+
Ω = isnothing(scenario_range) ? (1:get_nb_scenarios(instance)) : scenario_range
142+
intrinsic_delays = instance.intrinsic_delays[:, Ω]
143+
slacks = deepcopy(instance.slacks)
144+
for edge in edges(graph)
145+
slacks[src(edge), dst(edge)] = slacks[src(edge), dst(edge)][Ω]
146+
end
147+
125148
model = model_builder()
126-
set_silent(model)
149+
silent && set_silent(model)
127150

128151
if bin
129152
@variable(model, y[p in paths], Bin)
@@ -149,12 +172,23 @@ function compute_solution_from_selected_columns(
149172
end
150173

151174
function column_generation_algorithm(
152-
instance::Instance; bounding=false, use_convex_resources=false
175+
instance::Instance,
176+
scenario_range=nothing;
177+
bounding=false,
178+
use_convex_resources=false,
179+
silent=true,
153180
)
181+
Ω = isnothing(scenario_range) ? (1:get_nb_scenarios(instance)) : scenario_range
154182
_, _, columns, _, _ = column_generation(
155-
instance; bounding=bounding, use_convex_resources=use_convex_resources
183+
instance;
184+
bounding=bounding,
185+
use_convex_resources=use_convex_resources,
186+
scenario_range=Ω,
187+
silent=silent,
188+
)
189+
_, _, sol = compute_solution_from_selected_columns(
190+
instance, columns; scenario_range=Ω, silent=silent
156191
)
157-
_, _, sol = compute_solution_from_selected_columns(instance, columns)
158192
col_solution = solution_from_paths(sol, instance)
159193
return col_solution
160194
end

src/StochasticVehicleScheduling/solution/exact_algorithms/mip.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ Returns the optimal solution of the Stochastic VSP instance, by solving the asso
55
Quadratic constraints are linearized using Mc Cormick linearization.
66
Note: If you have Gurobi, use `grb_model` as `model_builder` instead of `highs_model`.
77
"""
8-
function compact_linearized_mip(instance::Instance; model_builder=scip_model, silent=true)
8+
function compact_linearized_mip(
9+
instance::Instance, scenario_range=nothing; model_builder=scip_model, silent=true
10+
)
911
(; graph, slacks, intrinsic_delays, vehicle_cost, delay_cost) = instance
1012
nb_nodes = nv(graph)
1113
job_indices = 2:(nb_nodes - 1)
@@ -15,7 +17,7 @@ function compact_linearized_mip(instance::Instance; model_builder=scip_model, si
1517
ε = intrinsic_delays
1618
Rmax = maximum(sum(ε; dims=1))
1719
nb_scenarios = size(ε, 2)
18-
Ω = 1:nb_scenarios
20+
Ω = isnothing(scenario_range) ? (1:nb_scenarios) : scenario_range
1921

2022
# Model definition
2123
model = model_builder()
@@ -88,7 +90,9 @@ Note: If you have Gurobi, use `grb_model` as `model_builder` instead of `highs_m
8890
!!! warning
8991
You need to use a solver that supports quadratic constraints to use this method.
9092
"""
91-
function compact_mip(instance::Instance; model_builder=scip_model, silent=true)
93+
function compact_mip(
94+
instance::Instance, scenario_range=nothing; model_builder=scip_model, silent=true
95+
)
9296
(; graph, slacks, intrinsic_delays, vehicle_cost, delay_cost) = instance
9397
nb_nodes = nv(graph)
9498
job_indices = 2:(nb_nodes - 1)
@@ -97,7 +101,7 @@ function compact_mip(instance::Instance; model_builder=scip_model, silent=true)
97101
# Pre-processing
98102
ε = intrinsic_delays
99103
nb_scenarios = size(ε, 2)
100-
Ω = 1:nb_scenarios
104+
Ω = isnothing(scenario_range) ? (1:nb_scenarios) : scenario_range
101105

102106
# Model definition
103107
model = model_builder()

0 commit comments

Comments
 (0)