Given the following formula

with the table below encode the relationship of `x_0`, `x_1` and `r` for Objective 2':

For objective 2, we can code it as following with Docplex, where we have either 0 or 1 for priority `p`.
CPriorityInFreight = mdl.binary_var_matrix(catPriorities, freights, name='CPriorityInFreight')
FreightMixture = mdl.binary_var_dict(freights, name='FreightMixture')
for p in catPriorities:
for f in freights:
# CPriorityInFreight[c, f] = 1 <-> priority c is in freight f
CPriorityInFreight[p, f] = (
1 <= mdl.sum(Assignment[o, f] for o in orders if get_order(o).CategoryPriority == p))
for f in freights:
# sums == 2 <-> we have both cat 0 and cat 1
FreightMixture[f] = (2 == mdl.sum(CPriorityInFreight[c, f] for c in catPriorities))
o2 = mdl.sum(FreightMixture[f] for f in freights)
In Objective 2', we now have the following code for decision variable declaration (with `FreightMixture` containing value `0,1,2`) and first formula
CPriorityInFreight = mdl.binary_var_matrix(catPriorities, freights, name='CPriorityInFreight')
FreightMixture = mdl.integer_var_dict(freights, name='FreightMixture')
for p in catPriorities:
for f in freights:
# CPriorityInFreight[c, f] = 1 <-> priority c is in freight f
CPriorityInFreight[p, f] = (
1 <= mdl.sum(Assignment[o, f] for o in orders if get_order(o).CategoryPriority == p))
But how do we translate these relationship on second formula of Objective 2' into Docplex?
(Of course if there are simpler way to achieve semantically equivalent formulas with Objective 2', feel free to suggest)
#DecisionOptimization