AMPL Robust Optimization Model

382 views
Skip to first unread message

rim...@gmail.com

unread,
Aug 31, 2015, 1:22:10 PM8/31/15
to AMPL Modeling Language
Hi everyone,
I created this topic to discuss the issues related to developing robust optimization models on AMPL.
Please share your experience/difficulties here!
Tnx!
Amir

rim...@gmail.com

unread,
Aug 31, 2015, 3:55:25 PM8/31/15
to AMPL Modeling Language, rim...@gmail.com
Can anyone know how to model the below equation in AMPL.
This is part of the robust optimization model...

Thanks in advance!
RO model.jpg

rim...@gmail.com

unread,
Sep 1, 2015, 3:00:56 AM9/1/15
to AMPL Modeling Language, rim...@gmail.com
Hi all,

I have difficulties modeling this equation in AMPL,
any help would be highly appreciated.
  


On Monday, August 31, 2015 at 1:22:10 PM UTC-4, rim...@gmail.com wrote:
RO model.jpg

Robert Fourer

unread,
Sep 3, 2015, 5:26:01 AM9/3/15
to am...@googlegroups.com
This expression relies on some unusual terminology which you would have to convert to AMPL's scalar algebraic form. You will need to rely on the context provided by the written work where this equation appears, in order to understand what it means and how to convert it.

Bob Fourer
am...@googlegroups.com

=======

rim...@gmail.com

unread,
Sep 4, 2015, 5:23:07 PM9/4/15
to AMPL Modeling Language, 4...@ampl.com
can I get some help as why the cplex gives me solution like this please?

ampl: reset;
ampl: option solver cplex;
ampl: model P1A.mod;
ampl: data P1A.dat;
ampl: solve;
CPLEX 12.6.1.0: optimal integer solution; objective 2500
0 MIP simplex iterations
0 branch-and-bound nodes
No basis.

Apparently, no itiration is being done!
Here is the model in asimlified version!

set surgery;
set room;
set day;

param R > 0;
param J > 0;
param S > 0;
param T > 0;
param V > 0;

param Psi {t in 1..T} binary;
param C1 {v in 1..V} >= 0;
param p1 {v in 1..V} >= 0, <= 1;
param A {s in 1..S, v in 1..V} >= 0;
param H >= 0;
param E >= 0;
param Hb := H - E >= 0;

var Xi {v in 1..V} binary;

minimize P1A: sum {v in 1..V} C1[v] * Xi[v];

subject to Eq1:
sum {v in 1..V} Xi[v] = 1;

subject to Eq2:
sum {s in 1..S} sum {v in 1..V} A[s,v] * H * Xi[v] <= sum {t in 1..T} Hb * R * (1 - Psi[t]);

victor.z...@gmail.com

unread,
Sep 8, 2015, 10:10:28 AM9/8/15
to am...@googlegroups.com, 4...@ampl.com
Most likely the solution was found during presolve. You can find other possible explanations in this OR Exchange answer.

HTH,
Victor

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at http://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.

rim...@gmail.com

unread,
Sep 10, 2015, 3:28:43 PM9/10/15
to AMPL Modeling Language, 4...@ampl.com
I have a stochastic parameter called E which is under scenarios as : param E {eps in 1..Epsilon} >= 0;
I have defined E to follow a Normal distribution and have also defined Five different scenarios as "eps= 1..5".
Now, when I make the *.dat file as below, it shows me error:
param 
E:=
1 Normal (180, 30)
2 Normal (210, 45)
3 Normal (240, 30)
4 Normal (180, 60)
5 Normal (300, 120);

Can anyone help what is that errors for? 
Thanks!
Amir

rim...@gmail.com

unread,
Sep 11, 2015, 4:37:48 PM9/11/15
to AMPL Modeling Language, 4...@ampl.com
Here is the error msg:

ampl: data RP1A.dat;

