def export_petri_to_spec(petri_net: PetriNet, filename, write_initial_marking=False): file = open(filename, "a") place_names = [] for p in petri_net.get_places(): place_names.append("x" + str(p)) file.write("vars\n\t") for place in place_names: file.write(place + " ") file.write("\n\nrules\n") for tran in petri_net.get_transitions(): pre = tran.get_pre() first = True for p in petri_net.get_places(): if pre[p] > 0: if first: file.write("\t") else: file.write(" , ") file.write(place_names[p] + " >= " + str(int(pre[p]))) first = False file.write(" ->\n") first = True incidence = tran.get_incidence() for p in petri_net.get_places(): if incidence[p] != 0: if not first: file.write(",\n") if incidence[p] > 0: file.write("\t\t" + place_names[p] + "' = " + place_names[p] + "+" + str(int(incidence[p]))) else: file.write("\t\t" + place_names[p] + "' = " + place_names[p] + "-" + str(int(incidence[p]) * (-1))) first = False file.write(";\n\n") if not write_initial_marking: file.close() return file.write("init\n\t") first = True init_mark = (petri_net.get_mark()) for p in petri_net.get_places(): if not first: file.write(" , ") if init_mark[p] == float("inf"): file.write(place_names[p] + " >= 1") else: file.write(place_names[p] + " = " + str(int(init_mark[p]))) first = False file.close()
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