1

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!

janw
  • 8,758
  • 11
  • 40
  • 62
  • 1
    Please don't add "solved". Instead, you can accept an answer by clicking the checkmark on the left side, if you like. – janw Jan 24 '21 at 21:03

2 Answers2

2

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
Przemyslaw Szufel
  • 40,002
  • 3
  • 32
  • 62
  • Please use the first option. The second adds linear constraints as opposed to variable bounds. – Oscar Dowson Jan 24 '21 at 19:26
  • @OscarDowson could you slightly elaborate on what is the difference? I am very curious on what happens when it goes to a solver. Does eg. Gurobi or CBC treats in some ways constraints differently than variable bounds? – Przemyslaw Szufel Jan 24 '21 at 19:58
  • Solvers effectively solve problems with linear constraints `A * x == 0` and bounds `l <= x <= u` (there are some transformations to get the users problem into this shape). Calling `@constraint` adds a new row to the `A` matrix. Adding the bounds in `@variable`, or calling `set_upper_bound` modifies the `l` and `u` vectors without adding a new row. It is always better to modify the bound vectors instead of the A matrix. – Oscar Dowson Jan 25 '21 at 04:02
0

THX. I do this and it works fine...

@variable(produktionsplanModell, x[1:11])
for i=1:11
  set_lower_bound(x[i], y[i])
  set_upper_bound(x[i], w[i])
end

because of my constraints look like that.

@constraint(produktionsplanModell, constraint[j=1:7], sum( A[j,i]*x[i] for i=1:11 ) <= b[j])