RP1A.dat, line 59 (offset 947):
expected number
ampl: 
Any idea?

On Tuesday, September 8, 2015 at 10:10:28 AM UTC-4, Victor wrote:

victor.z...@gmail.com

unread,
Sep 15, 2015, 1:55:02 PM9/15/15
to am...@googlegroups.com
You can't use expressions such as Normal(180, 30) in data statements. A simple fix is to define your parameter as

  param E_mean{S};
  param E_var{S};
  param E{s in S} = Normal(E_mean[s], E_var[s]);

and provide the data for E_mean and E_var:

  data;
  param: 
E_mean E_var :=
1 180 30
2 210 45
...
;

where S is an indexing set of E.

Alternatively you can set the data for E via AMPL script (the let statement).

HTH,
Victor

Amir Lamzi

unread,
Sep 15, 2015, 2:34:45 PM9/15/15
to am...@googlegroups.com
Thank you so much Vector.
You are so knowledgeable on AMPL!

--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/6GjLcxoKmVA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+uns...@googlegroups.com.

Amir Lm

unread,
May 30, 2016, 4:20:40 PM5/30/16
to AMPL Modeling Language
Hi,

can anyone please have a look at the below codes and let me know why I am getting ZERO values for the Teta[eps]?
What I am trying to achieve through the "Mio" and "d" is basically a mean and standard deviation of the objective function.
 
var Mio >= 0;
var d {eps in 1 ..Epsilon} >= 0;
var Teta {eps in 1..Epsilon} >= 0;

minimize P_Robust:
sum {t in 1..T} sum {z in 1..T} (c1[t,z] * sum {s in 1..S} Y[s,t,z]) + Mio + Lamda * sum {eps in 1..Epsilon} Pi[eps] * (d[eps]+ 2 * Teta[eps])

subject to Eq4_13:
Mio = sum {eps in 1..Epsilon} sum {s in 1..S} sum {t in 1..T} Pi[eps] * (c2 * Rho[s,t,eps] + c3 * Iota[s,t,eps]);

subject to Eq4_14 {eps in 1..Epsilon}:
d[eps] = sum {s in 1..S} sum {t in 1..T} c2 * Rho[s,t,eps] + sum {s in 1..S} sum {t in 1..T} c3 * Iota[s,t,eps] - sum {eps1 in 1..Epsilon} sum {s in 1..S} sum {t in 1..T} Pi[eps1] * (c2 * Rho[s,t,eps1] + c3 * Iota[s,t,eps1]);

subject to Eq4_18 {eps in 1..Epsilon}:
d[eps] + Teta[eps] >= 0;

Thanks!

Amir Lm

unread,
May 30, 2016, 4:30:16 PM5/30/16
to AMPL Modeling Language
The value for the parameters are as follows:
C2=20
C3=2
set eps=1,2,3,4
Pi[eps1]=0.75
Pi[eps2]=0.1
Pi[eps3]=0.075
Pi[eps4]=0.075

Any thoughts!

Victor Zverovich

unread,
May 31, 2016, 12:13:00 PM5/31/16
to am...@googlegroups.com
The only constraint where Teta appears is 

  subject to Eq4_18 {eps in 1..Epsilon}:
    d[eps] + Teta[eps] >= 0;

Since d[eps] >= 0, this doesn't impose any additional restriction on Teta[eps] (it is already >= 0 in the declaration). So if Tetas have nonnegative coefficients in the objective, the solver can rightfully set these variables to zero.

HTH,
Victor

--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.

Amir Lm

unread,
May 31, 2016, 12:59:15 PM5/31/16
to AMPL Modeling Language
Victor;

I greatly appreciate your help.
It did actually solve my problem!
Thanks a ton!

Amir Lm

