OR-Tools  8.2
TypeRegulationsConstraint

Detailed Description

The following constraint ensures that incompatibilities and requirements between types are respected.

It verifies both "hard" and "temporal" incompatibilities. Two nodes with hard incompatible types cannot be served by the same vehicle at all, while with a temporal incompatibility they can't be on the same route at the same time. The VisitTypePolicy of a node determines how visiting it impacts the type count on the route.

For example, for

  • three temporally incompatible types T1 T2 and T3
  • 2 pairs of nodes a1/r1 and a2/r2 of type T1 and T2 respectively, with
    • a1 and a2 of VisitTypePolicy TYPE_ADDED_TO_VEHICLE
    • r1 and r2 of policy ADDED_TYPE_REMOVED_FROM_VEHICLE
  • 3 nodes A, UV and AR of type T3, respectively with type policies TYPE_ADDED_TO_VEHICLE, TYPE_ON_VEHICLE_UP_TO_VISIT and TYPE_SIMULTANEOUSLY_ADDED_AND_REMOVED the configurations UV --> a1 --> r1 --> a2 --> r2, a1 --> r1 --> a2 --> r2 --> A and a1 --> r1 --> AR --> a2 --> r2 are acceptable, whereas the configurations a1 --> a2 --> r1 --> ..., or A --> a1 --> r1 --> ..., or a1 --> r1 --> UV --> ... are not feasible.

It also verifies same-vehicle and temporal type requirements. A node of type T_d with a same-vehicle requirement for type T_r needs to be served by the same vehicle as a node of type T_r. Temporal requirements, on the other hand, can take effect either when the dependent type is being added to the route or when it's removed from it, which is determined by the dependent node's VisitTypePolicy. In the above example:

  • If T3 is required on the same vehicle as T1, A, AR or UV must be on the same vehicle as a1.
  • If T2 is required when adding T1, a2 must be visited before a1, and if r2 is also visited on the route, it must be after a1, i.e. T2 must be on the vehicle when a1 is visited: ... --> a2 --> ... --> a1 --> ... --> r2 --> ...
  • If T3 is required when removing T1, T3 needs to be on the vehicle when r1 is visited: ... --> A --> ... --> r1 --> ... OR ... --> r1 --> ... --> UV --> ...

Definition at line 2300 of file routing.h.

Public Member Functions

 TypeRegulationsConstraint (const RoutingModel &model)
 
void Post () override
 This method is called when the constraint is processed by the solver. More...
 
void InitialPropagate () override
 This method performs the initial propagation of the constraint. More...
 
std::string DebugString () const override
 
void PostAndPropagate ()
 Calls Post and then Propagate to initialize the constraints. More...
 
virtual void Accept (ModelVisitor *const visitor) const
 Accepts the given visitor. More...
 
bool IsCastConstraint () const
 Is the constraint created by a cast from expression to integer variable? More...
 
virtual IntVarVar ()
 Creates a Boolean variable representing the status of the constraint (false = constraint is violated, true = constraint is satisfied). More...
 
Solversolver () const
 
void FreezeQueue ()
 This method freezes the propagation queue. More...
 
void UnfreezeQueue ()
 This method unfreezes the propagation queue. More...
 
void EnqueueDelayedDemon (Demon *const d)
 This method pushes the demon onto the propagation queue. More...
 
void EnqueueVar (Demon *const d)
 
void ExecuteAll (const SimpleRevFIFO< Demon * > &demons)
 
void EnqueueAll (const SimpleRevFIFO< Demon * > &demons)
 
void set_action_on_fail (Solver::Action a)
 
void reset_action_on_fail ()
 This method clears the failure callback. More...
 
void set_variable_to_clean_on_fail (IntVar *v)
 Shortcut for variable cleaner. More...
 
virtual std::string name () const
 Object naming. More...
 
void set_name (const std::string &name)
 
bool HasName () const
 Returns whether the object has been named or not. More...
 
virtual std::string BaseName () const
 Returns a base name for automatic naming. More...
 

Constructor & Destructor Documentation

◆ TypeRegulationsConstraint()

TypeRegulationsConstraint ( const RoutingModel model)
explicit

Definition at line 6417 of file routing.cc.

Member Function Documentation

