105105
106106abstract type AbstractProblemIterator end
107107
108+ abstract type AbstractParameterType end
109+
110+ abstract type POIParamaterType <: AbstractParameterType end
111+
112+ abstract type JuMPNLPParameterType <: AbstractParameterType end
113+
114+ abstract type JuMPParameterType <: AbstractParameterType end
115+
108116"""
109117 ProblemIterator(ids::Vector{UUID}, pairs::Dict{VariableRef, Vector{Real}})
110118
@@ -115,24 +123,30 @@ struct ProblemIterator{T<:Real} <: AbstractProblemIterator
115123 ids:: Vector{UUID}
116124 pairs:: Dict{VariableRef,Vector{T}}
117125 early_stop:: Function
126+ param_type:: Type{<:AbstractParameterType}
127+ pre_solve_hook:: Function
118128 function ProblemIterator (
119129 ids:: Vector{UUID} ,
120130 pairs:: Dict{VariableRef,Vector{T}} ,
121131 early_stop:: Function = (args... ) -> false ,
132+ param_type:: Type{<:AbstractParameterType} = POIParamaterType,
133+ pre_solve_hook:: Function = (args... ) -> nothing
122134 ) where {T<: Real }
123135 model = JuMP. owner_model (first (keys (pairs)))
124136 for (p, val) in pairs
125137 @assert length (ids) == length (val)
126138 end
127- return new {T} (model, ids, pairs, early_stop)
139+ return new {T} (model, ids, pairs, early_stop, param_type, pre_solve_hook )
128140 end
129141end
130142
131143function ProblemIterator (
132- pairs:: Dict{VariableRef,Vector{T}} ; early_stop:: Function = (args... ) -> false
133- ) where {T<: Real }
144+ pairs:: Dict{VariableRef,Vector{T}} ; early_stop:: Function = (args... ) -> false ,
145+ pre_solve_hook:: Function = (args... ) -> nothing ,
146+ param_type:: Type{<:AbstractParameterType} = POIParamaterType,
134147 ids = [uuid1 () for _ in 1 : length (first (values (pairs)))]
135- return ProblemIterator (ids, pairs, early_stop)
148+ ) where {T<: Real }
149+ return ProblemIterator (ids, pairs, early_stop, param_type, pre_solve_hook)
136150end
137151
138152"""
174188
175189function load (model_file:: AbstractString , input_file:: AbstractString , :: Type{T} ;
176190 batch_size:: Union{Nothing, Integer} = nothing ,
177- ignore_ids:: Vector{UUID} = UUID[]
191+ ignore_ids:: Vector{UUID} = UUID[],
192+ param_type:: Type{<:AbstractParameterType} = JuMPParameterType
178193) where {T<: FileType }
179194 # Load full set
180195 df = load (input_file, T)
@@ -191,31 +206,40 @@ function load(model_file::AbstractString, input_file::AbstractString, ::Type{T};
191206 # No batch
192207 if isnothing (batch_size)
193208 pairs = _dataframe_to_dict (df, model_file)
194- return ProblemIterator (ids, pairs )
209+ return ProblemIterator (pairs; ids= ids, param_type = param_type )
195210 end
196211 # Batch
197212 num_batches = ceil (Int, length (ids) / batch_size)
198213 idx_range = (i) -> (i- 1 )* batch_size+ 1 : min (i* batch_size, length (ids))
199- return (i) -> ProblemIterator (ids[idx_range (i)], _dataframe_to_dict (df[idx_range (i), :], model_file)), num_batches
214+ return (i) -> ProblemIterator (_dataframe_to_dict (df[idx_range (i), :], model_file);
215+ ids= ids[idx_range (i)], param_type= param_type), num_batches
200216end
201217
202218"""
203219 update_model!(model::JuMP.Model, p::VariableRef, val::Real)
204220
205221Update the value of a parameter in a JuMP model.
206222"""
207- function update_model! (model:: JuMP.Model , p:: VariableRef , val)
223+ function update_model! (:: Type{POIParamaterType} , model:: JuMP.Model , p:: VariableRef , val)
208224 return MOI. set (model, POI. ParameterValue (), p, val)
209225end
210226
227+ function update_model! (:: Type{JuMPNLPParameterType} , model:: JuMP.Model , p:: VariableRef , val)
228+ return set_parameter_value (p, val)
229+ end
230+
231+ function update_model! (:: Type{JuMPParameterType} , model:: JuMP.Model , p:: VariableRef , val)
232+ return fix (p, val)
233+ end
234+
211235"""
212236 update_model!(model::JuMP.Model, pairs::Dict, idx::Integer)
213237
214238Update the values of parameters in a JuMP model.
215239"""
216- function update_model! (model:: JuMP.Model , pairs:: Dict , idx:: Integer )
240+ function update_model! (model:: JuMP.Model , pairs:: Dict , idx:: Integer , param_type :: Type{<:AbstractParameterType} )
217241 for (p, val) in pairs
218- update_model! (model, p, val[idx])
242+ update_model! (param_type, model, p, val[idx])
219243 end
220244end
221245
@@ -228,7 +252,8 @@ function solve_and_record(
228252 problem_iterator:: ProblemIterator , recorder:: Recorder , idx:: Integer
229253)
230254 model = problem_iterator. model
231- update_model! (model, problem_iterator. pairs, idx)
255+ problem_iterator. pre_solve_hook (model)
256+ update_model! (model, problem_iterator. pairs, idx, problem_iterator. param_type)
232257 optimize! (model)
233258 status = recorder. filterfn (model)
234259 early_stop_bool = problem_iterator. early_stop (model, status, recorder)
0 commit comments