unread,
Jun 8, 2016, 5:23:14 PM6/8/16
to AMPL Modeling Language
Hi everyone,
I have developed a robust optimization model for an allocation problem.
The robust model works fine and I could get a reasonable result out of it.
When I tried to transfer the same model to the two-stage stochastic programming model, though, I faced with an "integer infeasible" results by AMPL.
here is the entire model. The data file is also attached.
How could I fix this?
 
Any help would be appreciated,
--------------------------------------
set room;
set specialty;
set day;
set scenario;

param O > 0;
param S > 0;
param T > 0;
param Epsilon > 0;

param h > 0;
param a {i in 1..O} > 0;
param k {s in 1..S, t in 1..T} >= 0;
param c1 {t in 1..T, z in 1..T} >= 0;
param c2 >= 0;
param c3 >= 0;

param e {s in 1..S, t in 1..T, eps in 1..Epsilon} > 0;
param g {s in 1..S, t in 1..T, eps in 1..Epsilon} >= 0;
param Pi {eps in 1 ..Epsilon} >= 0, <= 1;

var X {i in 1..O, s in 1..S, t in 1..T} >= 0, integer;
var U {s in 1..S, t in 1..T} >= 0;
var Y {s in 1..S, t in 1..T, z in 1..T} >= 0;
var Rho {s in 1..S, t in 1..T, eps in 1..Epsilon} >= 0;
var Iota {s in 1..S, t in 1..T, eps in 1..Epsilon} >= 0;
var Mio >= 0;

minimize P_Stochastic:
sum {t in 1..T} sum {z in 1..T} (c1[t,z] * sum {s in 1..S} Y[s,t,z]) + Mio;

subject to Eq4_2 {i in 1..O, t in 1..T}:
sum {s in 1..S} X[i,s,t] = a[i];

subject to Eq4_3 {t in 1..T}:
sum {s in 1..S} U[s,t] <= h;

subject to Eq4_4 {s in 1..S, t in 1..T}:
sum {i in 1..O} X[i,s,t] <= k[s,t];

subject to Eq4_5 {s in 1..S, t in 1..T, eps in 1..Epsilon}:
U[s,t] <= g[s,t,eps];

subject to Eq4_6 {s in 1..S, t in 1..T, eps in 1..Epsilon}:
sum {z in 1..T} Y[s,t,z] <= e[s,t,eps];

subject to Eq4_7 {s in 1..S, t in 1..T, eps in 1..Epsilon}:
Rho[s,t,eps] <= e[s,t,eps];

subject to Eq4_8 {s in 1..S, t in 1..T, eps in 1..Epsilon}:
Iota[s,t,eps] <= h;

subject to Eq4_13:
Mio = sum {eps in 1..Epsilon} sum {s in 1..S} sum {t in 1..T} Pi[eps] * (c2 * Rho[s,t,eps] + c3 * Iota[s,t,eps]);

subject to Eq4_15 {s in 1..S, t in 1..T, eps in 1..Epsilon}:
h * sum {i in 1..O} X[i,s,t] >= g[s,t,eps] - U[s,t] + sum {z in 1..T} Y[s,z,t];

subject to Eq4_16 {s in 1..S, t in 1..T, eps in 1..Epsilon}:
e[s,t,eps] = h * sum {i in 1..O} X[i,s,t] - g[s,t,eps] + U[s,t] - sum {z in 1..T} Y[s,z,t] + sum {z in 1..T} Y[s,t,z] + Rho[s,t,eps] - Iota[s,t,eps];

FKS3.dat

Victor Zverovich

unread,
Jun 9, 2016, 6:57:32 PM6/9/16
to am...@googlegroups.com
The relaxation is feasible so I'd check the constraints containing integer variables X.

HTH,
Victor

Amir Lm

unread,
Jun 10, 2016, 3:12:24 PM6/10/16
to AMPL Modeling Language
Hi Victor,

Thanks for the help.
I already checked the constraints containing variable X, and that's exactly where I am so confused about,
When I run the deterministic model, it works fine with no infeasible results,
But when it comes to stochastic model, variable X makes the model infeasible, 
X is a first stage decision variable in the stochastic programming model, so how would that makes the model infeasible?!
Can you give me some insight as to why it happens? 
And, how can I fix it?

