def execute_script(): log = pm4py.read_xes( os.path.join("..", "tests", "input_data", "running-example.xes")) alpha_petri_net, alpha_im, alpha_fm = pm4py.discover_petri_net_alpha(log) heuristics_petri_net, heuristics_im, heuristics_fm = pm4py.discover_petri_net_heuristics( log) tree = pm4py.discover_process_tree_inductive(log) print("tree discovered by inductive miner=") print(tree) inductive_petri_net, inductive_im, inductive_fm = pt_converter.apply(tree) print("is_wf_net alpha", is_wf_net.apply(alpha_petri_net)) print("is_wf_net heuristics", is_wf_net.apply(heuristics_petri_net)) print("is_wf_net inductive", is_wf_net.apply(inductive_petri_net)) print( "woflan alpha", woflan.apply(alpha_petri_net, alpha_im, alpha_fm, parameters={ woflan.Parameters.RETURN_ASAP_WHEN_NOT_SOUND: True, woflan.Parameters.PRINT_DIAGNOSTICS: False })) print( "woflan heuristics", woflan.apply(heuristics_petri_net, heuristics_im, heuristics_fm, parameters={ woflan.Parameters.RETURN_ASAP_WHEN_NOT_SOUND: True, woflan.Parameters.PRINT_DIAGNOSTICS: False })) print( "woflan inductive", woflan.apply(inductive_petri_net, inductive_im, inductive_fm, parameters={ woflan.Parameters.RETURN_ASAP_WHEN_NOT_SOUND: True, woflan.Parameters.PRINT_DIAGNOSTICS: False })) try: tree_alpha = wf_net_converter.apply(alpha_petri_net, alpha_im, alpha_fm) print(tree_alpha) except: traceback.print_exc() try: tree_heuristics = wf_net_converter.apply(heuristics_petri_net, heuristics_im, heuristics_fm) print(tree_heuristics) except: traceback.print_exc() try: tree_inductive = wf_net_converter.apply(inductive_petri_net, inductive_im, inductive_fm) print(tree_inductive) pm4py.view_process_tree(tree_inductive, format="svg") except: traceback.print_exc()
def check_soundness(petri_net: PetriNet, initial_marking: Marking, final_marking: Marking) -> bool: """ Check if a given Petri net is a sound WF-net. A Petri net is a WF-net iff: - it has a unique source place - it has a unique end place - every element in the WF-net is on a path from the source to the sink place A WF-net is sound iff: - it contains no live-locks - it contains no deadlocks - we are able to always reach the final marking For a formal definition of sound WF-net, consider: http://www.padsweb.rwth-aachen.de/wvdaalst/publications/p628.pdf Parameters --------------- petri_net Petri net initial_marking Initial marking final_marking Final marking Returns -------------- boolean Soundness """ from pm4py.algo.analysis.woflan import algorithm as woflan return woflan.apply(petri_net, initial_marking, final_marking)
def test_figure415(self): net = PetriNet("figure_4_15") p_1 = PetriNet.Place("p_1") p_2 = PetriNet.Place("p_2") p_3 = PetriNet.Place("p_3") p_4 = PetriNet.Place("p_4") p_5 = PetriNet.Place("p_5") p_6 = PetriNet.Place("p_6") p_7 = PetriNet.Place("p_7") net.places.add(p_1) net.places.add(p_2) net.places.add(p_3) net.places.add(p_4) net.places.add(p_5) net.places.add(p_6) net.places.add(p_7) t_1 = PetriNet.Transition("t_1", "t_1") t_2 = PetriNet.Transition("t_2", "t_2") t_3 = PetriNet.Transition("t_3", "t_3") t_4 = PetriNet.Transition("t_4", "t_4") t_5 = PetriNet.Transition("t_5", "t_5") t_6 = PetriNet.Transition("t_6", "t_6") net.transitions.add(t_1) net.transitions.add(t_2) net.transitions.add(t_3) net.transitions.add(t_4) net.transitions.add(t_5) net.transitions.add(t_6) petri_utils.add_arc_from_to(p_1, t_1, net) petri_utils.add_arc_from_to(t_1, p_3, net) petri_utils.add_arc_from_to(t_1, p_2, net) petri_utils.add_arc_from_to(t_1, p_5, net) petri_utils.add_arc_from_to(p_5, t_2, net) petri_utils.add_arc_from_to(p_5, t_5, net) petri_utils.add_arc_from_to(p_3, t_2, net) petri_utils.add_arc_from_to(p_3, t_4, net) petri_utils.add_arc_from_to(t_2, p_6, net) petri_utils.add_arc_from_to(t_2, p_4, net) petri_utils.add_arc_from_to(t_5, p_5, net) petri_utils.add_arc_from_to(t_5, p_3, net) petri_utils.add_arc_from_to(p_2, t_2, net) petri_utils.add_arc_from_to(t_3, p_2, net) petri_utils.add_arc_from_to(t_3, p_3, net) petri_utils.add_arc_from_to(t_3, p_4, net) petri_utils.add_arc_from_to(p_6, t_5, net) petri_utils.add_arc_from_to(p_6, t_6, net) petri_utils.add_arc_from_to(p_6, t_3, net) petri_utils.add_arc_from_to(t_4, p_6, net) petri_utils.add_arc_from_to(t_4, p_5, net) petri_utils.add_arc_from_to(p_4, t_3, net) petri_utils.add_arc_from_to(p_4, t_6, net) petri_utils.add_arc_from_to(p_4, t_4, net) petri_utils.add_arc_from_to(t_6, p_7, net) initial_marking = Marking() initial_marking[p_1] = 1 final_marking = Marking() final_marking[p_7] = 1 self.assertTrue(woflan.apply(net, initial_marking, final_marking, parameters={"print_diagnostics": False}))
def test_running_example_inductive(self): path = os.path.join("input_data", "running-example.xes") log = xes_import.apply(path) net, i_m, f_m = inductive_miner.apply(log) self.assertTrue( woflan.apply(net, i_m, f_m, parameters={"print_diagnostics": False}))
def execute_script(): log = xes_importer.apply( os.path.join("..", "tests", "input_data", "running-example.xes")) net, im, fm = alpha_miner.apply(log) is_sound, diagn = woflan.apply(net, im, fm, parameters={ "print_diagnostics": True, "return_diagnostics": True }) print("is_sound", is_sound) print(diagn)
if ENABLE_PETRI_EXPORTING: pnml_exporter.export_net(alpha_model, alpha_initial_marking, os.path.join( pnmlFolder, logNamePrefix + "_alpha.pnml"), final_marking=alpha_final_marking) t2 = time.time() print("time interlapsed for calculating Alpha Model", (t2 - t1)) if CHECK_SOUNDNESS: try: res_woflan, diagn = woflan.apply( alpha_model, alpha_initial_marking, alpha_final_marking, parameters={ "return_asap_when_not_sound": WOFLAN_RETURN_ASAP, "print_diagnostics": WOFLAN_PRINT_DIAGNOSTICS, "return_diagnostics": WOFLAN_RETURN_DIAGNOSTICS }) print("alpha woflan", res_woflan) except: if ENABLE_PETRI_EXPORTING_DEBUG: exce = traceback.format_exc() pnml_exporter.export_net( alpha_model, alpha_initial_marking, os.path.join(pnmlFolder, logNamePrefix + "_alpha.pnml"), final_marking=alpha_final_marking) F = open(logNamePrefix + "_alpha.txt", "w")