Route optimization reducing distance but with extra waiting time

Hello,

We’ve found a route optimization example where it appears as though the objective it is optimizing for is incorrect.

{
	"configuration": {
		"routing": {
			"calc_points": true,
			"consider_traffic": false,
			"fail_fast": true,
			"network_data_provider": "openstreetmap",
			"return_snapped_waypoints": true,
			"snap_preventions": [
				"motorway",
				"tunnel",
				"ferry"
			]
		}
	},
	"objectives": [
		{
			"type": "min",
			"value": "completion_time"
		}
	],
	"services": [
		{
			"address": {
				"curbside": "any",
				"lat": 51.0150235,
				"location_id": "78B9E319-176E-4A5E-90CC-42209C63A1E2",
				"lon": -2.6371345,
				"street_hint": "RNAS Yeovilton"
			},
			"duration": 780,
			"group": "medium",
			"id": "78B9E319-176E-4A5E-90CC-42209C63A1E2",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666855858
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.23445419999999,
				"location_id": "752ADC18-49D1-43BD-808C-7F7273D5A5CC",
				"lon": -2.8393871,
				"street_hint": "West Stoughton"
			},
			"duration": 780,
			"group": "medium",
			"id": "752ADC18-49D1-43BD-808C-7F7273D5A5CC",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666854005
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.2687203,
				"location_id": "8C054D6E-AB71-4422-A3D8-6B4843F8B875",
				"lon": -2.8919798,
				"street_hint": "Manor Farm"
			},
			"duration": 780,
			"group": "medium",
			"id": "8C054D6E-AB71-4422-A3D8-6B4843F8B875",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666859418
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.2816984,
				"location_id": "D7A812D1-7928-4E93-A2D0-59A494027625",
				"lon": -2.7699803,
				"street_hint": "Cheddar Gorge Lookout Tower"
			},
			"duration": 780,
			"group": "medium",
			"id": "D7A812D1-7928-4E93-A2D0-59A494027625",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666861242
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.281868,
				"location_id": "FEBD5B2C-88FF-4BE4-917B-2BE482B2B876",
				"lon": -2.7659364,
				"name": "Costa Coffee, Cheddar Cave",
				"street_hint": "Cheddar Cave"
			},
			"duration": 780,
			"group": "medium",
			"id": "FEBD5B2C-88FF-4BE4-917B-2BE482B2B876",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666857659
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.22517759999999,
				"location_id": "550CFCA4-E215-4338-990B-ED1A0A72E04B",
				"lon": -2.6712106,
				"name": "The Wookey Hole Inn, Wells",
				"street_hint": "Wookey Hole"
			},
			"duration": 780,
			"group": "medium",
			"id": "550CFCA4-E215-4338-990B-ED1A0A72E04B",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666861237
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.20893909999999,
				"location_id": "07FF1BBF-738C-41E5-9CDE-E874978C276E",
				"lon": -2.6427654,
				"street_hint": "The Bishop's Palace"
			},
			"duration": 780,
			"group": "medium",
			"id": "07FF1BBF-738C-41E5-9CDE-E874978C276E",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666855635
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.24973379999999,
				"location_id": "732AF20C-D35B-493A-AF10-FFABD11E8DF6",
				"lon": -2.6053744,
				"street_hint": "Green Ore"
			},
			"duration": 780,
			"group": "medium",
			"id": "732AF20C-D35B-493A-AF10-FFABD11E8DF6",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666854057
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.3319261,
				"location_id": "C11D7D68-1123-4EE8-BAF4-03213D3C1E8A",
				"lon": -2.2779075,
				"street_hint": "Tynings Way"
			},
			"duration": 780,
			"group": "medium",
			"id": "C11D7D68-1123-4EE8-BAF4-03213D3C1E8A",
			"priority": 1,
			"time_windows": []
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.341635,
				"location_id": "CEB14D91-2D05-4569-B8FA-E7F4E2A658F7",
				"lon": -2.251898,
				"street_hint": "Frome Rd"
			},
			"duration": 780,
			"group": "medium",
			"id": "CEB14D91-2D05-4569-B8FA-E7F4E2A658F7",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666854608
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.3473973,
				"location_id": "965EA9D1-DC13-4EDE-B984-B45432C69F18",
				"lon": -2.2507612,
				"street_hint": "Silver St"
			},
			"duration": 780,
			"group": "medium",
			"id": "965EA9D1-DC13-4EDE-B984-B45432C69F18",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666862244
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.3476074,
				"location_id": "45F644A4-BBBB-4B02-AE75-15EEFBD78E1D",
				"lon": -2.2502979,
				"street_hint": "Silver St"
			},
			"duration": 780,
			"group": "medium",
			"id": "45F644A4-BBBB-4B02-AE75-15EEFBD78E1D",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666859449
				}
			]
		}
	],
	"shipments": [],
	"vehicle_types": [
		{
			"profile": "car",
			"service_time_factor": 1,
			"speed_factor": 1,
			"type_id": "vhc_as4lajJon8e0UR9xR6TgawHayKP2"
		}
	],
	"vehicles": [
		{
			"earliest_start": 1666847700,
			"end_address": {
				"curbside": "any",
				"lat": 50.94664299999999,
				"location_id": "CE6FBC71-7990-4DF2-8150-8029E510AAB8",
				"lon": -2.5105,
				"street_hint": "Ludbourne Rd"
			},
			"return_to_depot": true,
			"start_address": {
				"curbside": "any",
				"lat": 50.94664299999999,
				"location_id": "2405EF6C-5D0D-4510-B9A9-F1B7E338ADC4",
				"lon": -2.5105,
				"street_hint": "Ludbourne Rd"
			},
			"type_id": "vhc_as4lajJon8e0UR9xR6TgawHayKP2",
			"vehicle_id": "as4lajJon8e0UR9xR6TgawHayKP2"
		}
	]
}