Many thanks!

Amir Lm

unread,
Jun 10, 2016, 3:17:29 PM6/10/16
to AMPL Modeling Language
I have also attached both deterministic and stochastic model for your kind review.
Thank you in advance for your help!


On Thursday, June 9, 2016 at 6:57:32 PM UTC-4, Victor wrote:
FKD3.dat
FKD3.mod
FKS3.dat
FKS3.mod

Victor Zverovich

unread,
Jun 13, 2016, 7:57:51 PM6/13/16
to am...@googlegroups.com
There is nothing unusual in that the SP is infeasible. Your base deterministic problem can be viewed as a special case of the stochastic problem with a single scenario. When you add scenarios you add new constraints and therefore some scenarios can introduce infesibility.

You can try evaluating your stochastic problem on a single scenario with the same data as in the deterministic problem to check that they produce the same results.

HTH,
Victor

Amir Lm

unread,
Jun 21, 2016, 5:43:13 PM6/21/16
to AMPL Modeling Language
Hi Victor,

I have developed a robust optimization model.
It may sound stupid, but the model gets into the solution in less than ONE second!!!
It is so weird to me that such a big robust optimization model with 1000's of variables and constraints can be solved so quick!
Testing the results obtain by the model shows that something is wrong!
the parameter Omega2 in the model is a penalty function to penalize the violation of the second stage constraint. So, Omega2=0 means there is no penalty for not satisfying the second stage constraint. The obtained results do NOT support this, though!!!
On the other hand, Omega2=INFINITY means that any amount of violation for the second stage constraints is hardly accepted. Again, the obtained results seem unreasonable!!
Can you please verify the model for me.
I just need you to run it and let me know if you see anything unusual.
I greatly appreciate your help.

Regards,
Amir
-------------------------------------------------------------------

FKtf3.mod 

set room;

set specialty;

set day;

set scenario;

 

param O > 0;

param S > 0;

param T > 0;

param Eps > 0;

 

param h > 0;

param a {i in 1..O} > 0;

param k {s in 1..S, t in 1..T} >= 0;

param c1 {t in 1..T, z in 1..T} >= 0;

param c2 >= 0;

param c3 >= 0;

param Lamda >= 0;

param Omega2 >= 0;

 

param e {s in 1..S, t in 1..T, eps in 1..Eps} >= 0;

param g {s in 1..S, t in 1..T, eps in 1..Eps} >= 0;

param Pi {eps in 1 ..Eps} >= 0, <= 1;

 

var X {i in 1..O, s in 1..S, t in 1..T} >= 0, integer;

var U {s in 1..S, t in 1..T} >= 0;

var Y {s in 1..S, t in 1..T, z in 1..T} >= 0;

var Rho {s in 1..S, t in 1..T, eps in 1..Eps} >= 0;

var Iota {s in 1..S, t in 1..T, eps in 1..Eps} >= 0;

var FC >= 0;

var SC >= 0;

var d {eps in 1 ..Eps};

var Teta {eps in 1..Eps} >= 0;

var f2 {s in 1..S, t in 1..T, eps in 1..Eps};

var Gama {s in 1..S, t in 1..T, eps in 1..Eps} >= 0;

 

minimize P_tradeoff:

FC + SC + Lamda * sum {eps in 1..Eps} Pi[eps] * (d[eps] + 2 * Teta[eps]) + Omega2 * sum {s in 1..S} sum {t in 1..T} sum {eps in 1..Eps} Pi[eps] * (f2[s,t,eps] + 2 * Gama[s,t,eps]);

 

subject to Eq4_01:

FC = sum {t in 1..T} sum {z in 1..T} (c1[t,z] * sum {s in 1..S} Y[s,t,z]);

 

