Skip to content

Commit d0c6901

Browse files
committed
Initial converted project.
1 parent c6f9212 commit d0c6901

17 files changed

Lines changed: 98 additions & 87 deletions

distributed_resource_optimization/__init__.py

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -64,48 +64,11 @@ async def main():
6464
"""
6565

6666
# Carrier layer
67-
from .carrier.core import Carrier, EventWithValue
68-
from .carrier.simple import (
69-
ActorContainer,
70-
SimpleCarrier,
71-
cid,
72-
start_coordinated_optimization,
73-
start_distributed_optimization,
74-
)
75-
76-
# Algorithm base
77-
from .algorithm.core import (
78-
CoordinatedDistributedAlgorithm,
79-
Coordinator,
80-
DistributedAlgorithm,
81-
OptimizationMessage,
82-
on_exchange_message,
83-
start_optimization,
84-
)
85-
86-
# COHDA
87-
from .algorithm.heuristic.cohda.core import (
88-
COHDAAlgorithmData,
89-
DefaultLocalDecider,
90-
LocalDecider,
91-
ScheduleSelection,
92-
SolutionCandidate,
93-
SystemConfig,
94-
TargetParams,
95-
WorkingMemory,
96-
act,
97-
cohda_default_performance,
98-
create_cohda_participant,
99-
create_cohda_participant_with_decider,
100-
create_cohda_start_message,
101-
create_from_updated_sysconf,
102-
decide,
103-
merge_candidates,
104-
merge_sysconfigs,
105-
perceive,
106-
result as cohda_result,
67+
from .algorithm.admm.consensus_admm import (
68+
ADMMConsensusGlobalActor,
69+
create_admm_start_consensus,
70+
create_consensus_target_reach_admm_coordinator,
10771
)
108-
from .algorithm.heuristic.cohda.decider import LocalSearchDecider
10972

11073
# ADMM
11174
from .algorithm.admm.core import (
@@ -120,22 +83,21 @@ async def main():
12083
from .algorithm.admm.flex_actor import (
12184
ADMMFlexActor,
12285
create_admm_flex_actor_one_to_many,
123-
result as admm_flex_result,
12486
)
125-
from .algorithm.admm.consensus_admm import (
126-
ADMMConsensusGlobalActor,
127-
create_admm_start_consensus,
128-
create_consensus_target_reach_admm_coordinator,
87+
from .algorithm.admm.flex_actor import (
88+
result as admm_flex_result,
12989
)
13090
from .algorithm.admm.sharing_admm import (
13191
ADMMSharingData,
13292
ADMMSharingGlobalActor,
13393
ADMMTargetDistanceObjective,
13494
create_admm_sharing_data,
135-
create_admm_start as create_sharing_admm_start,
13695
create_sharing_admm_coordinator,
13796
create_sharing_target_distance_admm_coordinator,
13897
)
98+
from .algorithm.admm.sharing_admm import (
99+
create_admm_start as create_sharing_admm_start,
100+
)
139101

140102
# Consensus
141103
from .algorithm.consensus.averaging import (
@@ -151,6 +113,50 @@ async def main():
151113
LinearCostEconomicDispatchConsensusActor,
152114
)
153115

116+
# Algorithm base
117+
from .algorithm.core import (
118+
CoordinatedDistributedAlgorithm,
119+
Coordinator,
120+
DistributedAlgorithm,
121+
OptimizationMessage,
122+
on_exchange_message,
123+
start_optimization,
124+
)
125+
126+
# COHDA
127+
from .algorithm.heuristic.cohda.core import (
128+
COHDAAlgorithmData,
129+
DefaultLocalDecider,
130+
LocalDecider,
131+
ScheduleSelection,
132+
SolutionCandidate,
133+
SystemConfig,
134+
TargetParams,
135+
WorkingMemory,
136+
act,
137+
cohda_default_performance,
138+
create_cohda_participant,
139+
create_cohda_participant_with_decider,
140+
create_cohda_start_message,
141+
create_from_updated_sysconf,
142+
decide,
143+
merge_candidates,
144+
merge_sysconfigs,
145+
perceive,
146+
)
147+
from .algorithm.heuristic.cohda.core import (
148+
result as cohda_result,
149+
)
150+
from .algorithm.heuristic.cohda.decider import LocalSearchDecider
151+
from .carrier.core import Carrier, EventWithValue
152+
from .carrier.simple import (
153+
ActorContainer,
154+
SimpleCarrier,
155+
cid,
156+
start_coordinated_optimization,
157+
start_distributed_optimization,
158+
)
159+
154160
# Mango carrier (optional — only imported if mango-agents is available)
155161
_MANGO_AVAILABLE = False
156162
try:

distributed_resource_optimization/algorithm/admm/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
from .consensus_admm import (
2+
ADMMConsensusGlobalActor,
3+
create_admm_start_consensus,
4+
create_consensus_target_reach_admm_coordinator,
5+
)
16
from .core import (
27
ADMMAnswer,
38
ADMMGenericCoordinator,
@@ -8,11 +13,6 @@
813
create_admm_start,
914
)
1015
from .flex_actor import ADMMFlexActor, create_admm_flex_actor_one_to_many
11-
from .consensus_admm import (
12-
ADMMConsensusGlobalActor,
13-
create_admm_start_consensus,
14-
create_consensus_target_reach_admm_coordinator,
15-
)
1616
from .sharing_admm import (
1717
ADMMSharingData,
1818
ADMMSharingGlobalActor,

distributed_resource_optimization/algorithm/admm/consensus_admm.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from __future__ import annotations
1818

1919
from dataclasses import dataclass
20-
from typing import Any
2120

2221
import numpy as np
2322

distributed_resource_optimization/algorithm/admm/flex_actor.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
class ADMMFlexActor(DistributedAlgorithm):
3333
"""Local ADMM actor that solves a box+coupling-constrained QP.
3434
35-
:param l: Lower-bound vector.
35+
:param lb: Lower-bound vector.
3636
:param u: Upper-bound vector.
3737
:param C: Coupling constraint matrix (rows: constraints, cols: variables).
3838
:param d: Coupling RHS vector.
@@ -41,13 +41,13 @@ class ADMMFlexActor(DistributedAlgorithm):
4141

