Hi everybody, I'm a beginner in Cplex trying to solve a problem (linear programming) to get dual values related to the constraints so as to use those values for the next application. My preliminary search reveals that we can get the dual values by using cplex.getDuals() function. I also understand that a prerequisite to use getDuals() is to write the constraints using IloRangeArray(). I have applied these in my problem context as follows:

IloModel model(env);
IloRangeArray  constraints(env, Nb_constraints); // Nb_constraints are total number of constraints

// data input
// a sample constraint is given as 
for( .. ){
    for( .. ){
        for( .. ){
            constraints.add(sum_food_inv <= capacity[s][w] * Delta_wh_hire_contract[s][w]);
        }
    }
}

model.add(constraints);
.
.
cplex.solve();

double vals[Nb_constraints]; // this is the array which stores the dual values. 
for(int c=0; c<Nb_constraints; c++)
    cplex.getDual(constraints[c]);

However, with this code though the program is able to solve the LP, it is unable to produce the dual values. Can anybody help me out to understand where am I going wrong with the code?

I greatly appreciate any help in this regards.

asked 03 Oct '16, 06:47

Ajinkya's gravatar image

Ajinkya
113
accept rate: 0%

edited 08 Dec '16, 08:53

fbahr's gravatar image

fbahr ♦
4.6k716

What specifically do you mean by "unable to produce the dual values"? What happens when getDual executes?

(03 Oct '16, 15:49) Paul Rubin ♦♦

Dear Paul, The code stops executing when it reaches to the statement cplex.getDual() with an unhandled exception (the debugging spots an error on the same line). Is is due to incompatibility or do I need to add the constraints using IloRange()?

(04 Oct '16, 00:21) Ajinkya

You have to be more specific as to what happens, e.g. do you have a compiler error, or a runtime error?

Have a look at the examples shipped with cplex on how to get the dual values, e.g.: cutstock.cpp, iloindefqpex1.cpp, ilolpex1.cpp, ilolpex4.cpp, ilolpex6.cpp, iloqcpdual.cpp, iloqpex1.cpp, ilosocpex1.cpp all use the function getDual(...).

Compile error: most likely you didn't use linear constraints.

Runtime error: most likely you modified the model after it has been solved, but before you query the dual information.

link

answered 05 Oct '16, 00:37

Joris%20Kinable's gravatar image

Joris Kinable
3381213
accept rate: 16%

Hi Ajinkya,

I have the same problem. Did you resolve the problem? Could you please help me with that? I do appreciate your help.

link

answered 07 Dec '16, 20:30

Maryam162's gravatar image

Maryam162
112
accept rate: 0%

Hi Maryam, Thanks for your query. I wish to tell that I am just a beginner in Cplex so I can answer in layman's terms. Hope you'll understand that.

In my program I have made following changes and then I get expected dual values. To be specific I have slightly changed the way in which I was defining the constraints using IloRangeArray(). Please see the sample program in the previous post. The modified program is:

IloModel model(env);

IloRangeArray constraints(env); // Declaring a RangeArray named "constraints" in the environment

// data input

// a sample constraint is given as

for(){

for(){

for(){

// now I'll declare range for the constraint defined above

IloRange range_constraint(env, -ILOInfinity, sum_food_inv, capacity[s][w] * Delta_wh_hire_contract[s][w]);

// this defines a range in the format of ILORange(env, LB, expression, UB)

// now I'm going to add the "range_constraint" to the model and IloRangeArray

model.add(range_constraint);

constraints.add(range_constraint);

}

}

}

and then after using Cplex.solve() you can retrieve the dual values using cplex.getDual() expressions.

link
This answer is marked "community wiki".

answered 07 Dec '16, 23:05

Ajinkya's gravatar image

Ajinkya
113
accept rate: 0%

Thanks Ajinkya! I am also a beginner in cplex. Your way worked well. I really appreciate your help.

link

answered 08 Dec '16, 02:33

Maryam162's gravatar image

Maryam162
112
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×231
×191
×10
×6

Asked: 03 Oct '16, 06:47

Seen: 1,921 times

Last updated: 08 Dec '16, 08:53

OR-Exchange! Your site for questions, answers, and announcements about operations research.