Advancing Generative Artificial Intelligence and Large Language Models for Demand Side Management with Internet of Electric Vehicles

Hanwen Zhang, Ruichen Zhang, Wei Zhang, Dusit Niyato, Yonggang Wen, Chunyan Miao

This paper presents a novel framework for automating Demand Side Management (DSM) in microgrids by leveraging Large Language Models (LLMs) enhanced with Retrieval-Augmented Generation (RAG). By bridging the gap between natural language requirements and executable optimization code, the authors demonstrate how to democratize complex energy management tasks, achieving an 8.13% reduction in operating costs through user-tailored scheduling.

TL;DR

The researchers propose an RAG-enhanced LLM framework that automates the entire lifecycle of energy optimization—from mathematical problem formulation to executable code generation and real-time user customization. This approach allows non-experts to manage microgrid resources, like electric vehicles, using natural language while outperforming traditional static manufacturer schedules.

What Problem Does This Paper Address?

Demand Side Management (DSM) is essential for balancing energy supply and demand in modern microgrids, especially with the rise of renewable energy and electric vehicles (EVs). However, creating effective DSM strategies is currently a manual, "hand-crafted" process.

Energy Management System (EMS) developers must manually derive complex mathematical models (like Mixed-Integer Linear Programming), encode them into specific programming frameworks, and constantly update them as device portfolios or user preferences change. This process is time-consuming, error-prone, and requires deep expertise in both power systems and software engineering. While standard AI has been used for forecasting, the actual optimization phase remains a significant bottleneck for automation.

Methods

The authors introduce a function-oriented workflow that uses a Generative AI agent to handle three core stages:

  1. Automatic Optimization Formulation: Translates natural language descriptions of a microgrid into a formal mathematical model.
  2. Automatic Code Generation: Converts those mathematical models into executable Python scripts (using the Pyomo library).
  3. Automatic Customizing Optimization: Allows end-users to modify schedules via natural language (e.g., "I need my EV charged to 80% by 3 PM").

The technical backbone is a RAG-enhanced LLM (specifically GPT-4o). As shown in Figure 2, the system doesn't just rely on the LLM's internal knowledge. Instead, it uses a Perception Module to encode user queries and a Retrieval Module to search a specialized RAG Knowledge Database. This database contains technical documents, MILP templates, and code snippets. By providing this "grounding" context, the LLM avoids common hallucinations and produces technically sound optimization formulations.

![Fig.

  1. A general framework design of a GenAI agent supporting modeling and code generation for IoT-enabled microgrid.](/figures/art_e7eaa28a4c38430397ebc754da0cedd6)

Datasets

The framework was validated using a microgrid scenario involving a home EMS, energy storage, EVs, PV systems, and various household appliances.

  • PV and Load Data: Real-world time-series data from the Customer Led Network Revolution (CLNR) project in the UK.
  • Pricing Data: Historical electricity pricing from Energy Stats UK (Octopus Energy).
  • RAG Corpus: A custom-built library of DSM technical papers and executable code templates.

Key Insights and Ideas

  • LLMs as Semantic Bridges: The core insight is that LLMs can act as a "translator" between human intent (natural language) and rigid mathematical solvers, provided they are grounded with domain-specific knowledge.
  • The Failure of "Vanilla" LLMs: The authors show that a baseline LLM (without RAG) often fails at energy optimization. It might forget to include revenue from selling power back to the grid or fail to account for binary variables that control whether an appliance is on or off.
  • Dynamic Customization: Unlike static manufacturer-provided schedules, this framework allows for "on-the-fly" adjustments. A user can change their schedule via a simple chat interface, and the system regenerates the underlying math and code automatically.
  • Hybrid AI Approach: The paper highlights how Discriminative AI (for forecasting) and Generative AI (for optimization logic) can collaborate within an EMS to create a "full-lifecycle digital twin."

![Fig.

  1. Overview of EMS with various AI approaches.](/figures/art_e32472f428484ef08f7d56d470c2c990)

Key Results

  • Formulation Accuracy: The RAG-enhanced model correctly identified all necessary variables and constraints (e.g., power balance, storage limits, and load types), whereas the baseline LLM produced "superficial" models that overlooked critical economic factors like grid-selling revenue.
  • Cost Efficiency: In a simulated 24-hour period, the customized optimization achieved an 8.13% cost reduction (£23.27) compared to the default manufacturer configuration (£25.33).
  • Operational Flexibility: The system successfully managed "Type 1" (interruptible) and "Type 2" (non-interruptible) loads, ensuring appliances like dishwashers ran in continuous blocks while flexible loads like vacuum cleaners shifted to low-price periods.

Limitations and Future Work

  • Cost and Latency: Continuous use of high-end LLM APIs can be expensive and introduce latency compared to pre-compiled static solvers.
  • Security: While the paper mentions anomaly detection, the potential for "prompt injection" or malicious user requests that could damage grid hardware remains a concern.
  • Scaling: The current study focuses on a single-home microgrid; future work is needed to test how this scales to larger communities or industrial microgrids.
  • Privacy: The authors suggest that future iterations should incorporate Federated Learning to protect user data while still benefiting from collective AI training.

Summary updated

BibTeX
@article{zhang2026advancing,
  author = {Hanwen Zhang and Ruichen Zhang and Wei Zhang and Dusit Niyato and Yonggang Wen and Chunyan Miao},
  title = {{Advancing Generative Artificial Intelligence and Large Language Models for Demand Side Management with Internet of Electric Vehicles}},
  journal = {IEEE Internet of Things Journal},
  year = {2026},
  doi = {10.1109/jiot.2026.3685302},
}
Figure