Skip to content

Commit c06866a

Browse files
committed
added an example
1 parent 7b0f3b3 commit c06866a

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

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

0 commit comments

Comments
 (0)