Max_time_in_vehicle constraint not working

Hi,

we start to make use of the max_time_in_vehicle constraint.
The documentation tells us, that you set it seconds. Half an hour would be 1.800 then.

When ever we set the parameter to a reasonable amount we don’t get a result, it always tells us, that there’s no route found

Here’s our request:

{
  "New item - 2": {
    "configuration": {
      "routing": {
        "calc_points": false
      }
    },
    "objectives": [
      {
        "type": "min",
        "value": "completion_time"
      }
    ],
    "vehicles": [
      {
        "vehicle_id": "vehicle_88496",
        "start_address": {
          "location_id": "location_start_88496",
          "lat": 48.755560000000003,
          "lon": 9.163038999999999,
          "name": ""
        },
        "type_id": "vehicletype_88496_small_truck",
        "return_to_depot": false
      },
      {
        "vehicle_id": "vehicle_94828",
        "start_address": {
          "location_id": "location_start_94828",
          "lat": 48.710349000000001,
          "lon": 9.094638,
          "name": ""
        },
        "type_id": "vehicletype_94828_small_truck",
        "return_to_depot": false
      },
      {
        "vehicle_id": "vehicle_80864",
        "start_address": {
          "location_id": "location_start_80864",
          "lat": 48.710349000000001,
          "lon": 9.2767,
          "name": ""
        },
        "type_id": "vehicletype_80864_small_truck",
        "return_to_depot": false
      },
      {
        "vehicle_id": "vehicle_70554",
        "start_address": {
          "location_id": "location_start_70554",
          "lat": 48.817135999999998,
          "lon": 9.094638,
          "name": ""
        },
        "type_id": "vehicletype_70554_small_truck",
        "return_to_depot": false
      },
      {
        "vehicle_id": "vehicle_21999",
        "start_address": {
          "location_id": "location_start_21999",
          "lat": 48.817135999999998,
          "lon": 9.2767,
          "name": ""
        },
        "type_id": "vehicletype_21999_small_truck",
        "return_to_depot": false
      },
      {
        "vehicle_id": "vehicle_78423",
        "start_address": {
          "location_id": "location_start_78423",
          "lat": 48.763742000000001,
          "lon": 9.094638,
          "name": ""
        },
        "type_id": "vehicletype_78423_small_truck",
        "return_to_depot": false
      },
      {
        "vehicle_id": "vehicle_32896",
        "start_address": {
          "location_id": "location_start_32896",
          "lat": 48.763742000000001,
          "lon": 9.2767,
          "name": ""
        },
        "type_id": "vehicletype_32896_small_truck",
        "return_to_depot": false
      },
      {
        "vehicle_id": "vehicle_90027",
        "start_address": {
          "location_id": "location_start_90027",
          "lat": 48.710349000000001,
          "lon": 9.185669000000001,
          "name": ""
        },
        "type_id": "vehicletype_90027_small_truck",
        "return_to_depot": false
      },
      {
        "vehicle_id": "vehicle_31805",
        "start_address": {
          "location_id": "location_start_31805",
          "lat": 48.817135999999998,
          "lon": 9.185669000000001,
          "name": ""
        },
        "type_id": "vehicletype_31805_small_truck",
        "return_to_depot": false
      },
      {
        "vehicle_id": "vehicle_98817",
        "start_address": {
          "location_id": "location_start_98817",
          "lat": 48.755560000000003,
          "lon": 9.163038999999999,
          "name": ""
        },
        "type_id": "vehicletype_98817_small_truck",
        "return_to_depot": false
      }
    ],
    "vehicle_types": [
      {
        "type_id": "vehicletype_88496_small_truck",
        "profile": "small_truck",
        "capacity": [
          16
        ],
        "speed_factor": 1.0,
        "service_time_factor": 1.0
      },
      {
        "type_id": "vehicletype_94828_small_truck",
        "profile": "small_truck",
        "capacity": [
          16
        ],
        "speed_factor": 1.0,
        "service_time_factor": 1.0
      },
      {
        "type_id": "vehicletype_80864_small_truck",
        "profile": "small_truck",
        "capacity": [
          16
        ],
        "speed_factor": 1.0,
        "service_time_factor": 1.0
      },
      {
        "type_id": "vehicletype_70554_small_truck",
        "profile": "small_truck",
        "capacity": [
          16
        ],
        "speed_factor": 1.0,
        "service_time_factor": 1.0
      },
      {
        "type_id": "vehicletype_21999_small_truck",
        "profile": "small_truck",
        "capacity": [
          16
        ],
        "speed_factor": 1.0,
        "service_time_factor": 1.0
      },
      {
        "type_id": "vehicletype_78423_small_truck",
        "profile": "small_truck",
        "capacity": [
          16
        ],
        "speed_factor": 1.0,
        "service_time_factor": 1.0
      },
      {
        "type_id": "vehicletype_32896_small_truck",
        "profile": "small_truck",
        "capacity": [
          16
        ],
        "speed_factor": 1.0,
        "service_time_factor": 1.0
      },
      {
        "type_id": "vehicletype_90027_small_truck",
        "profile": "small_truck",
        "capacity": [
          16
        ],
        "speed_factor": 1.0,
        "service_time_factor": 1.0
      },
      {
        "type_id": "vehicletype_31805_small_truck",
        "profile": "small_truck",
        "capacity": [
          16
        ],
        "speed_factor": 1.0,
        "service_time_factor": 1.0
      },
      {
        "type_id": "vehicletype_98817_small_truck",
        "profile": "small_truck",
        "capacity": [
          16
        ],
        "speed_factor": 1.0,
        "service_time_factor": 1.0
      }
    ],
    "shipments": [
      {
        "id": "13783",
        "name": "Uhlbacher Str. 203, 70329 Stuttgart",
        "pickup": {
          "address": {
            "location_id": "start_13783",
            "name": "Uhlbacher Str. 203, 70329 Stuttgart",
            "lat": 48.775078999999998,
            "lon": 9.2767
          },
          "duration": 0
        },
        "delivery": {
          "address": {
            "location_id": "end_13783",
            "name": "Hengstäcker 6, 70567 Stuttgart",
            "lat": 48.732044999999999,
            "lon": 9.129629
          },
          "duration": 0,
          "time_windows": [
            {
              "earliest": 26880,
              "latest": 27000
            }
          ]
        },
        "size": [
          1
        ],
        "priority": 3,
        "max_time_in_vehicle": 18000
      },
      {
        "id": "13784",
        "name": "Landhausstr. 234, 70188 Stuttgart",
        "pickup": {
          "address": {
            "location_id": "start_13784",
            "name": "Landhausstr. 234, 70188 Stuttgart",
            "lat": 48.783532999999998,
            "lon": 9.216531
          },
          "duration": 0
        },
        "delivery": {
          "address": {
            "location_id": "end_13784",
            "name": "Hengstäcker 6, 70567 Stuttgart",
            "lat": 48.732044999999999,
            "lon": 9.129629
          },
          "duration": 0,
          "time_windows": [
            {
              "earliest": 26880,
              "latest": 27000
            }
          ]
        },
        "size": [
          1
        ],
        "priority": 3,
        "max_time_in_vehicle": 18000
      },
      {
        "id": "13785",
        "name": "Hackstr. 15a, 70190 Stuttgart",
        "pickup": {
          "address": {
            "location_id": "start_13785",
            "name": "Hackstr. 15a, 70190 Stuttgart",
            "lat": 48.789642999999998,
            "lon": 9.199896000000001
          },
          "duration": 0
        },
        "delivery": {
          "address": {
            "location_id": "end_13785",
            "name": "Hengstäcker 6, 70567 Stuttgart",
            "lat": 48.732044999999999,
            "lon": 9.129629
          },
          "duration": 0,
          "time_windows": [
            {
              "earliest": 26880,
              "latest": 27000
            }
          ]
        },
        "size": [
          1
        ],
        "priority": 3,
        "max_time_in_vehicle": 18000
      },
      {
        "id": "13786",
        "name": "Tunzhofer Str. 20, 70191 Stuttgart",
        "pickup": {
          "address": {
            "location_id": "start_13786",
            "name": "Tunzhofer Str. 20, 70191 Stuttgart",
            "lat": 48.792076000000002,
            "lon": 9.177973
          },
          "duration": 0
        },
        "delivery": {
          "address": {
            "location_id": "end_13786",
            "name": "Hengstäcker 6, 70567 Stuttgart",
            "lat": 48.732044999999999,
            "lon": 9.129629
          },
          "duration": 0,
          "time_windows": [
            {
              "earliest": 26880,
              "latest": 27000
            }
          ]
        },
        "size": [
          1
        ],
        "priority": 3,
        "max_time_in_vehicle": 18000
      },
      {
        "id": "13787",
        "name": "Ehrlichweg 40c, 70565 Stuttgart",
        "pickup": {
          "address": {
            "location_id": "start_13787",
            "name": "Ehrlichweg 40c, 70565 Stuttgart",
            "lat": 48.710349000000001,
            "lon": 9.147313
          },
          "duration": 0
        },
        "delivery": {
          "address": {
            "location_id": "end_13787",
            "name": "Hengstäcker 6, 70567 Stuttgart",
            "lat": 48.732044999999999,
            "lon": 9.129629
          },
          "duration": 0,
          "time_windows": [
            {
              "earliest": 26880,
              "latest": 27000
            }
          ]
        },
        "size": [
          1
        ],
        "priority": 3,
        "max_time_in_vehicle": 18000
      },
      {
        "id": "13788",
        "name": "Bieler Weg 1c, 70619 Stuttgart",
        "pickup": {
          "address": {
            "location_id": "start_13788",
            "name": "Bieler Weg 1c, 70619 Stuttgart",
            "lat": 48.737240999999997,
            "lon": 9.21555
          },
          "duration": 0
        },
        "delivery": {
          "address": {
            "location_id": "end_13788",
            "name": "Hengstäcker 6, 70567 Stuttgart",
            "lat": 48.732044999999999,
            "lon": 9.129629
          },
          "duration": 0,
          "time_windows": [
            {
              "earliest": 26880,
              "latest": 27000
            }
          ]
        },
        "size": [
          1
        ],
        "priority": 3,
        "max_time_in_vehicle": 18000
      },
      {
        "id": "13789",
        "name": "Nordbahnhofstr. 161, 70191 Stuttgart",
        "pickup": {
          "address": {
            "location_id": "start_13789",
            "name": "Nordbahnhofstr. 161, 70191 Stuttgart",
            "lat": 48.804034999999999,
            "lon": 9.189537
          },
          "duration": 0
        },
        "delivery": {
          "address": {
            "location_id": "end_13789",
            "name": "Hengstäcker 6, 70567 Stuttgart",
            "lat": 48.732044999999999,
            "lon": 9.129629
          },
          "duration": 0,
          "time_windows": [
            {
              "earliest": 26880,
              "latest": 27000
            }
          ]
        },
        "size": [
          1
        ],
        "priority": 3,
        "max_time_in_vehicle": 18000
      },
      {
        "id": "13790",
        "name": "Brückenstr. 45, 70376 Stuttgart",
        "pickup": {
          "address": {
            "location_id": "start_13790",
            "name": "Brückenstr. 45, 70376 Stuttgart",
            "lat": 48.808487,
            "lon": 9.210132
          },
          "duration": 0
        },
        "delivery": {
          "address": {
            "location_id": "end_13790",
            "name": "Hengstäcker 6, 70567 Stuttgart",
            "lat": 48.732044999999999,
            "lon": 9.129629
          },
          "duration": 0,
          "time_windows": [
            {
              "earliest": 26880,
              "latest": 27000
            }
          ]
        },
        "size": [
          1
        ],
        "priority": 3,
        "max_time_in_vehicle": 18000
      },
      {
        "id": "13791",
        "name": "Brückenstr. 45, 70376 Stuttgart",
        "pickup": {
          "address": {
            "location_id": "start_13791",
            "name": "Brückenstr. 45, 70376 Stuttgart",
            "lat": 48.808487,
            "lon": 9.210132
          },
          "duration": 0
        },
        "delivery": {
          "address": {
            "location_id": "end_13791",
            "name": "Hengstäcker 6, 70567 Stuttgart",
            "lat": 48.732044999999999,
            "lon": 9.129629
          },
          "duration": 0,
          "time_windows": [
            {
              "earliest": 26880,
              "latest": 27000
            }
          ]
        },
        "size": [
          1
        ],
        "priority": 3,
        "max_time_in_vehicle": 18000
      },
      {
        "id": "13792",
        "name": "Hofener Str. 173b, 70374 Stuttgart",
        "pickup": {
          "address": {
            "location_id": "start_13792",
            "name": "Hofener Str. 173b, 70374 Stuttgart",
            "lat": 48.817135999999998,
            "lon": 9.227905
          },
          "duration": 0
        },
        "delivery": {
          "address": {
            "location_id": "end_13792",
            "name": "Hengstäcker 6, 70567 Stuttgart",
            "lat": 48.732044999999999,
            "lon": 9.129629
          },
          "duration": 0,
          "time_windows": [
            {
              "earliest": 26880,
              "latest": 27000
            }
          ]
        },
        "size": [
          1
        ],
        "priority": 3,
        "max_time_in_vehicle": 18000
      },
      {
        "id": "13793",
        "name": "Kienbachstr. 36, 70374 Stuttgart",
        "pickup": {
          "address": {
            "location_id": "start_13793",
            "name": "Kienbachstr. 36, 70374 Stuttgart",
            "lat": 48.801188000000003,
            "lon": 9.237583000000001
          },
          "duration": 0
        },
        "delivery": {
          "address": {
            "location_id": "end_13793",
            "name": "Hengstäcker 6, 70567 Stuttgart",
            "lat": 48.732044999999999,
            "lon": 9.129629
          },
          "duration": 0,
          "time_windows": [
            {
              "earliest": 26880,
              "latest": 27000
            }
          ]
        },
        "size": [
          1
        ],
        "priority": 3,
        "max_time_in_vehicle": 18000
      },
      {
        "id": "13794",
        "name": "Salacherstr. 38, 70327 Stuttgart",
        "pickup": {
          "address": {
            "location_id": "start_13794",
            "name": "Salacherstr. 38, 70327 Stuttgart",
            "lat": 48.775306999999998,
            "lon": 9.243641
          },
          "duration": 0
        },
        "delivery": {
          "address": {
            "location_id": "end_13794",
            "name": "Hengstäcker 6, 70567 Stuttgart",
            "lat": 48.732044999999999,
            "lon": 9.129629
          },
          "duration": 0,
          "time_windows": [
            {
              "earliest": 26880,
              "latest": 27000
            }
          ]
        },
        "size": [
          1
        ],
        "priority": 3,
        "max_time_in_vehicle": 18000
      },
      {
        "id": "13795",
        "name": "Niersteiner Str. 2, 70499 Stuttgart",
        "pickup": {
          "address": {
            "location_id": "start_13795",
            "name": "Niersteiner Str. 2, 70499 Stuttgart",
            "lat": 48.811185999999999,
            "lon": 9.123616999999999
          },
          "duration": 0
        },
        "delivery": {
          "address": {
            "location_id": "end_13795",
            "name": "Hengstäcker 6, 70567 Stuttgart",
            "lat": 48.732044999999999,
            "lon": 9.129629
          },
          "duration": 0,
          "time_windows": [
            {
              "earliest": 26880,
              "latest": 27000
            }
          ]
        },
        "size": [
          1
        ],
        "priority": 3,
        "max_time_in_vehicle": 18000
      },
      {
        "id": "13796",
        "name": "Böblinger Str. 55, 70199 Stuttgart",
        "pickup": {
          "address": {
            "location_id": "start_13796",
            "name": "Böblinger Str. 55, 70199 Stuttgart",
            "lat": 48.763091000000003,
            "lon": 9.161629
          },
          "duration": 0
        },
        "delivery": {
          "address": {
            "location_id": "end_13796",
            "name": "Hengstäcker 6, 70567 Stuttgart",
            "lat": 48.732044999999999,
            "lon": 9.129629
          },
          "duration": 0,
          "time_windows": [
            {
              "earliest": 26880,
              "latest": 27000
            }
          ]
        },
        "size": [
          1
        ],
        "priority": 3,
        "max_time_in_vehicle": 18000
      },
      {
        "id": "13797",
        "name": "Wolframstr. 64b, 70191 Stuttgart",
        "pickup": {
          "address": {
            "location_id": "start_13797",
            "name": "Wolframstr. 64b, 70191 Stuttgart",
            "lat": 48.793655999999999,
            "lon": 9.180611000000001
          },
          "duration": 0
        },
        "delivery": {
          "address": {
            "location_id": "end_13797",
            "name": "Hengstäcker 6, 70567 Stuttgart",
            "lat": 48.732044999999999,
            "lon": 9.129629
          },
          "duration": 0,
          "time_windows": [
            {
              "earliest": 26880,
              "latest": 27000
            }
          ]
        },
        "size": [
          1
        ],
        "priority": 3,
        "max_time_in_vehicle": 18000
      },
      {
        "id": "13798",
        "name": "Franziskaweg 20a, 70599 Stuttgart",
        "pickup": {
          "address": {
            "location_id": "start_13798",
            "name": "Franziskaweg 20a, 70599 Stuttgart",
            "lat": 48.716679999999997,
            "lon": 9.204832
          },
          "duration": 0
        },
        "delivery": {
          "address": {
            "location_id": "end_13798",
            "name": "Hengstäcker 6, 70567 Stuttgart",
            "lat": 48.732044999999999,
            "lon": 9.129629
          },
          "duration": 0,
          "time_windows": [
            {
              "earliest": 26880,
              "latest": 27000
            }
          ]
        },
        "size": [
          1
        ],
        "priority": 3,
        "max_time_in_vehicle": 18000
      },
      {
        "id": "13799",
        "name": "mercedesstr. 25, 70372 Stuttgart",
        "pickup": {
          "address": {
            "location_id": "start_13799",
            "name": "mercedesstr. 25, 70372 Stuttgart",
            "lat": 48.798336999999997,
            "lon": 9.217874999999999
          },
          "duration": 0
        },
        "delivery": {
          "address": {
            "location_id": "end_13799",
            "name": "Hengstäcker 6, 70567 Stuttgart",
            "lat": 48.732044999999999,
            "lon": 9.129629
          },
          "duration": 0,
          "time_windows": [
            {
              "earliest": 26880,
              "latest": 27000
            }
          ]
        },
        "size": [
          1
        ],
        "priority": 3,
        "max_time_in_vehicle": 18000
      },
      {
        "id": "13800",
        "name": "Büsnauerstr. 77, 70569 Stuttgart",
        "pickup": {
          "address": {
            "location_id": "start_13800",
            "name": "Büsnauerstr. 77, 70569 Stuttgart",
            "lat": 48.737836999999999,
            "lon": 9.094638
          },
          "duration": 0
        },
        "delivery": {
          "address": {
            "location_id": "end_13800",
            "name": "Hengstäcker 6, 70567 Stuttgart",
            "lat": 48.732044999999999,
            "lon": 9.129629
          },
          "duration": 0,
          "time_windows": [
            {
              "earliest": 26880,
              "latest": 27000
            }
          ]
        },
        "size": [
          1
        ],
        "priority": 3,
        "max_time_in_vehicle": 18000
      }
    ]
  }
}

