Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
Expand all | Collapse all

How to access the interval decision value in the CP solution via Java?

  • 1.  How to access the interval decision value in the CP solution via Java?

    Posted 06/11/09 03:12 PM

    Originally posted by: SystemAdmin


    [spleen said:]

    I have one simple scheduling model and I can now solve it efficiently. Now I would like to read the optimized interval value in the java interface function.
    I had done everything ok and the solution can be printed by
    opl.printSolution(System.out);

    However, one thing is quite difficult, at least for me.

    I defined a few decision variables like

    dvar boolean X[range1][range2];
    dvar interval Work [f in range1] [v in range2] optional size  List[f].workingTime ;
    dvar interval Workspan [f in range1];

    I have full read access to the decision variable X in the java project, yet I can not readout the Work array directly. I looked up in the java reference and found that there does exist a IloIntMap interface, yet does not exist a IloIntervalMap. I use the IloIntervalVarMap instead and it only reads out the interval variables instead of the decision values of those variables. Could you kindly tell me how to access that? Thanks in advance.
    Here is the code:

        IloIntervalVarMap Work = opl.getElement("Work").asIntervalVarMap();
        IloIntMap X = opl.getElement("X").asIntMap();
                ilog.concert.IloIntRange s1 = opl.getElement("range1").asIntRange();
                ilog.concert.IloIntRange s2 = opl.getElement("range2").asIntRange();

               
                // Iterate on the first indexer.
                for (int i  = 1; i <= s1.getSize(); i++ ){<br />                // Get the second dimension array from the first dimension.
                    IloIntervalVarMap sub = Work.getSub(i);
                    IloIntMap subx = X.getSub(i);
                    System.out.print(i);
                    // Iterate on the second indexer of x (that is the indexer of the subarray).
                    for (int j = 1; j<= s2.getSize(); j++){<br />                IloIntervalVar oneTrip  = sub.get(j);
                    int bl = subx.get(j);
                int start1 = oneTrip.getStartMax();
                int end2 = oneTrip.getEndMax();

                System.out.print(" bool = ");
                System.out.print(bl);           
                System.out.print(" start1 = ");
                System.out.print(start1);           
                    System.out.print(oneTrip);
                    System.out.print("\n");
                    if(oneTrip.isPresent()){
                    int start = oneTrip.getStartMax();
                    int end = oneTrip.getEndMax();
                    System.out.print(start);
                    System.out.print(end);
                    }
                   
                    }
            }




    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: How to access the interval decision value in the CP solution via Java?

    Posted 06/12/09 09:15 PM

    Originally posted by: SystemAdmin


    [afleischer said:]

    Hi,

    instead of

    int start = oneTrip.getStartMax();

    you could try

    int start = cp.getStart(oneTrip); where cp is the CP-Optimizer engine (IloCP) you used

    Alex
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: How to access the interval decision value in the CP solution via Java?

    Posted 08/29/10 08:18 AM

    Originally posted by: SystemAdmin


    Wow, I was looking for the solution for so long..

    Thanks!

    I wish the API was a little simpler to understand.

    Assaf
    #DecisionOptimization
    #OPLusingCPLEXOptimizer