def __search(sync_net, ini, fin, cost_function, skip, ret_tuple_as_trans_desc=False, max_align_time_trace=DEFAULT_MAX_ALIGN_TIME_TRACE): start_time = time.time() decorate_transitions_prepostset(sync_net) decorate_places_preset_trans(sync_net) closed = set() ini_state = utils.DijkstraSearchTuple(0, ini, None, None, 0) open_set = [ini_state] heapq.heapify(open_set) visited = 0 queued = 0 traversed = 0 trans_empty_preset = set(t for t in sync_net.transitions if len(t.in_arcs) == 0) while not len(open_set) == 0: if (time.time() - start_time) > max_align_time_trace: return None curr = heapq.heappop(open_set) current_marking = curr.m already_closed = current_marking in closed if already_closed: continue if current_marking == fin: return utils.__reconstruct_alignment(curr, visited, queued, traversed, ret_tuple_as_trans_desc=ret_tuple_as_trans_desc) closed.add(current_marking) visited += 1 possible_enabling_transitions = copy(trans_empty_preset) for p in current_marking: for t in p.ass_trans: possible_enabling_transitions.add(t) enabled_trans = [t for t in possible_enabling_transitions if t.sub_marking <= current_marking] trans_to_visit_with_cost = [(t, cost_function[t]) for t in enabled_trans if not ( t is not None and utils.__is_log_move(t, skip) and utils.__is_model_move(t, skip))] for t, cost in trans_to_visit_with_cost: traversed += 1 new_marking = utils.add_markings(current_marking, t.add_marking) if new_marking in closed: continue queued += 1 tp = utils.DijkstraSearchTuple(curr.g + cost, new_marking, curr, t, curr.l + 1) heapq.heappush(open_set, tp)
def __search(sync_net, ini, fin, cost_function, skip): """ Search function for the decomposed/recomposed alignments Parameters ------------ sync_net Synchronous Petri net ini Initial marking fin Final marking cost_function Cost function skip Skip symbol Returns ------------- ali Alignment (if not None) """ decorate_transitions_prepostset(sync_net) decorate_places_preset_trans(sync_net) closed = set() ini_state = utils.DijkstraSearchTuple(0, ini, None, None, 0) open_set = [ini_state] heapq.heapify(open_set) visited = 0 queued = 0 traversed = 0 trans_empty_preset = set(t for t in sync_net.transitions if len(t.in_arcs) == 0) while not len(open_set) == 0: curr = heapq.heappop(open_set) current_marking = curr.m already_closed = current_marking in closed if already_closed: continue if current_marking == fin: return utils.__reconstruct_alignment(curr, visited, queued, traversed, ret_tuple_as_trans_desc=True) closed.add(current_marking) visited += 1 possible_enabling_transitions = copy(trans_empty_preset) for p in current_marking: for t in p.ass_trans: possible_enabling_transitions.add(t) enabled_trans = [ t for t in possible_enabling_transitions if t.sub_marking <= current_marking ] trans_to_visit_with_cost = [ (t, cost_function[t]) for t in enabled_trans if not (t is not None and utils.__is_log_move(t, skip) and utils.__is_model_move(t, skip)) ] for t, cost in trans_to_visit_with_cost: traversed += 1 new_marking = utils.add_markings(current_marking, t.add_marking) if new_marking in closed: continue queued += 1 tp = utils.DijkstraSearchTuple(curr.g + cost, new_marking, curr, t, curr.l + 1) heapq.heappush(open_set, tp)