For a group of vehicles, specifies at what threshold(s) constraints
on visits will be relaxed and to which level. Shipments listed in
the skipped_shipment field are constrained to be skipped; i.e.,
they cannot be performed.
MutableSequence[int]
Specifies the vehicle indices to which the visit constraint
relaxations apply. If empty, this is considered the
default and the relaxations apply to all vehicles that
are not specified in other constraint_relaxations. There
can be at most one default, i.e., at most one constraint
relaxation field is allowed empty vehicle_indices. A
vehicle index can only be listed once, even within several
constraint_relaxations.
A vehicle index is mapped the same as
ShipmentRoute.vehicle_index,
if interpret_injected_solutions_using_labels is true
(see fields comment).
If relaxations is empty, the start time and sequence of all
visits on routes are fully constrained and no new visits may be
inserted or added to those routes. Also, a vehicle's start and end
time in routes is fully constrained, unless the vehicle is empty
(i.e., has no visits and has used_if_route_is_empty set to false
in the model).
relaxations(i).level specifies the constraint relaxation level
applied to a visit #j that satisfies:
route.visits(j).start_time >= relaxations(i).threshold_time
AND
j + 1 >= relaxations(i).threshold_visit_count
Similarly, the vehicle start is relaxed to relaxations(i).level
if it satisfies:
vehicle_start_time >= relaxations(i).threshold_time AND
relaxations(i).threshold_visit_count == 0 and the vehicle end
is relaxed to relaxations(i).level if it satisfies:
vehicle_end_time >= relaxations(i).threshold_time AND
To apply a relaxation level if a visit meets the
threshold_visit_count OR the threshold_time add two
relaxations with the same level: one with only
threshold_visit_count set and the other with only
threshold_time set. If a visit satisfies the conditions of
multiple relaxations, the most relaxed level applies. As a
result, from the vehicle start through the route visits in order to
the vehicle end, the relaxation level becomes more relaxed: i.e.,
the relaxation level is non-decreasing as the route progresses.
The timing and sequence of route visits that do not satisfy the
threshold conditions of any relaxations are fully constrained
and no visits may be inserted into these sequences. Also, if a
vehicle start or end does not satisfy the conditions of any
relaxation the time is fixed, unless the vehicle is empty.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[],[],null,["# Class ConstraintRelaxation (1.11.2)\n\nVersion latestkeyboard_arrow_down\n\n- [1.11.2 (latest)](/python/docs/reference/optimization/latest/google.cloud.optimization_v1.types.InjectedSolutionConstraint.ConstraintRelaxation)\n- [1.11.0](/python/docs/reference/optimization/1.11.0/google.cloud.optimization_v1.types.InjectedSolutionConstraint.ConstraintRelaxation)\n- [1.10.0](/python/docs/reference/optimization/1.10.0/google.cloud.optimization_v1.types.InjectedSolutionConstraint.ConstraintRelaxation)\n- [1.9.1](/python/docs/reference/optimization/1.9.1/google.cloud.optimization_v1.types.InjectedSolutionConstraint.ConstraintRelaxation)\n- [1.8.5](/python/docs/reference/optimization/1.8.5/google.cloud.optimization_v1.types.InjectedSolutionConstraint.ConstraintRelaxation)\n- [1.7.0](/python/docs/reference/optimization/1.7.0/google.cloud.optimization_v1.types.InjectedSolutionConstraint.ConstraintRelaxation)\n- [1.6.0](/python/docs/reference/optimization/1.6.0/google.cloud.optimization_v1.types.InjectedSolutionConstraint.ConstraintRelaxation)\n- [1.5.0](/python/docs/reference/optimization/1.5.0/google.cloud.optimization_v1.types.InjectedSolutionConstraint.ConstraintRelaxation)\n- [1.4.3](/python/docs/reference/optimization/1.4.3/google.cloud.optimization_v1.types.InjectedSolutionConstraint.ConstraintRelaxation)\n- [1.3.2](/python/docs/reference/optimization/1.3.2/google.cloud.optimization_v1.types.InjectedSolutionConstraint.ConstraintRelaxation)\n- [1.2.0](/python/docs/reference/optimization/1.2.0/google.cloud.optimization_v1.types.InjectedSolutionConstraint.ConstraintRelaxation)\n- [1.1.3](/python/docs/reference/optimization/1.1.3/google.cloud.optimization_v1.types.InjectedSolutionConstraint.ConstraintRelaxation)\n- [1.0.1](/python/docs/reference/optimization/1.0.1/google.cloud.optimization_v1.types.InjectedSolutionConstraint.ConstraintRelaxation)\n- [0.1.1](/python/docs/reference/optimization/0.1.1/google.cloud.optimization_v1.types.InjectedSolutionConstraint.ConstraintRelaxation) \n\n ConstraintRelaxation(mapping=None, *, ignore_unknown_fields=False, **kwargs)\n\nFor a group of vehicles, specifies at what threshold(s) constraints\non visits will be relaxed and to which level. Shipments listed in\nthe `skipped_shipment` field are constrained to be skipped; i.e.,\nthey cannot be performed.\n\nClasses\n-------\n\n### Relaxation\n\n Relaxation(mapping=None, *, ignore_unknown_fields=False, **kwargs)\n\nIf `relaxations` is empty, the start time and sequence of all\nvisits on `routes` are fully constrained and no new visits may be\ninserted or added to those routes. Also, a vehicle's start and end\ntime in `routes` is fully constrained, unless the vehicle is empty\n(i.e., has no visits and has `used_if_route_is_empty` set to false\nin the model).\n\n`relaxations(i).level` specifies the constraint relaxation level\napplied to a visit #j that satisfies:\n\n- `route.visits(j).start_time \u003e= relaxations(i).threshold_time` AND\n- `j + 1 \u003e= relaxations(i).threshold_visit_count`\n\nSimilarly, the vehicle start is relaxed to `relaxations(i).level`\nif it satisfies:\n\n- `vehicle_start_time \u003e= relaxations(i).threshold_time` AND\n- `relaxations(i).threshold_visit_count == 0` and the vehicle end is relaxed to `relaxations(i).level` if it satisfies:\n- `vehicle_end_time \u003e= relaxations(i).threshold_time` AND\n- `route.visits_size() + 1 \u003e= relaxations(i).threshold_visit_count`\n\nTo apply a relaxation level if a visit meets the\n`threshold_visit_count` OR the `threshold_time` add two\n`relaxations` with the same `level`: one with only\n`threshold_visit_count` set and the other with only\n`threshold_time` set. If a visit satisfies the conditions of\nmultiple `relaxations`, the most relaxed level applies. As a\nresult, from the vehicle start through the route visits in order to\nthe vehicle end, the relaxation level becomes more relaxed: i.e.,\nthe relaxation level is non-decreasing as the route progresses.\n\nThe timing and sequence of route visits that do not satisfy the\nthreshold conditions of any `relaxations` are fully constrained\nand no visits may be inserted into these sequences. Also, if a\nvehicle start or end does not satisfy the conditions of any\nrelaxation the time is fixed, unless the vehicle is empty."]]