@@ -6,7 +6,11 @@ Quadratic constraints are linearized using Mc Cormick linearization.
66Note: If you have Gurobi, use `grb_model` as `model_builder` instead of `highs_model`.
77"""
88function compact_linearized_mip (
9- instance:: Instance ; scenario_range= nothing , model_builder= scip_model, silent= true
9+ instance:: Instance ,
10+ θ= nothing ;
11+ scenario_range= nothing ,
12+ model_builder= scip_model,
13+ silent= true ,
1014)
1115 (; graph, slacks, intrinsic_delays, vehicle_cost, delay_cost) = instance
1216 nb_nodes = nv (graph)
@@ -28,13 +32,17 @@ function compact_linearized_mip(
2832 @variable (model, R[v in nodes, ω in Ω] >= 0 ) # propagated delay of job v
2933 @variable (model, yR[u in nodes, v in nodes, ω in Ω; has_edge (graph, u, v)] >= 0 ) # yR[u, v] = y[u, v] * R[u, ω]
3034
31- @objective (
32- model,
33- Min,
35+ obj = (
3436 delay_cost * sum (sum (R[v, ω] for v in job_indices) for ω in Ω) / nb_scenarios # average total delay
35- +
36- vehicle_cost * sum (y[1 , v] for v in job_indices) # nb_vehicles
37+ +
38+ vehicle_cost * sum (y[1 , v] for v in job_indices) # nb_vehicles
3739 )
40+ if ! isnothing (θ)
41+ @assert length (θ) == ne (graph)
42+ obj += sum (θ[a] * y[src (edge), dst (edge)] for (a, edge) in enumerate (edges (graph)))
43+ end
44+
45+ @objective (model, Min, obj)
3846
3947 # Flow contraints
4048 @constraint (
@@ -103,7 +111,11 @@ Note: If you have Gurobi, use `grb_model` as `model_builder` instead of `highs_m
103111 You need to use a solver that supports quadratic constraints to use this method.
104112"""
105113function compact_mip (
106- instance:: Instance ; scenario_range= nothing , model_builder= scip_model, silent= true
114+ instance:: Instance ,
115+ θ= nothing ;
116+ scenario_range= nothing ,
117+ model_builder= scip_model,
118+ silent= true ,
107119)
108120 (; graph, slacks, intrinsic_delays, vehicle_cost, delay_cost) = instance
109121 nb_nodes = nv (graph)
@@ -124,13 +136,17 @@ function compact_mip(
124136 @variable (model, R[v in nodes, ω in Ω] >= 0 ) # propagated delay of job v
125137 @variable (model, yR[u in nodes, v in nodes, ω in Ω; has_edge (graph, u, v)] >= 0 ) # yR[u, v] = y[u, v] * R[u, ω]
126138
127- @objective (
128- model,
129- Min,
139+ obj = (
130140 delay_cost * sum (sum (R[v, ω] for v in job_indices) for ω in Ω) / nb_scenarios # average total delay
131- +
132- vehicle_cost * sum (y[1 , v] for v in job_indices) # nb_vehicles
141+ +
142+ vehicle_cost * sum (y[1 , v] for v in job_indices) # nb_vehicles
133143 )
144+ if ! isnothing (θ)
145+ @assert length (θ) == ne (graph)
146+ obj += sum (θ[a] * y[src (edge), dst (edge)] for (a, edge) in enumerate (edges (graph)))
147+ end
148+
149+ @objective (model, Min, obj)
134150
135151 # Flow contraints
136152 @constraint (
@@ -170,6 +186,8 @@ $TYPEDSIGNATURES
170186SAA variant: build stochastic instance from `scenarios` then solve via
171187[`compact_mip`](@ref).
172188"""
173- function compact_mip (instance:: Instance , scenarios:: Vector{VSPScenario} ; kwargs... )
174- return compact_mip (build_stochastic_instance (instance, scenarios); kwargs... )
189+ function compact_mip (
190+ instance:: Instance , scenarios:: Vector{VSPScenario} , θ= nothing ; kwargs...
191+ )
192+ return compact_mip (build_stochastic_instance (instance, scenarios), θ; kwargs... )
175193end
0 commit comments