def init_table_normal(sigma, ota): """ Initial tables. """ S = [Element([], [])] R = [] E = [] for s in S: if ota.initstate_name in ota.accept_names: s.value.append(1) else: s.value.append(0) tables = [OTATable(S, R, E, parent=-1, reason="init")] for i in range(0, len(sigma)): temp_tables = [] for table in tables: new_tw = Timedword(sigma[i], 0) res = ota.is_accepted_delay([new_tw]) if res == -1: # Now at sink guesses = [True] else: guesses = [True, False] for guess in guesses: new_rtw = ResetTimedword(new_tw.action, new_tw.time, guess) new_element = Element([new_rtw], [res]) temp_R = table.R + [new_element] new_table = OTATable(S, temp_R, E, parent=-1, reason="init") temp_tables.append(new_table) tables = temp_tables return tables
def is_evidence_closed(self, ota): """ Determine whether the table is evidence-closed. """ flag = True table_tws = [s.tws for s in self.S] + [r.tws for r in self.R] new_added = [] for s in self.S: local_s = s.tws current_location_name = ota.run_resettimedwords(local_s) for e in self.E: temp_e = [] current_location = copy.deepcopy(current_location_name) reset = True clock_valuation = 0 if len(s.tws) > 0: reset = local_s[len(local_s) - 1].reset clock_valuation = local_s[len(local_s) - 1].time for tw in e: new_timedword = Timedword(tw.action, tw.time) if reset == False and new_timedword.time < clock_valuation: temp_e.append(ResetTimedword(tw.action, tw.time, True)) break else: for otatran in ota.trans: if otatran.source == current_location and otatran.is_pass(new_timedword): new_resettimedword = ResetTimedword(tw.action, tw.time, otatran.reset) temp_e.append(new_resettimedword) clock_valuation = new_timedword.time reset = otatran.reset if reset == True: clock_valuation = 0 current_location = otatran.target break temp_se = [rtw for rtw in s.tws] + [rtw for rtw in temp_e] prefs = prefixes(temp_se) for pref in prefs: if pref not in table_tws: table_tws.append(pref) new_tws = [tws for tws in pref] new_element = Element(new_tws, []) new_added.append(new_element) if len(new_added) > 0: flag = False return flag, new_added
def build_logical_resettimedwords(element, e, e_index): """ build a logical reset timedwords based on an element in S,R and a suffix e in E. """ lrtws = [tw for tw in element.tws] temp_suffixes_timedwords = [ResetTimedword(tw.action, tw.time, element.suffixes_resets[e_index][j]) for j, tw in enumerate(e)] lrtws = lrtws + temp_suffixes_timedwords return lrtws, True
def make_closed(new_S, new_R, move, table, sigma, ota): """ Make table closed. """ new_E = table.E closed_table = OTATable(new_S, new_R, new_E, parent=table.id, reason="makeclosed") table_tws = [s.tws for s in closed_table.S] + [r.tws for r in closed_table.R] temp_resets = [[]] for i in range(0, len(sigma)): dtws = lRTWs_to_DTWs(move.tws) res = ota.is_accepted_delay(dtws + [Timedword(sigma[i], 0)]) if res == -1: guesses = [True] else: guesses = [True, False] new_situations = [] for guess in guesses: new_rtw = ResetTimedword(sigma[i], 0, guess) for situation in temp_resets: temp = copy.deepcopy(situation) + [new_rtw] new_situations.append(temp) temp_resets = new_situations OTAtables = [] for situation in temp_resets: new_rs = [] for new_rtw in situation: new_r = [tw for tw in move.tws] + [new_rtw] if new_r not in table_tws: new_rs.append(Element(new_r, [], [])) temp_R = [r for r in new_R] + new_rs temp_table = OTATable(new_S, temp_R, new_E, parent=table.id, reason="makeclosed") OTAtables.append(temp_table) # guess the resets of suffixes for each prefix and fill OTAtables_after_guessing_resets = [] for otatable in OTAtables: new_r_start_index = len(new_R) new_r_end_index = len(otatable.R) temp_otatables = [otatable] for i in range(new_r_start_index, new_r_end_index): resets_situations = guess_resets_in_suffixes(otatable) new_tables = [] for j in range(0, len(resets_situations)): for temp_table in temp_otatables: new_table = copy.deepcopy(temp_table) temp_otatable = OTATable(new_table.S, new_table.R, new_table.E, parent=table.id, reason="makeclosed") temp_otatable.R[i].suffixes_resets = resets_situations[j] new_table = copy.deepcopy(temp_otatable) if fill(new_table.R[i], new_table.E, ota): new_tables.append(new_table) temp_otatables = [tb for tb in new_tables] OTAtables_after_guessing_resets = OTAtables_after_guessing_resets + temp_otatables return OTAtables_after_guessing_resets
def guess_ctx_reset(dtws, ota): """ When receiving a counterexample (delay timed word), guess all resets and return all reset delay timed words as ctx candidates. """ new_tws = [Timedword(tw.action, tw.time) for tw in dtws] ctxs = [[]] for i in range(len(new_tws)): templist = [] res = ota.is_accepted_delay(dtws[:i + 1]) # Whether the counterexample leads to the sink for rtws in ctxs: if res == -1: temp_r = rtws + [ResetTimedword(new_tws[i].action, new_tws[i].time, True)] templist.append(temp_r) else: temp_n = rtws + [ResetTimedword(new_tws[i].action, new_tws[i].time, False)] temp_r = rtws + [ResetTimedword(new_tws[i].action, new_tws[i].time, True)] templist.append(temp_n) templist.append(temp_r) ctxs = templist return ctxs
def dTWs_to_dRTWs(letterword, flag, ota): tws = findDelayTimedwords(letterword, flag, ota.sigma) dRTWs = [] if len(tws) == 0: return [] else: current_location = ota.initstate_name current_clock_valuation = 0 reset = True for tw in tws: if not reset: current_clock_valuation = current_clock_valuation + tw.time else: current_clock_valuation = tw.time for tran in ota.trans: if tran.source == current_location and tran.is_pass( Timedword(tw.action, current_clock_valuation)): dRTWs.append(ResetTimedword(tw.action, tw.time, tran.reset)) current_location = tran.target reset = tran.reset break return dRTWs
def guess_resets_in_newsuffix(table, fix_reset_i, fix_reset_j, reset_i, reset_j, ota): """ When making consistent, guess the resets in the new suffix. """ temp_suffixes_resets = [] new_e = table.E[-1] new_e_length = len(new_e) S_U_R_length = len(table.S) + len(table.R) length = S_U_R_length * new_e_length guesses = [] if new_e_length == 1: pass elif new_e_length == 2: for i in range(S_U_R_length): if i < len(table.S): to_sink = table.S[i].value[0] else: to_sink = table.R[i - len(table.S)].value[0] if i == fix_reset_i: guesses.append([reset_i]) elif i == fix_reset_j: guesses.append([reset_j]) elif to_sink == -1: guesses.append([True]) else: if i < len(table.S): prefix = table.S[i].tws else: prefix = table.R[i - len(table.S)].tws ltwR = prefix + [ResetTimedword(new_e[0].action, new_e[0].time, True), ResetTimedword(new_e[1].action, new_e[1].time, None)] ltwN = prefix + [ResetTimedword(new_e[0].action, new_e[0].time, False), ResetTimedword(new_e[1].action, new_e[1].time, None)] dtwR = lRTWs_to_DTWs(ltwR) dtwN = lRTWs_to_DTWs(ltwN) res_R = ota.is_accepted_delay(dtwR) res_N = ota.is_accepted_delay(dtwN) if res_R == -2: guesses.append([False]) elif res_N == -2: guesses.append([True]) elif res_R == res_N: guesses.append([True]) else: guesses.append([True, False]) else: for i in range(S_U_R_length): guesses.append([True, False]) temp_resets = [[]] for i in range(0, length): temp = [] for resets_situation in temp_resets: if i % new_e_length == new_e_length - 1: temp.append(resets_situation + [None]) else: guess = guesses[i // new_e_length] for g in guess: temp.append(resets_situation + [g]) temp_resets = temp for resets_situation in temp_resets: index = 0 suffixes_resets = [] for i in range(0, S_U_R_length): e_resets = resets_situation[index: index + new_e_length] suffixes_resets.append(e_resets) index = index + new_e_length temp_suffixes_resets.append(suffixes_resets) return temp_suffixes_resets