|
| 1 | +<p align="center"> |
| 2 | + <img src="docs/source/_static/logo.svg" width="200" alt="distributed-resource-optimization logo" /> |
| 3 | +</p> |
| 4 | + |
| 5 | +<p align="center"> |
| 6 | + <a href="https://github.com/Digitalized-Energy-Systems/mango-optimization/actions/workflows/test.yml"> |
| 7 | + <img src="https://github.com/Digitalized-Energy-Systems/mango-optimization/actions/workflows/test.yml/badge.svg" alt="Tests" /> |
| 8 | + </a> |
| 9 | + <a href="https://codecov.io/gh/Digitalized-Energy-Systems/mango-optimization"> |
| 10 | + <img src="https://codecov.io/gh/Digitalized-Energy-Systems/mango-optimization/branch/main/graph/badge.svg" alt="Coverage" /> |
| 11 | + </a> |
| 12 | + <img src="https://img.shields.io/badge/lifecycle-experimental-blue.svg" alt="lifecycle" /> |
| 13 | + <a href="https://github.com/Digitalized-Energy-Systems/mango-optimization/blob/main/LICENSE"> |
| 14 | + <img src="https://img.shields.io/badge/license-MIT-green.svg" alt="MIT License" /> |
| 15 | + </a> |
| 16 | + <a href="https://pypi.org/project/distributed-resource-optimization/"> |
| 17 | + <img src="https://img.shields.io/pypi/v/distributed-resource-optimization.svg" alt="PyPI" /> |
| 18 | + </a> |
| 19 | +</p> |
| 20 | + |
| 21 | +# Distributed Resource Optimization |
| 22 | + |
| 23 | +A Python package providing distributed optimization algorithms for coordinating flexible |
| 24 | +resources. Algorithms are implemented independently of any particular communication |
| 25 | +backend — a pluggable *carrier* abstraction lets you run the same algorithm code in a |
| 26 | +single asyncio process or across a real network via [mango-agents](https://github.com/OFFIS-DAI/mango). |
| 27 | + |
| 28 | +Three algorithm families are available: |
| 29 | + |
| 30 | +| Algorithm | Problem type | Coordination | |
| 31 | +|-----------|-------------|--------------| |
| 32 | +| **ADMM Sharing** | Continuous resource allocation, sum-to-target | Coordinator required | |
| 33 | +| **ADMM Consensus** | Agents converge to a shared target vector | Coordinator required | |
| 34 | +| **COHDA** | Combinatorial schedule selection, weighted L1 target | Fully distributed | |
| 35 | +| **Averaging Consensus** | Distributed averaging with optional gradient terms | Fully distributed | |
| 36 | + |
| 37 | +Two carriers are included: |
| 38 | + |
| 39 | +| Carrier | When to use | |
| 40 | +|---------|-------------| |
| 41 | +| **SimpleCarrier** | In-process asyncio simulation — zero overhead, ideal for prototyping and testing | |
| 42 | +| **MangoCarrier** | Networked multi-agent deployments via mango-agents | |
| 43 | + |
| 44 | +> **Note:** the package is still experimental. API may change between minor versions. |
| 45 | +
|
| 46 | +--- |
| 47 | + |
| 48 | +## Installation |
| 49 | + |
| 50 | +```bash |
| 51 | +pip install distributed-resource-optimization |
| 52 | +``` |
| 53 | + |
| 54 | +For networked deployments with [mango-agents](https://github.com/OFFIS-DAI/mango): |
| 55 | + |
| 56 | +```bash |
| 57 | +pip install "distributed-resource-optimization[mango]" |
| 58 | +``` |
| 59 | + |
| 60 | +For development: |
| 61 | + |
| 62 | +```bash |
| 63 | +git clone https://github.com/Digitalized-Energy-Systems/mango-optimization |
| 64 | +cd mango-optimization |
| 65 | +pip install -e ".[dev,docs]" |
| 66 | +``` |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## Quick Start |
| 71 | + |
| 72 | +### ADMM Sharing — flexible resource coordination |
| 73 | + |
| 74 | +Three resources must collectively match a power target. The sharing ADMM distributes the |
| 75 | +load optimally: |
| 76 | + |
| 77 | +```python |
| 78 | +import asyncio |
| 79 | +from distributed_resource_optimization import ( |
| 80 | + create_admm_flex_actor_one_to_many, |
| 81 | + create_sharing_target_distance_admm_coordinator, |
| 82 | + create_admm_sharing_data, |
| 83 | + create_admm_start, |
| 84 | + start_coordinated_optimization, |
| 85 | +) |
| 86 | + |
| 87 | +async def main(): |
| 88 | + # Three resources: 10 kW, 15 kW, 10 kW input capacities |
| 89 | + # Efficiency vectors map input to three output types |
| 90 | + flex1 = create_admm_flex_actor_one_to_many(10, [0.1, 0.5, -1.0]) |
| 91 | + flex2 = create_admm_flex_actor_one_to_many(15, [0.1, 0.5, -1.0]) |
| 92 | + flex3 = create_admm_flex_actor_one_to_many(10, [-1.0, 0.0, 1.0]) |
| 93 | + |
| 94 | + # Target combined output [-4, 0, 6] with first sector weighted x5 |
| 95 | + coordinator = create_sharing_target_distance_admm_coordinator() |
| 96 | + start = create_admm_start(create_admm_sharing_data([-4, 0, 6], [5, 1, 1])) |
| 97 | + |
| 98 | + await start_coordinated_optimization([flex1, flex2, flex3], coordinator, start) |
| 99 | + |
| 100 | + print(flex1.x) # optimal output for resource 1 |
| 101 | + print(flex2.x) # optimal output for resource 2 |
| 102 | + print(flex3.x) # optimal output for resource 3 |
| 103 | + |
| 104 | +asyncio.run(main()) |
| 105 | +``` |
| 106 | + |
| 107 | +### COHDA — combinatorial schedule coordination |
| 108 | + |
| 109 | +Each participant selects exactly one schedule from a discrete set; COHDA minimises the |
| 110 | +L1 distance of the aggregate to a target: |
| 111 | + |
| 112 | +```python |
| 113 | +import asyncio |
| 114 | +from distributed_resource_optimization import ( |
| 115 | + create_cohda_participant, |
| 116 | + create_cohda_start_message, |
| 117 | + start_distributed_optimization, |
| 118 | +) |
| 119 | + |
| 120 | +async def main(): |
| 121 | + actor1 = create_cohda_participant(1, [[0.0, 1, 2], [1, 2, 3]]) |
| 122 | + actor2 = create_cohda_participant(2, [[0.0, 1, 2], [1, 2, 3]]) |
| 123 | + |
| 124 | + start = create_cohda_start_message([1.2, 2.0, 3.0]) |
| 125 | + await start_distributed_optimization([actor1, actor2], start) |
| 126 | + |
| 127 | + print(actor1.memory.solution_candidate.schedules.sum(axis=0)) |
| 128 | + |
| 129 | +asyncio.run(main()) |
| 130 | +``` |
| 131 | + |
| 132 | +### Using SimpleCarrier directly |
| 133 | + |
| 134 | +For full control over message flow, create the container and carriers yourself: |
| 135 | + |
| 136 | +```python |
| 137 | +import asyncio |
| 138 | +from distributed_resource_optimization import ( |
| 139 | + ActorContainer, SimpleCarrier, cid, |
| 140 | + create_cohda_participant, create_cohda_start_message, |
| 141 | +) |
| 142 | + |
| 143 | +async def main(): |
| 144 | + container = ActorContainer() |
| 145 | + c1 = SimpleCarrier(container, create_cohda_participant(1, [[0.0, 1, 2], [1, 2, 3]])) |
| 146 | + c2 = SimpleCarrier(container, create_cohda_participant(2, [[0.0, 1, 2], [1, 2, 3]])) |
| 147 | + |
| 148 | + start = create_cohda_start_message([1.2, 2.0, 3.0]) |
| 149 | + c1.send_to_other(start, cid(c2)) |
| 150 | + await container.done_event.wait() |
| 151 | + |
| 152 | +asyncio.run(main()) |
| 153 | +``` |
| 154 | + |
| 155 | +--- |
| 156 | + |
| 157 | +## Documentation |
| 158 | + |
| 159 | +Full documentation including algorithm background, tutorials, and API reference is available at: |
| 160 | + |
| 161 | +**https://digitalized-energy-systems.github.io/mango-optimization/** |
| 162 | + |
| 163 | +--- |
| 164 | + |
| 165 | +## Contributing |
| 166 | + |
| 167 | +Contributions are welcome. Please open an issue or pull request on |
| 168 | +[GitHub](https://github.com/Digitalized-Energy-Systems/mango-optimization). |
| 169 | + |
| 170 | +--- |
| 171 | + |
| 172 | +## License |
| 173 | + |
| 174 | +[MIT](LICENSE) |
0 commit comments