Using cplex For Sensitivity Analysis

870 views
Skip to first unread message

Peffers, Michael

unread,
May 8, 2017, 7:58:46 AM5/8/17
to am...@googlegroups.com

Hi,

 

I am trying to perform sensitivity analysis on a model that I have built for my OR class and I cannot get it to give me the upper and lower ranges. My questions are:

1. Do I need to have a .dat file for the sensitivity analysis to work properly?

2. What am I doing wrong? Everything I am reading online tells me I am using the .up, .current, and .down correct?


AMPL keeps telling me:

Bad suffix .up for worth

context:  display   >>> x3.up, <<<  x3.current, x3.down;

Possible suffix values for worth.suffix:

       astatus   exitcode   message   no

       relax     result     sense     sno

       sstatus   stage      val   


Here is my model:

param investment = 20000;
param extcows = 30;
param exthens = 2000;
param cowsvalue = 35000;
param hensvalue = 5000;
param cowsdeprc = 0.1;
param hensdeprc = 0.25;
param totalwinterspringhours = 4000;
param totalsummerfallhours = 4500;
param totalland = 640;

var x1 >= 0 integer;    #new cows
var x2 >= 0 integer;    #new hens
var x3 >= 0;    #soy
var x4 >= 0;    #corn
var x5 >= 0;    #wheat

maximize worth: 1350*extcows + 5.25*exthens + 1350*x1 + 5.25*x2 +
                70*x3 + 60*(x4-extcows-x1) + 40*(x5-.05*(x2+exthens)) +
                (investment- 1500*x1 - 3*x2)+
                .9*(cowsvalue +1500*x1)+
                .75*(hensvalue + 3*x2)+
                (totalwinterspringhours - (x5*.6 + x3 + 0.9*x4 + 60*extcows + 60*x1 + 0.3*exthens + 0.3*x2))*5+
                (totalsummerfallhours - (1.4*x3 + 1.2*x4 + 0.7*x5 + 60*extcows + 60*x1 + 0.3*exthens + 0.3*x2))*5.5
                -40000;

subject to
winterspringhoursconst: x5*.6 + x3 + 0.9*x4 + 60*extcows + 60*x1 + 0.3*exthens + 0.3*x2 <= totalwinterspringhours;
summerfallhoursconst: 1.4*x3 + 1.2*x4 + 0.7*x5 + 60*extcows + 60*x1 + 0.3*exthens + 0.3*x2 <= totalsummerfallhours;
maxcowconst: extcows + x1 <= 42;
maxhensconst: exthens + x2 <= 5000;
maxacresconst: 2*extcows + 2*x1 + x3 + x4 + x5 <= 640;
investmentfundconst: 1500*x1 + 3*x2 <= 20000;
mincorncost: x4 - x1 >= extcows;
minwheatconst: x5 - .05*x2 >= .05*exthens;

Here is my .run file:
#    Reset command clears all the previous models, so that there are no conflicts
reset;

#    Load model onto the environment. Use relative path of the files (e.g. folder where the files is)
model c:/Users/amplide.mswin32/myModels/Farm_Case_Study.mod;

#    Solver Options
option solver cplex;
option cplex_options 'sensitivity';
option presolve 0;

#    Solver the problem
solve;

#    Objective function value
printf("************************************************************\n");
printf("Optimal objective function value:    ");
display worth;

#    Display primal solution
printf("Primal solution:    ");
display x1, x2, x3, x4, x5, x1.rc, x2.rc, x3.rc, x4.rc, x5.rc;

#    Display dual solution
printf("------------------------------------------------------------\n");
printf("Sensativity Analysis");
printf("Change to objective function coefficient:    \n");

display  x3.up, x3.current, x3.down;
#display x4.up, x4.current, x4.down;
#display x5.up, x5.current, x5.down;

printf("------------------------------------------------------------\n");
printf("Change to right-hand side:    \n");
#display winterspringhoursconst.lbs,winterspringhoursconst.ubs ;
#display summerfallhoursconst.up, summerfallhoursconst.current, summerfallhoursconst.down;
#display maxcowconst.up, maxcowconst.current, maxcowconst.down;
#display maxhensconst.up, maxhensconst.current, maxhensconst.down;
#display maxacresconst.up, maxacresconst.current, maxacresconst.down;
#display investmentfundconst.up, investmentfundconst.current, investmentfundconst.down;
#display mincorncost.up, mincorncost.current, mincorncost.down;
#display minwheatconst.up, minwheatconst.current, minwheatconst.down;
printf("************************************************************\n");

Thank you for any advice you can provide!

Regards,
Mike

Robert Fourer

unread,
May 8, 2017, 10:20:59 AM5/8/17
to am...@googlegroups.com
The CPLEX solver's algorithm for sensitivity analysis only applies to continuous linear programs. When some of the variables are declared as "integer" then the 'sensitivity' option is ignored (without any warning, unfortunately). To see that this option does in fact work with continuous variables, you could set "option relax_integrality 1;" to send a continuous relaxation of your problem to CPLEX -- see the listing copied below.

Bob Fourer
am...@googlegroups.com


ampl: option relax_integrality 1;
ampl: solve;

5 variables, all linear
8 constraints, all linear; 22 nonzeros
8 inequality constraints
1 linear objective; 5 nonzeros.

CPLEX 12.7.0.0: sensitivity
CPLEX 12.7.0.0: optimal solution; objective 115211
2 dual simplex iterations (1 in phase I)

suffix up OUT;
suffix down OUT;
suffix current OUT;

ampl: display _varname, _var.down,_var.current,_var.up;
: _varname _var.down _var.current _var.up :=
1 x1 123 510 1e+20
2 x2 -1e+20 -0.65 1.2075
3 x3 48.9 57.3 186.3
4 x4 -338.1 48.9 57.3
5 x5 -1e+20 33.15 57.3
;

=======
...


Reply all
Reply to author
Forward
0 new messages