Skip to content

Code Examples

This section provides comprehensive code examples for using Flio.ai API, demonstrating route calculation, vehicle routing optimization, and advanced generated model capabilities.

🎯 What You'll Find Here

Route API Examples

  • Multi-task routing: Calculate multiple routes in a single request
  • Waypoint routing: Add intermediate stops along your route
  • Alternative routes: Get multiple route options for comparison
  • Vehicle specifications: Truck routing with dimensions and hazardous goods
  • Route optimization: Minimize distance or duration
  • Feature avoidance: Avoid tunnels, ferries, toll roads, and more
  • Toll cost calculation: Get toll costs in multiple currencies

Optimize API Examples

  • Basic VRPTW: Vehicle Routing Problem with Time Windows
  • Multi-vehicle scenarios: Different vehicle types and capacities
  • Time window management: Strict delivery time constraints
  • Capacity optimization: Load balancing and vehicle utilization
  • Problem types: TSP, VRP, CVRP, VRPTW, PDP, MDHVRPTW

Generated Model Examples

  • Custom models: Using models generated through Flio.ai GPT
  • Industry-specific models: E-commerce, healthcare, construction
  • Constraint-specific models: Multi-depot, time-critical, capacity optimization
  • Advanced configurations: Custom parameters and multi-constraint handling

🚀 Getting Started

1. Choose Your Example Type

For Route API (Point-to-Point Navigation): - Calculate routes between specific locations - Ideal for turn-by-turn directions and navigation - Perfect for single or multiple route calculations - Use when you know your exact origin and destination

For Optimize API (Vehicle Routing Problems): - Solve complex multi-stop routing problems - Optimize assignment of jobs to multiple vehicles - Handle constraints like capacity, time windows, and priorities - Use when you need to plan efficient routes for fleets

For Generated Models: - Understand how models override standard parameters - Learn about model-specific configurations - Explore industry-specific use cases

2. Understand the Structure

Each example includes:

  • Complete payload: Ready-to-use JSON configuration
  • Python code: Full implementation with error handling
  • Response processing: How to handle and display results
  • Key differences: What changes when using models vs. standard API

3. Customize for Your Needs

  • Modify coordinates: Use your actual locations
  • Adjust constraints: Match your vehicle and job requirements
  • Test parameters: Experiment with different configurations
  • Scale up: Start small and expand gradually

🔧 Key Concepts

Route API Usage

  • Transport modes: Car, truck routing with different characteristics
  • Route optimization: Minimize distance or duration
  • Waypoints: Add intermediate stops along routes
  • Alternatives: Get multiple route options for comparison
  • Vehicle specifications: Length, width, height, axle count, hazardous goods
  • Feature avoidance: Avoid tunnels, ferries, tolls, seasonal closures
  • Toll calculations: Get toll costs in different currencies

Optimize API Usage

  • Problem types: TSP, VRP, CVRP, VRPTW, PDP, MDHVRPTW
  • Objectives: Distance, duration, cost, default
  • Solvers: Heuristic, mathematical
  • Constraints: Capacity, time windows, max distance, max tasks
  • Multi-vehicle: Assign jobs to multiple vehicles optimally

Generated Model Usage

  • Parameter override: problem, objective, solver are disabled
  • Custom logic: Business-specific algorithms and constraints
  • Advanced optimization: Specialized strategies for specific use cases
  • Performance tuning: Optimized for particular scenarios

💡 Best Practices

Code Organization

  1. Configuration section: Centralize API settings
  2. Payload structure: Organize vehicles, jobs, and options clearly
  3. Error handling: Implement robust response validation
  4. Response processing: Extract and display relevant information

Testing Strategy

  1. Start simple: Begin with basic examples
  2. Validate results: Ensure outputs match expectations
  3. Test edge cases: Try different data sizes and configurations
  4. Performance testing: Monitor response times and resource usage

Production Integration

  1. Environment variables: Secure API key management
  2. Rate limiting: Respect API usage limits
  3. Monitoring: Track success rates and performance
  4. Error logging: Capture and analyze failures

🚀 Next Steps

  1. Review examples: Understand the different APIs and approaches
  2. Choose your path: Route API for navigation, Optimize API for fleet routing, or generated models for custom solutions
  3. Start coding: Use examples as templates
  4. Customize: Adapt to your specific requirements
  5. Test thoroughly: Validate with real data
  6. Scale up: Expand to production use

These examples provide a solid foundation for building routing and optimization solutions with Flio.ai API. Whether you need simple point-to-point navigation or complex fleet optimization, start simple, learn the patterns, and gradually implement more complex scenarios.