def make_consistent(table, consistent_add, system): table.E.append(consistent_add) for i in range(0, len(table.S)): if is_valid(table.S[i].LRTWs): LTWs = LRTW_to_LTW(table.S[i].LRTWs) + consistent_add LRTWs, value = TQs(LTWs, system) temp_value = value table.S[i].values.append(temp_value) table.S[i].suffixes_resets.append(get_resets( LRTWs, consistent_add)) else: table.S[i].values.append(-1) table.S[i].suffixes_resets.append([True] * len(consistent_add)) for j in range(0, len(table.R)): if is_valid(table.R[j].LRTWs): LTWs = LRTW_to_LTW(table.R[j].LRTWs) + consistent_add LRTWs, value = TQs(LTWs, system) temp_value = value table.R[j].values.append(temp_value) table.R[j].suffixes_resets.append(get_resets( LRTWs, consistent_add)) else: table.R[j].values.append(-1) table.R[j].suffixes_resets.append([True] * len(consistent_add)) return table
def check_table_consistent(table): LRTWs_list = [] LTWs_list = [] for s in table.S: for i in range(1, len(s.LRTWs) + 1): temp_LRTWs = s.LRTWs[:i] temp_LTWs = LRTW_to_LTW(temp_LRTWs) if temp_LTWs in LTWs_list: guess_LRTWs = LRTWs_list[LTWs_list.index(temp_LTWs)] if guess_LRTWs != temp_LRTWs: return False else: LRTWs_list.append(temp_LRTWs) LTWs_list.append(temp_LTWs) for index in range(len(table.E)): if len(table.E[index]) >= 2: merge_LRTWs = s.LRTWs + combine_LRTWs_with_LTWs( table.E[index][:-1], s.suffixes_resets[index][:-1]) for i in range(len(s.LRTWs), len(merge_LRTWs) + 1): temp_LRTWs = merge_LRTWs[:i] temp_LTWs = LRTW_to_LTW(temp_LRTWs) if temp_LTWs in LTWs_list: guess_LRTWs = LRTWs_list[LTWs_list.index(temp_LTWs)] if guess_LRTWs != temp_LRTWs: return False else: LRTWs_list.append(temp_LRTWs) LTWs_list.append(temp_LTWs) for r in table.R: for j in range(1, len(r.LRTWs) + 1): temp_LRTWs = r.LRTWs[:j] temp_LTWs = LRTW_to_LTW(temp_LRTWs) if temp_LTWs in LTWs_list: guess_LRTWs = LRTWs_list[LTWs_list.index(temp_LTWs)] if guess_LRTWs != temp_LRTWs: return False else: LRTWs_list.append(temp_LRTWs) LTWs_list.append(temp_LTWs) for index in range(len(table.E)): if len(table.E[index]) >= 2: merge_LRTWs = r.LRTWs + combine_LRTWs_with_LTWs( table.E[index][:-1], r.suffixes_resets[index][:-1]) for i in range(len(r.LRTWs), len(merge_LRTWs) + 1): temp_LRTWs = merge_LRTWs[:i] temp_LTWs = LRTW_to_LTW(temp_LRTWs) if temp_LTWs in LTWs_list: guess_LRTWs = LRTWs_list[LTWs_list.index(temp_LTWs)] if guess_LRTWs != temp_LRTWs: return False else: LRTWs_list.append(temp_LRTWs) LTWs_list.append(temp_LTWs) return True
def fill_table_row(LRTWs, table, flag, system): # flag判断是否进入Error状态或查询是否有效 - flag为True表示已进入Error状态或无效 if flag: values = [-1] * len(table.E) system.mq_num += len(table.E) suffixes_resets = [] for e in table.E: value = [True] * len(e) suffixes_resets.append(value) element = Element(LRTWs, values, suffixes_resets) else: values = [] suffixes_resets = [] if is_valid(LRTWs): for e in table.E: LTWs = LRTW_to_LTW(LRTWs) + e tempLRTWs, tempValue = TQs(LTWs, system) if len(e) != 0: resetList = get_resets(tempLRTWs, e) value = tempValue else: resetList = [] value = tempValue values.append(value) suffixes_resets.append(resetList) else: for e in table.E: value = [True] * len(e) suffixes_resets.append(value) values = [-1] * len(table.E) system.mq_num += len(table.E) element = Element(LRTWs, values, suffixes_resets) return element
def minimize_counterexample(hypothesis, system, ctx): # Find sequence of reset information reset = [] DRTWs, outputs = system.test_DTWs(ctx) for drtw in DRTWs: reset.append(drtw.reset) # ctx to LTWs LTWs = LRTW_to_LTW(DRTW_to_LRTW(DRTWs)) # start minimize for i in range(len(LTWs)): while True: if i == 0 or reset[i - 1]: can_reduce = (LTWs[i].time > 0) else: can_reduce = (LTWs[i].time > LTWs[i - 1].time) if not can_reduce: break LTWs_temp = copy.deepcopy(LTWs) LTWs_temp[i] = TimedWord(LTWs[i].action, one_lower(LTWs[i].time)) flag, ctx = is_counterexample(hypothesis, system, LTW_to_DTW(LTWs_temp, reset)) if not flag: break LTWs = copy.deepcopy(LTWs_temp) return LTW_to_DTW(LTWs, reset)
def extend_R(s, actions, table, system): table_LRTWS = [s.LRTWs for s in table.S] + [r.LRTWs for r in table.R] for action in actions: LTWs = LRTW_to_LTW(s.LRTWs) + [TimedWord(action, 0)] LRTWs, value = TQs(LTWs, system) system.mq_num -= 1 if value == -1: element = fill_table_row(LRTWs, table, True, system) else: element = fill_table_row(LRTWs, table, False, system) if element.LRTWs not in table_LRTWS: table.R.append(element) return table