This section presents the proposed Hybrid AI-OCPP framework for city-scale EV charging. Figure 1 shows how city charging stations connect to the Hybrid AI and OCPP core. The framework integrates three components: a forecasting engine, an anomaly detection module, and a tariff-aware, fairness-constrained scheduling policy embedded in an OCPP 1.6/2.0.1-compliant architecture (Fig. 2).
Figure 1. The diagram shows how city charging stations connect to the Hybrid AI and OCPP core. Renewable and grid sources feed the stations. Forecasting, anomaly detection, and the GA + Q scheduler operate in the core. Decisions are sent with OCPP 1.6 and 2.0.1 operations. The outcome is lower peaks, better cost control, and fair access.
Fig. 1
Conceptual system architecture of the Hybrid AI and OCPP framework. Renewable and grid supplies feed EV charging stations that face peak demand, grid stability, and cost challenges. The framework integrates ensemble forecasting, anomaly detection, and a tariff and fairness aware scheduler within an OCPP compliant design, enabling optimized and stable charging that supports smart city goals.
Figure 2. The figure summarizes the practical gains for a smart city. The core uses forecasting and adaptive scheduling with OCPP messaging to turn city and grid inputs into measurable benefits. Energy efficiency improves, bills drop, grid stability strengthens, user experience improves, sustainability goals advance, and growth across vendors and sites is supported.
Fig. 2
Smart city benefits of the AI and OCPP charging framework. By embedding forecasting and adaptive scheduling within OCPP based communication, the system improves energy efficiency, reduces cost, strengthens grid stability, and supports growth across vendors and sites.
Novelty highlights of the proposed framework
This study couples ensemble forecasting, adaptive tariff-aware scheduling with fairness, and anomaly detection within a standards-compliant (OCPP) stack that targets deployment across heterogeneous EVSEs. Unlike prior works that evaluate forecasting or scheduling in isolation, our pipeline links a Prophet-XGBoost-GRU ensemble directly to a GA + Q scheduling policy and delivers decisions via OCPP messages for multi-vendor stations at city scale. On a two-year, city-scale dataset (1,553 operational days; 455 with tariff coverage), the scheduler yields deployment-realistic reductions of 5.0% (GA) and 8.2% (GA + Q) in both feeder peak and energy cost (Table 2), with near real-time runtimes.
Table 2 Novelty highlights of the Hybrid AI-OCPP framework.
The architecture captures the complete control pipeline, including state representation, policy learning, constraint evaluation, safety enforcement, and robustness assessment. By jointly considering economic objectives, grid limitations, and service requirements, the proposed framework ensures both operational feasibility and performance optimization under realistic and uncertain conditions.
From an analytical perspective, the novelty of the proposed framework lies not only in the integration of forecasting, scheduling, and anomaly detection, but in the coupling of deterministic constraint enforcement with adaptive optimization under a standards-compliant communication layer. Unlike prior works that treat prediction and control as separate modules, the present design ensures that forecast outputs directly inform a constrained optimization process whose decisions are immediately executable via OCPP messaging. This tight coupling enables both theoretical consistency (through energy conservation and bounded scheduling) and practical deployability.
Forecasting engine
We forecast charging demand \(\:{\widehat{D}}_{t}\)over a prediction horizon \(\:t\in\:[1,T]\)using an ensemble of statistical, machine learning, and deep learning models. Here, \(\:t\)denotes the time index, \(\:T\)is the forecasting horizon, and \(\:{\widehat{D}}_{t}\)represents the predicted demand at time \(\:t\).
Prophet
$$\:{D}_{t}=g\left(t\right)+s\left(t\right)+h\left(t\right)+{\epsilon}_{t}$$
(1)
where \(\:{D}_{t}\)is the observed demand at time \(\:t\), \(\:g\left(t\right)\)represents the trend component, \(\:s\left(t\right)\)captures seasonal patterns, \(\:h\left(t\right)\)models holiday effects, and \(\:{\epsilon}_{t}\)is the residual error term.
XGBoost
$$\:{\widehat{D}}_{t}=\sum\:_{k=1}^{K}{f}_{k}\left({x}_{t}\right),{f}_{k}\in\:\mathcal{F}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}\mathcal{\:}$$
(2)
$$\:\mathcal{L}=\sum\:_{i=1}^{n}l({y}_{i},{\widehat{y}}_{i})+\sum\:_{k=1}^{K}{\Omega\:}({f}_{k})$$
(3)
where \(\:{x}_{t}\)denotes the input feature vector at time \(\:t\), \(\:{f}_{k}\)represents the \(\:k\)-th decision tree in the ensemble, and \(\:\mathcal{F}\)is the space of possible trees. The loss function \(\:\mathcal{L}\)consists of a training loss term \(\:l({y}_{i},{\widehat{y}}_{i})\), which measures prediction error, and a regularization term \(\:{\Omega\:}\left({f}_{k}\right)\), which controls model complexity. Here, \(\:n\)is the number of training samples.
GRU (gated recurrent unit)
$$\:{z}_{t}=\sigma\:({W}_{z}{x}_{t}+{U}_{z}{h}_{t-1})$$
(4)
$$\:{r}_{t}=\sigma\:({W}_{r}{x}_{t}+{U}_{r}{h}_{t-1})$$
(5)
$$\:{\stackrel{\sim}{h}}_{t}=\text{t}\text{a}\text{n}\text{h}({W}_{h}{x}_{t}+{U}_{h}({r}_{t}\odot\:{h}_{t-1}\left)\right)$$
(6)
$$\:{h}_{t}=(1-{z}_{t})\odot\:{h}_{t-1}+{z}_{t}\odot\:{\stackrel{\sim}{h}}_{t}$$
(7)
where \(\:{x}_{t}\)is the input at time \(\:t\), \(\:{h}_{t}\)is the hidden state, and \(\:{h}_{t-1}\)is the previous hidden state. The variables \(\:{z}_{t}\)and \(\:{r}_{t}\)denote the update gate and reset gate, respectively, while \(\:\sigma\:(\cdot\:)\)is the sigmoid activation function and \(\:\text{t}\text{a}\text{n}\text{h}(\cdot\:)\)is the hyperbolic tangent function. The symbol \(\:\odot\:\)represents element-wise multiplication. The matrices \(\:W\)and \(\:U\)are learnable weight parameters.
Ensemble aggregation
$$\:{\widehat{D}}_{t}=\alpha\:{\widehat{D}}_{t}^{\text{Prophet}}+\beta\:{\widehat{D}}_{t}^{\text{XGB}}+\gamma\:{\widehat{D}}_{t}^{\text{GRU}},\alpha\:+\beta\:+\gamma\:=1$$
(8)
where \(\:{\widehat{D}}_{t}\)is the final predicted demand at time \(\:t\). The terms \(\:{\widehat{D}}_{t}^{\text{Prophet}}\), \(\:{\widehat{D}}_{t}^{\text{XGB}}\), and \(\:{\widehat{D}}_{t}^{\text{GRU}}\)represent predictions from Prophet, XGBoost, and GRU models, respectively. The coefficients \(\:\alpha\:\), \(\:\beta\:\), and \(\:\gamma\:\)are weighting factors that control the contribution of each model, with the constraint that their sum equals 1.
Anomaly detection moduleCNN-based detection
Charging sequences are reshaped into temporal matrices, and a convolutional neural network (CNN) is applied to learn patterns in the data:
where \(\:X\)is the input data matrix representing charging sequences, \(\:W\)denotes convolutional kernels, \(\:b\)is the bias term, and \(\:*\)represents the convolution operation. The function \(\:f(\cdot\:)\)is a nonlinear activation function, and \(\:y\)is the output of the CNN model.
Autoencoder (AE)
Reconstruction loss is used to detect anomalies:
$$\:{\mathcal{L}}_{AE}=\parallel\:X-\widehat{X}{\parallel\:}^{2}$$
(10)
where \(\:X\)is the original input data and \(\:\widehat{X}\)is its reconstructed version produced by the autoencoder. A high reconstruction error indicates potential anomalies.
Scheduling engine (GA + Q)Objective and constraints
Let \(\:{\mathcal{l}}_{t}\)denote the baseline load for a given day \(\:d\)at time step \(\:{\Delta\:}t\). We compute a scheduled load profile \(\:{x}_{t}\)that conserves total daily energy while reducing peak demand under a defined cap \(\:{C}_{d}\):
$$\:\sum\:_{t\in\:d}{x}_{t}\text{\hspace{0.17em}}{\Delta\:}t=\sum\:_{t\in\:d}{\mathcal{l}}_{t}\text{\hspace{0.17em}}{\Delta\:}t$$
(11)
$$\:{x}_{t}\le\:{C}_{d}+\rho\:{C}_{d}$$
where \(\:{x}_{t}\)is the scheduled load at time \(\:t\), and \(\:\rho\:\)is a small relaxation factor that allows limited flexibility above the cap.
The daily peak cap is defined as:
$$\:{C}_{d}=\eta\:\cdot\:\underset{t\in\:d}{\text{m}\text{a}\text{x}}{\mathcal{l}}_{t}$$
(12)
where \(\:\eta\:\)is a scaling parameter (typically less than 1) that determines the allowable peak relative to the original maximum load.
Operational policy (deterministic GA + Q)
We implement a deterministic, energy-conserving, bidirectional shifting strategy that operationalizes the GA + Q scheduling objective. This policy redistributes load across time while maintaining total daily energy.
In the first step, the baseline load \(\:{\mathcal{l}}_{t}\)is clipped at the daily cap \(\:{C}_{d}\), and the excess load is computed as:
$$\:{e}_{t}=\text{m}\text{a}\text{x}(0,\text{\hspace{0.25em}\hspace{0.05em}}{\mathcal{l}}_{t}-{C}_{d})$$
(13)
where \(\:{\mathcal{l}}_{t}\)is the baseline load at time \(\:t\), \(\:{C}_{d}\)is the daily peak cap, and \(\:{e}_{t}\)represents the excess energy that must be redistributed.
In the second step, the excess energy \(\:{e}_{t}\)is redistributed across time slots based on the electricity price \(\:{p}_{t}\), prioritizing lower-cost periods. The reallocation is performed within a symmetric time window of \(\:\pm\:{\Phi\:}\)hours around each time step. The allocation respects the available capacity in each slot, defined by \(\:\left({C}_{d}−{x}_{t}\right)\), where \(\:{x}_{t}\)is the scheduled load at time \(\:t\).
In the third step, a fairness constraint is applied to prevent excessive concentration of deferred load. The scheduled load is bounded as:
$$\:{x}_{t}\le\:{C}_{d}+{\gamma\:}_{d}$$
(14)
where \(\:{\gamma\:}_{d}\)is the 90th percentile of the capped load distribution for day \(\:d\), ensuring that no time slot receives disproportionate additional load.
In the final step, if residual energy remains after reallocation, a limited over-cap allowance is introduced. For the GA method, \(\:\rho\:=0\), while for the GA + Q method, \(\:\rho\:=0.02\). This allows at most \(\:\rho\:{C}_{d}\)additional load per time slot.
The parameters are set as follows:
$$\:({\eta\:}_{\text{GA}},{\eta\:}_{\text{GA+Q}})=\left(\text{0.95,0.90}\right),{\Phi\:}=20\text{\:h}$$
GA objective
A genetic algorithm formulation encodes charging start times and minimizes the following objective:
$$\:\underset{x}{\text{m}\text{i}\text{n}}\text{\hspace{0.25em}\hspace{0.05em}}J={\lambda\:}_{1}\cdot\:\underset{t}{\text{m}\text{a}\text{x}}{P}_{t}+{\lambda\:}_{2}\cdot\:C+{\lambda\:}_{3}\cdot\:\mathcal{W}$$
(15)
where \(\:{P}_{t}\)is the scheduled power at time \(\:t\), \(\:C\)is the total daily charging cost, and \(\:\mathcal{W}\)is a deferred-energy penalty term. The coefficients \(\:{\lambda\:}_{1}\), \(\:{\lambda\:}_{2}\), and \(\:{\lambda\:}_{3}\)are weighting parameters that balance peak reduction, cost, and service delay.
The deferred-energy proxy is defined as:
$${\mathcal{W}} = \sum {{\text{max}}} (0,{\text{p}}_{{{\text{req}}}} \left( {\text{t}} \right) – {\text{p}}_{{{\text{sch}}}} \left( {\text{t}} \right))\Delta {\text{t}}\left[ {{\text{kWh}}} \right]$$
(16)
where \(\:{p}_{\text{r}\text{e}\text{q}}\left(t\right)\)is the requested power and \(\:{p}_{\text{s}\text{c}\text{h}}\left(t\right)\)is the scheduled power at time \(\:t\). This term quantifies unmet demand over time.
Analytical characteristics of the scheduling policy
The proposed GA + Q scheduling framework exhibits several analytical properties that distinguish it from conventional approaches. First, the policy is energy-conserving by construction, as total daily demand is redistributed rather than curtailed. This ensures feasibility with respect to user demand while enabling peak reduction through temporal shifting.
Second, the use of a deterministic peak cap combined with bounded redistribution introduces stability in the optimization outcome. Unlike stochastic or purely reinforcement learning-based policies, the deterministic structure guarantees consistent day-level behavior under fixed inputs, which explains the observed zero-width confidence intervals in peak and cost reductions.
Third, the fairness constraint, implemented via percentile-based bounds, prevents concentration of deferred load in a small subset of time intervals. This acts as a regularization mechanism that balances global optimization objectives (cost and peak reduction) with service-level considerations, reducing the risk of extreme delays.
Finally, the hybrid GA + Q design combines global search (GA) with adaptive refinement (Q-learning). The GA explores feasible scheduling configurations under constraints, while Q-learning adjusts decisions based on local temporal dynamics. This combination improves robustness compared to standalone methods, particularly under variable demand patterns.
Peak and cost definitions and reductions
The peak load of a scheduled profile is defined as:
$$\:\text{Peak}\left(x\right)=\underset{t\in\:d}{\text{m}\text{a}\text{x}}{x}_{t}$$
(17)
where \(\:{x}_{t}\)is the scheduled load at time \(\:t\), and \(\:d\)represents the set of time steps within a given day.
The total energy cost is computed as:
$$\:\text{Cost}\left(x\right)=\sum\:_{t\in\:d}{x}_{t}\text{\hspace{0.17em}}{\Delta\:}t\text{\hspace{0.17em}}{p}_{t}$$
(18)
where \(\:{\Delta\:}t\)is the duration of each time interval, and \(\:{p}_{t}\)denotes the electricity price at time \(\:t\).
The percentage reduction in peak load relative to a baseline profile \(\:b\)is defined as:
$$\:{{\Delta\:}}_{\text{peak}}=100\cdot\:\frac{\text{Peak}\left(b\right)-\text{Peak}\left(x\right)}{\text{Peak}\left(b\right)}$$
(19)
where \(\:\text{Peak}\left(b\right)\)is the peak load of the baseline schedule and \(\:\text{Peak}\left(x\right)\)is the peak load after optimization.
Similarly, the percentage reduction in cost is defined as:
$$\:{{\Delta\:}}_{\text{cost}}=100\cdot\:\frac{\text{Cost}\left(b\right)-\text{Cost}\left(x\right)}{\text{Cost}\left(b\right)}$$
(20)
where \(\:\text{Cost}\left(b\right)\)and \(\:\text{Cost}\left(x\right)\)denote the total energy cost before and after scheduling, respectively.
OCPP Integration
Decisions are conveyed via OCPP operations. For OCPP 1.6, we use SetChargingProfile, ClearChargingProfile (per-connector schedules), GetCompositeSchedule (aggregate forecast), and RemoteStartTransaction and RemoteStopTransaction (admission control). Telemetry uses StatusNotification and MeterValues. For OCPP 2.0.1, the analogous Smart Charging services apply. Profiles use 15 min periods and a rolling horizon. The backend refreshes SetChargingProfile every 15 min with the next 24 h schedule, clearing stale entries via ClearChargingProfile.
Experimental setupDataset
We analyze a city-scale EVSE dataset with more than 10,000 sessions over 24 months (1,553 operational days). Price signals are available for a subset of days (455 out of 1,553), which are used for all cost-based statistics, while peak-based metrics use the full dataset.
Preprocessing
Timestamps are converted to local time (Asia/Kuala_Lumpur). Loads are resampled to a time interval of \(\:{\Delta\:}t=15\)min using summation for energy and averaging for power as appropriate. Short gaps of up to 60 min are linearly interpolated, while longer gaps are masked and excluded from cost statistics. Outliers above the 99.9th percentile are winsorized.
Tariffs
We use posted time-of-use (ToU) tariffs aligned to the 15 min grid. Days lacking tariff data are excluded from cost metrics but retained for peak analysis. Public holidays and weekends follow the same ToU structure unless otherwise specified.
Data splits and leakage control
Days are partitioned chronologically into training, validation, and test sets (e.g., 60/20/20 split) to avoid temporal leakage. All scheduling and anomaly detection results are reported on the held-out test set, while hyperparameters are tuned using validation data.
Baselines
The baseline methods include Forecast-as-Is (direct scheduling), Prophet-only, XGBoost-only, and GRU-only forecasters, Rule-based first-come-first-served (FCFS), GA-only, Q-learning-only, and the proposed Hybrid AI method (GA + Q).
Implementation
The framework is implemented using Python 3.10, with Prophet, XGBoost, TensorFlow/Keras, and scikit-learn libraries. The genetic algorithm (GA) is implemented using DEAP, and Q-learning is implemented as a custom module. Experiments are conducted on a system with an Intel i7-12700 K processor, 32 GB RAM, an RTX 3080 GPU, and Ubuntu 22.04 operating system.
Evaluation metricsForecasting accuracy
The forecasting performance is evaluated using Mean Absolute Error (MAE) and Root Mean Square Error (RMSE):
$$\:\text{M}\text{A}\text{E}=\frac{1}{n}\sum\:_{i=1}^{n}\mid\:{y}_{i}-{\widehat{y}}_{i}\mid$$
(21)
$$\:\text{R}\text{M}\text{S}\text{E}=\sqrt{\frac{1}{n}\sum\:_{i=1}^{n}({y}_{i}-{\widehat{y}}_{i}{)}^{2}\:}$$
(22)
where \(\:{y}_{i}\)is the actual observed value, \(\:{\widehat{y}}_{i}\)is the predicted value, and \(\:n\)is the number of samples.
Scheduling KPIs
Scheduling performance is evaluated using peak reduction (PR) and cost reduction (CR):
$$\:\text{P}\text{R}=100\cdot\:\frac{{P}_{\text{b}\text{a}\text{s}\text{e}}-{P}_{\text{m}\text{e}\text{t}\text{h}\text{o}\text{d}}}{{P}_{\text{b}\text{a}\text{s}\text{e}}}$$
(23)
$$\:\text{C}\text{R}=100\cdot\:\frac{{C}_{\text{b}\text{a}\text{s}\text{e}}-{C}_{\text{m}\text{e}\text{t}\text{h}\text{o}\text{d}}}{{C}_{\text{b}\text{a}\text{s}\text{e}}}$$
(24)
where \(\:{P}_{\text{b}\text{a}\text{s}\text{e}}\)and \(\:{C}_{\text{b}\text{a}\text{s}\text{e}}\)denote the baseline peak load and cost, respectively, while \(\:{P}_{\text{m}\text{e}\text{t}\text{h}\text{o}\text{d}}\)and \(\:{C}_{\text{m}\text{e}\text{t}\text{h}\text{o}\text{d}}\)represent the corresponding values after applying the scheduling method.
Means with 95% normal confidence intervals (CIs) are reported on a per-day basis. Peak metrics are computed using all 1,553 days, while cost metrics use the 455 days with tariff data. Under fixed parameters \(\:\left(\eta\:,{\Phi\:},\rho\:,{\gamma\:}_{d}\right)\), the policy is deterministic, resulting in constant day-level reductions (zero-width confidence intervals).
Anomaly detection
Anomaly detection performance is evaluated using ROC–AUC, with the operating threshold selected using Youden’s index:
$$\:J=\text{a}\text{r}\text{g}\underset{\tau\:}{\text{m}\text{a}\text{x}}\left(\text{T}\text{P}\text{R}\right(\tau\:)-\text{F}\text{P}\text{R}(\tau\:\left)\right)$$
(25)
where \(\:\tau\:\)is the decision threshold, \(\:\text{T}\text{P}\text{R}\)is the true positive rate, and \(\:\text{F}\text{P}\text{R}\)is the false positive rate.
We report confusion matrices along with Precision, Recall, and F1-score at the selected operating point. For deployment, thresholds can optionally be selected to satisfy a predefined false positive rate constraint (e.g., \(\:\le\:5\text{\%}\)).
Fairness
Where session-level logs are available, fairness is evaluated using the 95th percentile of waiting time, denoted as \(\:\text{P}95\left(\text{wait}\right)\), measured from arrival to charging start time. Otherwise, the aggregate proxy \(\:\mathcal{W}\)(defined earlier) is used.
Computational complexity and comparison with prior work
The EV charging scheduling problem is known to be computationally challenging and, in many formulations, NP-hard due to combinatorial assignment and temporal coupling constraints. Classical optimization approaches such as mixed-integer programming and dynamic programming exhibit exponential or pseudo-polynomial complexity, limiting scalability to large multi-station networks. Similarly, metaheuristic methods such as genetic algorithms and particle swarm optimization require multiple iterations over large solution spaces, leading to increased computational overhead, particularly as the number of EVs and time steps grows.
In contrast, the proposed scheduling policy adopts a structured and deterministic load-shifting mechanism with bounded search and local reallocation. The dominant computational cost arises from sorting time slots by tariff, yielding a complexity of \(\:O(T\text{l}\text{o}\text{g}T)\), where \(\:T\)is the number of time intervals per day, with additional linear-time adjustments for redistribution. This results in near-linear scalability with respect to the scheduling horizon.
Compared with centralized optimization frameworks reported in the literature, which may become computationally intensive without parallelization or decomposition, the proposed approach maintains low overhead and supports real-time execution on commodity hardware. This efficiency enables deployment in rolling-horizon control settings with frequent updates, which are typically infeasible for heavier optimization-based or learning-based methods.
Sensitivity
We evaluate sensitivity by varying parameters \(\:({\eta\:}_{\text{GA}},{\eta\:}_{\text{GA+Q}})\in\:\left\{\text{0.97,0.95,0.93}\right\}\times\:\left\{\text{0.92,0.90,0.88}\right\}\)and \(\:{\Phi\:}\in\:\left\{\text{8,12,20}\right\}\)hours. The mean peak and cost reductions remain within ± 0.5% points of the reported values.
Table 3 summarizes the key parameters used across different components of the proposed Hybrid AI–OCPP framework. The table lists model-specific configurations for forecasting methods (Prophet, XGBoost, and GRU), anomaly detection (Autoencoder), and optimization modules (GA and Q-learning), along with scheduler parameters. For clarity, \(\:\alpha\:\), \(\:\gamma\:\), and \(\:\epsilon\)denote the learning rate, discount factor, and exploration rate in Q-learning, respectively. The scheduler parameters \(\:{\eta\:}_{\text{GA}}\)and \(\:{\eta\:}_{\text{GA+Q}}\)control peak caps, \(\:{\Phi\:}\)defines the time-shifting window, \(\:\rho\:\)specifies the allowable over-cap relaxation, and \(\:{\gamma\:}_{d}\)represents the fairness envelope. These parameters govern model behavior, optimization dynamics, and fairness constraints in the overall system.
Table 3 Key parameters of the framework.
Table 4 summarizes the mathematical notation used throughout the methodology section. It defines all variables, parameters, and symbols associated with forecasting, scheduling, anomaly detection, and evaluation metrics. This table is provided to improve readability and ensure that all notation is clearly interpretable without requiring prior assumptions.
Table 4 Notation used in the methodology.Reproducibility
Random seeds are fixed (42) to ensure consistent experimental results. The implementation uses the following library versions: Prophet 1.x, XGBoost 1.x, TensorFlow 2.x, and scikit-learn 1.x. Scripts to regenerate all tables and figures, including scheduling outcomes, ROC curves, and confusion matrices, as well as synthetic anomaly score generators, are provided with the paper.
Ethics and privacy
All data logs are de-identified and aggregated at the feeder level. No personal data or precise geolocation information is used. Results are reported in aggregate form to reduce the risk of re-identification.