Skip to content

Commit

Permalink
allow any expansion for source SCC
Browse files Browse the repository at this point in the history
  • Loading branch information
kyuhyongpark committed Nov 14, 2023
1 parent c8f86cb commit 4fae0fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions nfvsmotifs/_sd_algorithms/expand_source_SCCs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

DEBUG = False

def expand_source_SCCs(sd: SuccessionDiagram, check_maa:bool=True) -> bool:
def expand_source_SCCs(sd: SuccessionDiagram,
expander=SuccessionDiagram.expand_bfs,
check_maa:bool=True) -> bool:
"""
1. percolate
2. find source nodes, fix combinations and then percolate
Expand Down Expand Up @@ -92,7 +94,7 @@ def expand_source_SCCs(sd: SuccessionDiagram, check_maa:bool=True) -> bool:
next_branches:list[int] = []
while len(source_scc_list) > 0:
source_scc = source_scc_list.pop(0)
scc_sd, exist_maa = find_scc_sd(clean_bnet, source_scc, check_maa)
scc_sd, exist_maa = find_scc_sd(clean_bnet, source_scc, expander, check_maa)

if exist_maa: # we check for maa, and it exists
continue
Expand Down Expand Up @@ -125,7 +127,7 @@ def expand_source_SCCs(sd: SuccessionDiagram, check_maa:bool=True) -> bool:
assert sd.G.nodes[node_id]["expanded"] == False # expand nodes from here
assert sd.G.nodes[node_id]["attractors"] == None # check attractors from here

sd.expand_bfs(node_id)
expander(sd, node_id)

return True

Expand Down Expand Up @@ -228,7 +230,8 @@ def find_source_SCCs(bn:BooleanNetwork) -> list[list[str]]:
return sorted(source_scc_list)


def find_scc_sd(bnet:str, source_scc:list[str], check_maa:bool) -> tuple[SuccessionDiagram, bool]:
def find_scc_sd(bnet:str, source_scc:list[str],
expander, check_maa:bool) -> tuple[SuccessionDiagram, bool]:
"""
TODO: better way that does not use bnet but rather bn directly or petri_net directly
to find the scc_sd would be useful.
Expand Down Expand Up @@ -268,7 +271,7 @@ def find_scc_sd(bnet:str, source_scc:list[str], check_maa:bool) -> tuple[Success

# Compute the succession diagram.
scc_sd = SuccessionDiagram(scc_bn)
fully_expanded = scc_sd.expand_bfs()
fully_expanded = expander(scc_sd)
assert fully_expanded

exist_maa = False
Expand Down
4 changes: 2 additions & 2 deletions tests/source_SCC_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_find_scc_sd():
A, B
B, A | A & C"""

scc_sd, _ = find_scc_sd(bnet, ["A", "B"], check_maa=True)
scc_sd, _ = find_scc_sd(bnet, ["A", "B"], expander=SuccessionDiagram.expand_bfs, check_maa=True)

assert scc_sd.G.nodes[0]["space"] == {}
assert scc_sd.G.nodes[1]["space"] == {"A":0, "B":0}
Expand Down Expand Up @@ -326,5 +326,5 @@ def test_attractor_search():
test_find_source_nodes()
test_perc_and_remove_constants_from_bn()
test_find_scc_sd()
# test_expansion()
test_expansion()
test_attractor_search()

0 comments on commit 4fae0fe

Please sign in to comment.