Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  variable access - array indexed with a tuple

    Posted 07/31/12 05:24 AM

    Originally posted by: CplexUser1453


    Hello

    I am dealing with a problem where one of the decision variables looks like a fairly sparse 3D array. Thanks to tuples I was able to write a fairly elegant OPL model. However now I have trouble accessing my representation through the JAVA API.

    Here is my OPL representation :

    tuple TripleIndex{
    int t;
    int u;
    int g;
    }

    {TripleIndex} Index = {<t,u,g> | t in Time, u in Urange, g in 1..Garray[t][u]};

    dvar boolean Xs in Index;

    Accesing my X variable in OPL scripting is easy :

    Xhttp://Index.find(t,u,g) (for a given t,u,g)

    Using the Java API I am capable of getting X and TripleIndex :

    IloTupleSchema Tindex = opl.getElement("TripleIndex").asTupleSchema();
    IloNumMap Xmap = opl.getElement("X").asNumMap();

    Here are my questions :
    1) How do I get my "Index" tuple from opl?
    2) Once I have all three elements, how do I do the equivalent of Xhttp://Index.find(t,u,g)?

    Thanks a lot!
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: variable access - array indexed with a tuple

    Posted 07/31/12 05:27 AM

    Originally posted by: CplexUser1453


    sorry the formatting is not right. Here is the message with good formatting :

    I am dealing with a problem where one of the decision variables looks like a fairly sparse 3D array. Thanks to tuples I was able to write a fairly elegant OPL model. However now I have trouble accessing my representation through the JAVA API.

    Here is my OPL representation :

    
    tuple TripleIndex
    { 
    
    int t; 
    
    int u; 
    
    int g; 
    }   
    {TripleIndex
    } Index = 
    {<t,u,g> | t in Time, u in Urange, g in 1..Garray[t][u]
    };   dvar 
    
    boolean X[s in Index];
    

    Accesing my X variable in OPL scripting is easy :
    
    X[Index.find(t,u,g)] (
    
    for a given t,u,g)
    

    Using the Java API I am capable of getting X and TripleIndex :

    IloTupleSchema Tindex = opl.getElement("TripleIndex").asTupleSchema();
    IloNumMap Xmap = opl.getElement("X").asNumMap();

    Here are my questions :
    1) How do I get my "Index" tuple from opl?
    2) Once I have all three elements, how do I do the equivalent of
    
    X[Index.find(t,u,g)] (
    
    for a given t,u,g)
    


    Thanks a lot!
    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: variable access - array indexed with a tuple

    Posted 07/31/12 09:42 AM

    Originally posted by: CplexUser1453


    Found the answer so let me repond to my question myself (as I have not found a similar topic on the forum and I think this is an example)

    So, it seems to me that with my OPL model defined as

    tuple TripleIndex{
    int t;
    int u;
    int g;
    }
     
    {TripleIndex} Index = {<t,u,g> | t in Time, u in Urange, g in 1..Garray[t][u]};
     
    dvar boolean X[s in Index];
    


    the equivalent of
    X[Index.find(t,u,g)]
    


    is :
    IloNumMap Xmap = opl.getElement("X").asNumMap();
    IloTupleBuffer buf = opl.getElement("Index").asTupleSet().makeTupleBuffer(-1);
    buf.setIntValue("t", tt);
    buf.setIntValue("u", uu);
    buf.setIntValue("g", gg);
    buf.commit();
    System.out.println(Xmap.get(index.find(buf)));
    


    This seems to work for me...
    #DecisionOptimization
    #OPLusingCPLEXOptimizer