@@ -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)
110121end
111122
@@ -115,15 +126,27 @@ end
115126Note: If you have Gurobi, use `grb_model` as `model_builder` instead od `glpk_model`.
116127"""
117128function 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(
149172end
150173
151174function 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
160194end
0 commit comments