Sitemap
enefitit

Enefit IT is a publication where data scientist, software developers and energy technology experts share their knowledge and expertise about the energy technology.

Optimization of electric-vehicle charging adjusted by planned trips

10 min readNov 20, 2025

--

Press enter or click to view image in full size

Electric-vehicle trips planned by the driver significantly affect the charging schedule and result in the natural trade-off between charging cost and the comfort of vehicle usage. Here, we discuss several realistic use cases and show that charging cost may vary by up to an order of magnitude depending on the level of comfort required from the vehicle usage.

Nowadays, more and more electronic devices rely on rechargeable batteries as their main source of energy. These batteries can vary in capacity in a very wide range: from several Wh in a typical AAA battery to hundreds of MWh in large-scale or grid-connected storage systems. As a result, the cost of the battery recharge can be in some cases negligible, and in others extremely large. The good news is that the charging cost can often be influenced by users if they are able to choose when to charge their batteries. This is because electricity prices are usually volatile due to natural uncertainty in the electricity markets so that charging during off-peak hours is much less expensive than during peak periods.

At Enefit, we develop smart optimization algorithms that reduce the charging costs of batteries operating in various environments — such as smart homes of prosumers, grids with co-located generation assets, electric vehicles (EVs) on the go, to name a few. In this post, we focus on the latter scenario and discuss an EV whose driver has a list of planned trips to complete during the day, with the goal of achieving the lowest possible charging cost.

To make the analysis as realistic as possible, we take a single day, 3 September 2025, as an example, and assume that the EV charging price on that day equals the Nord Pool spot price plus a small fixed margin, as specified in the agreement with the electricity provider. We also assume V1G-type charger, i.e. EV can only charge (take energy from the grid) and cannot discharge (send energy back to the grid). Regarding the EV battery itself, we consider its capacity 40 kWh and charging power 10 kW. These values are typical of popular compact hatchbacks, such as Nissan Leaf or Renault Zoe.

To schedule EV charging against fluctuating electricity prices optimally, we use the optimization algorithm developed at Enefit. The core idea of the algorithm is to determine how much to charge on an hourly basis so that the overall electricity bill is minimized. Below, we analyze different charging schedules obtained under specific constraints representing the driver’s planned trips.

EV constantly connected to the charger

The most efficient way for an EV to achieve the lowest electricity bill is to stay connected to a charger for the whole day without interruptions. In this case, the algorithm can select the most profitable hours for charging.

Press enter or click to view image in full size

The image shows the charging prices during the day of interest (blue staircase line) and the optimal charging schedule, shown as the evolution of the EV battery’s state of charge (SOC, black line). Here we assume that before the optimization run, the initial SOC is always zero, while the final SOC is always set to fully charge the battery. The algorithm selected 12:00 — 15:59 to gradually charge the EV, as these hours are the cheapest. The net bill is 0.74 Eur for this scenario.

Compared to the batteries which may be constantly connected to the grid, the main purpose of an EV is to be on the go and thus disconnected from the charger. Therefore, the considered scenario is of minor interest to the EV driver. However, it serves as a lower bound for the charging cost.

One long trip

Let’s consider a scenario involving a single trip planned by an EV driver. We characterize the trip by two parameters:

  • duration of 11 consecutive hours, and
  • an expected energy loss of 7 kWh.

The starting hour of the trip is not specified. The optimization algorithm should determine the starting time of the planned trip such that, when the EV is connected to the charger, its charging schedule results in the lowest possible cost.

Press enter or click to view image in full size

In the plot, the shaded area indicates the hours identified by the algorithm as optimal for the EV to be driving. The white background shows the hours when the EV should be connected to the charger.

The SOC pattern suggests that the optimal schedule is as follows: charge 00:00–00:59, undertake the trip 01:00–11:59 and then recharge 12:00–15:59 until the battery is full. This outcome is intuitive. We want to take advantage of the most cost-effective charging period 12:00 — 15:59, so the journey must be completed before that time. It is also possible to schedule the journey after this low-price period; however, doing so consumes energy that must be replenished later in the day, when electricity prices are higher. As a result, this alternative leads to a higher total cost and is therefore suboptimal.

Along with the optimal schedule, we observe an increased charging cost of 1.49 Eur. The difference between 1.49 and 0.74 Eur, equal to 0.75 Eur, represents the amount paid to cover the 7 kWh of energy consumed during the trip.

Three short trips: office, shop, and kindergarten

Let’s assume that the single long journey considered in the previous scenario consists of three trips: to the office, to the shop, and to the kindergarten.

In the earlier case, we assumed that the EV driver completed these trips consecutively as the single long journey. Let’s now allow for pauses between the trips to enable recharging. We characterize the short trips as follows:

  • Office: duration of 8 consecutive hours, expected energy loss of 3 kWh
  • Shop: duration of 2 consecutive hours, expected energy loss of 3 kWh
  • Kindergarten: duration of 1 hour, expected energy loss of 1 kWh

The total duration and total energy loss of all three short trips are the same as for the single long journey considered previously.

Press enter or click to view image in full size

In the plot, the algorithm schedules these trips during the hours shown by the shaded rectangles. We expect that dividing a long journey into shorter ones can reduce the total cost, since short trips can be placed during local price peaks, while nearby off-peak hours can be used for recharging.

Get Artjom Vargunin’s stories in your inbox

Join Medium for free to get updates from this writer.

It should be noted that the optimization results strongly depend on the underlying logistics — specifically, how the trip destinations are connected to the charger by the road network.

Press enter or click to view image in full size

In this post, we consider trip-destination points arranged so that the EV always passes the charger when traveling between them, as shown in the left panel. The connectors between destinations represent roads, and their lengths are proportional to the corresponding journey energy losses.

