Skip to content

Commit

Permalink
Parameter -> ParameterRef
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Apr 19, 2019
1 parent d23242a commit 0ef3644
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/BendersBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function parametrized_function(var::StructuredVariableRef,
structured_model::StructuredModel,
model::JuMP.Model,
variable_map::Dict{Int, JuMP.VariableRef},
parameter_map::Dict{Int, ParameterJuMP.Parameter})
parameter_map::Dict{Int, ParameterJuMP.ParameterRef})
if var.model === structured_model
return variable_map[var.idx]
elseif var.model === structured_model.parent
Expand All @@ -24,9 +24,9 @@ function parametrized_function(aff::JuMP.GenericAffExpr{C, StructuredVariableRef
structured_model::StructuredModel,
model::JuMP.Model,
variable_map::Dict{Int, JuMP.VariableRef},
parameter_map::Dict{Int, ParameterJuMP.Parameter}) where C
parameter_map::Dict{Int, ParameterJuMP.ParameterRef}) where C
param_aff = ParameterJuMP.PAE{C}(JuMP.GenericAffExpr{C, JuMP.VariableRef}(aff.constant),
JuMP.GenericAffExpr{C, ParameterJuMP.Parameter}(zero(C)))
JuMP.GenericAffExpr{C, ParameterJuMP.ParameterRef}(zero(C)))
for (coef, var) in JuMP.linear_terms(aff)
JuMP.add_to_expression!(param_aff,
coef,
Expand All @@ -44,15 +44,15 @@ function parametrized_function(quad::JuMP.GenericQuadExpr{C, StructuredVariableR
structured_model::StructuredModel,
model::JuMP.Model,
variable_map::Dict{Int, JuMP.VariableRef},
parameter_map::Dict{Int, ParameterJuMP.Parameter}) where C
parameter_map::Dict{Int, ParameterJuMP.ParameterRef}) where C
param_aff = parametrized_function(quad.aff, structured_model, model, variable_map, parameter_map)
if param_aff isa ParameterJuMP.PAE
error("parametrized quadratic functions are not supported yet")
#quadv = JuMP.GenericQuadExpr{C, JuMP.VariableRef}(param_aff.v)
#quadp = JuMP.GenericQuadExpr{C, ParameterJuMP.Parameter}(param_aff.p)
#quadp = JuMP.GenericQuadExpr{C, ParameterJuMP.ParameterRef}(param_aff.p)
else
quadv = JuMP.GenericQuadExpr{C, JuMP.VariableRef}(param_aff)
quadp = JuMP.GenericQuadExpr{C, ParameterJuMP.Parameter}(zero(C))
quadp = JuMP.GenericQuadExpr{C, ParameterJuMP.ParameterRef}(zero(C))
end
for (coef, var1, var2) in JuMP.quadterms(quad)
if var1.model === structured_model && var2.model == structured_model
Expand All @@ -77,7 +77,7 @@ struct ParametrizedModel
variable_map::Dict{Int, JuMP.VariableRef}
# Map between index of structured variable in `structured_model.parent`
# and the corresponding parameter in `model`.
parameter_map::Dict{Int, ParameterJuMP.Parameter}
parameter_map::Dict{Int, ParameterJuMP.ParameterRef}
# Cost of children
θ::Dict{Int, JuMP.VariableRef}
end
Expand All @@ -92,7 +92,7 @@ function ParametrizedModel(structured_model::StructuredModel, args...; kwargs...
name = structured_model.varnames[index]
variable_map[index] = JuMP.add_variable(model, var, name)
end
parameter_map = Dict{Int, ParameterJuMP.Parameter}()
parameter_map = Dict{Int, ParameterJuMP.ParameterRef}()
for (index, con) in structured_model.constraints
name = structured_model.connames[index]
param_fun = parametrized_function(con.func, structured_model, model,
Expand Down
4 changes: 2 additions & 2 deletions src/Benders_pmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mutable struct Solution
variable_value::Dict{JuMP.VariableRef, Float64}
# Map between the parameter
# and the dual value
parameter_dual::Dict{Parameter, Float64}
parameter_dual::Dict{ParameterRef, Float64}
end

function optimize(model::ParametrizedModel)
Expand Down Expand Up @@ -39,7 +39,7 @@ function optimize(model::ParametrizedModel)
variable_value[θ] = JuMP.value(θ)
end
end
parameter_dual = Dict{Parameter, Float64}()
parameter_dual = Dict{ParameterRef, Float64}()
for parameter in values(model.parameter_map)
parameter_dual[parameter] = JuMP.dual(parameter)
end
Expand Down

0 comments on commit 0ef3644

Please sign in to comment.