diff --git a/topology.py b/topology.py index 3a1ecb5594390a0b80b31dc81cb82efac55bd0ab..29acdebef7422e8064ac1629faf7d120e2ca7a80 100644 --- a/topology.py +++ b/topology.py @@ -45,22 +45,22 @@ for name, klass in inspect.getmembers(module, inspect.isclass): component_library[name] = klass -class ConnectorMode(Enum): - EMPTY = 1 - SINGLE_CONTRACTED = 2 - SINGLE = 3 - MULTIPLE = 4 +# class ConnectorMode(Enum): +# EMPTY = 1 +# SINGLE_CONTRACTED = 2 +# SINGLE = 3 +# MULTIPLE = 4 class Connector: def __init__(self, name): self.name = name self.flows = [] - self.other_sides = [] + # self.other_sides = [] - def replace_flow(self, flow, replacement): - index = [i for i in range(len(self.flows)) if self.flows[i] == flow][0] - self.flows[index] = replacement + # def replace_flow(self, flow, replacement): + # index = [i for i in range(len(self.flows)) if self.flows[i] == flow][0] + # self.flows[index] = replacement class SumConnection: @@ -69,17 +69,17 @@ class SumConnection: self.out_flows = out_flows self.loss_factor = loss_factor - def replace_flow(self, flow, replacement): - if flow in self.in_flows: - index = [i for i in range(len(self.in_flows)) if self.in_flows[i] == flow][ - 0 - ] - self.in_flows[index] = replacement - else: - index = [ - i for i in range(len(self.out_flows)) if self.out_flows[i] == flow - ][0] - self.out_flows[index] = replacement + # def replace_flow(self, flow, replacement): + # if flow in self.in_flows: + # index = [i for i in range(len(self.in_flows)) if self.in_flows[i] == flow][ + # 0 + # ] + # self.in_flows[index] = replacement + # else: + # index = [ + # i for i in range(len(self.out_flows)) if self.out_flows[i] == flow + # ][0] + # self.out_flows[index] = replacement class Topology: @@ -144,9 +144,9 @@ class Topology: connector_from = self._connectors[flow_from] connector_to = self._connectors[flow_to] connector_from.flows.append(flow) - connector_from.other_sides.append(connector_to) + # connector_from.other_sides.append(connector_to) connector_to.flows.append(flow) - connector_to.other_sides.append(connector_from) + # connector_to.other_sides.append(connector_from) elif connection["type"] == "Sum": index = len(self._sum_connections) in_flows = [] @@ -162,7 +162,7 @@ class Topology: out_flows.append(flow) connector = self._connectors[member] connector.flows.append(flow) - connector.other_sides.append(index) + # connector.other_sides.append(index) if "loss_factor" in connection: loss_factor = connection["loss_factor"] else: @@ -171,43 +171,43 @@ class Topology: SumConnection(in_flows, out_flows, loss_factor) ) - self._removed_flows = dict() - - for connector in self._connectors.values(): - if len(connector.flows) == 0: - connector.mode = ConnectorMode.EMPTY - elif len(connector.flows) > 1: - connector.mode = ConnectorMode.MULTIPLE - else: - # the connector is single, but if we can contract depends on the other side - other_side = connector.other_sides[0] - if isinstance(other_side, Connector): - # the other side is a connector - # test if the connector on the other side has been assigned a mode - if hasattr(other_side, "mode"): - # the connector on the other side has been assigend a mode, so it could be contracted - if other_side.mode != ConnectorMode.SINGLE_CONTRACTED: - # it is not, we can contract - connector.mode = ConnectorMode.SINGLE_CONTRACTED - else: - # it is, we cannot contract - connector.mode = ConnectorMode.SINGLE - else: - # the connector on the other side has not been assigend a mode, so it is not contracted, so we can contract - connector.mode = ConnectorMode.SINGLE_CONTRACTED - else: - # the other side is a sum connection so we can contract - other_side = self._sum_connections[other_side] - connector.mode = ConnectorMode.SINGLE_CONTRACTED - # contract the connector - if connector.mode == ConnectorMode.SINGLE_CONTRACTED: - # remove flow from topology - flow_to_remove = connector.flows[0] - self._flows.remove(flow_to_remove) - self._removed_flows[flow_to_remove] = connector.name - # replace flow in both connectors - connector.flows[0] = connector.name - other_side.replace_flow(flow_to_remove, connector.name) + # self._removed_flows = dict() + + # for connector in self._connectors.values(): + # if len(connector.flows) == 0: + # connector.mode = ConnectorMode.EMPTY + # elif len(connector.flows) > 1: + # connector.mode = ConnectorMode.MULTIPLE + # else: + # # the connector is single, but if we can contract depends on the other side + # other_side = connector.other_sides[0] + # if isinstance(other_side, Connector): + # # the other side is a connector + # # test if the connector on the other side has been assigned a mode + # if hasattr(other_side, "mode"): + # # the connector on the other side has been assigend a mode, so it could be contracted + # if other_side.mode != ConnectorMode.SINGLE_CONTRACTED: + # # it is not, we can contract + # connector.mode = ConnectorMode.SINGLE_CONTRACTED + # else: + # # it is, we cannot contract + # connector.mode = ConnectorMode.SINGLE + # else: + # # the connector on the other side has not been assigend a mode, so it is not contracted, so we can contract + # connector.mode = ConnectorMode.SINGLE_CONTRACTED + # else: + # # the other side is a sum connection so we can contract + # other_side = self._sum_connections[other_side] + # connector.mode = ConnectorMode.SINGLE_CONTRACTED + # # contract the connector + # if connector.mode == ConnectorMode.SINGLE_CONTRACTED: + # # remove flow from topology + # flow_to_remove = connector.flows[0] + # self._flows.remove(flow_to_remove) + # self._removed_flows[flow_to_remove] = connector.name + # # replace flow in both connectors + # connector.flows[0] = connector.name + # other_side.replace_flow(flow_to_remove, connector.name) if "additional_model_logic" in configuration: self._additional_model_logic = configuration["additional_model_logic"] @@ -435,8 +435,8 @@ class Topology: enable = logic["enable"] for i, connection in enumerate(logic["connections"]): flow = connection["from"] + "_" + connection["to"] - if flow in self._removed_flows: - flow = self._removed_flows[flow] + # if flow in self._removed_flows: + # flow = self._removed_flows[flow] flow_var = o_block.component_dict[flow] def rule(m, t):