Hi, I am trying to construct a StructuredModel using a function (SSLP) defined as follows:
using Random
using StructJuMP
function SSLP(nJ::Int, nI::Int, nS::Int, seed::Int=1)::JuMP.Model
Random.seed!(seed)
J = 1:nJ
I = 1:nI
S = 1:nS
Z = []
c = rand(40:80,nJ)
q = rand(0:25,nI,nJ,nS)
q0 = ones(nJ)*1000
d = q
u = 1.5*sum(d)/nJ
v = nJ
w = NaN
Jz = []
h = rand(0:1,nI,nS)
Pr = ones(nS)/nS
# construct JuMP.Model
model = StructuredModel(num_scenarios=nS)
## 1st stage
@variable(model, x[j=J], Bin)
@objective(model, Min, sum(c[j]*x[j] for j in J))
@constraint(model, sum(x[j] for j in J) <= v)
@constraint(model, [z=Z], sum(x[j] for j in Jz[z]) >= w[z])
## 2nd stage
for s in S
sb = StructuredModel(parent=model, id = s, prob = Pr[s])
@variable(sb, y[i=I,j=J], Bin)
@variable(sb, y0[j=J] >= 0)
@objective(sb, Min, -sum(q[i,j,s]*y[i,j] for i in I for j in J) + sum(q0[j]*y0[j] for j in J))
@constraint(sb, [j=J], sum(d[i,j]*y[i,j] for i in I) - y0[j] <= u*x[j])
@constraint(sb, [i=I], sum(y[i,j] for j in J) == h[i,s])
end
return model
end
m = SSLP(5,5,5)
Unexpectedly, it produces a BoundsError like the following screenshot:
May I ask you can also reproduce the same error? Thanks in advance.
Hi, I am trying to construct a StructuredModel using a function (SSLP) defined as follows:
Unexpectedly, it produces a BoundsError like the following screenshot:
May I ask you can also reproduce the same error? Thanks in advance.