In reality, the roads between destination points may not pass the charger, as illustrated in the right panel. In the example shown, there are two possible routes between the charger, office, and shop. One option consists of two separate trips — charger → office → charger and charger → shop → charger. The other option is a single continuous journey — charger → office → shop → charger. The former may differ from the latter in terms of total duration and corresponding energy loss, and therefore may result in different optimization outcomes. This aspect requires additional attention and will not be discussed further in this post.

Kindergarten trip at 8:00

In previous scenarios, the optimization tended to schedule EV trips during nighttime hours. Many EV drivers may find it undesirable.

To make the optimization more user-friendly and better reflect everyday routines, we introduce an option to mark certain trips as mandatory by specifying their fixed starting time. Mandatory trips are not optimized with respect to their start time; they are treated as strictly predefined.

Press enter or click to view image in full size

In our example, the morning trip to the kindergarten is defined as mandatory and set to start at 8:00. As shown in the image, this mandatory trip significantly alters the charging schedule: the long office trip is shifted to evening hours, whereas previously it was scheduled differently. Consequently, introducing mandatory trips can lead to an increase in charging costs.

Trips order: office, then shop

Another feature introduced to improve EV-driver comfort is the ability to specify the order of trips. In this example, we require the office trip to occur before the shopping trip.

Press enter or click to view image in full size

The image shows the resulting charging schedule, which includes the mandatory kindergarten trip and the requirement that shopping takes place after office work. The algorithm attempts to use local peak hours for the trips while respecting all given constraints. As a result, the total charging cost becomes twice as high compared to the previous example without trip ordering.

Kindergarten planned at 8:00, office at 10:00, shopping after 8:00

Similar to trip ordering, a trip can also be constrained by the time of day. In this case, the EV driver can specify the earliest hour at which a trip is allowed to start.

Press enter or click to view image in full size

We consider a scenario with mandatory trips to the kindergarten and the office, starting at 8:00 and 10:00 respectively, and a shopping trip that is allowed only after 8:00. Since trips cannot overlap, the shopping trip can occur only after 18:00. Under these constraints, the algorithm schedules the shopping trip at 19:00 in order to take advantage of local peak hours. As a result, the charging cost reaches 4.81 EUR.

Conclusion

Obtaining an EV charging schedule is not a straightforward optimization task, largely because of the unpredictable trips that EV drivers may undertake. As shown in this post, there is often a trade-off between minimizing charging costs and maintaining driver comfort. As usual, comfort is not free.

We demonstrate that everyday routines can significantly increase daily charging costs — from an initial 0.74 EUR up to 4.81 EUR in the scenario considered. This is a substantial shift and suggests that EV drivers have considerable potential to reduce their expenses by refining their planned trips.

Technical note

A key step in defining the optimization task is the formalization of the EV trip. We used Google’s open-source optimization suite OR-Tools to formulate the corresponding linear optimization problem. For each trip, we introduce two list-type variables as follows:

is_ev_away = [model.BoolVar(f'is_ev_away{i}') for i in time_idx] 
# e.g. [False, True, True, True, False] for trip starting at 2nd hour

ev_away_idx = [model.BoolVar(f'is_ev_away_idx{i}') for i in time_idx]
# e.g. [False, True, False, False, False] for trip starting at 2nd hour

The first list specifies the hours during which the EV is away, while the second identifies the trip’s starting hour, see comments in the code. Each element in these lists is an optimizable Boolean variable in the model. Using the trip’s predefined duration, we can then formulate the corresponding constraints.

model.Add(sum(ev_away_idx) == 1) 
model.Add(sum(is_ev_away) == duration)

The first constraint ensures that the trip can have only one starting hour, while the second enforces the predefined trip duration.

Additional constraints ensure that the elements of is_ev_away are True for consecutive hours by applying a linear mapping between the two lists. This topic is outside the scope of the present post.

In this section, we focus instead on ordering trips relative to one another or relative to a particular hour of the day. We introduced an ev_away_idx list, which—after the optimization is completed—identifies the index corresponding to the trip’s starting hour. Knowing this index allows us to impose constraints on the trip’s start time. In NumPy, this index would typically be obtained using the argmax function. The challenge here is to express the equivalent of the argmax operation in a form suitable for linear optimization. To address this, we introduce a set of auxiliary variables

ev_away_idx_value_aux = [model.BoolVar(f'ev_away_idx_value_aux{i}') for i in time_idx] 
# e.g. [False, True, True, True, True] for trip starting at 2nd hour

ev_away_idx_value = model.IntVar(0, len(time_idx)-1, 'ev_away_idx_value')
# e.g. 1 for trip starting at 2nd hour

We want to define the ev_away_idx_value_aux list so that it contains only True values for all hours at or after the trip’s starting hour. We also want ev_away_idx_value to equal the index at which ev_away_idx is True. This latter requirement is equivalent to computing argmax(ev_away_idx), which we implement through the following constraints

for i in time_idx: 
model.Add(ev_away_idx_value_aux[i] == sum(ev_away_idx[: i + 1]))
# ev_away_idx = [False, True, False, False, False] results in
# ev_away_idx_value_aux = [False, True, True, True, True]

model.Add(ev_away_idx_value == len(time_idx) - sum(ev_away_idx_value_aux))
# ev_away_idx_value_aux = [False, True, True, True, True] results in
# ev_away_idx_value = 1

The first constraint forces ev_away_idx_value_aux to satisfy its intended structure, while the second computes essentially argmax(ev_away_idx) by leveraging the length of the optimization window.

The benefit of having ev_away_idx_value is straightforward: it allows us to control the trip’s starting hour and to order multiple trips according to the EV driver’s plans.

--

--

Artjom Vargunin
Artjom Vargunin
enefitit
enefitit