Example #1
0
def is_total_order(graph: DiGraph) -> bool:
    reflexive = is_reflexive(graph)
    anti_symmetric = is_anti_symmetric(graph)
    transitive = is_transitive(graph)
    all_relatione = all(
        graph.has_edge(x, y) and graph.has_edge(y, x)
        for x, y in get_set_combination(graph.nodes))

    return reflexive and anti_symmetric and transitive and all_relatione
Example #2
0
def generate_relations(
    nodes: Set[int],
    condition: Callable[[int, int], bool],
    inverse: bool = False,
) -> Iterator[Tuple[int, int]]:
    for node_x, node_y in get_set_combination(nodes):
        if condition(node_x, node_y):
            if inverse:
                yield (node_y, node_x)
                continue
            yield (node_x, node_y)
Example #3
0
def get_all_mcs(graph: DiGraph) -> Iterator[Tuple[Set[Any], Any]]:
    for node_x, node_y in get_set_combination(graph.nodes):
        yield ({node_x, node_y}, _get_mcs(graph, node_x, node_y))
Example #4
0
def is_not_transitive(graph: DiGraph) -> bool:
    return any(not graph.has_edge(x, z)
               for x, y in get_set_combination(graph.nodes)
               if x != y and graph.has_edge(x, y) for z in graph.adj[y]
               if y != z)
Example #5
0
def is_lattice(graph: DiGraph) -> bool:
    nodes = graph.nodes

    return all(
        get_mcs(graph, x, y) and get_mci(graph, x, y)
        for x, y in get_set_combination(nodes) if x != y)