4242
def __init__(
4343
self,
44-
l: np.ndarray,
44+
lb: np.ndarray,
4545
u: np.ndarray,
4646
C: np.ndarray,
4747
d: np.ndarray,
4848
S: np.ndarray,
4949
) -> None:
50-
self.l = l
50+
self.lb = lb
5151
self.u = u
5252
self.C = C
5353
self.d = d
@@ -79,7 +79,7 @@ def _local_update(actor: ADMMFlexActor, v: np.ndarray, rho: float) -> np.ndarray
7979
)
8080

8181
constraints = [
82-
x_var >= actor.l,
82+
x_var >= actor.lb,
8383
x_var <= actor.u,
8484
actor.C @ x_var <= actor.d,
8585
]
@@ -148,8 +148,8 @@ def create_admm_flex_actor_one_to_many(
148148

149149
p_arr = np.zeros(len(eta_arr)) if P is None else np.asarray(P, dtype=float)
150150

151-
l = np.minimum(np.zeros(len(tech_cap)), tech_cap)
151+
lb = np.minimum(np.zeros(len(tech_cap)), tech_cap)
152152
u = np.maximum(tech_cap, np.zeros(len(tech_cap)))
153153
C, d = _create_C_and_d(tech_cap)
154154

155-
return ADMMFlexActor(l=l, u=u, C=C, d=d, S=-p_arr)
155+
return ADMMFlexActor(lb=lb, u=u, C=C, d=d, S=-p_arr)

distributed_resource_optimization/algorithm/admm/sharing_admm.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@
2121
from __future__ import annotations
2222

2323
from dataclasses import dataclass
24-
from typing import Any
2524

2625
import cvxpy as cp
2726
import numpy as np
2827

2928
from .core import ADMMGenericCoordinator, ADMMGlobalActor, ADMMGlobalObjective, ADMMStart
3029

31-
3230
# ---------------------------------------------------------------------------
3331
# Global objective (currently informational only)
3432
# ---------------------------------------------------------------------------

distributed_resource_optimization/algorithm/consensus/averaging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from __future__ import annotations
2121

22-
from dataclasses import dataclass, field
22+
from dataclasses import dataclass
2323
from typing import TYPE_CHECKING, Any, Callable
2424

2525
import numpy as np

distributed_resource_optimization/algorithm/heuristic/cohda/core.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,8 @@ def decide(
439439
candidate: SolutionCandidate,
440440
) -> tuple[SystemConfig, SolutionCandidate]:
441441
"""Dispatch to the right decide implementation for *decider*."""
442-
from .decider import LocalSearchDecider, decide as local_search_decide
442+
from .decider import LocalSearchDecider
443+
from .decider import decide as local_search_decide
443444

444445
if isinstance(decider, LocalSearchDecider):
445446
return local_search_decide(cohda_data, decider, sysconfig, candidate)
@@ -564,7 +565,9 @@ def create_cohda_participant(
564565
"""
565566
if isinstance(schedule_set, list):
566567
_frozen = [[float(x) for x in s] for s in schedule_set]
567-
provider: Callable = lambda _: [np.array(s) for s in _frozen]
568+
569+
def provider(_: Any, _frozen: list = _frozen) -> list:
570+
return [np.array(s) for s in _frozen]
568571
else:
569572
provider = schedule_set
570573

distributed_resource_optimization/carrier/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
from .core import Carrier, EventWithValue
2-
from .simple import ActorContainer, SimpleCarrier, cid, start_coordinated_optimization, start_distributed_optimization
2+
from .simple import (
3+
ActorContainer,
4+
SimpleCarrier,
5+
cid,
6+
start_coordinated_optimization,
7+
start_distributed_optimization,
8+
)
39

410
__all__ = [
511
"Carrier",

distributed_resource_optimization/carrier/mango.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,18 @@ async def main():
5454
from __future__ import annotations
5555

5656
import asyncio
57-
from dataclasses import dataclass, field
57+
from dataclasses import dataclass
5858
from typing import TYPE_CHECKING, Any
5959
from uuid import uuid4
6060

61-
from mango import Role, sender_addr as mango_sender_addr
61+
from mango import Role
62+
from mango import sender_addr as mango_sender_addr
6263

6364
from .core import Carrier
6465

6566
if TYPE_CHECKING:
6667
from mango import AgentAddress
68+
6769
from ..algorithm.core import Coordinator, DistributedAlgorithm
6870

6971

tests/admm/test_consensus_admm.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
from __future__ import annotations
44

5-
import pytest
65
import numpy as np
6+
import pytest
77

88
from distributed_resource_optimization import (
99
ADMMFlexActor,
1010
create_admm_flex_actor_one_to_many,
11-
create_consensus_target_reach_admm_coordinator,
1211
create_admm_start_consensus,
12+
create_consensus_target_reach_admm_coordinator,
1313
start_coordinated_optimization,
1414
)
1515

@@ -107,7 +107,7 @@ async def test_consensus_admm_complex_four_actors():
107107
Each actor is at its upper bound, so the solution reproduces the box limits.
108108
"""
109109
flex_actor1 = ADMMFlexActor(
110-
l=[0.0, 0.0, 0.0],
110+
lb=[0.0, 0.0, 0.0],
111111
u=[6.428571428571429, 0.0, 4.5],
112112
C=np.array([
113113
[1.0, 1.0, 1.0],
@@ -120,7 +120,7 @@ async def test_consensus_admm_complex_four_actors():
120120
S=np.array([0.0, 0.0, 0.0]),
121121
)
122122
flex_actor2 = ADMMFlexActor(
123-
l=[0.0, 0.0, 0.0],
123+
lb=[0.0, 0.0, 0.0],
124124
u=[0.04000000000000001, 0.06, 0.1],
125125
C=np.array([
126126
[1.0, 1.0, 1.0],
@@ -133,7 +133,7 @@ async def test_consensus_admm_complex_four_actors():
133133
S=np.array([0.0, 0.0, 0.0]),
134134
)
135135
flex_actor3 = ADMMFlexActor(
136-
l=[0.0, 0.0, 0.0],
136+
lb=[0.0, 0.0, 0.0],
137137
u=[0.3, 0.0, 0.3333333333333333],
138138
C=np.array([
139139
[1.0, 1.0, 1.0],
@@ -146,7 +146,7 @@ async def test_consensus_admm_complex_four_actors():
146146
S=np.array([0.0, 0.0, 0.0]),
147147
)
148148
flex_actor4 = ADMMFlexActor(
149-
l=[0.0, 0.0, 0.0],
149+
lb=[0.0, 0.0, 0.0],
150150
u=[1.5, 0.0, 1.6666666666666665],
151151
C=np.array([
152152
[1.0, 1.0, 1.0],

0 commit comments

Comments
 (0)