'OR Tools - force visits to specific nodes

I'm using or-tools with a VRP and adding a time constraint that allows dropped nodes

(basically limiting the trip duration to 8 hours)

But I'm struggling to include particular nodes that HAVE to be visited.

What I'm attempting is to lower the penalty for nodes where a visit is required, but this seems to have no effect.

Is there another way round this problem?

# nodes that have to be visited
mandatory = [True, False, False, False , False, True ]

# Allow to drop nodes.
penalties = [99999 if x is False else 0 for x in mandatory]

for node in range(1, len(data['distance_matrix'])):
    routing.AddDisjunction([manager.NodeToIndex(node)], penalties[node-1])


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source