Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Model Library
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FOCUS
Model Library
Commits
5c6699a7
Commit
5c6699a7
authored
1 year ago
by
Christoph von Oy
Browse files
Options
Downloads
Patches
Plain Diff
Introduced loss factor for OneToOne connections
parent
e5ce585a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
topology.py
+45
-36
45 additions, 36 deletions
topology.py
with
45 additions
and
36 deletions
topology.py
+
45
−
36
View file @
5c6699a7
...
@@ -63,7 +63,7 @@ class Connector:
...
@@ -63,7 +63,7 @@ class Connector:
# self.flows[index] = replacement
# self.flows[index] = replacement
class
Sum
Connection
:
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
]
#
connect
or_to.other_sides.append(connector_from)
self
.
_
connect
ions_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
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment