> ## Documentation Index
> Fetch the complete documentation index at: https://stage-docs.getswitch.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Solve Multi-Fleet Routing (Two-Phase Greedy)

> Distribute a pool of operations across multiple vehicles (fleets) and compute an optimized route for each vehicle using a two-phase greedy approach:

1) Greedy assignment of tasks to vehicles with an affinity score
2) Single-vehicle route optimization reusing the existing solver

Constraints on capacities, time and space are preserved per-vehicle.

**Failure Modes:**
- **401**: Missing or invalid authentication credentials
- **403**: Insufficient permissions
- **422**: Invalid request data (coordinates, capacities, fleet config)
- **500**: Routing optimization failure or internal error

**Required Auth Scopes:**
- `redistribution:read`



## OpenAPI

````yaml /api-reference/openapi.json post /operations/routing/multi-fleet
openapi: 3.1.0
info:
  title: SWITCH API
  version: '1.0'
  description: >-
    The SWITCH API gives mobility and logistics teams programmatic access to
    SWITCH forecasts, fleet operations, routing and analytics. Every request is
    authenticated with an API key sent as a bearer token.
servers:
  - url: https://stage-api.getswitch.io
    description: Stage
security: []
tags:
  - name: Forecast
    description: Demand forecasts per zone and time window.
  - name: Operations
    description: Fleet imbalance, rebalancing suggestions and generated tasks.
  - name: Routing
    description: Route optimisation for single and multiple fleets.
  - name: Routing Sessions
    description: Saved routing sessions, their routes and drivers.
  - name: Routing Operations
    description: Complete, undo and re-route the stops of a route.
  - name: Fleet Management
    description: Your depots, stations, drivers and cargo vehicles.
  - name: Integrations
    description: Vehicles, statuses and commands on your fleet platform.
  - name: Station Based Analytics
    description: Analytics for station-based (docked) services.
  - name: Zone Based Analytics
    description: Analytics for free-floating services, by zone.
  - name: Free Float Analytics
    description: Trip history for free-floating services.
  - name: Transit Analytics
    description: Punctuality and service delivery for public transit.
  - name: Live
    description: Real-time fleet, delivery and transit status.
  - name: Grids
    description: Spatial grids used by forecasts and analytics.
  - name: API Keys
    description: Create and manage the API keys you call this API with.
paths:
  /operations/routing/multi-fleet:
    post:
      tags:
        - Routing
      summary: Solve Multi-Fleet Routing (Two-Phase Greedy)
      description: >-
        Distribute a pool of operations across multiple vehicles (fleets) and
        compute an optimized route for each vehicle using a two-phase greedy
        approach:


        1) Greedy assignment of tasks to vehicles with an affinity score

        2) Single-vehicle route optimization reusing the existing solver


        Constraints on capacities, time and space are preserved per-vehicle.


        **Failure Modes:**

        - **401**: Missing or invalid authentication credentials

        - **403**: Insufficient permissions

        - **422**: Invalid request data (coordinates, capacities, fleet config)

        - **500**: Routing optimization failure or internal error


        **Required Auth Scopes:**

        - `redistribution:read`
      operationId: solve_multi_fleet_routing
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MultiFleetRoutingPayload'
        required: true
      responses:
        '200':
          description: >-
            Multi-fleet routing plan generated. Returns per-vehicle optimized
            routes with operation sequencing, timing, and a list of unassigned
            operations.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MultiFleetRoutingResponse'
        '401':
          description: Unauthorized. Token is missing or invalid.
        '403':
          description: Forbidden. Insufficient permissions.
        '422':
          description: >-
            Unprocessable Entity. Invalid request data such as invalid
            coordinates, negative capacities, or malformed fleet configuration.
        '500':
          description: Internal Server Error.
      security:
        - HTTPBearer: []
        - HTTPBearer: []
