Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates now that is ParameterJuMP released #72

Merged
merged 6 commits into from
Apr 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Manifest.toml
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ os:
- linux
- osx
julia:
- 0.7
- 1.0
- 1.1
notifications:
email: false
sudo: false
Expand All @@ -14,7 +14,5 @@ addons:
- liblapack-dev
- libgmp-dev
- libglpk-dev
before_script:
- julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuMP", rev="master")); Pkg.add(PackageSpec(url="https://github.com/JuliaStochOpt/ParameterJuMP.jl.git"))'
after_success:
- julia -e 'cd(Pkg.dir("StructJuMP")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
25 changes: 25 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name = "StructJuMP"
uuid = "34f15cae-5318-50c9-93d3-9feadd34e321"
repo = "https://github.com/StructJuMP/StructJuMP.jl.git"
version = "0.1.0"

[deps]
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
ParameterJuMP = "774612a8-9878-5177-865a-ca53ae2495f9"

[compat]
JuMP = "0.19"
MathOptInterface = "0.8"
ParameterJuMP = "0.1"
julia = "1"

[extras]
ECOS = "e2685f51-7e38-5353-a97d-a921fd2c8199"
GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6"
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["GLPK", "Test", "ECOS", "Ipopt"]
4 changes: 0 additions & 4 deletions REQUIRE

This file was deleted.

18 changes: 9 additions & 9 deletions src/BendersBridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ 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
if !haskey(parameter_map, var.idx)
parameter_map[var.idx] = ParameterJuMP.Parameter(model)
parameter_map[var.idx] = ParameterJuMP.add_parameter(model)
end
return parameter_map[var.idx]
else
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
6 changes: 3 additions & 3 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 All @@ -50,7 +50,7 @@ function set_parent_solution!(model::ParametrizedModel, parent::ParametrizedMode
for (index, parameter) in model.parameter_map
vref = parent.variable_map[index]
value = parent_solution.variable_value[vref]
ParameterJuMP.setvalue!(parameter, value)
JuMP.fix(parameter, value)
end
end

Expand Down
3 changes: 0 additions & 3 deletions test/REQUIRE

This file was deleted.