Inspiration

The project is inspired by the rapid growth of e-commerce and the global push toward sustainable transportation in 2025. Urban areas face increasing congestion, air pollution, and inefficiencies in last-mile delivery, exacerbated by the transition to EV fleets. Traditional routing tools often overlook EV-specific constraints like battery range and charging needs, leading to downtime, higher costs, and missed sustainability goals. This solution exists to bridge these gaps, leveraging AI and automated data pipelines to create smarter, greener logistics systems. It draws from real-world trends, such as the rise in EV adoption driven by policies like the EU's Green Deal and the US Inflation Reduction Act, and aims to make advanced optimization accessible beyond large enterprises.

What it does

The "AI-Optimized Urban Freight Routing for Electric Delivery Fleets" is an end-to-end AI application that optimizes delivery routes for EV fleets in urban logistics. It integrates real-time and static EV charging data from the NREL Nearest Stations API with traffic information from TomTom APIs (Incident Details and Flow Segment Data) to generate efficient, sustainable routes that minimize delays, emissions, and operational costs. Key functionalities include: accepting user shipment details (origin, destination, vehicle range, payload); combining static charger locations with real-time traffic incidents and flow speeds; using predictive AI to forecast delays and generative AI to suggest low-emission alternatives; and visualizing optimized routes on interactive maps with estimated time savings and emissions reductions.

How we built it

We built the project using Python 3.12 with uv as the package manager for dependencies. The core is a custom Fivetran connector (using Fivetran SDK) that ingests novel data sources: TomTom for traffic incidents (v5) and flow (v4), and NREL Nearest Stations (v1) for EV chargers. Data is loaded into Google BigQuery for ETL, where geospatial joins and feature engineering prepare it for analysis (e.g., ST_GEOGPOINT for locations). Vertex AI handles optimization: AutoML for time-series forecasting of delays and Gemini for generative route suggestions. The UI is a Streamlit dashboard with Google Maps integration. We used ruff for linting/formatting (via ruff.toml with PEP 8 compliance), pytest for testing with coverage (pytest-cov), and Redis for caching/rate limiting in the connector. Environment variables are managed via python-dotenv in a .env file. Scripts for linting (check_or_fix_linting.py), building with format (build_with_format.py), and running (run_project.py) streamline development. GitHub Actions enforce linting and coverage on push/PR.

Challenges we ran into

Integrating disparate APIs posed challenges: TomTom's rate limits (60/min) and NREL's (1000/hr) required Redis caching and custom rate limiting to avoid quota breaches during syncs. Aligning project structure for Fivetran's SDK (e.g., package naming, init.py files) led to ModuleNotFoundError issues, resolved by restructuring into ev_freight_router/ subpackage. BigQuery geospatial queries needed optimization for joins between traffic points and station locations. Vertex AI model training on simulated data required careful feature engineering to avoid hallucinations in generative outputs. Managing environment variables securely without hardcoding keys involved python-dotenv, but ensuring consistency across scripts and CI was tricky. Ruff.toml configuration conflicts with docstring conventions (e.g., Google style vs. D203/D212 rules) caused errors, fixed by explicit ignores. Overall, balancing hackathon timeline with robust testing/coverage was demanding.

Accomplishments that we're proud of

We're proud of building a fully functional custom Fivetran connector that ingests novel data sources (TomTom traffic and NREL chargers) with caching and incremental sync, enabling seamless ELT to BigQuery. Achieving 90%+ test coverage with pytest-cov and enforcing code quality via ruff linting in GitHub Actions demonstrates robust engineering. The BigQuery geospatial optimizations and Vertex AI integration deliver tangible impacts: simulations show 15-20% emissions reduction per trip and 10-25% cost savings. Deploying a responsive Streamlit UI with interactive Google Maps visualizations, all within a hackathon timeframe, highlights our efficient workflow using uv and scripts for build/run. Aligning with sustainability goals (e.g., supporting net-zero initiatives) while democratizing AI for SMEs in a $1.5T market is a key achievement.

What we learned

We learned the intricacies of Fivetran's Connector SDK for custom ETL from unsupported APIs, including schema inference and incremental syncs with cursors. Integrating geospatial data in BigQuery (e.g., ST_DISTANCE for route scoring) deepened our understanding of spatial analysis. Working with rate-limited APIs like TomTom and NREL taught us caching strategies with Redis to ensure reliability. Ruff.toml configuration emphasized consistent code style enforcement, while pytest-cov highlighted the importance of coverage for AI pipelines. Managing secrets via python-dotenv and .env reinforced secure practices. Overall, combining Vertex AI's forecasting/generative models with traffic/charging data showed how AI amplifies sustainability in logistics, but requires careful handling of data freshness and model hallucinations.

What's next for AI-Optimized Urban Freight Routing for EV Delivery Fleets

Next, we'll expand the connector to support more APIs (e.g., Open Charge Map for global stations) and dynamic user locations via app inputs. Enhance Vertex AI with multi-agent simulations for scenario testing (e.g., "high traffic" vs. "low battery"). Integrate real-time Pub/Sub triggers in BigQuery for alerts on low chargers or incidents. Add production features like multi-user support in Streamlit and deployment to Google Cloud Run. Explore partnerships with logistics firms (e.g., UPS) for pilots, aiming for open-source contributions to Fivetran's ecosystem. Long-term: Scale to include weather APIs for range prediction and ML models for fleet utilization optimization.

Built With

  • python
  • fivetran-connector-sdk
  • google-cloud-bigquery
  • google-cloud-aiplatform
  • apache-beam[gcp]
  • streamlit
  • requests
  • redis
  • python-dotenv
  • pytest
  • pytest-cov
  • ruff
  • uv
  • tomtom-apis
  • nrel-api
  • google-maps-api

Built With

  • fivetran-connector-sdk
  • google-cloud-aiplatform
  • google-cloud-bigquery
  • python
  • redis
  • ruff
  • streamlit
  • uv
Share this project:

Updates