Exemplo n.º 1
0
    def __init__(self, petri_net: PetriNet, mark: np.array):
        """
        Constructor
        """
        assert (isinstance(petri_net, PetriNet)), "Has to be a Petri Net"

        self._petriNet = petri_net
        self._dim = petri_net.get_dim()
        self._accelerations = np.array([])

        self._root = CovNode(mark, self._dim, 0, None)
        self._vertices = [self._root]  # a list of all the vertices
        self._front = [
            self._root
        ]  # a list of the vertices which still weren't processed
        self._verSet = {
            tuple(self._root.marking)
        }  # A set of all the marks, used to increase speed(hash)

        # Options for the run of generate_cov_tree():
        self.timeout = float("inf")  # The time out for generate_cov_tree()

        self.keep_accelerations = True  # Remember and reuse previous accelerations

        self.use_z3_to_guess_accelerations = False  # Use z3 to try to guess some accelerations before starting for
        self.z3_timeout = 10  # z3_timeout time

        self.check_for_correctness = True  # in the end of generate_cov_tree() preform a few checks for correctness

        # setting the graph traversal:
        self._type_of_graph_traversal = 1
        self.pushFront = self.push_into_front_function()
        self.popFront = self.pop_next_vertex_func()
        self.deleteFromFront = self.remove_from_front_function()

        # Variables for performance:
        self.verbose = False
        self.max_size = 1
        self.max_size_of_acc = 0
        self.use_of_acc = 0
        self.count = 0
        self.max_depth = 0
        self.number_of_deleted_nodes = 0
        self.number_of_deleted_decedents = 0
        self.max_depth_of_acc = 0
        self.average_num_of_successors = 0
        self.num_of_comparisons = 0
        self.average_vertics_size = 1
        self.num_of_accelaration_tried = 0
        self.num_of_rechecks = 0
Exemplo n.º 2
0
def export_petri_to_valmari(petri_net: PetriNet, filename):
    file = open(filename, "a")

    # file.write("samples = []")
    # file.write("omega = float('inf')")
    # file.write("def Init():")
    file.write("%d %d \n" % (petri_net.get_dim(), len(petri_net.get_transitions())))

    trun_num = 1
    for tran in petri_net.get_transitions():

        place_num = 1
        for p in (tran.get_incidence() + tran.get_pre()):
            if p <= 0:
                place_num += 1
                continue
            file.write("-%d \n" % trun_num)
            file.write("0 %d \n" % p)
            file.write("%d \n" % place_num)
            place_num += 1
        place_num = 1
        for p in tran.get_pre():
            if p <= 0:
                place_num += 1
                continue
            file.write("%d \n" % place_num)
            file.write("0 %d \n" % p)
            file.write("-%d \n" % trun_num)
            place_num += 1
        trun_num += 1

    file.write("0 \n")

    place_num = 1
    for p in petri_net.get_mark():
        if p <= 0:
            place_num += 1
            continue
        if p == float("inf"):
            file.write("-32767 \n")
            file.write("%d \n" % place_num)
        else:
            file.write("-%d \n" % p)
            file.write("%d \n" % place_num)
        place_num += 1

    file.write("0 \n")
    file.close()
Exemplo n.º 3
0
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