Skip to main content
emobility.academy
M.TechCharging & gridAdvanced About 8 weeksMATLAB & Simulink

Smart Charging Scheduling under Time-of-Use Tariffs

Formulate and solve an optimisation that schedules charging for a fleet of EVs under a time-of-use tariff, a site power limit and each vehicle's departure deadline. The study compares linear and mixed-integer formulations with uncontrolled charging on cost, peak demand and deadline compliance.

Tools: MATLAB · Optimization Toolbox

Smart Charging Scheduling under Time-of-Use Tariffs: Learners at an EV charging panel trainer in a DIYguru workshop
Representative photo from DIYguru's EV lab, not of this specific project.

The problem

Depots and apartment complexes pay more for electricity at peak times and often have a limited connection capacity. If every EV starts charging on arrival, cost and peak demand are both high. Scheduling can shift charging to cheaper hours while still meeting every driver's departure time. This is a classic optimisation problem that students can formulate, solve and test properly.

Objectives

  • Formulate the scheduling problem with decision variables, constraints and a cost objective.
  • Solve it as a linear program and as a mixed-integer program with discrete charger power levels.
  • Compare cost, peak demand and deadline compliance with uncontrolled charging.
  • Test robustness to uncertain arrival times and energy needs.
  • Report solve time as fleet size grows.

What you need

Tools and toolboxes

  • MATLAB — Data generation, scenario handling, plotting and the rolling-horizon loop.
  • Optimization Toolbox — Problem-based formulation with optimproblem and optimvar, solved with linprog and intlinprog.
  • Parallel Computing Toolbox — Optional: parfor for the fleet-size and uncertainty runs. An ordinary for loop gives the same results, only more slowly.

Software

  • MATLAB R2023b or later
  • A time-of-use tariff structure from the user's local utility, or example values
  • Fleet arrival and departure data in CSV, real or synthetic

Extra parts and data

None beyond the software above.

Key concepts

Time-of-use tariff
Electricity price varies by time band, for example a higher peak rate in the evening and a lower rate at night. Shifting energy to cheaper bands lowers cost without reducing energy.
Linear program
An optimisation with a linear objective and linear constraints over continuous variables. It solves quickly and gives a global optimum, which makes it a good first formulation.
Mixed-integer program
Adds integer or binary variables, here to model chargers that can only run at fixed power levels or be on or off. It is more realistic but harder to solve.
Rolling horizon
The schedule is re-optimised at each time step with the latest information, and only the first step is applied. It handles uncertain arrivals without needing perfect foresight.

