Advanced Constraints
Beyond basic routing constraints, the VRP solver supports sophisticated business rules for compliance, safety, and operational requirements. This guide covers advanced constraints including driving limits, tag matching, vehicle restrictions, and adherence penalties.Drive Time Constraints
Maximum Continuous Drive Time
Enforce legal or safety limits on continuous driving:Maximum seconds of continuous driving before a break is required
Legal Compliance: Many jurisdictions have mandatory driving time limits. Examples:
- EU: 4.5 hours continuous driving max
- US DOT: Complex hours-of-service rules
- Always verify local regulations
Drive Time Ordering
Ensure jobs are visited in chronological order based on actual drive times:Drive Time Ordering prevents the solver from scheduling later appointments before earlier ones on the same route, even if it might be more efficient.
Tag-Based Constraints
Hard Tag Matching
Enforce strict requirements for skills, certifications, or equipment:Soft Tag Preferences
Create preferences without hard requirements:Tag Matching Rules
1
Hard Tags Must Match
Job with hard tag → Resource must have same hard tag
2
Soft Tags Create Preference
Mismatched soft tags incur penalties based on weight
3
Resource Tags Don't Restrict
Resources can have tags that jobs don’t require
4
Weight Calculation
Penalty = tagWeight × tagViolationWeight × mismatchCount
Vehicle Restrictions
Disallowed Vehicles
Explicitly prevent certain resources from servicing specific jobs:Restriction Priority:
disallowedResources
- Never assign these (hard constraint)allowedResources
- Only assign from this list (hard constraint)preferredResources
- Try these first (soft constraint)
Complex Restriction Example
Overtime Constraints
Overtime Penalties
Configure penalties for work beyond regular hours:Overtime Behavior
Planning Adherence
Maintaining Planned Schedules
Penalize deviations from existing plans:Adherence Calculation
Planned Arrival Penalty = |actual_arrival - planned_arrival| × plannedWeightResource Change Penalty = (resource_changed ? 1 : 0) × plannedResourceWeight
Use Cases for Planning Adherence
Customer Communications
Customer Communications
When customers have been notified of arrival times, minimize changes to maintain trust.
Incremental Optimization
Incremental Optimization
Re-optimize routes while keeping most assignments stable.
Partial Replanning
Partial Replanning
Add new jobs while minimizing disruption to existing schedule.
Constraint Interactions
Constraint Priority Hierarchy
1
Hard Constraints (Absolute)
- Time windows (hard)
- Capacity limits
- Disallowed resources
- Hard tags
- Shift boundaries (without overtime)
2
Soft Constraints (Weighted)
- Soft time windows
- Overtime penalties
- Tag preferences
- Planning adherence
- Preferred resources
3
Optimization Objectives
- Minimize total cost
- Minimize travel time
- Balance workload
- Maximize urgency satisfaction
Complex Constraint Example
Performance Considerations
Constraint Complexity Impact:Low Impact:
- Basic tag matching
- Disallowed resources
- Simple overtime penalties
- Many soft constraints
- Complex tag hierarchies
- Planning adherence with many jobs
- Drive time ordering
- Many overlapping soft constraints
- Complex overtime structures
Optimization Tips
- Use Hard Constraints Sparingly: Each hard constraint reduces solution space
- Balance Weights: Keep soft constraint weights in reasonable ratios
- Test Incrementally: Add constraints one at a time to identify conflicts
- Monitor Infeasibility: Too many constraints can make problems unsolvable
Troubleshooting
Common Issues
Jobs Not Assigned Due to Constraints
Jobs Not Assigned Due to Constraints
Symptoms: High unassigned job countCheck:
- Tag requirements vs available resources
- Disallowed resource lists
- Time window compatibility
- Capacity constraints
- Review tag assignments
- Verify resource capabilities
- Consider soft constraints instead of hard
- Enable partial planning
Unexpected Constraint Violations
Unexpected Constraint Violations
Symptoms: Soft constraints violated despite high weightsCheck:
- Competing constraint weights
- Hard constraint conflicts
- Resource availability
- Increase specific constraint weights
- Review weight ratios
- Check for conflicting requirements
- Add more resources
Poor Solution Quality
Poor Solution Quality
Symptoms: Valid but inefficient routesCheck:
- Too many hard constraints
- Conflicting soft constraints
- Insufficient optimization time
- Convert some hard constraints to soft
- Adjust weight balance
- Increase solve time limit
- Simplify constraint model
Debugging Constraints
Use the explanation endpoint to understand constraint impacts:- Active constraints for each assignment
- Constraint violations and penalties
- Why certain assignments weren’t made
Best Practices
1
Start Simple
Begin with essential constraints only:
- Basic time windows
- Required capacities
- Critical tags
2
Add Incrementally
Layer in advanced constraints:
- Soft preferences
- Overtime rules
- Planning adherence
3
Monitor Impact
Track key metrics:
- Constraint violation counts
- Solution quality scores
- Computation time
- Unassigned job reasons
4
Document Rules
Maintain clear documentation:
- Business reason for each constraint
- Weight selection rationale
- Expected behavior
- Fallback strategies