When optimizing this request then we get a:

		"distance": 191170,
		"time": 11885,
		"transport_time": 11885,
		"completion_time": 28440,
		"waiting_time": 7195,

But if we add a relation to force a specific service to be first:

{
	"configuration": {
		"routing": {
			"calc_points": true,
			"consider_traffic": false,
			"fail_fast": true,
			"network_data_provider": "openstreetmap",
			"return_snapped_waypoints": true,
			"snap_preventions": [
				"motorway",
				"tunnel",
				"ferry"
			]
		}
	},
	"objectives": [
		{
			"type": "min",
			"value": "completion_time"
		}
	],
	"relations": [
		{
			"groups": [
				"high",
				"medium"
			],
			"type": "in_sequence"
		}
	],
	"services": [
		{
			"address": {
				"curbside": "any",
				"lat": 51.0150235,
				"location_id": "78B9E319-176E-4A5E-90CC-42209C63A1E2",
				"lon": -2.6371345,
				"street_hint": "RNAS Yeovilton"
			},
			"duration": 780,
			"group": "medium",
			"id": "78B9E319-176E-4A5E-90CC-42209C63A1E2",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666855858
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.23445419999999,
				"location_id": "752ADC18-49D1-43BD-808C-7F7273D5A5CC",
				"lon": -2.8393871,
				"street_hint": "West Stoughton"
			},
			"duration": 780,
			"group": "medium",
			"id": "752ADC18-49D1-43BD-808C-7F7273D5A5CC",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666854005
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.2687203,
				"location_id": "8C054D6E-AB71-4422-A3D8-6B4843F8B875",
				"lon": -2.8919798,
				"street_hint": "Manor Farm"
			},
			"duration": 780,
			"group": "medium",
			"id": "8C054D6E-AB71-4422-A3D8-6B4843F8B875",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666859418
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.2816984,
				"location_id": "D7A812D1-7928-4E93-A2D0-59A494027625",
				"lon": -2.7699803,
				"street_hint": "Cheddar Gorge Lookout Tower"
			},
			"duration": 780,
			"group": "medium",
			"id": "D7A812D1-7928-4E93-A2D0-59A494027625",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666861242
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.281868,
				"location_id": "FEBD5B2C-88FF-4BE4-917B-2BE482B2B876",
				"lon": -2.7659364,
				"name": "Costa Coffee, Cheddar Cave",
				"street_hint": "Cheddar Cave"
			},
			"duration": 780,
			"group": "medium",
			"id": "FEBD5B2C-88FF-4BE4-917B-2BE482B2B876",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666857659
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.22517759999999,
				"location_id": "550CFCA4-E215-4338-990B-ED1A0A72E04B",
				"lon": -2.6712106,
				"name": "The Wookey Hole Inn, Wells",
				"street_hint": "Wookey Hole"
			},
			"duration": 780,
			"group": "medium",
			"id": "550CFCA4-E215-4338-990B-ED1A0A72E04B",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666861237
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.20893909999999,
				"location_id": "07FF1BBF-738C-41E5-9CDE-E874978C276E",
				"lon": -2.6427654,
				"street_hint": "The Bishop's Palace"
			},
			"duration": 780,
			"group": "medium",
			"id": "07FF1BBF-738C-41E5-9CDE-E874978C276E",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666855635
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.24973379999999,
				"location_id": "732AF20C-D35B-493A-AF10-FFABD11E8DF6",
				"lon": -2.6053744,
				"street_hint": "Green Ore"
			},
			"duration": 780,
			"group": "medium",
			"id": "732AF20C-D35B-493A-AF10-FFABD11E8DF6",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666854057
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.3319261,
				"location_id": "C11D7D68-1123-4EE8-BAF4-03213D3C1E8A",
				"lon": -2.2779075,
				"street_hint": "Tynings Way"
			},
			"duration": 780,
			"group": "high",
			"id": "C11D7D68-1123-4EE8-BAF4-03213D3C1E8A",
			"priority": 1,
			"time_windows": []
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.341635,
				"location_id": "CEB14D91-2D05-4569-B8FA-E7F4E2A658F7",
				"lon": -2.251898,
				"street_hint": "Frome Rd"
			},
			"duration": 780,
			"group": "medium",
			"id": "CEB14D91-2D05-4569-B8FA-E7F4E2A658F7",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666854608
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.3473973,
				"location_id": "965EA9D1-DC13-4EDE-B984-B45432C69F18",
				"lon": -2.2507612,
				"street_hint": "Silver St"
			},
			"duration": 780,
			"group": "medium",
			"id": "965EA9D1-DC13-4EDE-B984-B45432C69F18",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666862244
				}
			]
		},
		{
			"address": {
				"curbside": "any",
				"lat": 51.3476074,
				"location_id": "45F644A4-BBBB-4B02-AE75-15EEFBD78E1D",
				"lon": -2.2502979,
				"street_hint": "Silver St"
			},
			"duration": 780,
			"group": "medium",
			"id": "45F644A4-BBBB-4B02-AE75-15EEFBD78E1D",
			"priority": 2,
			"time_windows": [
				{
					"earliest": 1666859449
				}
			]
		}
	],
	"shipments": [],
	"vehicle_types": [
		{
			"profile": "car",
			"service_time_factor": 1,
			"speed_factor": 1,
			"type_id": "vhc_as4lajJon8e0UR9xR6TgawHayKP2"
		}
	],
	"vehicles": [
		{
			"earliest_start": 1666847700,
			"end_address": {
				"curbside": "any",
				"lat": 50.94664299999999,
				"location_id": "CE6FBC71-7990-4DF2-8150-8029E510AAB8",
				"lon": -2.5105,
				"street_hint": "Ludbourne Rd"
			},
			"return_to_depot": true,
			"start_address": {
				"curbside": "any",
				"lat": 50.94664299999999,
				"location_id": "2405EF6C-5D0D-4510-B9A9-F1B7E338ADC4",
				"lon": -2.5105,
				"street_hint": "Ludbourne Rd"
			},
			"type_id": "vhc_as4lajJon8e0UR9xR6TgawHayKP2",
			"vehicle_id": "as4lajJon8e0UR9xR6TgawHayKP2"
		}
	]
}

Then we get:

		"distance": 267421,
		"time": 14775,
		"transport_time": 14775,
		"completion_time": 25309,
		"waiting_time": 1174,

Which has a higher distance, but a shorter completion time, which is the objective of the request. With the first example, the completion time is much later because of the added waiting time required at some services, whereas in the second example we avoid the waiting time in exchange for more transport time.

I think this is probably a rare example and that most of the time the optimization does the right thing, but I thought I’d report it in case it is helpful on your end.

Powered by Discourse