Skip to content

Commit

Permalink
add additional PN->NX functionality that returns both PN->NX and NX-P…
Browse files Browse the repository at this point in the history
…N dictiornaries
  • Loading branch information
fit-sebastiaan-van-zelst committed Jan 25, 2022
1 parent 4b78a7a commit 2200a0f
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion pm4py/objects/petri_net/utils/networkx_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ def create_networkx_directed_graph(net, weight=None):
inv_dictionary
Correspondence between NetworkX nodes and Petri net entities
"""
# forward to new function
G, d, id = create_networkx_directed_graph_ret_dict_both_ways(net,weight)
return G,id

def create_networkx_directed_graph_ret_dict_both_ways(net, weight=None):
"""
Create a NetworkX directed graph from a Petri net
Parameters
--------------
net
Petri net
Returns
--------------
graph
NetworkX digraph
dictionary
dict mapping Petri net nodes to NetworkX nodes
inv_dictionary
dict mapping NetworkX nodes to Petri net nodes
"""
import networkx as nx

graph = nx.DiGraph()
Expand All @@ -89,4 +111,4 @@ def create_networkx_directed_graph(net, weight=None):
graph.edges[source, target]["weight"] = weight[inv_dictionary[source]]
else:
graph.edges[source, target]["weight"] = weight[inv_dictionary[target]]
return graph, inv_dictionary
return graph, dictionary, inv_dictionary

0 comments on commit 2200a0f

Please sign in to comment.