Reputation: 45
as the title indicates, when incorporating time window, vehicle constraints for nodes, in some scenarios the constraints are too strict and I am unable to produce an output.
How can I make the constraints optional or soft but reflect that in a cost (utility) function, so I can rank my solutions?
Used combinations of constraints to solve the VRPTW but it turned out to be unsolvable, how to make it solvable but reflect the degree to which I am violating the constraints?
Upvotes: 3
Views: 350
Reputation: 9291
Please try to use
void RoutingDimension::SetCumulVarSoftUpperBound(
int64_t index,
int64_t upper_bound,
int64_t coefficient);
and/or
void RoutingDimension::SetCumulVarSoftLowerBound(
int64_t index,
int64_t upper_bound,
int64_t coefficient);
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.
Upvotes: 3