Decision Optimization

 View Only
Expand all | Collapse all

Cplex allowed_assignments behavior

  • 1.  Cplex allowed_assignments behavior

    Posted Wed January 04, 2023 09:33 AM
    Hi,

    I've been using CPLEX with Python 3.7, and I have tried to do the following example:

    x_var = integer_var(min=0, max=3, name="x")
    model = CpoModel(name="MyModel")
    
    model.add(modeler.allowed_assignments(x_var, [0]))
    model.add(modeler.allowed_assignments(x_var, [1]))
    
    params = CpoParameters(
        RandomSeed=0,
        SearchType="MultiPoint",
        LogVerbosity="Quiet",
        WarningLevel=3,
    )
    solver = CpoSolver(model, params=params)
    solve_result = solver.solve()
    
    x_sol = solve_result[x_var]
    
    print(x_sol)  # prints two​

    The code above outputs two, even that there are two constraints that specify that allowed assignments are "0" and "1".

    Using the following three constraints does not change the output:
    model.add(modeler.allowed_assignments(x_var, [0]))
    model.add(modeler.allowed_assignments(x_var, [1]))
    model.add(modeler.equal(x_var, 2))​

    But when removing one of the allowed_assignments I get an error
    model.add(modeler.allowed_assignments(x_var, [0]))
    model.add(modeler.equal(x_var, 2))



    I thought that in the first example, adding two allowed assignments on the same expression with different values would make cplex fail, can someone explain to me the behavior of allowed_assigments? can it be used multiple times on the same variable?

    ------------------------------
    Waad Nakhleh
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Cplex allowed_assignments behavior

    Posted Thu January 05, 2023 01:28 PM
    Hello,
    If I remember well, there was a related bug in a previous version of the Python interface that did not interpret correctly the unary allowed_assignments constraint.
    I just checked that it works correctly in the last versions of CP Optimizer and DoCplex. So you need to update your version.

    As for the expected behavior of the unary allowed_assignments constraint: sure you can have several for the same variable, each one restricts the possible values for the variable, then it amounts to take the intersection of all the specified sets of values. So, in your case with two allowed_assignments constraints specifying two sets of size one that do not intersect, a no solution answer is expected.


    ------------------------------
    Olivier Lhomme
    ------------------------------