Adding a hard and soft upper bound constraint of number of locations to visit (VRP)

I went through the Vehicle Routing Problem example and was able to replicate it. On the example, there is a constraint added for vehicle maximum distance as shown below:

dimension_name = 'Distance'
transit_callback_index,
0,  # no slack
3000,  # vehicle maximum travel distance
True,  # start cumul to zero
dimension_name)
distance_dimension = routing.GetDimensionOrDie(dimension_name)
distance_dimension.SetGlobalSpanCostCoefficient(100)


Similar to the CVRP, how do I modify the constraint for the number of locations that each vehicle can visit (either global or by each vehicle) rather than the demand?

The idea is to create another dimension ('visit') that is incremented by 1 on each visit. Then use SetCumulVarSoftUpperBound on the cumul variable of that dimension at the end of each route.