Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Cplex 12.8 IloRange::setLinearCoefs within UserCutCallback halting

    Posted 05/10/18 12:49 PM

    Originally posted by: A.Florio


    I have code that works on Cplex 12.7 but has stopped working on 12.8. It is a simple TSP solver with SECs added dynamically.

    Within the UserCutCallback, when the first SEC violation is identified (when solving the relaxation at the root node of branch-and-bound), I create IloRange and, when setting up the cut with setLinearCoefs, the execution simply halts. No exception is raised. CPU becomes idle.

    Architecture: macOS 10.13.4

    Apple LLVM version 9.1.0 (clang-902.0.39.1)

    Code:

     

    ILOUSERCUTCALLBACK2(TSPSolverMinCut, IloNumVarArray, xijs, Instance, instance) {

        const double CUTTOL=1e-2;

        IloNumArray valscplex(getEnv());

        getValues(valscplex, xijs);

        vector<vector<double>> vals(instance.numNodes()+1,

                vector<double>(instance.numNodes()+1, 0));

        for (int k=0, i=0; i<=instance.numNodes(); ++i)

            for (int j=0; j<=instance.numNodes(); ++j, ++k)

                if (i!=j)

                    vals[i][j]=valscplex[k];

        valscplex.end();

        // subtour elimination constraints (fractional) (global cuts)

        {

            MinCutSolver mincut(vals);

            MinCutSolution sol=mincut.solve();

            if (sol.value()<1-CUTTOL) {

                IloRange sec(getEnv(), 1, IloInfinity);

                IloNumVarArray vars(getEnv());

                IloNumArray coeffs(getEnv());

                for (int i=0; i<=instance.numNodes(); ++i) {

                    if (sol.minCut()[i]) {      // i is in the cut

                        for (int j=0; j<=instance.numNodes(); ++j) {

                            if (i!=j && !sol.minCut()[j]) { // j is NOT in the cut

                                vars.add(xijs[i*(instance.numNodes()+1)+j]);

                                coeffs.add(1.0);

                            }

                        }

                    }

                }

                try {

                    sec.setLinearCoefs(vars, coeffs);        // Execution is halting HERE

                } catch (...) {        // No exceptions raised

                    cout<<"exception caught!"<<endl;

                    exit(-1);

                }

                add(sec);

                vars.end();

                coeffs.end();

            }

        }

    }


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Cplex 12.8 IloRange::setLinearCoefs within UserCutCallback halting

    Posted 05/10/18 01:12 PM

    That seems familiar :-(

    Can you please try the solution described here. Note that despite my claim, the fix did not make it into 12.8 :-(


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Cplex 12.8 IloRange::setLinearCoefs within UserCutCallback halting

    Posted 05/10/18 02:18 PM

    Originally posted by: A.Florio


    I added env.setNormalizer(false) just before cplex.solve(), and also getEnv().setNormalizer(false) in the 1st line of the UserCutCallback, but the problem persists.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Cplex 12.8 IloRange::setLinearCoefs within UserCutCallback halting

    Posted 05/10/18 02:31 PM

    OK, I have to look deeper then. This may take a while.

    In the meantime, do things work any better if you create 'sec' like so:

    IloRange sec(getEnv(), 1, IloScalProd(vars, coeffs), IloInfinity)

    ? (after populating vars and coeffs)


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Cplex 12.8 IloRange::setLinearCoefs within UserCutCallback halting

    Posted 05/10/18 04:44 PM

    Originally posted by: A.Florio


    Yes, great workaround, that solved the problem. Thank you very much for your prompt answers!

    Also, setNormalizer(false) is not needed when using this workaround.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Cplex 12.8 IloRange::setLinearCoefs within UserCutCallback halting

    Posted 05/11/18 03:07 AM

    Thank you for your feedback!

    I confirmed that the issue boils down to the same bug that is described in the thread I linked to.

    I also confirm that in this variant of the problem, setNormalizer() is neither helpful nor needed to work around the problem.

    While looking at your code I noticed something: there may be a memory leak since you are not end()ing 'sec'. If you look at the user cut examples iloadmipex5.cpp and ilobendersatsp.cpp you can see that a cut that is instantiated in the callback is always added like this

    add(cut).end();

    This is independent of the deadlock but may still improve your code.


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Cplex 12.8 IloRange::setLinearCoefs within UserCutCallback halting

    Posted 05/11/18 03:38 AM

    Originally posted by: A.Florio


    Thanks, I did not know that!

     


    #CPLEXOptimizers
    #DecisionOptimization