Ejemplo n.º 1
0
def get_cycles_petri_net_transitions(net):
    """
    Get the cycles of a Petri net (returning only list of transitions belonging to the cycle)

    Parameters
    -------------
    net
        Petri net

    Returns
    -------------
    cycles
        Cycles (transitions) of the Petri net
    """
    import networkx as nx

    graph, inv_dictionary = create_networkx_directed_graph(net)
    cycles = nx.simple_cycles(graph)
    cycles_trans = []
    for cycle in cycles:
        cycles_trans.append([])
        for el in cycle:
            if el in inv_dictionary and type(
                    inv_dictionary[el]) is PetriNet.Transition:
                cycles_trans[-1].append(inv_dictionary[el])
    return cycles_trans
Ejemplo n.º 2
0
def get_strongly_connected_subnets(net):
    """
    Get the strongly connected components subnets in the Petri net

    Parameters
    -------------
    net
        Petri net

    Returns
    -------------
    strongly_connected_transitions
        List of strongly connected transitions of the Petri net
    """
    import networkx as nx

    graph, inv_dictionary = create_networkx_directed_graph(net)
    sccg = list(nx.strongly_connected_components(graph))
    strongly_connected_subnets = []
    for sg in list(sccg):
        if len(sg) > 1:
            subnet = petri.petrinet.PetriNet()
            imarking = petri.petrinet.Marking()
            fmarking = petri.petrinet.Marking()
            corr = {}
            for node in sg:
                if node in inv_dictionary:
                    if type(inv_dictionary[node]
                            ) is petri.petrinet.PetriNet.Transition:
                        prev_trans = inv_dictionary[node]
                        new_trans = petri.petrinet.PetriNet.Transition(
                            prev_trans.name, prev_trans.label)
                        corr[node] = new_trans
                        subnet.transitions.add(new_trans)
                    if type(inv_dictionary[node]
                            ) is petri.petrinet.PetriNet.Place:
                        prev_place = inv_dictionary[node]
                        new_place = petri.petrinet.PetriNet.Place(
                            prev_place.name)
                        corr[node] = new_place
                        subnet.places.add(new_place)
            for edge in graph.edges:
                if edge[0] in sg and edge[1] in sg:
                    add_arc_from_to(corr[edge[0]], corr[edge[1]], subnet)
            strongly_connected_subnets.append([subnet, imarking, fmarking])

    return strongly_connected_subnets
Ejemplo n.º 3
0
def get_cycles_petri_net_places(net):
    """
    Get the cycles of a Petri net (returning only list of places belonging to the cycle)

    Parameters
    -------------
    net
        Petri net

    Returns
    -------------
    cycles
        Cycles (places) of the Petri net
    """
    graph, inv_dictionary = create_networkx_directed_graph(net)
    cycles = nx.simple_cycles(graph)
    cycles_places = []
    for cycle in cycles:
        cycles_places.append([])
        for el in cycle:
            if el in inv_dictionary and type(inv_dictionary[el]) is petri.petrinet.PetriNet.Place:
                cycles_places[-1].append(inv_dictionary[el])
    return cycles_places