Skip to content

Every second weekend free

Rewards if an employee has every second weekend (Sat, Sun) free.

Feature Request

In the final presentation of our project another implemenation of Free Days Near Weekend was requested. This is our new, complementary objective, but there is room for improvement. More details can be found in this open issue.

Implemented using Google's OR Tools

src/cp/objectives/every_second_weekend_free.py
# Penalty = 1 if (w1_free AND w2_free) OR (NOT w1_free AND NOT w2_free)
model.add(same_status_penalty == 1).only_enforce_if([w1_free, w2_free])
model.add(same_status_penalty == 1).only_enforce_if(
    [w1_free.Not(), w2_free.Not()]
)
model.add(same_status_penalty == 0).only_enforce_if(
    [w1_free, w2_free.Not()]
)
model.add(same_status_penalty == 0).only_enforce_if(
    [w1_free.Not(), w2_free]
)

penalties.append(same_status_penalty)

Our application will iterate through every pair of consective weekends. If both weekends have the same status, meaning both are free or both are assigned, it gets a penalty. That way we encourage weekends with different status, enforcing a alternating behaviour, if possible.