Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Collect Variables Value using OPL C++ API IloOplModelSource

    Posted 05/14/12 09:42 AM

    Originally posted by: SystemAdmin


    Hi,

    I build a C++ project from a model and a data file, as it is done in the given example mulprod, using the classes IloOplModelSource and IloOplDataSource.
    It is possible to get back the objective value, using the well named function getObjValue(), and to print the variables value, with printSolution(cout), but is it possible to actually collect then to use them in another optimization ? (Of course, I can always print them in a file and read it afterwards, but ... it does not seem very clever and it might compute errors)

    I am aware that, as I imported the model from a file, variables do not have an actual C++ (only the string in the .mod) name so I cannot call them, but as it is done in Python ( the get_values() metod), it might exists in C++ - well it should, as the API is more developped in this language...

    Question : Is there an efficent way to get the solution values ?

    Thanks, Adrian
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: Collect Variables Value using OPL C++ API IloOplModelSource

    Posted 05/14/12 11:51 AM
    Hi,

    you can have access to the decision variables after the solve.

    In the example mulprod you mentioned, after

    opl.postProcess();
    


    you may add

    IloNumVarMap inv = opl.getElement("Inv").asNumVarMap();
    cout << "Number of dimensions of Inv" 
    << inv.getNbDim() << endl;
    


    that will give

    Number of dimensions of Inv2

    I hope this helps you

    Regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: Collect Variables Value using OPL C++ API IloOplModelSource

    Posted 05/15/12 02:40 AM

    Originally posted by: SystemAdmin


    Thanks for you answer.

    I had managed to go so far, but then I'm stuck.
    Long story short, in my OPL model, I have to variables, one matrix MSET1SET2 and the other is a tuple indexed array T<a,b,c>.
    I opl.getElement.asNumVarMap() or asIntVarMap() them, but then which operator or function have I to use to get the values (like M[i][j] or Ta,b,c) ?

    Thanks
    Adrian
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: Collect Variables Value using OPL C++ API IloOplModelSource

    Posted 05/15/12 02:40 AM

    Originally posted by: SystemAdmin


    Thanks for you answer.

    I had managed to go so far, but then I'm stuck.
    Long story short, in my OPL model, I have to variables, one matrix MSET1SET2 and the other is a tuple indexed array T<a,b,c>.
    I opl.getElement.asNumVarMap() or asIntVarMap() them, but then which operator or function have I to use to get the values (like M[i][j] or Ta,b,c) ?

    Thanks
    Adrian
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: Collect Variables Value using OPL C++ API IloOplModelSource

    Posted 05/15/12 03:25 AM

    Originally posted by: SystemAdmin


    Indeed,
    I have no problem for the matrix or array type, I just convert them into IloNumArray (and not Var) and I can access the values with MIloInt(i).get(IloInt(j))
    But my real issue is for the tuple indexed array, because I do not know the relation between (a,b,c) and k with T<a,b,c> in OPL and T[k] in IloCplex
    Adrian
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: Collect Variables Value using OPL C++ API IloOplModelSource

    Posted 05/15/12 04:39 AM
    Hi,

    the example iterators.cpp in opl\examples\opl_interfaces\cpp\src could help you.
    The sample3 function is a good example.

    Regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 7.  Re: Collect Variables Value using OPL C++ API IloOplModelSource

    Posted 05/15/12 05:19 AM

    Originally posted by: SystemAdmin


    Thanks for the tip, it is actually quite interesting,

    But my problem is different.
    In the example, this is the case of a tuple array, string indexed.
    Mine is a boolean array, tuple indexed...
    The issue is that I do not know the relation between the index (wich is an int in a range that do not start at 0 or 1 because ther are other variables declared before I guess) of the array and the associated tuple.

    Hope it's clear enough...
    Thanks,
    Adrian
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: Collect Variables Value using OPL C++ API IloOplModelSource

    Posted 05/15/12 07:52 AM
    Hi,

    suppose you have

    tuple t
    {
     int x;
    int y;
    }
     
    {t} s={<1,2>,<2,1>};
     
    int z[s]=[10,5];
    


    then to read this you can use

    IloTupleSet s = opl.getElement("s").asTupleSet();
                    IloMapIndexArray indices(env);
                    IloTuple tuple=s.makeFirst();;
                    
                    IloIntMap z = opl.getElement("z").asIntMap();
                    int value=z.get(tuple);
                    cout << value << endl;
                    IloTuple tuple2=s.makeTuple(1);
                    int value2=z.get(tuple2);
                    cout << value2 << endl;
    

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: Collect Variables Value using OPL C++ API IloOplModelSource

    Posted 05/15/12 08:08 AM

    Originally posted by: SystemAdmin


    Perfect!

    Thanks
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: Collect Variables Value using OPL C++ API IloOplModelSource

    Posted 05/15/12 08:13 AM

    Originally posted by: SystemAdmin


    What is the use fot the following line ?

    IloMapIndexArray indices(env);
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 11.  Re: Collect Variables Value using OPL C++ API IloOplModelSource

    Posted 05/15/12 08:42 AM
    hi,

    IloMapIndexArray indices(env);
    


    is useless.

    regards
    #DecisionOptimization
    #OPLusingCPLEXOptimizer