Decision Optimization

 View Only
Expand all | Collapse all

allDifferent constraint for optional interval variables

  • 1.  allDifferent constraint for optional interval variables

    Posted Wed September 07, 2022 10:59 AM
    Hey everyone,

    I'm currently developing a scheduling model with docplex.cp (Python) where I need to schedule multiple tasks in two machines.

    I need to use an allDifferent constraint to ensure that the starting time of certain tasks are different from others, which means I'm using a constraint similar to this one:

    for m in M:
    mdl.add_constraint(all_diff([start_of(opttask[j,m]) for j in J]))

    The problem is that the variable opttask is optional. This means that in the case of two tasks being assigned to the same machine (e.g., opttask[1,1] and opttask[2,1]), the interval variables associated with those two tasks will not exist in the other machine (e.g., opttask[1,2] and opttask[2,2]). Due to this situation, the constraint above does not work because the results for start_of(opttask[1,2]) and start_of(opttask[2,2]) are the same.

    Is there any way to create an exception for this kind of constraint when the interval variables don't exist? Let me know if I wasn't clear enough and I can try to explain better.

    Thank you in advance,
    Paulo

    ------------------------------
    Paulo Nascimento
    ------------------------------

    #DecisionOptimization


  • 2.  RE: allDifferent constraint for optional interval variables

    Posted Wed September 07, 2022 12:29 PM
    Hi Paulo,
    The `start_of` function takes an optional argument: `absentValue` (`docplex.cp.modeler.start_of(interval, absentValue=None)`).
    So, one could assign a different negative `absentValue` for each `opttask` (since starttime is always positive, there should be no collision between present intervals starttime and these negative `absentValues`).
    This is not very elegant, but this trick should do what you want.

    Best regards,

    Hugues

    ------------------------------
    Hugues Juille
    ------------------------------