subject to Eq4_02:

SC = sum {s in 1..S} sum {t in 1..T} sum {eps in 1..Eps} Pi[eps] * (c2 *  Rho[s,t,eps] + c3 * Iota[s,t,eps]);

 

subject to Eq4_03 {eps in 1..Eps}:

d[eps] = sum {s in 1..S} sum {t in 1..T} (c2 * Rho[s,t,eps] + c3 * Iota[s,t,eps]) - sum {s in 1..S} sum {t in 1..T} sum {eps1 in 1..Eps} Pi[eps1] * (c2 * Rho[s,t,eps1] + c3 * Iota[s,t,eps1]);

 

subject to Eq4_04 {s in 1..S, t in 1..T, eps in 1..Eps}:

f2[s,t,eps] = e[s,t,eps] - h * sum {i in 1..O} X[i,s,t] + g[s,t,eps] - U[s,t] + sum {z in 1..T} Y[s,z,t] - sum {z in 1..T} Y[s,t,z] + Rho[s,t,eps] - Iota[s,t,eps];

 

subject to Eq4_2 {i in 1..O, t in 1..T}:

sum {s in 1..S} X[i,s,t] = a[i];

 

subject to Eq4_3 {t in 1..T}:

sum {s in 1..S} U[s,t] <= h;

 

subject to Eq4_4 {s in 1..S, t in 1..T}:

sum {i in 1..O} X[i,s,t] <= k[s,t];

 

subject to Eq4_5 {s in 1..S, t in 1..T, eps in 1..Eps}:

U[s,t] <= g[s,t,eps];

 

subject to Eq4_6 {s in 1..S, t in 1..T, eps in 1..Eps}:

sum {z in 1..T} Y[s,t,z] <= e[s,t,eps];

 

subject to Eq4_7 {s in 1..S, t in 1..T, eps in 1..Eps}:

Rho[s,t,eps] <= e[s,t,eps];

 

subject to Eq4_8 {s in 1..S, t in 1..T, eps in 1..Eps}:

Iota[s,t,eps] <= h;

 

subject to Eq4_15 {s in 1..S, t in 1..T, eps in 1..Eps}:

h * sum {i in 1..O} X[i,s,t] >= g[s,t,eps] - U[s,t] + sum {z in 1..T} Y[s,z,t];

 

subject to Eq4_16 {s in 1..S, t in 1..T, eps in 1..Eps}:

e[s,t,eps] = h * sum {i in 1..O} X[i,s,t] - g[s,t,eps] + U[s,t] - sum {z in 1..T} Y[s,z,t] + sum {z in 1..T} Y[s,t,z] + Rho[s,t,eps] - Iota[s,t,eps];

 

subject to Eq4_18 {eps in 1..Eps}:

d[eps] + Teta[eps] >= 0;

 

subject to Eq4_20 {s in 1..S, t in 1..T, eps in 1..Eps}:

f2[s,t,eps] + Gama[s,t,eps] >= 0;

 

 

FKtf3.dat

data;

param O = 2;

param S = 6;

param T = 5;

param Eps = 4;

 

set room:=                 1      2;

set specialty:=             1      2      3      4      5      6;

set day:=                  1      2      3      4      5;

set scenario:=             1      2      3      4;

 

param h = 8;

 

param

              a:=

1             1

2             8;

 

param k:

              1      2      3      4      5:=

 

1             2      3      3      3      2

2             2      2      2      3      2

3             3      3      2      2      2

4             3      2      2      3      2

5             2      2      3      3      3

6             3      2      2      3      2;

 

param

              Pi:=

1             0.75

2             0.10         

3             0.075

4             0.075;

 

param c1:

       1      2      3      4      5:=

 

1      350    50     100    150    200

2      300    350    50     100    150

3      250    300    350    50     100

4      200    250    300    350    50

5      150    200    250    300    350

;

 

param

              c2 = 80;

             

