Job priorities

There are two types of job priorities:

  • assignment priority: the solver tries to avoid such jobs to be unassigned by maximizing their total value. Assignment priority is modeled by value property on the job and used within the maximize-value objective.
  • order priority: the solver tries to assign such jobs prior others, close to beginning of the route. Order priority is modeled by order property on the job.

Basic job value example

The example below demonstrates how to use assignment priority by defining value on the jobs. The source problem has a single vehicle with limited capacity, therefore one job has to be unassigned. The solver is forced to skip the cheapest one as it has no value associated with it.

Please note, that there is no need to redefine objective to include maximize-value one as it will be added automatically on top of default.

Problem

{
  "plan": {
    "jobs": [
      {
        "id": "job1",
        "deliveries": [
          {
            "places": [
              {
                "location": {
                  "lat": 52.52599,
                  "lng": 13.45413
                },
                "duration": 300
              }
            ],
            "demand": [
              1
            ]
          }
        ],
        "value": 50
      },
      {
        "id": "job2",
        "deliveries": [
          {
            "places": [
              {
                "location": {
                  "lat": 52.5225,
                  "lng": 13.4095
                },
                "duration": 240
              }
            ],
            "demand": [
              1
            ]
          }
        ],
        "value": 100
      },
      {
        "id": "job3",
        "deliveries": [
          {
            "places": [
              {
                "location": {
                  "lat": 52.5320,
                  "lng": 13.3950
                },
                "duration": 60
              }
            ],
            "demand": [
              1
            ]
          }
        ]
      }
    ]
  },
  "fleet": {
    "vehicles": [
      {
        "typeId": "vehicle",
        "vehicleIds": [
          "vehicle_1"
        ],
        "profile": {
          "matrix": "normal_car"
        },
        "costs": {
          "fixed": 22.0,
          "distance": 0.0002,
          "time": 0.005
        },
        "shifts": [
          {
            "start": {
              "earliest": "2019-07-04T09:00:00Z",
              "location": {
                "lat": 52.5316,
                "lng": 13.3884
              }
            }
          }
        ],
        "capacity": [
          2
        ]
      }
    ],
    "profiles": [
      {
        "name": "normal_car"
      }
    ]
  }
}

Solution

{
  "statistic": {
    "cost": 28.060000000000002,
    "distance": 4800,
    "duration": 1020,
    "times": {
      "driving": 480,
      "serving": 540,
      "waiting": 0,
      "break": 0
    }
  },
  "tours": [
    {
      "vehicleId": "vehicle_1",
      "typeId": "vehicle",
      "shiftIndex": 0,
      "stops": [
        {
          "location": {
            "lat": 52.5316,
            "lng": 13.3884
          },
          "time": {
            "arrival": "2019-07-04T09:00:00Z",
            "departure": "2019-07-04T09:00:00Z"
          },
          "distance": 0,
          "load": [
            2
          ],
          "activities": [
            {
              "jobId": "departure",
              "type": "departure"
            }
          ]
        },
        {
          "location": {
            "lat": 52.5225,
            "lng": 13.4095
          },
          "time": {
            "arrival": "2019-07-04T09:02:55Z",
            "departure": "2019-07-04T09:06:55Z"
          },
          "distance": 1752,
          "load": [
            1
          ],
          "activities": [
            {
              "jobId": "job2",
              "type": "delivery"
            }
          ]
        },
        {
          "location": {
            "lat": 52.52599,
            "lng": 13.45413
          },
          "time": {
            "arrival": "2019-07-04T09:12:00Z",
            "departure": "2019-07-04T09:17:00Z"
          },
          "distance": 4800,
          "load": [
            0
          ],
          "activities": [
            {
              "jobId": "job1",
              "type": "delivery"
            }
          ]
        }
      ],
      "statistic": {
        "cost": 28.060000000000002,
        "distance": 4800,
        "duration": 1020,
        "times": {
          "driving": 480,
          "serving": 540,
          "waiting": 0,
          "break": 0
        }
      }
    }
  ],
  "unassigned": [
    {
      "jobId": "job3",
      "reasons": [
        {
          "code": "CAPACITY_CONSTRAINT",
          "description": "does not fit into any vehicle due to capacity"
        }
      ]
    }
  ]
}