Skip to content

Commit

Permalink
Remove notion of Arc
Browse files Browse the repository at this point in the history
Signed-off-by: Sylvain Leclerc <sylvain.leclerc@rte-france.com>
  • Loading branch information
sylvlecl committed Feb 12, 2024
1 parent bbb3cb1 commit d140acf
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 45 deletions.
1 change: 0 additions & 1 deletion src/andromede/study/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
TimeSeriesData,
)
from .network import (
Arc,
Component,
Network,
Node,
Expand Down
25 changes: 0 additions & 25 deletions src/andromede/study/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,6 @@ class Node(Component):
pass


@dataclass(frozen=True)
class Arc:
"""
An arc between 2 nodes of the network.
TODO: we could imagine that it would be a component.
"""

id: str
node1_id: str
node2_id: str


@dataclass(frozen=True)
class PortRef:
component: Component
Expand Down Expand Up @@ -128,7 +116,6 @@ class Network:
def __init__(self, id: str):
self.id: str = id
self._nodes: Dict[str, Node] = {}
self._arcs: Dict[str, Arc] = {}
self._components: Dict[str, Component] = {}
self._connections: List[PortsConnection] = []

Expand Down Expand Up @@ -168,18 +155,6 @@ def all_components(self) -> Iterable[Component]:
"""
return itertools.chain(self.nodes, self.components)

def add_arc(self, arc: Arc) -> None:
self._check_node_exists(arc.node1_id)
self._check_node_exists(arc.node2_id)
self._arcs[arc.id] = arc

def get_arc(self, arc_id: str) -> Arc:
return self._arcs[arc_id]

@property
def arcs(self) -> Iterable[Arc]:
return self._arcs.values()

def connect(self, port1: PortRef, port2: PortRef) -> None:
ports_connection = PortsConnection(port1, port2)
self._connections.append(ports_connection)
Expand Down
22 changes: 3 additions & 19 deletions tests/andromede/test_andromede.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import pytest

from andromede.expression import literal, param, var
from andromede.expression.expression import port_field
from andromede.expression.indexing_structure import IndexingStructure
from andromede.libs.standard import (
BALANCE_PORT_TYPE,
Expand All @@ -27,14 +26,7 @@
THERMAL_CLUSTER_MODEL_HD,
UNSUPPLIED_ENERGY_MODEL,
)
from andromede.model import (
Constraint,
Model,
ModelPort,
float_parameter,
float_variable,
model,
)
from andromede.model import Model, ModelPort, float_parameter, float_variable, model
from andromede.model.model import PortFieldDefinition, PortFieldId
from andromede.simulation import (
BlockBorderManagement,
Expand All @@ -43,7 +35,6 @@
build_problem,
)
from andromede.study import (
Arc,
ConstantData,
DataBase,
Network,
Expand All @@ -59,26 +50,19 @@ def test_network() -> None:
network = Network("test")
assert network.id == "test"
assert list(network.nodes) == []
assert list(network.arcs) == []
assert list(network.components) == []
assert list(network.all_components) == []
assert list(network.connections) == []

with pytest.raises(KeyError):
network.get_node("N")
with pytest.raises(KeyError):
network.get_arc("L")

N1 = Node(model=NODE_BALANCE_MODEL, id="N1")
N2 = Node(model=NODE_BALANCE_MODEL, id="N2")
network.add_node(N1)
network.add_node(N2)
assert list(network.nodes) == [N1, N2]
assert network.get_node(N1.id) == N1

with pytest.raises(ValueError):
network.add_arc(Arc("L", "N", "N2"))
network.add_arc(Arc("L", "N1", "N2"))
assert list(network.arcs) == [Arc("L", "N1", "N2")]
assert network.get_arc("L") == Arc("L", "N1", "N2")
assert network.get_component("N1") == Node(model=NODE_BALANCE_MODEL, id="N1")
with pytest.raises(KeyError):
network.get_component("unknown")
Expand Down

0 comments on commit d140acf

Please sign in to comment.