Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Tuple Index in Java & CPLEX Concert

    Posted Thu June 03, 2021 12:23 PM
    Hello,

    I am currently migrating the optimization model from CPLEX OPL to CPLEX Concert Technology + Java.

    In Java, I would like to define the decision variables based on tuple structure. Would you please help me how to define it?

    For example, I have a decision variable in OPL as below.

    tuple INDEX{
          int employeeID;
          int offeringID;
    }
    {INDEX} indexes {<e, o> | e in employees, o in offerings}
    dvar int+ schedule [indexes] in 0..1;


    In order to define the decision variable (X) in Java, I first defined class data structure.
    class INDEX{
           int employeeID;
           int offeringID;
    }
    List<INDEX> indexes = new ArrayList<INDEX>();

    IloNumVar[] schedule = cplex.numVarArray(indexes.size(), 0, 1, IloNumVarType.Int);

    I would like to have the constraint ( cplex.addEQ(cplex.sum(schedule[indexes]), 1) ), sum of schedule over indexes has to be equal to 1.

    The above cplex.addEQ function does not work. Would you please help me how to defined tuple-based decision variables and constraints in Java?

    Thank you for your help!

    ------------------------------
    Sung Hwang
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Tuple Index in Java & CPLEX Concert

    Posted Thu June 03, 2021 03:20 PM
    If you are summing overall index values, you can just use cplex.sum(schedule). If you are summing only for certain indices, you probably will want to use a loop.

    IloLinearNumExpr expr = cplex.linearNumExpr();
    for (int i = 0; i < indexes.size(); i++) {
      if (...) {
        expr.addTerm(1.0, schedule[i]);
      }
    }
    cplex.addEq(expr, 1.0);

    where ... is a logical test to determine if the index is included in the summation.

    As a side note, to facilitate moving between the integer index of schedule[] and your INDEX tuples, you might want to use either a Map<INDEX, Integer> or a Map<INDEX, IloNumVar> (and maybe a Map<IloNumVar, INDEX> in the opposite direction).

    ------------------------------
    Paul Rubin
    Professor Emeritus
    Michigan State University
    ------------------------------



  • 3.  RE: Tuple Index in Java & CPLEX Concert

    Posted Thu June 03, 2021 04:02 PM
    So I can't define a decision variable using tuple (class structure data) in Java.

    Thank you Dr. Rubin for your comment!


    ------------------------------
    Sung Hwang
    ------------------------------