Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
968 views
in Technique[技术] by (71.8m points)

julia jump: declare array with variable upper and lower limit

I am trying to solve a sensitivity analysis using Julia (JUMP). I am stuck at the following problem:

I am trying to declare a variable that has both an upper and a lower limit to feed it to the lp_objective_perturbation_range function. That function requires the reference of an array as input.

I have tried the following syntax:

# L?sung Aufgabe 1
println("L?sung Aufgabe 1")

# Produktionsplan auf Grundlage der Ausgangswerte
println("Produktionsplan auf Grundlage der Ausgangswerte")
produktionsplanModell = Model(with_optimizer(GLPK.Optimizer))

# Bereits angefallene Fixkosten
# Modenschau - 8.100.000 USD
# Designer   -   860.000 USD
fixkosten = 8100000 + 860000

c = [33.75; 66.25; 26.625; 210;  22; 136; 60.5; 53.5; 143.25; 110; 155.25]

A = [  0   0   0   0   0   2   0   0 1.5   2 1.5;
     0.5 1.5   0   0   0   0   0   0   0   0   0;
       0   0   0 1.5   0   0   0   0   0   0   0;
       0   0   0   0 1.5   3   0   0   0   0   0;
       0   0   0   0   0   0 1.5 0.5   0   0   0;
       0   0 1.5   0   0   0   0   0   2   0   0;
       0   0   0   0   0   0   0   0   0   3 2.5;]

b = [28000.0; 30000; 9000; 20000; 18000; 30000; 45000]

w = [60000.0;15000;20000; 4000; 6000; 5500; 9000;15000;15000; 7000; 5000]

y = [0.0; 0; 0; 0; 0; 0; 0; 0; 2800; 4200; 3000]

# Definition der Variablen
@variable(produktionsplanModell, w[i] >= x[i] >= y[i] for i=1:11)

Unfortunately, this isn't working. So I need an array that has the following definition and can be assigned to the model:

@variable(produktionsplanModell, 60000 >= x1  >=    0)
@variable(produktionsplanModell, 15000 >= x2  >=    0)
@variable(produktionsplanModell, 20000 >= x3  >=    0)
@variable(produktionsplanModell,  4000 >= x4  >=    0)
@variable(produktionsplanModell,  6000 >= x5  >=    0)
@variable(produktionsplanModell,  5500 >= x6  >=    0)
@variable(produktionsplanModell,  9000 >= x7  >=    0)
@variable(produktionsplanModell, 15000 >= x8  >=    0)
@variable(produktionsplanModell, 15000 >= x9  >= 2800)
@variable(produktionsplanModell,  7000 >= x10 >= 4200)
@variable(produktionsplanModell,  5000 >= x11 >= 3000)

Is it possible to do that? Rest of the program is working fine. Thanks in advance!

question from:https://stackoverflow.com/questions/65874081/julia-jump-declare-array-with-variable-upper-and-lower-limit

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The correct syntax is:

@variable(produktionsplanModell , y[i] <= x[i=1:11] <= w[i] )

Hence you need to define the loop inside variable declaration.

Of course another option is:

@variable(produktionsplanModell, x[1:11] )
for i in 1:11
   @constraint(produktionsplanModell , w[i] <= x[i] <= y[i])
end

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...