The problem
Electric bus operators must complete a fixed timetable with buses whose range is limited and whose charging competes for a limited number of chargers and a capped grid connection. Charging at the wrong time raises energy cost and demand charges; charging too little strands a bus. Scheduling is a mixed-integer optimisation that is small enough to solve exactly for one route yet rich enough for an M.Tech thesis.
Objectives
- Model trip energy for each bus from route data and a consumption model.
- Formulate a mixed-integer linear programme for charger assignment and charging power.
- Solve it with intlinprog under SOC, charger and grid-power constraints.
- Compare with an uncontrolled 'charge on arrival' baseline.
- Study the effect of battery size, charger count and tariff structure.
What you need
Tools and toolboxes
- MATLAB — Timetable and energy data handling, constraint construction and result plots.
- Optimization Toolbox — Problem-based optimisation (optimproblem) solved with intlinprog for the mixed-integer schedule.
- Simulink (optional) — Re-simulating SOC along each bus's day with the chosen schedule and a longitudinal energy model.
Software
- MATLAB R2023b or later
- Optimization Toolbox
- CSV files for the timetable, trip distances and tariff
Extra parts and data
None beyond the software above.
Key concepts
- Time-of-day tariff
- Electricity price that varies by hour, often cheaper at night. Shifting charging into cheap hours lowers cost if SOC limits allow.
- Mixed-integer linear programme
- An optimisation with linear cost and constraints where some variables, here charger-assignment decisions, are binary. intlinprog solves it with branch-and-bound.
- Energy-balance constraint
- For each bus and time slot, SOC at the next slot equals SOC now plus charged energy times efficiency minus trip energy, all divided by capacity.
- Demand charge
- A cost based on the peak power drawn in a billing period. Including it, or a grid-power cap, spreads charging over time.
Step-by-step guide
- 1
Define the example route and fleet
Set up an example route of 25 km per one-way trip, eight buses, a timetable from 06:00 to 22:00 with 20-minute layovers at the terminal, and example buses with 250 kWh packs. Allow charging at the depot overnight (four 60 kW chargers) and at the terminal during layovers (one 150 kW charger). Set a grid limit at the depot and an example two-band tariff. Store the timetable as a MATLAB table.
Checkpoint: A Gantt-style plot of bus activity across the day showing trips, layovers and depot time.
- 2
Estimate trip energy
Estimate energy per trip with a consumption model, for example 1.0 to 1.3 kWh/km for a 12 m bus depending on load and air-conditioning, or by running a longitudinal model in Simulink on a bus-style cycle with stop frequency matched to the route. Add a margin for traffic. Store energy per trip per bus in the timetable. Note the source and assumptions clearly, because the schedule depends on them.
Checkpoint: Trip energies in a sensible range, with total daily energy per bus less than usable battery energy plus feasible charging.
- 3
Discretise time
Divide the day into 15-minute slots. For each bus and slot, mark whether it is on a trip, at the terminal or at the depot. Charging is only allowed at a location with a charger. Build availability matrices that will become bounds on the charging variables. Check that the slot length is short enough to represent a 20-minute layover usefully.
Checkpoint: Availability matrices whose total counts match the timetable's layover and depot hours.
- 4
Formulate with the problem-based approach
Create optimvar variables: charging power P(bus, slot) at each location, continuous with upper bound set by availability and charger rating, and binary assignment x(bus, slot). Link them with P ≤ P_max·x. Add charger count constraints: the sum of x at each location and slot must not exceed the number of chargers. Add SOC states with energy-balance equality constraints and bounds between 20 and 95 per cent.
Checkpoint: The problem displays with show() and the variable and constraint counts match a hand estimate.
- 5
Add the cost and grid limit
Set the objective as the sum over slots of tariff × charged energy. Add the depot grid-power limit as a constraint on total depot power in each slot. Optionally add a demand-charge variable D with total power ≤ D in every slot and D times its price in the objective. Require each bus's final SOC to be at least its starting SOC, so the schedule can repeat daily.
Checkpoint: The objective and constraints are linear, and the problem is classified as a MILP by the solver.
- 6
Solve and check feasibility
Solve with solve(), which calls intlinprog. Set a relative gap tolerance and a time limit. If infeasible, find which constraint group causes it by relaxing one at a time, for example terminal charger count. Record solve time and optimality gap. Plot SOC trajectories for every bus and charging power per charger. Also plot total depot power per slot against the grid limit, and check that charging moves into cheaper tariff hours where SOC limits allow.
Checkpoint: An optimal or near-optimal solution with all bus SOC trajectories inside limits.
- 7
Build the baseline
Simulate charge-on-arrival: each bus charges at full power whenever it reaches a free charger until full, with first-come first-served queuing. Compute cost, depot peak power and whether any bus falls below the SOC limit. This represents operation without scheduling and gives the comparison point. Use the same timetable, trip energies and starting SOC as the optimised case, and compute cost with the same tariff, so the comparison isolates the effect of scheduling alone.
Checkpoint: Baseline cost and peak power recorded, with the depot peak higher than the optimised schedule.
- 8
Verify by re-simulation
Take the optimised charging plan and re-simulate each bus's SOC with a finer time step, using actual trip energies with ±10 per cent random variation. Check how often SOC limits are violated. This tests whether the plan is robust to the uncertainty that the optimiser did not see, an important check before trusting it. Run at least a hundred random samples so the violation count is meaningful, and report the smallest SOC reached by any bus across all samples.
Checkpoint: A violation count under random variation, and a margin value that removes violations.
- 9
Scenario studies
Re-solve with smaller batteries (200 kWh), one fewer depot charger, a three-band tariff and a tighter grid limit. Tabulate cost, peak power and feasibility. Identify the binding constraint in each scenario from the dual values or by testing relaxations. These results are the practical insights for an operator. Report solve time for each scenario as well, since harder scenarios can take much longer and an operator may need to re-plan quickly when a bus breaks down.
Checkpoint: A scenario table identifying the binding constraint for each case.
- 10
Report
Document data sources and assumptions, the formulation with equations, solver settings, results against baseline, robustness test and scenarios. Be explicit that consumption, tariffs and timetable are example values. State the limitations: deterministic energy, no battery ageing and fixed slot resolution. Include the timetable, the optimisation script and the scenario settings as appendices, so the schedule and every table can be regenerated by another student with a different route.
Checkpoint: A report with the formulation, a cost and peak-power comparison and scenario insights.
Testing & validation
- Availability matrices match the timetable.
- Solver returns an optimal or bounded-gap solution with all constraints satisfied.
- Re-simulation with finer time steps and energy variation stays within SOC limits after adding margin.
- Optimised cost and peak power compared with charge-on-arrival.
Expected results
A MILP charging schedule for an example electric bus route that meets the timetable within SOC, charger and grid limits at lower energy cost and peak power than charge-on-arrival, with robustness and scenario studies.
Research angle for your M.Tech thesis
Research questions: how much cost and peak demand can optimised charging save over charge-on-arrival for a realistic Indian bus route, and how robust is that schedule to uncertain trip energy? Metrics: daily energy cost, depot peak power, SOC limit violations under variation, and solve time. Baselines: charge-on-arrival and a simple night-only heuristic. Using real or carefully justified timetable and consumption data, and quantifying robustness, strengthens the work. A robust or stochastic extension, with an honest comparison against the deterministic schedule, is a credible conference or journal contribution.
Take it further
- Add stochastic trip energy with a robust or chance-constrained formulation.
- Include battery ageing cost from depth of discharge.
- Add on-site solar generation at the depot.
- Jointly optimise bus-to-trip assignment with charging.
Viva and review questions
Why do you need binary variables?
The number of chargers limits how many buses can charge at once, which requires a yes or no assignment per bus and slot; continuous power alone cannot express that limit.
Why require final SOC to be at least the initial SOC?
Without it the optimiser could leave buses nearly empty at the end of the day to save cost, which would not repeat the next day.
How did you check the schedule is robust?
By re-simulating it with random variation in trip energy and counting SOC limit violations, then adding a margin until violations disappeared.
Learn it at DIYguru
These DIYguru courses and programmes teach what this project needs.
