Optimize: Suggest Insertion

POST /api/v1/optimize/suggest-insertion

Find the best place to insert one or more new jobs into an existing solution, without disturbing the rest of the plan more than necessary.

Description

Accepts an InsertionRequest: the base problem, the current_solution (existing routes), and the new_jobs to insert. Internally, the existing solution is converted to locks.routes and the new jobs are appended to the base problem's jobs list; a normal solve then finds the cheapest way to weave the new jobs in. This is the right tool for a dispatcher screen that needs "where should this new job go" without a full re-plan.

Request body: InsertionRequest

NameTypeRequiredDefaultDescription
baseOptimizationRequestrequired-The full problem definition.
current_solutionSeedSolutionrequired-{{routes: [{{resource_id, stops: [{{job_id}}, ...]}}]}} describing the plan as currently executed/planned.
new_jobsJob[]requiredmin 1 itemNew jobs to insert.

Response

Full OptimizationResponse with the new jobs inserted into the routes (or reported in unserved if no feasible insertion exists).

Examples

curl -X POST https://api.fieldgenius.be/api/v1/optimize/suggest-insertion \
  -H "Content-Type: application/json" \
  -H "X-API-Key: your-adapter-key" \
  -H "X-Client-Key: your-client-key" \
  -d '{
    "base": {
      "travel": { "distance_matrix": [[0,6,9,7],[6,0,5,4],[9,5,0,6],[7,4,6,0]] },
      "resources": [{ "id": "van-01", "depot_index": 0 }],
      "jobs": [{ "id": "stop-a", "location_index": 1 }, { "id": "stop-b", "location_index": 2 }]
    },
    "current_solution": {
      "routes": [{ "resource_id": "van-01", "stops": [{ "job_id": "stop-a" }, { "job_id": "stop-b" }] }]
    },
    "new_jobs": [{ "id": "stop-urgent-c", "location_index": 3 }]
  }'
import httpx

payload = {
    "base": {
        "travel": {"distance_matrix": [[0, 6, 9, 7], [6, 0, 5, 4], [9, 5, 0, 6], [7, 4, 6, 0]]},
        "resources": [{"id": "van-01", "depot_index": 0}],
        "jobs": [{"id": "stop-a", "location_index": 1}, {"id": "stop-b", "location_index": 2}],
    },
    "current_solution": {
        "routes": [{"resource_id": "van-01", "stops": [{"job_id": "stop-a"}, {"job_id": "stop-b"}]}]
    },
    "new_jobs": [{"id": "stop-urgent-c", "location_index": 3}],
}
headers = {"X-API-Key": "your-adapter-key", "X-Client-Key": "your-client-key"}
resp = httpx.post("https://api.fieldgenius.be/api/v1/optimize/suggest-insertion", json=payload, headers=headers)
print(resp.json()["routes"][0]["activities"])

Errors

StatusCodeResolution
422VALIDATION_ERRORThe augmented request (base jobs + new_jobs + locks) fails validation.
422SOLVER_INFEASIBLENo feasible insertion exists under the current locks and constraints; the new job appears in unserved if it was optional, or the call fails if mandatory.

FieldGenius VRP API documentation. Generated from the engineering source of truth (.tex docs and app/ source).