Integrate Fetched Data with Route Optimization API
After successfully retrieving the necessary data from Motive, the next step is to integrate this data with the NextBillion.ai Route Optimization API.
Follow the steps below to map the fetched Motive data to the API parameters and configure the optimization settings.
Step 1: Map and Configure Parameters
First, prepare the data and configuration parameters. Here's an explanation of the key components:
- vehicles: Array to store vehicle data.
- shifts, starts, ends: Arrays for storing shift-related data.
- veh_attr, stop_attr: Arrays for vehicle and stop attributes.
- vehicle_index: Index to track vehicles.
- shiftStart, shiftEnd: Convert shift times to UNIX timestamp format.
Step 2: Build the Optimization Problem
Create job arrays and indexed lists of locations by iterating through all stops.
- location_index: Index to track locations.
- location: Array to store location data.
- jobs: Array to store job data including job ID, description, location index, and service time.
Step 3: Add Shift Start/End Locations
Include shift start and end locations in the index.
Step 4: Define Vehicles and Their Attributes
Configure vehicle-related data including start index, time window, maximum tasks, and fixed costs.
- veh_fixed_cost: Incremental cost associated with each vehicle.
- vehicles: Array to store vehicle details including ID, start index, time window, max tasks, and costs.
- locations: Object to store all locations.
- options: Configuration for routing mode.
Step 5: Store Data and Trigger Optimization
Store the configured data in local storage and trigger the optimization process.