# Decision Optimization

View Only

## Exctraction of Dual values C++ - 2D Array

• #### 1.  Exctraction of Dual values C++ - 2D Array

Posted Fri February 16, 2024 10:48 AM

Greetings, Community!

I'm currently working on extracting the dual values of the constraints outlined below:

for(r in resources, t in time)

AvailabilityCons:

sum( s in schedule) s.X_Time[t] * lambda[s] <= Available[r][t];

While I've managed to access and transfer them successfully to the subproblem using CPLEX OPL, I'm facing a challenge in doing so using C++. I've referred to the cutstock example, which worked well for a 1-D array scenario, but in my case, it's a 2D array. Could someone guide me on how to extract and transfer the dual values to the subproblem using C++? Below is the C++ program I've developed:

IloNumMap DualW = subDataElements.getElement("AvailabilityDual").asNumMap();
IloConstraintMap AvailabilityConsFill = masterRC.getOplModel().getElement("AvailabilityCons").asConstraintMap();

for (IloInt i = 1; i <= nbRes; i++) {
IloForAllRange resConstraint = AvailabilityConsFill.get(i);

for (IloInt j = 1; j <= nbTime; j++) {

DualW.set(i, masterCplex.getDual(resConstraint[j]));
}
}
#Decision Optimization

------------------------------
Dheeban Kumar
------------------------------

• #### 2.  RE: Exctraction of Dual values C++ - 2D Array

Posted Wed February 21, 2024 01:03 PM

Hello, you can use tuples:

``````tuple index {
typeOfResource resource;
typeOfTime time;
}
{index} Indexes = {<r,t> | r in resources, t in time};
for(i in Indexes)
AvailabilityCons:
sum( s in schedule) s.X_Time[i.time] * lambda[s] <= Available[i.resource][i.time];
or
sum( s in schedule) s.X_Time[i.time] * lambda[s] <= Available[i];

IloTupleSet indexSet = masterRC.getOplModel().getElement("Indexes").asTupleSet();
IloNumMap DualW = subDataElements.getElement("AvailabilityDual").asNumMap();
IloConstraintMap AvailabilityConsFill = masterRC.getOplModel().getElement("AvailabilityCons").asConstraintMap();
for (IloTupleIterator it(indexSet); it.ok(); ++it) {
IloTuple t = *it;
IloForAllRange r = AvailabilityConsFill.get(t);
DualW.set(t, masterCplex.getDual(r));
}

where AvailabilityDual is defined as follows in the .mod files float AvailabilityDual[Indexes] = ...;``````

------------------------------
Olivier Lhomme
------------------------------

• #### 3.  RE: Exctraction of Dual values C++ - 2D Array

Posted Thu February 22, 2024 01:43 PM

Thank you, Olivier. It worked. Much appreciated.

------------------------------
Dheeban Kumar Srinivasan Sampathi
------------------------------