◆ Accept()

void Accept ( ModelVisitor *const  visitor) const
virtualinherited

Accepts the given visitor.

Reimplemented in Pack, and IfThenElseCt.

Definition at line 3247 of file constraint_solver.cc.

◆ BaseName()

std::string BaseName ( ) const
virtualinherited

Returns a base name for automatic naming.

Reimplemented in BooleanVar.

Definition at line 2515 of file constraint_solver.cc.

◆ DebugString()

std::string DebugString ( ) const
overridevirtualinherited

Reimplemented from PropagationBaseObject.

Reimplemented in Pack, IfThenElseCt, and GlobalVehicleBreaksConstraint.

Definition at line 3237 of file constraint_solver.cc.

◆ EnqueueAll()

void EnqueueAll ( const SimpleRevFIFO< Demon * > &  demons)
inherited

Definition at line 2521 of file constraint_solver.cc.

◆ EnqueueDelayedDemon()

void EnqueueDelayedDemon ( Demon *const  d)
inlineinherited

This method pushes the demon onto the propagation queue.

It will be processed directly if the queue is empty. It will be enqueued according to its priority otherwise.

Definition at line 3192 of file constraint_solver.h.

◆ EnqueueVar()

void EnqueueVar ( Demon *const  d)
inlineinherited

Definition at line 3193 of file constraint_solver.h.

◆ ExecuteAll()

void ExecuteAll ( const SimpleRevFIFO< Demon * > &  demons)
inherited

Definition at line 2517 of file constraint_solver.cc.

◆ FreezeQueue()

void FreezeQueue ( )
inlineinherited

This method freezes the propagation queue.

It is useful when you need to apply multiple modifications at once.

Definition at line 3183 of file constraint_solver.h.

◆ HasName()

bool HasName ( ) const
inherited

Returns whether the object has been named or not.

Definition at line 2513 of file constraint_solver.cc.

◆ InitialPropagate()

void InitialPropagate ( )
overridevirtual

This method performs the initial propagation of the constraint.

It is called just after the post.

Implements Constraint.

Definition at line 6465 of file routing.cc.

◆ IsCastConstraint()

bool IsCastConstraint ( ) const
inherited

Is the constraint created by a cast from expression to integer variable?

Definition at line 3253 of file constraint_solver.cc.

◆ name()

std::string name ( ) const
virtualinherited

Object naming.

Reimplemented in PiecewiseLinearExpr.

Definition at line 2505 of file constraint_solver.cc.

◆ Post()

void Post ( )
overridevirtual

This method is called when the constraint is processed by the solver.

Its main usage is to attach demons to variables.

Implements Constraint.

Definition at line 6450 of file routing.cc.

◆ PostAndPropagate()

void PostAndPropagate ( )
inherited

Calls Post and then Propagate to initialize the constraints.

This is usually done in the root node.

Definition at line 3239 of file constraint_solver.cc.

◆ reset_action_on_fail()

void reset_action_on_fail ( )
inlineinherited

This method clears the failure callback.

Definition at line 3206 of file constraint_solver.h.

◆ set_action_on_fail()

void set_action_on_fail ( Solver::Action  a)
inlineinherited

Definition at line 3200 of file constraint_solver.h.

◆ set_name()

void set_name ( const std::string &  name)
inherited

Definition at line 2509 of file constraint_solver.cc.

◆ set_variable_to_clean_on_fail()

void set_variable_to_clean_on_fail ( IntVar v)
inlineinherited

Shortcut for variable cleaner.

Definition at line 3209 of file constraint_solver.h.

◆ solver()

Solver * solver ( ) const
inlineinherited

Definition at line 3179 of file constraint_solver.h.

◆ UnfreezeQueue()

void UnfreezeQueue ( )
inlineinherited

This method unfreezes the propagation queue.

All modifications that happened when the queue was frozen will be processed.

Definition at line 3187 of file constraint_solver.h.

◆ Var()

IntVar * Var ( )
virtualinherited

Creates a Boolean variable representing the status of the constraint (false = constraint is violated, true = constraint is satisfied).

It returns nullptr if the constraint does not support this API.

Definition at line 3257 of file constraint_solver.cc.


The documentation for this class was generated from the following files: