Decision Optimization

 View Only
  • 1.  CPO: Fixing an integer variable

    IBM Champion
    Posted Tue June 21, 2022 04:15 PM
    I have a CP Optimizer model (coded in Java) with integer variable vector `x`. Some entries in `x` are fixed in the problem. The following seemingly redundant code works when I create variable `x[i]` (where `j` is its required value).
    x[i] = cp.intVar(j, j, "x_" + i);
    cp.add(cp.eq(x[i], j));
    ​

    If I comment out the second line, however, the solver takes the liberty of setting `x[i]` to something other than `j`. (Specifically, in at least one instance `j` is 1 and the variable is assigned the value 4.) According to the documentation for `IloModeler.intVar()`, the first two arguments are bounds on the variable. Am I missing something, or is this a bug?



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


  • 2.  RE: CPO: Fixing an integer variable

    Posted Wed June 22, 2022 08:34 AM

    Hello Paul,

    I did not manage to reproduce this with any small code.

    You use cp.exportModel to dump your model and check that nothing unexpected is happening before CP Optimizer gets to see your model.

    Another thought is that x[i] is overwritten with another variable in your program and then you pick up the value of the wrong variable after the solve.

    Please let me know how you get on.

    Regards,

    Paul



    ------------------------------
    Paul Shaw
    ------------------------------



  • 3.  RE: CPO: Fixing an integer variable

    Posted Wed June 22, 2022 09:18 AM
    Hello

    What if you do cp.add(x[i]) ?Maybe in the absence of any constraint on x, cp presolve could remove the variable 

    David

    ------------------------------
    David Gravot
    ------------------------------



  • 4.  RE: CPO: Fixing an integer variable

    IBM Champion
    Posted Wed June 22, 2022 11:37 AM
    Paul and David: Thanks for the tips. It turns out that while x[i] was not being overwritten, it's upper bound was (incorrectly) changed later in the code. So the bug was mine.

    Paul

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