components:
  schemas:
    MultiFleetRoutingPayload:
      properties:
        fleets:
          items:
            $ref: '#/components/schemas/Fleet'
          type: array
          title: Fleets
          description: List of available vehicles/fleets
        operation_pool:
          items:
            $ref: '#/components/schemas/Operation'
          type: array
          title: Operation Pool
          description: Pool of operations to be distributed among fleets
        must_include_vehicles:
          items:
            type: string
          type:
            - array
            - 'null'
          title: Must Include Vehicles
          description: >-
            Optional list of vehicle IDs whose operations should be heavily
            prioritized across all fleets. Operations targeting a vehicle in
            this list have their profit multiplied by 1000, making them very
            likely to be assigned and included in the optimized routes.
      type: object
      required:
        - fleets
        - operation_pool
      title: MultiFleetRoutingPayload
      description: Payload for multi-fleet routing optimization.
      examples:
        - fleets:
            - end_point:
                latitude: 45.4781
                longitude: 9.2272
              id: van-1
              max_capacities:
                charged_battery: 10
                empty_battery: 10
                vehicles: 4
              max_duration: 120
              start_capacities:
                charged_battery: 10
                empty_battery: 0
                vehicles: 0
              start_point:
                latitude: 45.4781
                longitude: 9.2272
              start_time: '2026-11-30T08:00:00Z'
            - end_point:
                latitude: 45.4781
                longitude: 9.2272
              id: van-2
              max_capacities:
                vehicles: 6
              max_duration: 90
              start_capacities:
                vehicles: 0
              start_point:
                latitude: 45.4781
                longitude: 9.2272
              start_time: '2026-11-30T08:00:00Z'
          operation_pool:
            - additional_notes: Battery level (12.0%) below threshold (20.0%)
              generated_at: '2026-11-30T07:55:00Z'
              latitude: 45.4642
              longitude: 9.1856
              operation_type: battery_swap
              priority: high
              priority_value: 2.4
              vehicle_id: acme-sc-0193
              vehicle_properties:
                battery_level: 12
                id: acme-sc-0193
                last_moved: '2026-11-30T06:41:03Z'
                last_seen: '2026-11-30T07:50:12Z'
                lat: 45.4642
                licence_plate: SC0193
                lon: 9.1856
                status: available
                vehicle_model: S-200
                vehicle_type: scooter
              zone_id: '1042'
            - additional_notes: 'Zone surplus 1.0 vehicles (threshold: 1.5)'
              generated_at: '2026-11-30T07:55:00Z'
              latitude: 45.4671
              longitude: 9.1883
              operation_type: pickup
              priority: medium
              priority_value: 2.1
              valid_from: '2026-11-30T08:00:00Z'
              valid_until: '2026-11-30T09:00:00Z'
              vehicle_id: acme-sc-0457
              zone_id: '1042'
            - additional_notes: 'Zone deficit 1.2 vehicles (threshold: -2.0)'
              generated_at: '2026-11-30T07:55:00Z'
              latitude: 45.4645
              longitude: 9.1992
              operation_type: dropoff
              priority: high
              priority_value: 4.8
              valid_from: '2026-11-30T09:00:00Z'
              vehicle_id: acme-sc-0457
              zone_id: '1043'
    MultiFleetRoutingResponse:
      properties:
        fleet_plans:
          items:
            $ref: '#/components/schemas/FleetRoutingPlan'
          type: array
          title: Fleet Plans
          description: Individual routing plans for each fleet
        unassigned_operations:
          items:
            $ref: '#/components/schemas/Operation'
          type: array
          title: Unassigned Operations
          description: Operations that couldn't be assigned to any fleet
        total_profit:
          type: number
          title: Total Profit
          description: Sum of profits from all fleet routes
      type: object
      required:
        - fleet_plans
        - total_profit
      title: MultiFleetRoutingResponse
      description: Response for multi-fleet routing optimization.
      examples:
        - fleet_plans:
            - fleet_id: van-1
              plan:
                - expected_arrival: '2026-11-30T08:14:00Z'
                  operation:
                    additional_notes: Battery level (12.0%) below threshold (20.0%)
                    generated_at: '2026-11-30T07:55:00Z'
                    latitude: 45.4642
                    longitude: 9.1856
                    operation_type: battery_swap
                    priority: high
                    priority_value: 2.4
                    vehicle_id: acme-sc-0193
                    vehicle_properties:
                      battery_level: 12
                      id: acme-sc-0193
                      last_moved: '2026-11-30T06:41:03Z'
                      last_seen: '2026-11-30T07:50:12Z'
                      lat: 45.4642
                      licence_plate: SC0193
                      lon: 9.1856
                      status: available
                      vehicle_model: S-200
                      vehicle_type: scooter
                    zone_id: '1042'
                  routing_parameters:
                    capacity_delta:
                      charged_battery: -1
                      empty_battery: 1
                    profit: 2.4
                  step: 0
              total_distance: 7.9
              total_duration: 41
              total_profit: 2.4
              utilization:
                charged_battery: 10
                empty_battery: 1
                vehicles: 0
            - fleet_id: van-2
              plan:
                - expected_arrival: '2026-11-30T08:23:00Z'
                  operation:
                    additional_notes: 'Zone surplus 1.0 vehicles (threshold: 1.5)'
                    generated_at: '2026-11-30T07:55:00Z'
                    latitude: 45.4671
                    longitude: 9.1883
                    operation_type: pickup
                    priority: medium
                    priority_value: 2.1
                    valid_from: '2026-11-30T08:00:00Z'
                    valid_until: '2026-11-30T09:00:00Z'
                    vehicle_id: acme-sc-0457
                    zone_id: '1042'
                  routing_parameters:
                    capacity_delta:
                      vehicles: 1
                    profit: 2.1
                  step: 0
                - expected_arrival: '2026-11-30T09:02:00Z'
                  operation:
                    additional_notes: 'Zone deficit 1.2 vehicles (threshold: -2.0)'
                    generated_at: '2026-11-30T07:55:00Z'
                    latitude: 45.4645
                    longitude: 9.1992
                    operation_type: dropoff
                    priority: high
                    priority_value: 4.8
                    valid_from: '2026-11-30T09:00:00Z'
                    vehicle_id: acme-sc-0457
                    zone_id: '1043'
                  routing_parameters:
                    capacity_delta:
                      vehicles: -1
                    profit: 4.8
                  step: 1
              total_distance: 10.6
              total_duration: 63.5
              total_profit: 6.9
              utilization:
                vehicles: 1
          total_profit: 9.3
          unassigned_operations: []
    Fleet:
      properties:
        id:
          type: string
          title: Id
          description: Unique identifier for the fleet/vehicle
        start_point:
          $ref: '#/components/schemas/Point'
          description: Starting point for this fleet/vehicle
        end_point:
          $ref: '#/components/schemas/Point'
          description: Ending point for this fleet/vehicle
        start_capacities:
          additionalProperties:
            type: integer
          propertyNames:
            enum:
              - vehicles
              - charged_battery
              - empty_battery
              - space
          type: object
          title: Start Capacities
          description: Initial capacities for this fleet/vehicle
        max_capacities:
          additionalProperties:
            type: integer
          propertyNames:
            enum:
              - vehicles
              - charged_battery
              - empty_battery
              - space
          type: object
          title: Max Capacities
          description: Maximum capacities for this fleet/vehicle
        start_time:
          type: string
          format: date-time
          title: Start Time
          description: Starting time for this fleet/vehicle
        max_duration:
          type: number
          title: Max Duration
          description: Maximum duration in minutes for this fleet/vehicle
        start_space:
          type: number
          title: Start Space
          description: Initial space available in the vehicle
          default: 10
        refill_capacities:
          additionalProperties:
            type: integer
          propertyNames:
            enum:
              - vehicles
              - charged_battery
              - empty_battery
              - space
          type:
            - object
            - 'null'
          title: Refill Capacities
          description: >-
            Total depot stock available for refilling across all stops. Positive
            values represent the total number of items at the depot; each refill
            loads the vehicle up to max_capacities, drawing from this stock
            until it is exhausted. Negative values mark capacities that are
            unloaded (dumped to 0) at the depot with no limit. Keys not present
            are left untouched.
          examples:
            - charged_battery: 68
              empty_battery: -1
        depot_service_time:
          type: number
          title: Depot Service Time
          description: >-
            Time in minutes the vehicle spends at depot per refill stop. Only
            used when refill_capacities is set.
          default: 5
        max_depot_refills:
          type:
            - integer
            - 'null'
          title: Max Depot Refills
          description: >-
            Maximum number of depot refill stops allowed. None means unlimited
            (bounded by max_duration). 0 disables the feature.
      type: object
      required:
        - id
        - start_point
        - end_point
        - start_capacities
        - max_capacities
        - start_time
        - max_duration
      title: Fleet
      description: Represents a vehicle/fleet in a multi-fleet routing scenario.
    Operation:
      properties:
        vehicle_id:
          type:
            - string
            - 'null'
          title: Vehicle Id
          description: >-
            Vehicle ID associated with the operation. Null for dropoffs
            generated by the suggestion strategies: a dropoff targets a zone,
            not a vehicle.
        latitude:
          type: number
          title: Latitude
          description: Latitude of the operation's location
        longitude:
          type: number
          title: Longitude
          description: Longitude of the operation's location
        zone_id:
          type: string
          title: Zone Id
          description: Zone ID where the operation is located
        operation_type:
          type: string
          title: Operation Type
          description: Type of operation, e.g., pickup, dropoff, or battery swap
        priority:
          type: string
          enum:
            - low
            - medium
            - high
            - must
          title: Priority
          description: Priority level of the operation, e.g., low, medium, or high
        priority_value:
          type: number
          minimum: 0
          title: Priority Value
          description: >-
            Continuous profit value used by the routing solver. Computed by
            suggest strategies as base_profit_for_op_type * urgency_factor
            (urgency in [1.0, 2.0]). The 'priority' enum is metadata only,
            except 'must' which still triggers hard-include.
        additional_notes:
          type:
            - string
            - 'null'
          title: Additional Notes
          description: >-
            Free-text notes about the operation, e.g. imbalance deficit or idle
            time.
        battery_level:
          type:
            - number
            - 'null'
          title: Battery Level
          description: Current battery level of the vehicle, if applicable
        generated_at:
          type: string
          format: date-time
          title: Generated At
          description: Timestamp when the operation was generated
        valid_from:
          type:
            - string
            - 'null'
          format: date-time
          title: Valid From
          description: Start of the validity window for this operation
        valid_until:
          type:
            - string
            - 'null'
          format: date-time
          title: Valid Until
          description: End of the validity window for this operation
        vehicle_properties:
          $ref: '#/components/schemas/VehicleWithoutZone'
          description: >-
            Full vehicle snapshot at the time the operation was generated.
            Serializable to VehicleWithoutZone. Populated by suggest strategies
            and preserved through the routing response so callers can persist it
            to the DB.
      type: object
      required:
        - vehicle_id
        - latitude
        - longitude
        - zone_id
        - operation_type
        - priority
        - priority_value
        - generated_at
      title: Operation
      description: |-
        Represents an operation to be performed.

        This schema includes details such as the operation's location, type,
        priority, and associated vehicle.
      examples:
        - additional_notes: 'Zone surplus 1.0 vehicles (threshold: 1.5)'
          generated_at: '2026-11-30T07:55:00Z'
          latitude: 45.4671
          longitude: 9.1883
          operation_type: pickup
          priority: medium
          priority_value: 2.1
          valid_from: '2026-11-30T08:00:00Z'
          valid_until: '2026-11-30T09:00:00Z'
          vehicle_id: acme-sc-0457
          zone_id: '1042'
    FleetRoutingPlan:
      properties:
        fleet_id:
          type: string
          title: Fleet Id
          description: ID of the fleet/vehicle
        plan:
          items:
            $ref: '#/components/schemas/RoutingStep'
          type: array
          title: Plan
          description: Ordered routing steps for this fleet
        total_profit:
          type: number
          title: Total Profit
          description: Total profit achieved by this fleet's route
        total_duration:
          type: number
          title: Total Duration
          description: Total duration of this fleet's route in minutes
        total_distance:
          type: number
          title: Total Distance
          description: Total distance of this fleet's route in kilometers
        utilization:
          additionalProperties:
            type: integer
          propertyNames:
            enum:
              - vehicles
              - charged_battery
              - empty_battery
              - space
          type: object
          title: Utilization
          description: >-
            Maximum capacity usage for each capacity type during this fleet's
            route
          examples:
            - charged_battery: 6
              empty_battery: 4
              vehicles: 8
      type: object
      required:
        - fleet_id
        - plan
        - total_profit
        - total_duration
        - total_distance
      title: FleetRoutingPlan
      description: Routing plan for a single fleet/vehicle.
    Point:
      properties:
        latitude:
          type: number
          title: Latitude
        longitude:
          type: number
          title: Longitude
      type: object
      required:
        - latitude
        - longitude
      title: Point
      description: Represents a geographical point with latitude and longitude.
    VehicleWithoutZone:
      properties:
        id:
          type: string
          title: Id
          description: Unique identifier for the vehicle
        licence_plate:
          type:
            - string
            - 'null'
          title: Licence Plate
          description: Licence plate number of the vehicle
        lat:
          type:
            - number
            - 'null'
          title: Lat
          description: Latitude of the vehicle's current location
        lon:
          type:
            - number
            - 'null'
          title: Lon
          description: Longitude of the vehicle's current location
        vehicle_type:
          type:
            - string
            - 'null'
          title: Vehicle Type
          description: Type of the vehicle, e.g., 'scooter', 'bike', 'car'
        vehicle_model:
          type:
            - string
            - 'null'
          title: Vehicle Model
          description: Model of the vehicle, e.g., 'Model X', 'Model Y'
        battery_level:
          type:
            - integer
            - 'null'
          title: Battery Level
          description: Battery level of the vehicle, e.g., 100 for 100%
        battery_level_master:
          type:
            - integer
            - 'null'
          title: Battery Level Master
          description: >-
            Master battery level percentage (custom MDS setup only). None when
            not reported by the provider.
        last_seen:
          type:
            - string
            - 'null'
          format: date-time
          title: Last Seen
          description: Timestamp of the last time the vehicle was seen in the system
        last_moved:
          type:
            - string
            - 'null'
          format: date-time
          title: Last Moved
          description: Timestamp of the last time the vehicle moved
        status:
          type:
            - string
            - 'null'
          title: Status
          description: Current status of the vehicle, e.g., 'available', 'in-use'
      type: object
      required:
        - id
        - battery_level
      title: VehicleWithoutZone
      description: >-
        Represents a vehicle without zone assignment.


        Base schema containing all vehicle attributes except zone_id.

        Used when a grid service is not available and spatial zone mapping is
        skipped.
    RoutingStep:
      properties:
        operation:
          $ref: '#/components/schemas/Operation'
          description: Operation to be performed in this step
        step:
          type: integer
          title: Step
          description: Step number in the redistribution plan
        expected_arrival:
          type: string
          format: date-time
          title: Expected Arrival
          description: Expected arrival time at the operation location
        routing_parameters:
          additionalProperties: true
          type: object
          title: Routing Parameters
          description: Routing parameters for this step
          examples:
            - capacity_delta:
                charged_battery: 0
                empty_battery: 0
                vehicles: 1
              profit: 3
      type: object
      required:
        - operation
        - step
        - expected_arrival
        - routing_parameters
      title: RoutingStep
      description: |-
        Represents a single step in a redistribution plan.

        This schema includes details about the vehicle, its target zone, and
        the operation to be performed.
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer
      description: >-
        An API key, sent as `Authorization: Bearer <key>`. Create one in the
        SWITCH Copilot under **Settings → API keys** (needs the API keys
        permission in your company), or with `POST /auth/api-keys`. The key is
        shown once, at creation.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.