# Trouble in retrieving dual values in an LP

 0 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

 1 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. answered 05 Oct '16, 00:37 Joris Kinable 338●1●2●13 accept rate: 16%
 0 Hi Ajinkya, I have the same problem. Did you resolve the problem? Could you please help me with that? I do appreciate your help. answered 07 Dec '16, 20:30 Maryam162 11●2 accept rate: 0%
 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 11●3 accept rate: 0%
 0 Thanks Ajinkya! I am also a beginner in cplex. Your way worked well. I really appreciate your help. answered 08 Dec '16, 02:33 Maryam162 11●2 accept rate: 0%
 toggle preview community wiki

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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