Step-by-step guide

  1. 1

    Define the scenario

    Use an example depot with 30 EVs, 7.4 kW chargers, a 120 kW site limit and a time-of-use tariff with three bands. Vehicles arrive between 17:00 and 21:00 and depart between 06:00 and 09:00, each needing 15–40 kWh. Use a 15-minute time step over 16 hours (64 steps). Generate synthetic data with a fixed seed, or load real fleet data if available.

    Checkpoint: A table of vehicles with arrival, departure and energy need, plus a tariff plot.

  2. 2

    Build the uncontrolled baseline

    Simulate each vehicle charging at full power from arrival until its energy is met, then sum site power. Compute total cost, peak demand and whether the site limit is exceeded. Check that all vehicles finish. This baseline is what the optimisation must beat, so make sure it is computed exactly as described. Apply the same charging efficiency to the baseline as to the optimisation, so the comparison is on equal terms. Record each vehicle's finish time so slack in its window can be seen.

    Checkpoint: A baseline site-power curve with an evening peak, its total cost and peak value.

  3. 3

    Formulate the LP

    Using the problem-based workflow, create P = optimvar('P',N,T,'LowerBound',0,'UpperBound',Pmax). Set P to zero outside each vehicle's availability window. Constraints: sum over t of P(i,t)·Δt·η equals the energy need for each vehicle; sum over i of P(i,t) at most the site limit for each t. Objective: sum over t of price(t)·sum over i of P(i,t)·Δt. Solve with solve(prob), which calls linprog. Write the problem with the problem-based workflow rather than building matrices by hand; it is easier to read and check. Inspect the formulation with show or write before solving.

    Checkpoint: The solver returns an optimal exit flag, every vehicle's energy constraint holds within tolerance and site power never exceeds the limit.

  4. 4

    Analyse the LP solution

    Plot the site power profile against the tariff. Most charging should move to the cheapest band. Compute cost savings and peak reduction versus the baseline. Inspect a few individual schedules. Note any vehicles with tight windows that are forced to charge during expensive periods, and check the dual values of the site-limit constraint to see when the limit binds. Note that LP solutions are often not unique when several hours share the same price, so individual schedules can look arbitrary while total cost is the same.

    Checkpoint: A plot showing charging concentrated in the low-price band and a cost lower than the baseline.

  5. 5

    Add peak-demand charges

    Many commercial tariffs include a charge on the maximum demand. Add an auxiliary variable Pmax_site with constraints sum over i of P(i,t) at most Pmax_site for every t, and add demand_rate times Pmax_site to the objective. Solve again and compare. The schedule should spread charging more evenly across the cheap band. Use an example demand rate and state it clearly. Plot the energy-only and demand-charge site profiles together so the flattening of the peak is easy to see.

    Checkpoint: Peak site power falls compared with the energy-only LP, with a small change in energy cost.

  6. 6

    Formulate the MILP

    Model chargers that operate at discrete levels, for example 0, 3.7 or 7.4 kW. Introduce binary variables for each level and require exactly one per vehicle per step. Solve with intlinprog and set a relative gap tolerance and a time limit. Compare cost with the LP; the LP gives a lower bound on the MILP cost. Report the final relative gap and the solve time. If the solver hits the time limit, state the best bound and the best feasible solution separately rather than presenting the result as optimal.

    Checkpoint: MILP cost equal to or slightly above the LP cost, with every power value at an allowed level.

  7. 7

    Scale-up and solve time

    Run fleets of 10, 30, 100 and 300 vehicles. Record solve time and gap for LP and MILP. Plot solve time against fleet size. Note where MILP becomes too slow for 15-minute re-optimisation and discuss decomposition or heuristics as alternatives. Generate each larger fleet from the same distributions so the problems are comparable. Run each size several times with different random fleets, because solve time for integer programs varies a lot from one instance to the next, and plot the median with its range.

    Checkpoint: A solve-time plot showing LP times staying short while MILP grows faster with fleet size.

  8. 8

    Handle uncertainty with rolling horizon

    Implement a rolling-horizon loop: at each step, re-solve the LP for vehicles currently known and present, apply the first-step powers, update energy remaining and advance. Add arrival-time noise and energy-need noise so the plan must adapt. Compare cost and deadline misses against the perfect-foresight LP. Generate the noisy actual arrivals and energy needs separately from the forecasts the controller sees, with a fixed seed, so the same uncertainty can be applied to every method and the comparison stays fair.

    Checkpoint: Rolling-horizon cost slightly above perfect foresight, with zero or a reported small number of unmet deadlines.

  9. 9

    Report

    Present the formulation in equations, the baseline, LP, demand-charge LP, MILP and rolling-horizon results in one comparison table: cost, peak, deadline compliance and solve time. Discuss practical limits: tariff data accuracy, charger communication and driver behaviour. Explain how a site operator would use the method. Include the full mathematical formulation in a table of sets, variables, parameters, constraints and objective, so another student could rebuild it from the report alone without the code.

    Checkpoint: A comparison table with all methods and a clear recommendation backed by numbers.

Testing & validation

  • Every vehicle's energy constraint satisfied within solver tolerance.
  • Site limit never exceeded in any optimised schedule.
  • MILP cost bounded below by LP cost.
  • Rolling-horizon results reported against perfect foresight.

Expected results

A set of working LP and MILP scheduling formulations with a rolling-horizon controller, compared with uncontrolled charging on cost, peak demand, deadline compliance and solve time.

Research angle for your M.Tech thesis

Research questions: how much of the perfect-foresight saving does a rolling-horizon LP retain under realistic arrival uncertainty, and when is the extra realism of discrete charger levels worth the MILP solve time? Baselines: uncontrolled charging and a simple rule (start at the cheapest band). Metrics: energy and demand cost, peak, unmet energy and solve time. Real depot data, or a public charging-session dataset if available, would strengthen the claims. A careful comparison on real data with a sensitivity study on uncertainty could support a conference paper.

Take it further

  • Add on-site PV and a stationary battery to the optimisation.
  • Add battery degradation cost to the objective.
  • Use stochastic or robust optimisation for uncertain arrivals.
  • Add V2G discharge as a decision variable.

Viva and review questions

Why is the LP solution a lower bound for the MILP?

The LP allows any power between limits, which includes every discrete schedule. The best continuous schedule is therefore at least as cheap as the best discrete one.

What does a non-zero dual value on the site-limit constraint tell you?

That the limit is binding at that time step, and the dual value is how much total cost would fall per extra kW of site capacity at that step.

Why use a rolling horizon rather than one day-ahead solve?

Arrival times and energy needs are uncertain. Re-optimising as information arrives adapts the schedule without needing perfect forecasts.

Learn it at DIYguru

These DIYguru courses and programmes teach what this project needs.

Related EV projects

All 100 MATLAB & Simulink EV projects