Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Solution Pool Decision Variable Values Using OPL Java API

    Posted 01/11/15 02:17 PM

    Originally posted by: mathygirl


    The way I create a cplex object is as follows:
     
    IloOplFactory oplF = new IloOplFactory();
     
    cplex = oplF.createCplex();
     
    After invoking cplex.solve(),  I was able to get the following commands to work:
     
    int numsol = cplex.getSolnPoolNsolns();
     
    for (int s=0; s<numsol; s++) {
        System.out.println("solution " + s + ": objective =  "+ cplex.getObjValue(s));
    }
    However, I would also like to extract out decision variable values for each solution in the solution pool. 
     
    I know of the example Populate.java, but the cplex object created there is done through the CPLEX library by 
     
    IloCplex cplex = new IloCplex();
     
    The example does not work for my cplex object.
     
    Is it possible to extract out decision variable information for each solution in the solution pool given that I've created my cplex object via the OPL Java API?

    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Solution Pool Decision Variable Values Using OPL Java API

    Posted 01/12/15 03:22 AM

    Hi,

    you should use in the class IloOplModel the function public boolean setPoolSolution(int solId)

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Solution Pool Decision Variable Values Using OPL Java API

    Posted 01/12/15 07:36 AM

    There are overloads for IloCplex.getValue() that allow you to specify a solution number:

    double getValue(IloNumVar var, int soln)
    double[] getValues(IloNumVar[] var, int soln)

    See also the reference documentation (there are more overloads than I listed here).


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Solution Pool Decision Variable Values Using OPL Java API

    Posted 01/12/15 11:00 AM

    Originally posted by: mathygirl


    How do I obtain the IloNumVar object required as the first input to the getValue() method? I have no access to the IloLPMatrix class from the cplex object I've created.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Solution Pool Decision Variable Values Using OPL Java API

    Posted 01/12/15 11:55 AM

    You can use IloCplex.getModel() to get a reference to the model that was extracted and then use IloModel.iterator() to iterate over all model elements. There are code snippets on this Forum that illustrate how to get all variables in the model using this method.

    Also, you probably have an instance of IloOplModel, right. Shouldn't IloOplModel.getElement(String) give you access to the variables (provided you know their name in the OPL model)? I am not an expert in the OPL API so I may be wrong here.


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Solution Pool Decision Variable Values Using OPL Java API

    Posted 01/12/15 12:20 PM

    Originally posted by: mathygirl


    The decision variable I extract is of type IloIntVarMap (it is a boolean map), so I can't extract it as an IloNumVar object, it seems like. 


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Solution Pool Decision Variable Values Using OPL Java API

    Posted 01/12/15 12:34 PM

    Hi

    you may have a look at examples in

    CPLEX_Studio1261\opl\examples\opl_interfaces\java

    for example

    IloNumMap duals = subDataElements.getElement("Duals").asNumMap();

    if you replace asNumMap by asNumVarMap you ll get IloNumVar

    regards

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Solution Pool Decision Variable Values Using OPL Java API

    Posted 01/12/15 01:22 PM

    Originally posted by: mathygirl


    Thank you so much for pointing this out. This works.


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Solution Pool Decision Variable Values Using OPL Java API

    Posted 01/12/15 01:24 PM

    Originally posted by: mathygirl


    Since I am now able to create an IloNumVar object, the getValue() method is now working for me to obtain the decision  variable values for each solution in the solution pool. Thank you so much!


    #CPLEXOptimizers
    #DecisionOptimization