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
------------------------------