Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Tuple in JAVA API

    Posted 08/10/18 09:54 PM

    Originally posted by: Bahman


    Hello Everyone,

     

    I have coded and ran my model in CPLEX OPL API, and It works fine. I am migrating to JAVA API. I had defined a tuple in CPLEX STUDIO (in OP:I) and I do not know if I need to define a tuple3 and List<Tuple>,, or a separate class to write the set of tuples (representing arcs).I do not know what is the best way to define the arcs that I had defined them in opl in tuples, and how to make use of that as a dimension of my decision variable X, in JAVA API. A  MWE  is presented as follows:

     

    {int} Y=asSet(1..7);
    {int} T=asSet(1..10);
    {int} K=asSet(1..42);

    int b[Y][K][G]=...;
    {string} G=...; 

     

    tuple Sleg {
    int i;
    int j;
    float l;
    }
    {Sleg} Slegs with i,j in Y=...; 

     

    Then one of the decision Variable: 

    dvar int+ X[Slegs][K][G][T];

     

    and one of the constraints (flow conservation constraint in particular):

    forall (i in Y, k in K, g in G)
      CtFC: 
       sum(<i,j,l> in Slegs, t in T) X[<i,j,l>][k][g][t] - sum (<j,i,l> in Slegs, t in T) X[<j,i,l>][k][g][t]==b[i][k][g];

     

     I would appreciate if you could help me out to define the tuple, decision variable and the the set set of constraint written above as flow conservation constraints. 

     

    Regards,
    Bahman


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Tuple in JAVA API

    Posted 08/11/18 02:40 AM

    One way to implement this would be

    1. Represent your tuple as a class Sleg. This class would just have 3 public fields: i, j, l.
    2. Represent the set 'Slegs' as an array of instances of Slegs (maybe first collect into a List<> during creation and then use toArray())
    3. The dimension of the decision variable is then given by Slegs.length
    4. An index 0 <= k < Sleg.length gives to you things: the tuple Slegs[k] as well as the index to find the decision variable indexed by <i,j,l>.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Tuple in JAVA API

    Posted 08/13/18 04:23 PM

    Originally posted by: Bahman


    Thanks Daniel, 

     

    Which is better: to define a Map like this: <Integer, Slegs> map = new HashMap<Integer, Slegs>;  and use the Integer as the key to use for iteration. or .ToArray as you suggested above?

     

    class Sleg {
    public int i;
    public int j;
    public double l;
     
     
    List<Sleg> Slegs = new ArrayList<Sleg>();
    Object[] sL = Slegs.toArray();
     
    //Map <Integer, Sleg> slTup = new HashMap<Integer, Sleg>();
     
    int[][] u = new int [sL.length][G];
     
    }

    I would really appreciate if you could show me how I would instantiate the Sleg and add tuples into that like this: Slegs {<1,2,500>, <2,3,450>, <3,4,375>, <2,5,560>, <5,7,448>}

    int u[sL.Length][G]  = ... for instance: u[<1,2,500>][1] = 300; u[<1,2,500>][2] = 80; and etc.

     

    Regards
    Bahman


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Tuple in JAVA API

    Posted 08/14/18 12:55 AM

    Using a map is only useful if the index set is sparse (which in your case I think it is not), otherwise using an array (or a java.util.Vector) is more efficient.

    For the other question I am not sure I understand: are you asking how to instantiate a class in Java?


    #CPLEXOptimizers
    #DecisionOptimization