def test_banana_land(self): petri = PetriNet(6) # Adding transitions: petri.add_transition( OmegaTransition(np.array([1, 0, 0, 0, 0, 0]), np.array([-1, 1, 1, 0, 0, 0]))) petri.add_transition( OmegaTransition(np.array([1, 0, 0, 0, 0, 0]), np.array([-1, 1, 0, 1, 0, 0]))) petri.add_transition( OmegaTransition(np.array([1, 0, 0, 0, 0, 0]), np.array([-1, 0, 1, 1, 0, 0]))) petri.add_transition( OmegaTransition(np.array([0, 1, 0, 0, 0, 0]), np.array([0, 0, 0, 0, 1, 0]))) petri.add_transition( OmegaTransition(np.array([0, 0, 0, 1, 0, 0]), np.array([0, 0, 0, -1, 0, 1]))) petri.add_transition( OmegaTransition(np.array([0, 0, 1, 0, 1, 0]), np.array([0, 0, 0, 0, -1, 1]))) # Marking the net: petri.mark_the_petri_net(OmegaMarking(np.array([1, 0, 0, 0, 0, 0]))) # Initializing the tree: cov_tree = CovTree(petri, petri.get_mark()) anti_chain = cov_tree.generate_cov_tree(True) self.assertEqual(len(anti_chain), 4) markings = [] for node in anti_chain: markings.append(node.get_mark()) self.assertTrue(OmegaMarking(np.array([1, 0, 0, 0, 0, 0])) in markings) self.assertTrue( OmegaMarking(np.array([0, 1, 1, 0, float("inf"), float("inf")])) in markings) self.assertTrue( OmegaMarking(np.array([0, 1, 0, 1, float("inf"), 0])) in markings) self.assertTrue(OmegaMarking(np.array([0, 0, 1, 1, 0, 0])) in markings) self.assertTrue(len(cov_tree._accelerations) == 2)
def test_cov_tree_accelerate(self): petri = PetriNet(4) mark1 = OmegaMarking(np.array([1, 3, 6, float("inf")])) node1 = CovNode(mark1, mark1.get_dim()) mark2 = OmegaMarking(np.array([1, 3, 5, float("inf")])) node2 = CovNode(mark2, mark2.get_dim(), node1._depth, node1) tr = CovTree(petri, mark1) mark0 = OmegaMarking(np.array([0, 2, 5, 0])) node0 = CovNode(mark0, mark0.get_dim(), tr.get_root()) node1.change_parent(node0) tr.add_node(node0) tr.add_node(node1) tr.add_node(node2) tr._accelerate(node2, True) self.assertTrue(len(tr._accelerations) == 1)
def test_Alain_2005(self): petri = PetriNet(7) # Adding transitoins: petri.add_transition( OmegaTransition(np.array([1, 0, 0, 0, 0, 0, 0]), np.array([-1, 1, 0, 0, 0, 0, 0]))) petri.add_transition( OmegaTransition(np.array([1, 0, 0, 0, 0, 0, 0]), np.array([-1, 0, 0, 0, 0, 0, 1]))) petri.add_transition( OmegaTransition(np.array([1, 0, 0, 0, 0, 0, 0]), np.array([-1, 0, 0, 0, 0, 1, 0]))) petri.add_transition( OmegaTransition(np.array([0, 0, 0, 0, 0, 1, 0]), np.array([0, 0, 0, 1, 2, -1, 0]))) petri.add_transition( OmegaTransition(np.array([0, 1, 0, 0, 0, 0, 0]), np.array([0, -1, 1, 0, 0, 0, 0]))) petri.add_transition( OmegaTransition(np.array([0, 0, 1, 0, 0, 0, 0]), np.array([0, 0, -1, 1, 0, 0, 0]))) petri.add_transition( OmegaTransition(np.array([0, 0, 0, 1, 0, 0, 0]), np.array([0, 0, 1, -1, 1, 0, 0]))) petri.add_transition( OmegaTransition(np.array([0, 0, 0, 0, 0, 0, 1]), np.array([0, 1, 0, 0, 1, 0, -1]))) # Marking the net: petri.mark_the_petri_net(OmegaMarking(np.array([1, 0, 0, 0, 0, 0, 0]))) # Initializing the tree: cov_tree = CovTree(petri, petri.get_mark()) anti_chain = cov_tree.generate_cov_tree() self.assertEqual(len(anti_chain), 6)
# cov.check_for_correctness = False cov.timeout = 900 cov.type_of_graph_traversal = 'DFS' # # cov.use_z3_to_guess_accelerations = True # # cov.z3_timeout = 15 # # # cProfile.run('cov.generate_cov_tree()') # # cProfile.run('cov.generate_cov_tree()') # # anti_chain = cov.generate_cov_tree() # # cov.check_for_cover(target, petri_file) cov.generate_cov_tree() quit() petri_file = "/home/ikhmelnitsky/Desktop/svn/min cover/min_cover_code/benchmarks/mincover/mist/PN/mesh3x2.spec" petri, target = load_petri_net_from_spec(petri_file, True) cov = CovTree(petri, petri.get_mark()) cov.keep_accelerations = True cov.verbose = True # cov.check_for_correctness = False cov.timeout = 900 cov.type_of_graph_traversal = 'DFS' # # cov.use_z3_to_guess_accelerations = True # # cov.z3_timeout = 15 # # # cProfile.run('cov.generate_cov_tree()') # # cProfile.run('cov.generate_cov_tree()') # # anti_chain = cov.generate_cov_tree() # # cov.check_for_cover(target, petri_file) cov.generate_cov_tree() run_benchmarks("/home/ikhmelnitsky/Desktop/svn/min cover/min_cover_code/benchmarks/big_coverabillty","/home/ikhmelnitsky/Desktop/svn/min cover/min_cover_code/benchmarks/big_coverabillty/results")
def test_mesh_2x2(self): petri = load_petri_net_from_spec("benchmarks/mesh2x2.spec") cov = CovTree(petri, petri.get_mark().get_marking()) cov.check_for_correctness = False anti_chain = cov.generate_cov_tree() self.assertEqual(len(anti_chain), 256)
def test_cov_tree_create_insert_delete(self): petri = PetriNet(4) mark1 = OmegaMarking(np.array([1, 3, 6, float("inf")])) node1 = CovNode(mark1, mark1.get_dim()) mark2 = OmegaMarking(np.array([1, 3, 5, float("inf")])) node2 = CovNode(mark2, mark2.get_dim(), node1._depth, node1) tr = CovTree(petri, mark1) mark0 = OmegaMarking(np.array([0, 2, 5, 0])) node0 = CovNode(mark0, mark0.get_dim(), tr.get_root()) node1.change_parent(node0) tr.add_node(node0) tr.add_node(node1) tr.add_node(node2) # print(node2.GetMark()._marking) self.assertEqual(len(tr.get_vertices()), 4) tr.delete_node(node2) self.assertEqual(len(tr.get_vertices()), 3) tr.delete_node(node0) self.assertEqual(len(tr.get_vertices()), 1)
def run_benchmark(name, petri: petri_net.PetriNet, time_out, init_marking=None, with_acc=True): benchmark = Benchmark(name) print("starting %s" % name + " numb of trans: " + str(len(petri.get_transitions())) + " num of places: " + str(petri.get_dim())) start_time = time.time() if init_marking is None: cov = CovTree(petri, petri.get_mark()) else: cov = CovTree(petri, init_marking) cov.keep_accelerations = with_acc cov.type_of_graph_traversal = "DFS" cov.use_z3_to_guess_accelerations = False cov.check_for_correctness = False cov.verbose = True cov.timeout = time_out benchmark.clover = cov.generate_cov_tree() benchmark.timeout = benchmark.clover is None elapsed_time = time.time() - start_time benchmark.max_vertices = cov.max_size benchmark.max_accelerations = cov.max_size_of_acc benchmark.final_accelerations = len(cov._accelerations) benchmark.final_vertices = len(cov._verSet) benchmark.used_accelerations = cov.use_of_acc benchmark.time = elapsed_time benchmark.places = len(petri.get_places()) benchmark.transitions = len(petri.get_transitions()) benchmark.num_of_comparisons = cov.num_of_comparisons benchmark.num_of_recheck = cov.num_of_rechecks return benchmark, cov