# Charge stops planned on a curve, not a division

`POST /v1/ev/plan` answers the question an EV driver actually has: can this car make this journey, and where does it have to stop. It runs a physics consumption model over the route's own legs, integrates each charge session over the vehicle's charging curve rather than dividing energy by peak power, and picks stops so the state of charge never breaches the reserve floor. When no plan exists it answers `feasible: false` with the named cause and the furthest point the car can reach, rather than inventing one.

## Why is dividing energy by peak power wrong?

Because a DC charging session is a curve that tapers as the pack fills, and treating it as a rate is the single biggest error in naive EV trip planners. A 150 kW charge point does not deliver 150 kW from 20% to 80%. Take the rated figure as a rate and you will promise a driver a 20-minute stop that takes 35, and the error compounds across every stop in the journey.

So charge times here are integrated over the vehicle's own charging curve, capped by the charge point's rated power. The `stops[]` entries report `arrive_soc`, `depart_soc` and `charge_s` separately, so you can see what the model actually thought would happen rather than a single duration you have to trust.

## How does it plan?

The routing engine has no EV costing, so the whole planner is gateway-side, composing the existing `/route`, `/elevation` and `/matrix` machinery with a published physics model and the operator charge-point data the deployment ingests. The sequence:

1. **A base route** in `auto` costing, with your `costing_options` passed through verbatim.
2. **Leg sampling.** Each manoeuvre becomes one leg with its own length and average speed, which is finer than a leg summary and makes the steady-state consumption model better.
3. **Elevation, or an honest absence.** Where elevation is available, every leg boundary is sampled and each leg gets its real climb and fall. Where it is not, legs carry no gradient, consumption runs on the flat, and the response says `gradient_data: "absent"`. A gradient is never silently assumed to be zero, because "flat" and "we do not know" are different answers.
4. **The direct plan.** If the car arrives at or above `min_arrival_soc` without ever dropping below `reserve_soc`, that is the plan. No charger lookup and no matrix call happen at all.
5. **Candidates**, otherwise: charge points projected onto the route, kept only where the vehicle can plug in at a rated power inside the corridor, and capped spread along the route rather than ranked by power. A planner needs reach where a search needs kilowatts.
6. **One matrix per window**, so every hop's time and distance are engine-computed rather than a straight-line guess.
7. **Greedy with lookahead.** Stops are chosen so the charge never breaches `reserve_soc`, preferring a stop that finishes the journey, then the furthest one, then the cheapest by driving plus charging time. A charger from which nothing further can be reached even on a full battery is refused rather than taken, and that lookahead is what stops a greedy planner stranding a driver at the last charge point before a gap.
8. **The final geometry** is the route recomputed through the chosen stops, so what comes back is the journey actually described.

```sh
curl -fsS -X POST "https://api.mapmap.ai/v1/ev/plan" \
  -H "Authorization: Bearer $MAPMAP_API_KEY" -H "Content-Type: application/json" \
  -d '{"origin": {"lat": 51.50, "lon": -0.12},
       "destination": {"lat": 55.95, "lon": -3.19},
       "profile": "small_hatch",
       "start_soc": 0.9, "reserve_soc": 0.15,
       "connectors": ["ccs"], "min_kw": 50}'
```

`profile` is one of `small_hatch`, `saloon` (the default), `suv` or `van`, or an object of your own vehicle's parameters layered over a named base: `battery_kwh`, `usable_fraction`, `mass_kg`, `drag_area_m2`, `rolling_resistance_coefficient`, `drivetrain_efficiency`, `regen_efficiency`, `aux_kw`, `charge_curve` and `connectors`.

## What does it say when there is no plan?

A `200` with `feasible: false`, never an error to retry and never a fabricated plan.

```json
{
  "feasible": false,
  "plan": { "feasible": false, "stops": 0, "arrival_soc": null },
  "stops": [],
  "reason": {
    "code": "out_of_range",
    "message": "The next usable charge point is further away than the vehicle can travel before breaching the reserve state of charge. This is a gap in the corridor, not a routing failure."
  },
  "furthest_reachable": {
    "along_route_position": 0.889, "distance_m": 395111.1,
    "lat": 54.5556, "lon": -0.5
  }
}
```

`reason.code` is one of `no_chargers_in_corridor`, `connector_mismatch`, `chargers_unrated`, `below_min_kw`, `out_of_range`, `dead_end`, `stop_limit`, `no_charge_curve`, `dataset_empty` or `unroutable`. Those are different problems with different fixes, and collapsing them into one failure would leave a client with nothing to do but retry.

The `note` on an infeasible answer always carries the coverage statement, which names the operators whose charge points this deployment holds. That matters more than it sounds: an empty result means "none from these operators", never "no chargers here", and a planner that lets those two be confused will eventually tell somebody a road has no charging on it when it does.

## What are the numbers actually worth?

Bounded rather than tuned, and the response says so in a `provenance` block. The consumption model is a road-load decomposition in the form the UNECE WLTP regulation uses for chassis dynamometer setting, with constants from ISO 2533, the CGPM and the EU tyre-label classes. Against published motorway consumption for each default vehicle it reads within 15%, and consistently low.

Outside constant speed it is weaker. It does not model acceleration, so it under-reads stop-start driving. Charging curves are published best-case figures measured on a warm pack, so a cold one charges more slowly than the plan says. A hop's energy is sliced from the base route's legs, with the detour surplus charged as one gradient-unknown leg. And `power_kw_source` distinguishes a rating the operator declared from one derived from voltage, amperage and phases, so the two are never presented as the same thing; a charge point with no rated connector cannot be planned against at all, because a charge time cannot be invented for it.

## What it does not do

**It is a static planner over the operator feeds this deployment ingests.** There is no live bay availability, and the response says `status_live: false` rather than implying otherwise. Bring your own OCPI feed if you need to know whether the bay is free when you arrive.

**It does not price a stop.** It optimises for driving plus charging time, not for tariff. Ranking charge points along a route you have already decided you can drive is a different endpoint, `POST /v1/charging/along`, and it ranks them by highest charging power first, not by price. Cheapest-first ranking is for fuel, on `POST /v1/fuel/along`.

**It is `auto` costing only.** No truck profile, no ADR object, and consequently it is never priced as a premium call.

**It answers `501` where no charge-point directory is configured**, with `urn:sn-gateway:problem:charging-not-enabled`, which you can feature-detect on rather than discover in production.

## What it costs, and what you must display

One flat block of 10 standard calls per request. The planner fans out to at most two internal routes, one height request and one matrix window set, none of which is metered again, so the flat 10 is the whole bill for a journey plan. At the standard rate that is 0.5p.

Display the returned `charging_attribution` with the plan. It is a licence obligation, and a charge point whose operator carries no recorded attribution is dropped before it is ever served.

## Try it

The full parameter table, the response shape and the model's own citations are in the [EV route planning section of the analysis guide](/docs/analysis#ev-route-planning-post-v1evplan). Agents reach the same planner as the `plan_ev_route` tool on the [MCP server](/docs/mcp), which is how the app in [An EV charging app built on the public MapMap SDK](/news/agents-built-ev-app) would be built today. A plan is a plan, not a promise, and `gradient_data` tells you whether even the terrain was known.
