Skip to content

Optimize Examples

Optimize API usage examples and scenarios.


1. Simple Multi-Vehicle Distribution

Basic VRP scenario:

{
  "vehicles": [
    {
      "id": "vehicle_1",
      "start": {"latitude": 41.0082, "longitude": 28.9784},
      "end": {"latitude": 41.0082, "longitude": 28.9784},
      "time_window": ["08:00:00", "18:00:00"],
      "constraints": {
        "vehicleType": "van",
        "capacity": 100,
        "capacityType": "weight_kg"
      }
    }
  ],
  "jobs": [
    {
      "id": "job_1",
      "start": {"latitude": 41.0100, "longitude": 28.9800},
      "end": {"latitude": 41.0150, "longitude": 28.9850},
      "amount": 20,
      "amount_type": "weight_kg",
      "priority": 50
    }
  ],
  "options": {
    "minimize": "cost"
  }
}

Python Example

import requests

API_BASE_URL = "https://api.flio.ai"
API_KEY = "YOUR-API-KEY"

payload = {
    "vehicles": [
        {
            "id": "vehicle_1",
            "start": {"latitude": 41.0082, "longitude": 28.9784},
            "end": {"latitude": 41.0082, "longitude": 28.9784},
            "time_window": ["08:00:00", "18:00:00"],
            "constraints": {
                "vehicleType": "van",
                "capacity": 100,
                "capacityType": "weight_kg"
            }
        }
    ],
    "jobs": [
        {
            "id": "job_1",
            "start": {"latitude": 41.0100, "longitude": 28.9800},
            "end": {"latitude": 41.0150, "longitude": 28.9850},
            "amount": 20,
            "priority": 50
        }
    ],
    "options": {"minimize": "cost"}
}

url = f"{API_BASE_URL}/solver/optimize?apiKey={API_KEY}"
response = requests.post(url, json=payload)
result = response.json()

print(f"Total Cost: {result['summary']['cost']}")
print(f"Vehicles Used: {result['summary']['routes']}")
print(f"Unassigned Jobs: {result['summary']['unassigned']}")

2. Time-Windowed Delivery

Delivery using time_windows (plural):

{
  "vehicles": [
    {
      "id": "vehicle_1",
      "start": {"latitude": 41.0082, "longitude": 28.9784},
      "time_window": ["08:00:00", "18:00:00"]
    }
  ],
  "jobs": [
    {
      "id": "job_1",
      "start": {
        "latitude": 41.0100,
        "longitude": 28.9800,
        "service": 300,
        "time_windows": [["09:00:00", "12:00:00"]]
      },
      "end": {"latitude": 41.0150, "longitude": 28.9850}
    }
  ],
  "options": {"minimize": "duration"}
}

3. Skills-Matched Scenario

Specialized vehicle-job matching:

{
  "vehicles": [
    {
      "id": "refrigerated_truck",
      "start": {"latitude": 41.0082, "longitude": 28.9784},
      "skills": [1]
    }
  ],
  "jobs": [
    {
      "id": "frozen_goods",
      "start": {"latitude": 41.0100, "longitude": 28.9800},
      "end": {"latitude": 41.0150, "longitude": 28.9850},
      "skills": [1]
    }
  ],
  "options": {"minimize": "cost"}
}

Skill 1 = Refrigerated vehicle


4. Long-Distance with Breaks

Vehicle breaks using breaks:

{
  "vehicles": [
    {
      "id": "vehicle_1",
      "start": {"latitude": 41.0082, "longitude": 28.9784},
      "time_window": ["06:00:00", "20:00:00"],
      "breaks": [
        {
          "time_windows": [["12:00:00", "13:00:00"]],
          "service": 2700,
          "description": "Lunch break"
        }
      ]
    }
  ],
  "jobs": [...],
  "options": {"minimize": "distance"}
}

5. Capacity-Typed Scenario

Usage with different capacityType values:

{
  "vehicles": [
    {
      "id": "truck_1",
      "start": {"latitude": 41.0082, "longitude": 28.9784},
      "constraints": {
        "capacity": 24,
        "capacityType": "pallet"
      }
    }
  ],
  "jobs": [
    {
      "id": "job_1",
      "start": {"latitude": 41.0100, "longitude": 28.9800},
      "end": {"latitude": 41.0150, "longitude": 28.9850},
      "amount": 4,
      "amount_type": "pallet"
    },
    {
      "id": "job_2",
      "start": {"latitude": 41.0110, "longitude": 28.9810},
      "end": {"latitude": 41.0160, "longitude": 28.9860},
      "amount": 6,
      "amount_type": "pallet"
    }
  ],
  "options": {"minimize": "distance"}
}

6. Comprehensive Example

Example including all features:

{
  "vehicles": [
    {
      "id": "vehicle_1",
      "start": {"latitude": 41.0082, "longitude": 28.9784},
      "end": {"latitude": 41.0082, "longitude": 28.9784},
      "time_window": ["08:00:00", "18:00:00"],
      "skills": [1, 2],
      "breaks": [
        {
          "time_windows": [["12:00:00", "13:00:00"]],
          "service": 2700
        }
      ],
      "constraints": {
        "vehicleType": "truck",
        "capacity": 5000,
        "capacityType": "weight_kg",
        "per_km": 5,
        "per_hour": 100
      }
    }
  ],
  "jobs": [
    {
      "id": "job_1",
      "start": {
        "latitude": 41.0100,
        "longitude": 28.9800,
        "service": 300,
        "time_windows": [["09:00:00", "12:00:00"]]
      },
      "end": {"latitude": 41.0150, "longitude": 28.9850},
      "amount": 500,
      "amount_type": "weight_kg",
      "priority": 80,
      "skills": [1]
    }
  ],
  "options": {
    "minimize": "cost",
    "timeout": 30,
    "avoid_tolls": false
  }
}

Optimize Examples — Flio.ai

Next Steps