Please try to use
void RoutingDimension::SetCumulVarSoftUpperBound(
int64_t index,
int64_t upper_bound,
int64_t coefficient);
ref: https://github.com/google/or-tools/blob/f460e9b0fcd444c37878ec64be9822d40fb375f4/ortools/constraint_solver/routing.h#L2905-L2914
and/or
void RoutingDimension::SetCumulVarSoftLowerBound(
int64_t index,
int64_t upper_bound,
int64_t coefficient);
ref: https://github.com/google/or-tools/blob/f460e9b0fcd444c37878ec64be9822d40fb375f4/ortools/constraint_solver/routing.h#L2927-L2937
note: Supposing you have
0 ---- [min_hard -- [min_soft --- max_soft] -- max_hard] --- vehicle_capacity
You could use (in Python)
index = manager.NodeToIndex(42)
time_dimension = routing.GetDimensionOrDie('Time')
time_dimension.CumulVar(index).SetRange(min_hard, max_hard)
penalty = 100
time_dimension.SetCumulVarSoftLowerBound(index, min_soft, penalty)
time_dimension.SetCumulVarSoftUpperBound(index, max_soft, penalty)
if vehicle visit index
at max_soft + k
then the objective will have k * penalty
extra cost.