Here’s the answer (look at the unassigned - leg):

{
  "New item - 2": {
    "copyrights": [
      "GraphHopper",
      "OpenStreetMap contributors"
    ],
    "job_id": "5ac97d80-1ad7-471c-a5f0-21ccdc8f959c",
    "status": "finished",
    "waiting_time_in_queue": 0,
    "processing_time": 409,
    "solution": {
      "costs": 0,
      "distance": 0,
      "time": 0,
      "transport_time": 0,
      "completion_time": 0,
      "max_operation_time": 0,
      "waiting_time": 0,
      "service_duration": 0,
      "preparation_time": 0,
      "no_vehicles": 0,
      "no_unassigned": 18,
      "routes": [
      ],
      "unassigned": {
        "services": [
        ],
        "shipments": [
          "13790",
          "13793",
          "13783",
          "13794",
          "13791",
          "13792",
          "13797",
          "13786",
          "13798",
          "13787",
          "13795",
          "13784",
          "13785",
          "13796",
          "13799",
          "13788",
          "13800",
          "13789"
        ],
        "breaks": [
        ],
        "details": [
          {
            "id": "13790",
            "code": 23,
            "reason": "could not be assigned due to max-time-in-vehicle constraint"
          },
          {
            "id": "13793",
            "code": 23,
            "reason": "could not be assigned due to max-time-in-vehicle constraint"
          },
          {
            "id": "13783",
            "code": 23,
            "reason": "could not be assigned due to max-time-in-vehicle constraint"
          },
          {
            "id": "13794",
            "code": 23,
            "reason": "could not be assigned due to max-time-in-vehicle constraint"
          },
          {
            "id": "13791",
            "code": 23,
            "reason": "could not be assigned due to max-time-in-vehicle constraint"
          },
          {
            "id": "13792",
            "code": 23,
            "reason": "could not be assigned due to max-time-in-vehicle constraint"
          },
          {
            "id": "13797",
            "code": 23,
            "reason": "could not be assigned due to max-time-in-vehicle constraint"
          },
          {
            "id": "13786",
            "code": 23,
            "reason": "could not be assigned due to max-time-in-vehicle constraint"
          },
          {
            "id": "13798",
            "code": 23,
            "reason": "could not be assigned due to max-time-in-vehicle constraint"
          },
          {
            "id": "13787",
            "code": 23,
            "reason": "could not be assigned due to max-time-in-vehicle constraint"
          },
          {
            "id": "13795",
            "code": 23,
            "reason": "could not be assigned due to max-time-in-vehicle constraint"
          },
          {
            "id": "13784",
            "code": 23,
            "reason": "could not be assigned due to max-time-in-vehicle constraint"
          },
          {
            "id": "13785",
            "code": 23,
            "reason": "could not be assigned due to max-time-in-vehicle constraint"
          },
          {
            "id": "13796",
            "code": 23,
            "reason": "could not be assigned due to max-time-in-vehicle constraint"
          },
          {
            "id": "13799",
            "code": 23,
            "reason": "could not be assigned due to max-time-in-vehicle constraint"
          },
          {
            "id": "13788",
            "code": 23,
            "reason": "could not be assigned due to max-time-in-vehicle constraint"
          },
          {
            "id": "13800",
            "code": 23,
            "reason": "could not be assigned due to max-time-in-vehicle constraint"
          },
          {
            "id": "13789",
            "code": 23,
            "reason": "could not be assigned due to max-time-in-vehicle constraint"
          }
        ]
      }
    }
  }
}

