|
14 | 14 | to_tuple_list, |
15 | 15 | ) |
16 | 16 |
|
17 | | -from .api.api import ( |
18 | | - MaxBisimAlgorithm, |
19 | | - find_max_bisimulation, |
20 | | - saha_iter, |
21 | | - total_saha, |
22 | | -) |
| 17 | + |
| 18 | +class Algorithms(Enum): |
| 19 | + PaigeTarjan = auto() |
| 20 | + DovierPiazzaPolicriti = auto() |
| 21 | + |
| 22 | + |
| 23 | +def compute_maximum_bisimulation( |
| 24 | + graph: nx.DiGraph, |
| 25 | + initial_partition, |
| 26 | + algorithm=Algorithm.PaigeTarjan, |
| 27 | +): |
| 28 | + """Compute the maximum bisimulation of the given graph, possibly using |
| 29 | + an initial partition (or labeling set). The preferred algorithm may be |
| 30 | + chosen as well (*Paige-Tarjan* or *Dovier-Piazza-Policriti*). |
| 31 | +
|
| 32 | + Example: |
| 33 | + >>> import networkx as nx |
| 34 | + >>> from bispy import compute_maximum_bisimulation, Algorithms |
| 35 | + >>> graph = nx.balanced_tree(2,3, create_using=nx.DiGraph) |
| 36 | + >>> compute_maximum_bisimulation(graph) |
| 37 | + [(3, 4, 5, 6), (7, 8, 9, 10, 11, 12, 13, 14), (1, 2), (0,)] |
| 38 | + >>> compute_maximum_bisimulation(graph), |
| 39 | + algorithm=Algorithms.DovierPiazzaPolicriti) |
| 40 | + [(3, 5, 6), (7, 8, 9, 10, 11, 12, 13, 14), (0,), (2,), (1,), (4,)] |
| 41 | +
|
| 42 | + :param graph: The input graph. |
| 43 | + :param initial_partition: A partition of the set of nodes of the graph, |
| 44 | + two nodes in different blocks of this partition cannot be bisimilar. |
| 45 | + Defaults to the trivial initial partition. |
| 46 | + :param algorithm: The algorithm used to compute the maximum bisimulation. |
| 47 | + :returns: The maximum bisimulation of the given graph, with the given |
| 48 | + initial partition. |
| 49 | + """ |
| 50 | + |
| 51 | + if algorithm == Algorithms.PaigeTarjan: |
| 52 | + return paige_tarjan(graph, initial_partition) |
| 53 | + elif algorithm == Algorithms.DovierPiazzaPolicriti: |
| 54 | + return dovier_piazza_policriti(graph, initial_partition) |
0 commit comments