Skip to content
Snippets Groups Projects
Commit 5c6699a7 authored by Christoph von Oy's avatar Christoph von Oy
Browse files

Introduced loss factor for OneToOne connections

parent e5ce585a
No related branches found
No related tags found
No related merge requests found
...@@ -63,7 +63,7 @@ class Connector: ...@@ -63,7 +63,7 @@ class Connector:
# self.flows[index] = replacement # self.flows[index] = replacement
class SumConnection: class Connection:
def __init__(self, in_flows, out_flows, loss_factor): def __init__(self, in_flows, out_flows, loss_factor):
self.in_flows = in_flows self.in_flows = in_flows
self.out_flows = out_flows self.out_flows = out_flows
...@@ -133,22 +133,28 @@ class Topology: ...@@ -133,22 +133,28 @@ class Topology:
) )
self._flows = [] self._flows = []
self._sum_connections = [] self._connections = []
self._connections_map = dict()
for connection in configuration["connections"]: for connection in configuration["connections"]:
index = len(self._connections)
if connection["type"] == "OneToOne": if connection["type"] == "OneToOne":
flow_from = connection["from"] flow_from = connection["from"]
flow_to = connection["to"] in_flow = flow_from + "_" + str(index)
flow = flow_from + "_" + flow_to self._flows.append(in_flow)
self._flows.append(flow)
connector_from = self._connectors[flow_from] connector_from = self._connectors[flow_from]
connector_from.flows.append(in_flow)
# connector_from.other_sides.append(index)
in_flows = [in_flow]
flow_to = connection["to"]
out_flow = str(index) + "_" + flow_to
self._flows.append(out_flow)
connector_to = self._connectors[flow_to] connector_to = self._connectors[flow_to]
connector_from.flows.append(flow) connector_to.flows.append(out_flow)
# connector_from.other_sides.append(connector_to) # connector_to.other_sides.append(index)
connector_to.flows.append(flow) out_flows = [out_flow]
# connector_to.other_sides.append(connector_from) self._connections_map[flow_from, flow_to] = index
elif connection["type"] == "Sum": elif connection["type"] == "Sum":
index = len(self._sum_connections)
in_flows = [] in_flows = []
out_flows = [] out_flows = []
for member in connection["members"]: for member in connection["members"]:
...@@ -167,9 +173,7 @@ class Topology: ...@@ -167,9 +173,7 @@ class Topology:
loss_factor = connection["loss_factor"] loss_factor = connection["loss_factor"]
else: else:
loss_factor = 0.0 loss_factor = 0.0
self._sum_connections.append( self._connections.append(Connection(in_flows, out_flows, loss_factor))
SumConnection(in_flows, out_flows, loss_factor)
)
# self._removed_flows = dict() # self._removed_flows = dict()
...@@ -399,17 +403,17 @@ class Topology: ...@@ -399,17 +403,17 @@ class Topology:
o_block.add(connector.name + "_sum", pyo.Constraint(o_block.T, rule=rule)) o_block.add(connector.name + "_sum", pyo.Constraint(o_block.T, rule=rule))
for i, sum_connection in enumerate(self._sum_connections): for i, connection in enumerate(self._connections):
def rule(m, t): def rule(m, t):
return pyo.quicksum( return pyo.quicksum(
o_block.component_dict[out_flow][t] o_block.component_dict[out_flow][t]
for out_flow in sum_connection.out_flows for out_flow in connection.out_flows
) == pyo.quicksum( ) == pyo.quicksum(
o_block.component_dict[in_flow][t] o_block.component_dict[in_flow][t]
for in_flow in sum_connection.in_flows for in_flow in connection.in_flows
) * ( ) * (
1.0 - sum_connection.loss_factor 1.0 - connection.loss_factor
) )
o_block.add(str(i) + "_sum", pyo.Constraint(o_block.T, rule=rule)) o_block.add(str(i) + "_sum", pyo.Constraint(o_block.T, rule=rule))
...@@ -434,10 +438,15 @@ class Topology: ...@@ -434,10 +438,15 @@ class Topology:
if logic["type"] == "ConnectionEnable": if logic["type"] == "ConnectionEnable":
enable = logic["enable"] enable = logic["enable"]
for i, connection in enumerate(logic["connections"]): for i, connection in enumerate(logic["connections"]):
flow = connection["from"] + "_" + connection["to"] flow_from = connection["from"]
flow_to = connection["to"]
if (flow_from, flow_to) in self._connections_map:
connection = self._connections[
self._connections_map[flow_from, flow_to]
]
# if flow in self._removed_flows: # if flow in self._removed_flows:
# flow = self._removed_flows[flow] # flow = self._removed_flows[flow]
flow_var = o_block.component_dict[flow] flow_var = o_block.component_dict[connection.in_flows[0]]
def rule(m, t): def rule(m, t):
if enable[t] == 0: if enable[t] == 0:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment