0

One of the arguments of a function in Cplex concert C++ has IloNumArray type and it must be an empty dynamic array. The size of the array is not known until the end of the solution. I declared the array like this:

    const IloNumVarArray var(env);
    IloNumArray down;
    IloNumArray up;
    IloInt64 iteration1 = var.getSize();
    IloCplex::getStrongBranch(down, up, var, iteration1);  

But I got this error: no instance of overloaded function matches the argument list

The link is here. The down and up arrays have to be dynamic arrays.

usercp
  • 9
  • 3

1 Answers1

0

The examples that are included with CPLEX show how to do this. For example, this snippet comes from ilolpex4.cpp:

  IloNumArray vals(env);
  cplex.getValues(vals, var);

You can find the examples under <COSDIR>/cplex/examples/src/cpp where <COSDIR> is the location you installed ILOG CPLEX Optimization Studio. A description of the examples can be found here.

EDIT:

In your code snippet, you have not initialized down and up.

The following modification to the ilolpex2.cpp example works fine on my x86-64 Linux machine:

  cplex.extract(model);
  if ( !cplex.solve() ) {
     env.error() << "Failed to optimize LP" << endl;
     throw(-1);
  }
  else {
     IloNumArray down(env);
     IloNumArray up(env);
     IloInt64 itmax = cplex.getParam(IloCplex::Param::Simplex::Limits::Iterations);
     cplex.getStrongBranch(down, up, var, itmax);

     for (int i = 0; i < var.getSize(); ++i) {
        env.out() << var[i].getName()
                  << "(" << down[i] << ", " << up[i]
                  << ")" << endl;
     }
  }

The documentation for the underlying CPXstrongbranch function is here.

rkersh
  • 4,447
  • 2
  • 22
  • 31
  • Thank you for your reply. Unfortunately, I get the same error again. I would like to implement this function [https://www.ibm.com/support/knowledgecenter/SSSA5P_12.7.0/ilog.odms.cplex.help/refcallablelibrary/cpxapi/strongbranch.html]. As I understood, I have to define the downobj as a dynamic and empty array then the function fills it with the desired values. – usercp Apr 11 '20 at 18:51
  • Please show us the line of code where the error is coming from and the types of the arguments and the entire error message. Also, your link didn't work. Which CPLEX function are you calling? – rkersh Apr 11 '20 at 19:04
  • Thank you very much @rkersh for your help. I got error 1017. I saw your answer about this error on this page( https://stackoverflow.com/questions/51737277/cplex-quadratic-objective-cplex-error-1017-not-available-for-mixed-integer-prob ). I use importModel method to import benchmarks so I don't specify any type for variables. How can I fix this error? – usercp Apr 14 '20 at 16:23
  • Your model must contain integer variables, or MIP modeling constructs such as indicator constraints, SOS constraints, etc. You'll need to convert the models to be LPs before using `CPXstrongbranch`. – rkersh Apr 14 '20 at 17:13
  • The benchmarks I use are MIP problems like "air05" and "aflow30" which they LPs and have binary and continuous variables. You mean all variables in a problem must be integer? I declare variables with IloNumVarArray type. – usercp Apr 14 '20 at 19:29
  • Please revisit the documentation for [CPXstrongbranch](https://www.ibm.com/support/knowledgecenter/SSSA5P_12.10.0/ilog.odms.cplex.help/refcallablelibrary/cpxapi/strongbranch.html) (as provided in my answer above). It sounds like you think this function does something different than it actually does. You need to have a Linear Program (not a MIP) in memory in order to use this function. – rkersh Apr 15 '20 at 15:39
  • I'm sorry. I was wrong. Your means was LP relaxation. I converted the variables to ILOFLOAT with IloConversion. The model runs two times but I get that error again I wrote this code before extract model. for (int i = 0; i < var.getSize(); i++){IloConversion conv = (IloConversion(env, var[i], ILOFLOAT));model.add(conv);} Do I have to change the var argument in getstrongbranch function? Or it's converted. – usercp Apr 16 '20 at 15:40
  • I'm guessing you already figured this out, but after adding the `IloConversion`'s to the model you should be able to call `getStrongBranch` with the original `var` argument; you should not have to change types, etc. By the way, rather than adding many `IloConversion`'s you can do it in one step with `model.add(IloConversion(env, var, ILOFLOAT));`. – rkersh Apr 17 '20 at 17:19