timeDimStart = duration_dimension.CumulVar(routing.Start(v))
timeDimEnd = duration_dimension.CumulVar(routing.End(v))
solver.Add(timeDimEnd <= timeDimStart + shift_time + max_overtime)
But how can we add a penalty (soft constraint) when
timeDimEnd - timeDimStart >= shift_time ??
Basically we want to add to the objective something like:
(timeDimEnd - timeDimStart - shift_time if timeDimEnd - timeDimStart >= shift_time else 0)*penalty
Is that possible ?
Thank you
--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/68ed4eb5-3e66-4c1f-9c0a-882f86007e41n%40googlegroups.com.
shift_duration = 'Shift_duration'
routing.AddDimension(
shift_duration_callback_index,
infinity,
infinity,
True,
shift_duration)
shift_duration_dimension = routing.GetDimensionOrDie(shift_duration)
for v in range(num_vehicles):
timeDimStart = duration_dimension.CumulVar(routing.Start(v))
timeDimEnd = duration_dimension.CumulVar(routing.End(v))
shiftDuration = shift_duration_dimension.CumulVar(routing.End(v))
solver.Add(shiftDuration == timeDimEnd-timeDimStart)
shift_duration_dimension.SetCumulVarSoftUpperBound(
routing.End(v),
shift_time_soft_upper_bound(v),
overtime_cost(v)
)
Thanks for sharing that clever hack.
One concern I have is that the route cost will slowly increase
without
bound. Cutting and pasting from your code:
{.quotesubsequent}route_start = distance_dimension.CumulVar(pickup_index) route_end = distance_dimension.CumulVar(delivery_index) route_cost = route_cost_dimension.CumulVar(delivery_index) solver.Add(route_cost == route_end - route_start) route_cost_dimension.SetCumulVarSoftUpperBound( delivery_index, request.max_route_length, detour_cost )
So the second pickup and delivery by a vehicle, the
route_cost_dimension must necessarily be greater than the
first, as
the slack is only positive. So there is no way at the second
delivery
node that the route cost will actually be
route_end - route_start,
correct?
I know the soft bound will ignore this detail and do its best, but
it
seems only the first trip will really be aiming for the max route
length, whereas every future trip will be max route length less
any
overage from prior trips (as the dimension will continue to
increase)
I was thinking that perhaps it would be cleaner for those 2nd,
3rd,
etc dropoffs if the route cost dimension could somehow reset at
delivery nodes. A priori you know both the shortest distance from
pickup to delivery and the acceptable overage, so each delivery
node
could subtract one or both quantities (leveraging the
(undocumented)
fact that dimensions have a hard floor at zero). Then the soft
bound
could be that the route cost dimension is zero at the end of the
route, so that the net extra time is minimized.
But again, nice hack
James
>= shift_time else 0)penalty *Is that possible ?
Thank you
--
You received this message because you are subscribed to the Google
Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/or-tools-discuss/68ed4eb5-3e66-4c1f-9c0a-882f86007e41n%40googlegroups.com
--
You received this message because you are subscribed to the Google Groups "or-tools-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to or-tools-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/or-tools-discuss/4b85fc35-a81e-48ac-aa76-9abcb1b7b0f3n%40googlegroups.com.
James E. Marca
Activimetrics LLC
shift_duration = 'Shift_duration'
routing.AddConstantDimensionWithSlack(
0,
infinity, # attention order changed, this is maximum cumul
infinity, # maximum slack
True,
shift_duration)
shift_duration_dimension = routing.GetDimensionOrDie(shift_duration)
for v in range(num_vehicles):
timeDimStart = duration_dimension.CumulVar(routing.Start(v))
timeDimEnd = duration_dimension.CumulVar(routing.End(v))
shiftDuration = shift_duration_dimension.CumulVar(routing.End(v))
solver.Add(shiftDuration == timeDimEnd-timeDimStart)
shift_duration_dimension.SetCumulVarSoftUpperBound(
routing.End(v),
shift_time_soft_upper_bound(v),
overtime_cost(v)
)