Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Acess opl elements with java

    Posted 06/11/15 06:27 AM

    Originally posted by: aaapb


    Hi,

    I'm implementing Bender´s decomposition in Opl with an external function in java to obtain the extreme rays and I have two questions:

    • If I solve de sub problem inside the opl model can I access the constraints inside the external function in order to get the Farkas certificate? How?
    • If I use the external function to solve the sub problem and get the Farkas certificate then I need to access a multidimensional array opl element. For one dimensional arrays I've done

    for(inti = 0; i < NbItems; i++)

    {

           custo_sub[i] = (int)oplcusto_sub.asIntMap().get(1+i); 

    }

     

    But when I try to adapt that to a multidimensional array it gives me an error saying    the method get(int) in the type IloIntMap is not applicable for the arguments (int, int). Is there another method to apply to multidimensional arrays?

     

    Regards,

    Ana


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Acess opl elements with java

    Posted 06/11/15 07:11 AM

    Hi,

    you have an example on how to call an exttrnal java method in CPLEX_Studio1261\opl\examples\opl_interfaces\java\javaknapsack

    In CPLEX_Studio1261\opl\examples\opl_interfaces\java\iterators you will find an iterator on a 2D array.

    // Iterate on the first indexer.
            for (java.util.Iterator it1 = s1.iterator(); it1.hasNext();) {
                String sub1 = (String) it1.next();
                // Get the 2nd dimension array from the 1st dimension.
                IloIntMap sub = x.getSub(sub1);
                // Iterate on the second indexer of x (that is the indexer of the
                // sub array).
                for (java.util.Iterator it2 = s2.iterator(); it2.hasNext();) {
                    String sub2 = (String) it2.next();
                    // We are in the last dimension of the array, so we can directly
                    // use the get method.
                    System.out.println(sub1 + " " + sub2 + " " + sub.get(sub2));
                }
            }

    regards

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Acess opl elements with java

    Posted 06/11/15 09:05 AM

    Originally posted by: aaapb


    Hi,

    Thanks for your reply.

    I'm working based on that javaknapsack example which use an external function to solve the sub problem. That´s the reason for the first question… I think that I need to solve the sub problem inside the external function in order to get the Farkas certificate, right? I can´t access the Farkas certificate inside the external function if the sub problem was solve inside the opl model, right?

    In order to solve the sub problem in the external function I need to work with the values of arrays opl elements so I need to access them and store them in news arrays define in java. The code presented before works with one dimensional arrays and it´s used in the javaknapsack example. In the iterators example we only access to 2D.   

    Regards,

    Ana


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Acess opl elements with java

    Posted 06/12/15 02:34 PM

    Hi

    for the first question you send to the external java function the cplex object itself.

    for the secondquestion, x is a 2D array in iterators.mod

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Acess opl elements with java

    Posted 06/17/15 02:34 PM

    Originally posted by: aaapb


    Hi,

    Thanks for your reply but I can't solve my problem… If I understand correctly your answer I can access the opl model in my external function.

    So, suppose I have a model generate and solve in opl( var subModelOpl=new IloOplModel(subModelDef,subModelCplex); subModelOpl.generate(); subModelCplex.solve();) and the problem is infeasible. Then I need to use an external function in java to get the extreme rays based on dual.Farkas function.

    Based in the knapsack example I use a function

    public void updateInputs(IloOplModel subModelOpl)

                    {

                                   try{

                                                   IloCplex primal=new IloCplex();

                                                   primal= subModelOpl.getCplex();

                                               …

    But when I run my model and ask for primal.dualFarkas I get java.lang.NullPointerException which means that the result of subModelOpl.getCplex() is NULL… There is another way to access the subModelOpl generate and solve in opl?

    Best regards,

    Ana


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Acess opl elements with java

    Posted 06/18/15 02:27 AM

    Hi,

    in the java external call why do not you simply send the cplex object ?

    public void getMoreInfo(IloCplex myCplex)

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Acess opl elements with java

    Posted 06/24/15 11:32 AM

    Originally posted by: aaapb


    Hi,

    Thanks for your reply. I've tried your suggestion but I got a mismatch error. However, I find another way to access de cplex model with this code:

    public double[] getMoreInfo(IloOplModel subModelOpl)

                    { IloCplex primal;

                                   try{

                                                   primal= subModelOpl.getCplex();

    And when I write these lines:

                                                   IloCplex.Status status=primal.getStatus();                                              

                                                  System.out.println("CPLEX status: "+ status);

                                                   System.out.println("obj="+primal.getObjValue());

    I can get the information about the status and the objective value but I can't access the variables values or apply dualFarkas function (primal.dualFarkas(farkasConstraints, farkasValues)). In the first case it doesn't recognize the variable and in the second I get:

     java.lang.RuntimeException: internal error: bad cast

    at ilog.concert.cppimpl.IloConcertUtils.ToCppIloConstraint(IloConcertUtils.java:223)

    at ilog.concert.cppimpl.IloConcertUtils.ToCppIloConstraintArray(IloConcertUtils.java:371)

    at ilog.cplex.IloCplex.dualFarkas(IloCplex.java:17915)

    at javaRay.Ray.getMoreInfo(Ray.java:43)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.lang.reflect.Method.invoke(Method.java:483)

    at ilog.opl.IloOplExternalCall.callJava(IloOplExternalCall.java:196)

     

    Best regards,

    Ana


    #DecisionOptimization
    #OPLusingCPLEXOptimizer