param

              c3 = 40;

 

param

              Lamda = 0.1;

             

param

              Omega2 = 100;

      

param e:

              1      2      3      4:=   

 

1      1      7.03   8.33   3.13   10.93

1      2      5.88   7.18   1.98   9.78

1      3      9.49   10.79  5.59   13.39

1      4      5.93   7.23   2.03   9.83

1      5      7.40   8.70   3.50   11.30

2      1      16.01  16.68  14.00  18.02

2      2      13.68  14.35  11.67  15.69

2      3      14.33  15.00  12.32  16.34

2      4      13.44  14.11  11.43  15.45

2      5      13.32  13.99  11.31  15.33

3      1      12.50  12.93  11.21  14.22

3      2      13.42  13.85  12.13  15.14

3      3      12.92  13.35  11.63  14.64

3      4      12.43  12.86  11.14  14.15

3      5      12.42  12.85  11.13  14.14

4      1      13.80  14.77  10.89  17.68

4      2      16.12  17.09  13.21  20.00

4      3      14.58  15.55  11.67  18.46

4      4      13.88  14.85  10.97  17.76

4      5      14.87  15.84  11.96  18.75

5      1      13.82  14.35  12.23  15.94

5      2      13.09  13.62  11.50  15.21

5      3      16.29  16.82  14.70  18.41

5      4      12.55  13.08  10.96  14.67

5      5      12.79  13.32  11.20  14.91

6      1      14.58  15.56  11.64  18.50

6      2      15.30  16.28  12.36  19.22

6      3      15.00  15.98  12.06  18.92

6      4      12.85  13.83  9.91   16.77

6      5      13.30  14.28  10.36  17.22

;

 

param g:

              1      2      3      4:=   

 

1      1      3.91   5.21   0.00   7.81

1      2      3.27   4.57   0.00   7.17

1      3      5.27   6.57   1.37   9.17

1      4      3.30   4.60   0.00   7.20

1      5      4.11   5.41   0.21   8.01

2      1      5.34   6.01   3.33   7.35

2      2      4.56   5.23   2.55   6.57

2      3      4.78   5.45   2.77   6.79

2      4      4.48   5.15   2.47   6.49

2      5      4.44   5.11   2.43   6.45

3      1      3.12   3.55   1.83   4.41

3      2      3.36   3.79   2.07   4.65

3      3      3.23   3.66   1.94   4.52

3      4      3.11   3.54   1.82   4.40

3      5      3.11   3.54   1.82   4.40

4      1      3.45   4.42   0.54   6.36

4      2      4.03   5.00   1.12   6.94

4      3      3.65   4.62   0.74   6.56

4      4      3.47   4.44   0.56   6.38

4      5      3.72   4.69   0.81   6.63

5      1      3.45   3.98   1.86   5.04

5      2      3.27   3.80   1.68   4.86

5      3      4.07   4.60   2.48   5.66

5      4      3.14   3.67   1.55   4.73

5      5      2.91   3.44   1.32   4.50

6      1      3.65   4.63   0.71   6.59

6      2      3.83   4.81   0.89   6.77

6      3      3.75   4.73   0.81   6.69

6      4      3.21   4.19   0.27   6.15

6      5      3.32   4.30   0.38   6.26

;

-------------------------------------------------------------------

Victor Zverovich

unread,
Jun 22, 2016, 4:49:57 PM6/22/16
to am...@googlegroups.com
Unfortunately I don't have time to check your model and I am not completely sure what the problem is from your explanation. As for the problem size, your problem has only a few hundred variables and constraints after presolve, so it's actually pretty small.

HTH,
Victor

Amir Lamzi

unread,
Jun 22, 2016, 8:51:52 PM6/22/16
to am...@googlegroups.com
Appreciate your comment, Victor.

--
You received this message because you are subscribed to a topic in the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ampl/6GjLcxoKmVA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ampl+uns...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages