diff --git a/README.md b/README.md index 7f5e9d2..3dc15a0 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,17 @@ -Open-EnergyMesh: Offline-First Distributed Microgrid Orchestration (MVP) +# Open-EnergyMesh Offline-First Microgrid Platform (MVP) -Overview -- A minimal, open MVP for offline-first distributed microgrid orchestration. -- Core concepts implemented in this MVP: - - Simple in-memory data model for devices, DERs, forecasts, and price quotes. -- This repository provides a scaffold for rapid iteration toward a larger ecosystem, with a testable, self-contained surface that can be extended by future agents. +This repository provides a minimal in-memory MVP for offline-first distributed microgrid orchestration. +Core concepts: +- EnergyMesh orchestrates devices such as Inverters and Meters and computes energy flow. +- ADMM-like scaffold is included as a forward-looking compositional optimization hook. +- Data contracts and adapters allow plugging in additional devices (DERs, storage, etc.). -How it maps to the Open-EnergyMesh vision -- Data model and APIs: A lightweight in-code model (Device, Inverter, Meter, DER, Forecast, PriceQuote) with a simple EnergyMesh orchestrator. The current tests exercise a basic energy-flow calculation. -- Offline-first mesh: The MVP is intentionally in-memory and offline-friendly; future work can layer on delta-sync and reconnection logic. -- Forecasting and pricing: Placeholders exist (Forecast, PriceQuote) to plug in forecasting and pricing engines as plug-ins. -- Governance and trading: Scaffolding is planned; this MVP focuses on core energy-flow calculation to enable early testing of edge behavior. -- Security and privacy: The MVP is a foundation; security models (DIDs, DTLS/TLS) and privacy controls can be added in subsequent iterations. - -Getting started +Usage - Install dependencies: npm install -- Run tests: npm test (or ./test.sh) -- Source: src/mesh.js defines the in-memory data model and EnergyMesh orchestration. -- Tests: test/test.js exercises a basic energy-flow calculation using Inverter and Meter components. +- Run tests: npm test -Extending the MVP -- Add more detailed data models (Event, Trade, Forecast, PriceQuote) and richer flow logic. -- Implement a small open API surface (JSON/Protobuf) and a schema registry for versioned contracts. -- Introduce a pluggable forecasting and pricing engine (local and federated options). -- Build a delta-sync protocol for offline periods and reconnection. -- Implement governance scaffolding for lightweight peer-to-peer trading and community rules. +Notes +- This MVP emphasizes offline resilience and a clean path toward modular optimization layers. +- See src/mesh.js and src/solver_admm.js for the basic in-memory implementation and the ADMM scaffold. -Development and contribution -- This project adheres to the Open-EnergyMesh vision of interoperability and resilience. -- see AGENTS.md for the architectural guidance and testing commands. - -License -- MIT - -Ready-to-publish marker -- A ready-to-publish marker will be placed at the repository root when the project is fully production-ready. +License: MIT diff --git a/src/mesh.js b/src/mesh.js index 9c13735..2712f5f 100644 --- a/src/mesh.js +++ b/src/mesh.js @@ -49,6 +49,16 @@ class Forecast { } } +const { AdmmSolver } = (() => { + try { + // Lazy require to avoid circular/optional dependency issues in tests + // eslint-disable-next-line global-require + return require('./solver_admm'); + } catch (e) { + return { AdmmSolver: class {} }; + } +})(); + class EnergyMesh { constructor() { this.devices = new Map(); // id -> Device @@ -57,6 +67,8 @@ class EnergyMesh { this.ders = new Map(); // id -> DER this.quotes = []; this.forecasts = []; + // Lightweight ADMM-like solver placeholder + this.admm = new (AdmmSolver || class {})(); } // Device helpers @@ -126,6 +138,20 @@ class EnergyMesh { netFlowW: generation - consumption }; } + + // Placeholder ADMM-like flow computation that delegates to the solver. + // For now, it mirrors computeFlow() to preserve current behavior. + computeFlowADMM() { + // In a future iteration, local problems would be posted to admm.step(...) and + // the returned primal/dual would influence generation decisions. + const base = this.computeFlow(); + // No-op: return the same result to preserve legacy behavior during MVP + return { + generationW: base.generationW, + consumptionW: base.consumptionW, + netFlowW: base.netFlowW + }; + } } module.exports = { diff --git a/src/solver_admm.js b/src/solver_admm.js new file mode 100644 index 0000000..4787cae --- /dev/null +++ b/src/solver_admm.js @@ -0,0 +1,28 @@ +// Minimal ADMM-like scaffold for Open-EnergyMesh +// This is a plug-in abstraction that represents the compositional optimization layer +// described in the MVP roadmap. It currently provides a no-op step implementation +// so the runtime can evolve without breaking existing behavior. + +class AdmmSolver { + constructor() { + // In a full implementation, this would hold state for primal/dual variables + this.version = '0.1-admm-skeleton'; + } + + // Accept a local problem payload and return a short step result + // localData shape is application-defined; here we keep a permissive contract + step(localData) { + // No real computation yet; return a conservative delta that could be used + // by a real solver in future iterations. We mirror the input as the 'primal'. + return { + primal: localData, + dual: {}, + delta: 0, + converged: true + }; + } +} + +module.exports = { + AdmmSolver +};