Skip to content

Commit ac55b4d

Browse files
authored
Merge pull request #85 from StructJuMP/kkim
Update JuMP to v1.0.0 and others
2 parents e0b66e9 + 90a4634 commit ac55b4d

File tree

11 files changed

+62
-27
lines changed

11 files changed

+62
-27
lines changed

Project.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "StructJuMP"
22
uuid = "34f15cae-5318-50c9-93d3-9feadd34e321"
33
repo = "https://github.com/StructJuMP/StructJuMP.jl.git"
4-
version = "0.2.0"
4+
version = "0.3.0"
55

66
[deps]
77
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
@@ -10,10 +10,10 @@ MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
1010
ParameterJuMP = "774612a8-9878-5177-865a-ca53ae2495f9"
1111

1212
[compat]
13-
JuMP = "0.21.3"
14-
MathOptInterface = "0.9.14"
15-
ParameterJuMP = "0.2"
16-
julia = "1"
13+
JuMP = "0.23, 1"
14+
MathOptInterface = "1"
15+
ParameterJuMP = "0.4.1"
16+
julia = "1.6"
1717

1818
[extras]
1919
ECOS = "e2685f51-7e38-5353-a97d-a921fd2c8199"

examples/dcap.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using StructJuMP
2+
using Random
3+
4+
function DCAP(nR::Int, nN::Int, nT::Int, nS::Int, seed::Int=1)::StructuredModel
5+
6+
# set random seed (default=1)
7+
Random.seed!(seed)
8+
9+
# generate & store instance data
10+
## sets
11+
R = 1:nR
12+
N = 1:nN
13+
T = 1:nT
14+
S = 1:nS
15+
16+
## parameters
17+
a = rand(nR, nT) * 5 .+ 5
18+
b = rand(nR, nT) * 40 .+ 10
19+
c = rand(nR, nN, nT, nS) * 5 .+ 5
20+
c0 = rand(nN, nT, nS) * 500 .+ 500
21+
d = rand(nN, nT, nS) .+ 0.5
22+
Pr = ones(nS)/nS
23+
24+
# construct JuMP.Model
25+
model = StructuredModel(num_scenarios = nS)
26+
27+
## 1st stage
28+
@variable(model, x[i=R,t=T] >= 0)
29+
@variable(model, u[i=R,t=T], Bin)
30+
@objective(model, Min, sum(a[i,t]*x[i,t] + b[i,t]*u[i,t] for i in R for t in T))
31+
@constraint(model, [i=R,t=T], x[i,t] - u[i,t] <= 0)
32+
33+
## 2nd stage
34+
for s in S
35+
sb = StructuredModel(parent=model, id = s, prob = Pr[s])
36+
# @variable(sb, y[i=R, j=N, t=T], Bin)
37+
@variable(sb, 0 <= y[i=R, j=N, t=T] <= 1)
38+
#@variable(sb, z[j=N,t=T] >= 0) # originally implemented variable (continuous)
39+
# @variable(sb, z[j=N,t=T], Bin) # modify as SIPLIB 1.0
40+
@variable(sb, 0 <= z[j=N,t=T] <= 1)
41+
@objective(sb, Min, sum(c[i,j,t,s]*y[i,j,t] for i in R for j in N for t in T) + sum(c0[j,t,s]*z[j,t] for j in N for t in T))
42+
@constraint(sb, [i=R, t=T], -sum(x[i,tau] for tau in 1:t) + sum(d[j,t,s]*y[i,j,t] for j in N) <= 0)
43+
@constraint(sb, [j=N, t=T], sum(y[i,j,t] for i in R) + z[j,t] == 1)
44+
end
45+
46+
return model
47+
end

examples/parmodel1.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ firststage = StructuredModel()
66
@constraint(firststage, x[1] * x[2] == 10)
77

88
for scen in 1:2
9-
bl = StructuredModel(parent=firststage, id=scen)
9+
local bl = StructuredModel(parent=firststage, id=scen)
1010
@variable(bl, y)
1111
@constraint(bl, x[2]^2 + x[1]*y 5)
1212
@objective(bl, Min, (x[1]+x[2])*y)

examples/parmodel2.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ firststage = StructuredModel()
66
@objective(firststage, Min, x[1]^2 + x[2]^2)
77

88
for scen in 1:2
9-
bl = StructuredModel(parent=firststage, id=scen)
9+
local bl = StructuredModel(parent=firststage, id=scen)
1010
@variable(bl, y[1:2])
1111
@constraint(bl, x[3-scen] + sum(y) 0)
1212
@constraint(bl, x[3-scen] + sum(y) 50)

examples/parmodel3.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ firststage = StructuredModel()
66
@objective(firststage, Min, x[1]^2 + x[2]^2 + x[1]*x[2])
77

