POST route optimization problem | Shortest stops first

I was comparing the optimized paths, and I realised that the POST route optimization problem is not showing the shortest stops first. For example:

{
  "relations": [
    {
      "type": "in_sequence",
      "groups": ["order_1", "order_2"],
      "vehicle_id": "v1"
    },
    {
      "type": "in_same_route",
      "ids": ["s1", "s2", "s3", "s4"]
    }
  ],
  "configuration": {
    "routing": {
      "calc_points": true,
      "return_snapped_waypoints": true
    }
  },
  "objectives": [
    {
      "type": "min",
      "value": "completion_time"
    }
  ],
  "vehicles": [
    {
      "vehicle_id": "v1",
      "type_id": "custom_vehicle_type",
      "start_address": {
        "location_id": "v1",
        "lat": 10.06645,
        "lon": -69.30911
      },
      "earliest_start": 1508839200,
      "return_to_depot": false
    }
  ],
  "vehicle_types": [
    {
      "type_id": "custom_vehicle_type",
      "profile": "car"
    }
  ],
  "services": [
    {
      "id": "s1",
      "type": "pickup",
      "address": {
        "location_id": "s1",
        "lat": 10.06659,
        "lon": -69.31078
      },
      "group": "order_1"
    },
    {
      "id": "s2",
      "type": "delivery",
      "address": {
        "location_id": "s2",
        "lat": 10.06682,
        "lon": -69.30875
      },
      "group": "order_1"
    },
    {
      "id": "s3",
      "type": "pickup",
      "address": {
        "location_id": "s4",
        "lat": 10.06872,
        "lon": -69.30731
      },
      "group": "order_2"
    },
    {
      "id": "s4",
      "type": "delivery",
      "address": {
        "location_id": "s3",
        "lat": 10.06771,
        "lon": -69.30763
      },
      "group": "order_2"
    }
  ]
}

It has chosen a stop with 0.71 km of distance, that belongs to the group order_1.

Now when I try the second group order_2 isolated, it shows a shortest distance.

{
  "relations": [
    {
      "type": "in_sequence",
      "groups": ["order_2"],
      "vehicle_id": "v1"
    },
    {
      "type": "in_same_route",
      "ids": ["s3", "s4"]
    }
  ],
  "configuration": {
    "routing": {
      "calc_points": true,
      "return_snapped_waypoints": true
    }
  },
  "objectives": [
    {
      "type": "min",
      "value": "completion_time"
    }
  ],
  "vehicles": [
    {
      "vehicle_id": "v1",
      "type_id": "custom_vehicle_type",
      "start_address": {
        "location_id": "v1",
        "lat": 10.06645,
        "lon": -69.30911
      },
      "earliest_start": 1508839200,
      "return_to_depot": false
    }
  ],
  "vehicle_types": [
    {
      "type_id": "custom_vehicle_type",
      "profile": "car"
    }
  ],
  "services": [
    {
      "id": "s3",
      "type": "pickup",
      "address": {
        "location_id": "s1",
        "lat": 10.06872,
        "lon": -69.30731
      },
      "group": "order_2"
    },
    {
      "id": "s4",
      "type": "delivery",
      "address": {
        "location_id": "s2",
        "lat": 10.06771,
        "lon": -69.30763
      },
      "group": "order_2"
    }
  ]
}

It shows in the first stop a 0.57 km of distance which is shorter than the order_1.

In other words, combining these two orders it should start by the shortest distance which is order_2 and then order_1. That’s how I see the “Optimization Route”, let me know if I am missing something.

Thanks.

I’m not sure why this is but I’ve found that for this section, it only works correctly when you put the Ids in two at a time.

"type": "in_same_route",
"ids": ["s1", "s2", "s3", "s4"]

For example, this is how I had to set it up to make sure the sequence and same route were being honored:

	{			
		"type": "in_sequence",		
		"ids": ["Shipment-A-PU","Shipment-A-DL"]		
	},			
	{			
		"type": "in_same_route",		
		"ids": ["Shipment-A-PU","Shipment-A-DL"]		
	},			
	{			
		"type": "in_sequence",		
		"ids": ["Shipment-B-PU","Shipment-B-DL"]		
	},			
	{			
		"type": "in_same_route",		
		"ids": ["Shipment-B-PU","Shipment-B-DL"]		
	},			

@Franklin_Perdomo the distance in the table is the total distance from the start. So in your first example the distance from your first delivery s2 to the second pickup s3 (with location s4!?) is 1.43-0.94=0.49km. You can easier measure the distances between locations with GraphHopper Maps or directly in the JSON response. Does this clarify your misunderstanding?

Also instead of relations with the group feature you can have a look into shipments which is more powerful and might make your case easier.

You’re right @karussell thank you very much. I was confused for a while.