There you can see, even if set the max_time_in_vehicle to 18.000, it doesn’t work.

What is our mistake? What do we wrong?

Does anyone has an Idea? :confused:

Each shipment must be delivered at 26880 at the earliest. If the start time of the vehicles is not defined, all vehicles start at time 0. This means here that the shipments are picked up shortly after 0 and are then approx. 26880 sec. in the vehicle. If the max. time in the vehicle may not be greater than 18000 sec. then this shipment cannot be transported.

1 Like

So just to get it right:

  • all shipments are picked up as soon as possible
  • they stay in the car until the “earliest” drop time arrives

So the question is

  • if we have a drop time window "earliest": 26880 to "latest": 27000 (7:28 to 7:30)
  • how do we set the max_time_in_vehicle parameter?
  • 27.000 - 1.800 = 25.200 ? (7:30 minus 00:30)? Is that right?

And also:

  • if we have a * time window "earliest": 21600 to "latest": 27000 (6:00 to 7:30)
  • how do we say, that the delivery can be anytime in this timeframe but only with maximum 1800 seconds in the car?

You should specify a reasonable “earliest_start” time for your vehicles. Unfortunately, we do not optimize the start times yet, so you must always specify them in advance.

1 Like

Okay, I see.

Then we come close to the solution we want. There are some situations where this approach produces some flaws, but we can handle it guess. Thanks for helping!