88
for scen in 1:2
9-
bl = StructuredModel(parent=firststage, id=scen)
9+
local bl = StructuredModel(parent=firststage, id=scen)
1010
@variable(bl, y[1:2])
1111
@constraint(bl, x[3-scen] + sum(y) 0)
1212
@constraint(bl, x[3-scen] + sum(y) 50)

examples/parmodel4.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ firststage = StructuredModel()
66
@objective(firststage, Min, x[1]^2 + x[2]^2 + x[1]*x[2])
77

88
for scen in 1:100
9-
bl = StructuredModel(parent=firststage, id=scen)
9+
local bl = StructuredModel(parent=firststage, id=scen)
1010
@variable(bl, y[1:2])
1111
idx = (isodd(scen) ? 1 : 2)
1212
@constraint(bl, x[idx] + sum(y) 0)

examples/transportation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ for i in factories
4040
end
4141

4242
for (s, elem) in enumerate(scenarios)
43-
bl = StructuredModel(parent=m, id=s)
43+
local bl = StructuredModel(parent=m, id=s)
4444
@variable(bl, 0 <= salesw[i=centers] <= demand[i,s])
4545
@variable(bl, wastew[centers] >= 0)
4646
@objective(bl, Max, sum(price*prob[s]*salesw[j] for j=centers) - sum(wastecost*prob[s]*wastew[j] for j=centers))

src/BendersBridge.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ struct ParametrizedModel
8282
θ::Dict{Int, JuMP.VariableRef}
8383
end
8484
function ParametrizedModel(structured_model::StructuredModel, args...; kwargs...)
85-
if structured_model.parent === nothing
86-
model = Model(args...; kwargs...)
87-
else
88-
model = ModelWithParams(args...; kwargs...)
89-
end
85+
model = Model(args...; kwargs...)
9086
variable_map = Dict{Int, JuMP.VariableRef}()
9187
for (index, var) in structured_model.variables
9288
name = structured_model.varnames[index]

src/Benders_pmap.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function set_parent_solution!(model::ParametrizedModel, parent::ParametrizedMode
4747
for (index, parameter) in model.parameter_map
4848
vref = parent.variable_map[index]
4949
value = parent_solution.variable_value[vref]
50-
JuMP.fix(parameter, value)
50+
JuMP.set_value(parameter, value)
5151
end
5252
end
5353

@@ -66,7 +66,7 @@ function add_cutting_planes(master_model, master_solution, sub_models, sub_solut
6666
if sol.feasible
6767
JuMP.add_to_expression!(aff, -1.0, master_model.θ[id])
6868
# Check if the cut is useful
69-
if JuMP.value(aff, vref -> master_solution.variable_value[vref]) - TOL < 0
69+
if JuMP.value(vref -> master_solution.variable_value[vref], aff) - TOL < 0
7070
continue
7171
end
7272
else

src/StructJuMP.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ Base.copy(v::StructuredVariableRef) = v
8888
Base.:(==)(v::StructuredVariableRef, w::StructuredVariableRef) = v.model === w.model && v.idx == w.idx
8989
JuMP.owner_model(v::StructuredVariableRef) = v.model
9090
JuMP.isequal_canonical(v::StructuredVariableRef, w::StructuredVariableRef) = v == w
91-
JuMP.variable_type(::StructuredModel) = StructuredVariableRef
9291
function JuMP.add_variable(m::StructuredModel, v::JuMP.AbstractVariable, name::String="")
9392
m.nextvaridx += 1
9493
vref = StructuredVariableRef(m, m.nextvaridx)
@@ -231,7 +230,6 @@ struct StructuredConstraintRef
231230
model::StructuredModel # `model` owning the constraint
232231
idx::Int # Index in `model.constraints`
233232
end
234-
JuMP.constraint_type(::StructuredModel) = StructuredConstraintRef
235233
function JuMP.add_constraint(m::StructuredModel, c::JuMP.AbstractConstraint, name::String="")
236234
m.nextconidx += 1
237235
cref = StructuredConstraintRef(m, m.nextconidx)

test/printhook.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,10 @@ Subject to
2727
x + y = 1.0
2828
"""
2929
@test sprint(show, parent) == """
30-
A JuMP Model
30+
An Abstract JuMP Model
3131
Minimization problem with:
3232
Variables: 2
33-
Objective function type: GenericQuadExpr{Float64,StructJuMP.StructuredVariableRef}
33+
Objective function type: GenericQuadExpr{Float64, StructJuMP.StructuredVariableRef}
3434
Constraint: 1
3535
Names registered in the model: x, y"""
36-
@test sprint(show, "text/latex", parent) == """
37-
\$\$ \\begin{alignat*}{1}\\min\\quad & x^2 + y\\\\
38-
\\text{Subject to} \\quad & x + y = 1.0\\\\
39-
\\end{alignat*}
40-
\$\$"""
41-
#@test occursin("Child", str)
4236
end

0 commit comments

Comments
 (0)