Decision Optimization

Expand all | Collapse all

Search Phases with Java API

  • 1.  Search Phases with Java API

    Posted Mon August 23, 2021 09:38 AM

    Hello,

    I have been using CP Optimizer for the past few months and I master the basics. Now I would like to get further and use search phases in order to get solutions faster. I have only one small group of variables that I want to fix early in the process, with no priority relation between them.

    My problem is that I have tried a few different ways and each of them leads to errors. I am using the Java API and I have not found many examples for this API on the internet. I think that I do not manipulate IloIntVarArray and IloSearchPhase objects properly…

    Here is a simplified version of how I proceed :


    IloIntVarArray keyVarArray = new ilog.concert.cppimpl.IloIntVarArray();
    for(IloIntVar var : [my key variables]) {
        keyVarArray.add(var);
    }
    cp.setSearchPhases((IloSearchPhase) keyVarArray);

     


    This does not lead to any compiling error but then when I run the code I get the following error at .add(var)

    Error : java.lang.RuntimeException: internal error (Please notify IBM)

     

    I have tried to add a : keyVarArray .getSize(); right after the initialization of keyVarArray and it leads to the same error...

    Would you please help me find what I am doing wrong.

    Thank's a lot !

    PS : I do not use environment, if this is my main problem let me know…



    ------------------------------
    Louis Marot
    ------------------------------


  • 2.  RE: Search Phases with Java API

    Posted Mon August 23, 2021 01:13 PM
    Hello,
    you can write:

    IloIntVar[] x = cp.intVarArray(num);
    ...
    IloSearchPhase phase = cp.searchPhase(x);
    cp.setSearchPhases(phase);
    cp.solve(); // or cp.startNewSearch();

    You can find several java examples in the directory cpoptimizer/examples/src/java.
    For a more complete API, e.g. for specifying the variable/value order in the search phase, you can look at the java API doc of CP Optimizer https://www.ibm.com/docs/en/icos/20.1.0?topic=manual-ilogcp

    ol

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



  • 3.  RE: Search Phases with Java API

    Posted Tue August 24, 2021 03:55 AM
    Ok thank you very much it worked and helped me to solve my problem quicker 

    I will have a look at the directory cpoptimizer/examples/src/java.

    Tnahk's again


    ------------------------------
    Louis Marot
    ------------------------------