Originally posted by: JDalal
I am using C++/CPLRX 12 to implement Benders decomposition. Got some issues in using getRay().
I have gone through posts related to getRay() by previous users in this forum. Those helped me to fix some first-time user issues like turning off pre-solve, using Primal as RootAlg etc.
I am trying to explain my issue with a very small example.
Now, in Benders, I solve an IP as master problem (MP), pass the binary vector Y to dual subproblem(DSP). The objective of DSP contains terms of Y vector, like : x[0]*y_MP[0] + x[1]*y_MP[1]+... where y_MP[i] are the values passed from MP. Obviously, many x[i] coefficients will be 0 in DSP. After invoking cplex.solve() when I try to use the following code, I get error due to array index getting out of bound :
{code}
IloNumVarArray vars(envSub);
IloNumArray vals(envSub);
cplex.getRay(vals, vars);
cout<<"see size==="<<vars.getSize()<<endl;
for (int i = 0; i < vars.getSize(); ++i)
cout << i << ", " << vals[i] << " [" << vars"<< std::endl;
{\code}
On a closer look, I found that as per model formulation I have total 200 variables. But, many of them have 0 coefficients and only 56 variables are there with nonzero coefficients in the model. But, vars.getSize() returns 200, not 56 what I expected. From earlier threads, I thought that getRay() returns sparse representation - eliminating zero coefficient variables.
Can someone please explain my mistake?
#CPLEXOptimizers#DecisionOptimization