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_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: Dict[PetriNet.Place, int], final_marking: Dict[PetriNet.Place, int]) -> 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.evaluation.soundness.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) utils.add_arc_from_to(p_1, t_1, net) utils.add_arc_from_to(t_1, p_3, net) utils.add_arc_from_to(t_1, p_2, net) utils.add_arc_from_to(t_1, p_5, net) utils.add_arc_from_to(p_5, t_2, net) utils.add_arc_from_to(p_5, t_5, net) utils.add_arc_from_to(p_3, t_2, net) utils.add_arc_from_to(p_3, t_4, net) utils.add_arc_from_to(t_2, p_6, net) utils.add_arc_from_to(t_2, p_4, net) utils.add_arc_from_to(t_5, p_5, net) utils.add_arc_from_to(t_5, p_3, net) utils.add_arc_from_to(p_2, t_2, net) utils.add_arc_from_to(t_3, p_2, net) utils.add_arc_from_to(t_3, p_3, net) utils.add_arc_from_to(t_3, p_4, net) utils.add_arc_from_to(p_6, t_5, net) utils.add_arc_from_to(p_6, t_6, net) utils.add_arc_from_to(p_6, t_3, net) utils.add_arc_from_to(t_4, p_6, net) utils.add_arc_from_to(t_4, p_5, net) utils.add_arc_from_to(p_4, t_3, net) utils.add_arc_from_to(p_4, t_6, net) utils.add_arc_from_to(p_4, t_4, net) 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))
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)
def calc_and_time_soudness(): start_time = time.time() is_sound = woflan.apply( petrinet_res, initial_mark, final_mark, parameters={ woflan.Parameters.RETURN_ASAP_WHEN_NOT_SOUND: True, woflan.Parameters.PRINT_DIAGNOSTICS: False, woflan.Parameters.RETURN_DIAGNOSTICS: False }) calc_duration = time.time() - start_time return str(is_sound), calc_duration
def soundness_woflan(petri_net, initial_marking, final_marking): """ Check soundness using WOFLAN Parameters --------------- petri_net Petri net initial_marking Initial marking final_marking Final marking Returns -------------- boolean Soundness """ from pm4py.evaluation.soundness.woflan import algorithm as woflan return woflan.apply(petri_net, initial_marking, final_marking)
def soundness_woflan(petri_net, initial_marking, final_marking): """ Check soundness using WOFLAN Parameters --------------- petri_net Petri net initial_marking Initial marking final_marking Final marking Returns -------------- boolean Soundness """ import warnings warnings.warn( 'pm4py.soundness_woflan() is deprecated, use pm4py.check_soundness() instead' ) from pm4py.evaluation.soundness.woflan import algorithm as woflan return woflan.apply(petri_net, initial_marking, final_marking)
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))
def test_figure42(self): net = PetriNet("figure_4_2") 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") p_8 = PetriNet.Place("p_8") 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) net.places.add(p_8) 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") t_7 = PetriNet.Transition("t_7", "t_7") t_8 = PetriNet.Transition("t_8", "t_8") 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) net.transitions.add(t_7) net.transitions.add(t_8) utils.add_arc_from_to(p_1, t_1, net) utils.add_arc_from_to(t_1, p_6, net) utils.add_arc_from_to(t_1, p_4, net) utils.add_arc_from_to(p_4, t_4, net) utils.add_arc_from_to(p_4, t_5, net) utils.add_arc_from_to(t_2, p_6, net) utils.add_arc_from_to(t_2, p_4, net) utils.add_arc_from_to(t_4, p_3, net) utils.add_arc_from_to(t_4, p_5, net) utils.add_arc_from_to(t_5, p_7, net) utils.add_arc_from_to(t_7, p_4, net) utils.add_arc_from_to(p_3, t_2, net) utils.add_arc_from_to(p_3, t_3, net) utils.add_arc_from_to(p_5, t_2, net) utils.add_arc_from_to(p_5, t_3, net) utils.add_arc_from_to(p_5, t_4, net) utils.add_arc_from_to(p_7, t_6, net) utils.add_arc_from_to(p_8, t_7, net) utils.add_arc_from_to(p_8, t_8, net) utils.add_arc_from_to(t_3, p_2, net) utils.add_arc_from_to(p_6, t_6, net) utils.add_arc_from_to(t_6, p_5, net) utils.add_arc_from_to(t_8, p_8, net) initial_marking = Marking() initial_marking[p_1] = 1 final_marking = Marking() final_marking[p_2] = 1 self.assertFalse(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}))
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")