Decision Optimization

Decision Optimization

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

 View Only
  • 1.  CP Optimizer multidimensional element operation

    Posted Wed April 26, 2023 12:24 PM

    I'm using the Java API to CP Optimizer. If I want to use an integer variable as an index to a 1-D variable array (IloIntVar[]), IloCP.element() works fine. My question is whether there is an "elegant" method to use two IloIntVar instances to index a 2-D variable array (IloIntVar[][]). Trying to do this with two applications of element() does not work. I was hoping that calling element() with an IloIntVar[][] argument would return one row of the matrix (IloIntVar[]), but it throws an error.

    The inelegant solution is to flatten the 2-D matrix to a 1-D matrix by doing arithmetic on the indices (converting (i, j) to a single index k), but that makes the code both a bit hard to read and a bit prone to programmer error. Is there a better approach?

    Thanks,
    Paul



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


  • 2.  RE: CP Optimizer multidimensional element operation

    Posted Thu April 27, 2023 06:18 AM

    There is no direct way to model an element over a 2-D array of variables (or values), you have to flatten the array and index it with n*x + y.

    In the case you have a 2-D array of values the domain reduction of n*x + y is an approximation on bounds (as for most linear constraints in CP Optimizer). It can be beneficial to add a strong constraint over the indexes

    strong([x, y])

    At presolve, this will enumerate all combinations of values for x and y and create an allowedAssignments constraint over x, y, and any variable that is fixed by fixing x and y. On flattened n-dimensional element constraints over values this provides a perfect domain reduction in most cases.

    Using a strong for 2-D array of variables can give more domain reductions as well if there are implied fixed variables when x and y are fixed. It depends on the model. 

    Philippe


    ------------------------------
    Philippe Refalo
    IBM ILOG CP Optimizer
    ------------------------------



  • 3.  RE: CP Optimizer multidimensional element operation

    Posted Thu April 27, 2023 11:48 AM

    Thanks Philippe. I was not aware of the strong constraint.

    Paul



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