Skip to content

Commit

Permalink
better criteria for finding feed forward networks
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcortes committed Dec 31, 2020
1 parent fb3ecb4 commit 6d43f95
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions biosteam/_network.py
Expand Up @@ -288,14 +288,15 @@ def _insert_network(self, index, network, has_overlap=True):
self._update_from_newly_added_network(network)

def _add_subnetwork(self, subnetwork):
if self == subnetwork: return
path = self.path
isa = isinstance
done = False
subnetworks = self.subnetworks
has_overlap = True
path_tuple = tuple(path)
recycle = self.recycle
if recycle is subnetwork.recycle:
if recycle and subnetwork.recycle and recycle.sink is subnetwork.recycle.sink:
# Feed forward scenario
subpath = subnetwork.path
for i, item in enumerate(subpath):
Expand All @@ -316,17 +317,17 @@ def _add_subnetwork(self, subnetwork):
for i in path_tuple:
if isa(i, Unit):
continue
elif i.issubset(subnetwork):
subnetwork._add_subnetwork(i)
index = path.index(i)
path.remove(i)
try: subnetworks.remove(i)
except: pass
self._insert_network(index, subnetwork)
done = True
elif not subnetwork.isdisjoint(i):
i._add_subnetwork(subnetwork)
self._update_from_newly_added_network(subnetwork)
elif not subnetwork.isdisjoint(i):
if len(subnetwork.path) > len(i.path):
subnetwork._add_subnetwork(i)
index = path.index(i)
path.remove(i)
try: subnetworks.remove(i)
except: pass
self._insert_network(index, subnetwork)
else:
i._add_subnetwork(subnetwork)
self._update_from_newly_added_network(subnetwork)
done = True
if not done:
for index, item in enumerate(path_tuple):
Expand Down

0 comments on commit 6d43f95

Please sign in to comment.