Overview

Period rules enable you to set operational constraints that apply across all shifts for a resource. These rules ensure compliance with regulations, safety requirements, and operational policies by limiting or requiring specific work patterns.

Period rules are particularly useful for implementing driver regulations, union agreements, and safety policies that span multiple shifts.

Available Rule Types

Drive Time Rules

Control the amount of time resources spend driving:

maxDriveTime
integer

Maximum driving time in seconds allowed during the period

minDriveTime
integer

Minimum driving time in seconds required during the period

Work Time Rules

Manage total working hours:

maxWorkTime
integer

Maximum total work time in seconds (includes driving and service time)

minWorkTime
integer

Minimum total work time in seconds required

Use minimum drive time rules cautiously. They may force the solver to create longer routes than necessary to meet the minimum requirement.

Implementation Example

This example demonstrates how a maximum drive time rule affects route planning:

{
  "resources": [
    {
      "name": "R-1",
      "start": {
        "latitude": 50.923554431590595,
        "longitude": 4.890691212789399
      },
      "shifts": [
        {
          "from": "2023-01-13T08:00:00",
          "to": "2023-01-13T22:00:00"
        }
      ],
      "rules": [
        {
          "maxDriveTime": 10000  // ~2.78 hours max driving
        }
      ]
    }
  ],
  "jobs": [
    {
      "name": "JOB-1",
      "location": {
        "latitude": 50.54963315022148,
        "longitude": 4.848855475505483
      },
      "duration": 3600
    },
    {
      "name": "JOB-2",
      "location": {
        "latitude": 50.65910297910443600,
        "longitude": 4.007987934186738
      },
      "duration": 3600
    },
    // Jobs 3-10 with various locations...
  ],
  "options": {
    "partialPlanning": true
  }
}

Common Rule Patterns

Standard Driver Regulations

European driving regulations:

{
  "rules": [
    {
      "maxDriveTime": 32400,    // 9 hours daily driving
      "maxWorkTime": 50400       // 14 hours total work
    }
  ]
}

Minimum Utilization Requirements

Ensure resources meet minimum productivity:

{
  "rules": [
    {
      "minWorkTime": 21600,      // Minimum 6 hours work
      "maxWorkTime": 36000       // Maximum 10 hours work
    }
  ]
}

Combined Rules

Multiple rules work together:

{
  "rules": [
    {
      "maxDriveTime": 25200,     // Max 7 hours driving
      "minDriveTime": 7200,      // Min 2 hours driving
      "maxWorkTime": 36000,      // Max 10 hours total
      "minWorkTime": 14400       // Min 4 hours total
    }
  ]
}

Rule Scope and Application

Period Definition

Rules apply to the entire planning period, not individual shifts:

{
  "shifts": [
    {"from": "2023-01-13T08:00:00", "to": "2023-01-13T12:00:00"},
    {"from": "2023-01-13T13:00:00", "to": "2023-01-13T17:00:00"}
  ],
  "rules": [
    {
      "maxDriveTime": 18000  // Applies across BOTH shifts
    }
  ]
}

Multi-Day Planning

For multi-day scenarios, rules apply per day:

{
  "shifts": [
    {"from": "2023-01-13T08:00:00", "to": "2023-01-13T17:00:00"},
    {"from": "2023-01-14T08:00:00", "to": "2023-01-14T17:00:00"}
  ],
  "rules": [
    {
      "maxDriveTime": 25200  // Resets each day
    }
  ]
}

Best Practices

1

Start with regulatory requirements

Implement legally required limits first (e.g., DOT hours of service, EU driving time regulations).

2

Add operational constraints

Layer in company policies and union agreements after regulatory compliance.

3

Test with partial planning

Enable partialPlanning: true when rules might prevent full job assignment.

4

Monitor rule impact

Use the explanation API to understand how rules affect job assignments.

5

Balance min/max rules

Avoid overly restrictive combinations that create infeasible scenarios.

Troubleshooting

Too Many Unassigned Jobs

If rules cause excessive unassigned jobs:

Inefficient Routes

When minimum rules force unnecessary travel:

Replace minimum drive time rules with minimum job count or revenue targets to achieve utilization goals without forcing inefficient routing.

Advanced Scenarios

Time-Based Rule Variations

While not directly supported, you can simulate time-based variations using multiple resources:

{
  "resources": [
    {
      "name": "Driver-Morning",
      "shifts": [{"from": "06:00", "to": "14:00"}],
      "rules": [{"maxDriveTime": 25200}]  // 7 hours
    },
    {
      "name": "Driver-Evening", 
      "shifts": [{"from": "14:00", "to": "22:00"}],
      "rules": [{"maxDriveTime": 21600}]  // 6 hours (different limit)
    }
  ]
}

Combining with Other Constraints

Rules work alongside other VRP features:

{
  "resources": [{
    "name": "R-1",
    "rules": [{"maxDriveTime": 28800}],
    "breaks": [
      {
        "type": "DRIVE",
        "duration": 2700,        // 45-min break
        "afterDriveTime": 16200  // After 4.5 hours driving
      }
    ],
    "maxDistance": 300000        // 300km daily limit
  }]
}

Performance Impact

Period rules are evaluated continuously during optimization. Complex rule combinations may increase solve time, especially with tight constraints that limit feasible solutions.

Consider:

  • Fewer, simpler rules perform better than many complex rules
  • Hard rules that severely limit options increase computation time
  • Partial planning helps when rules make full assignment impossible