def test_forwardcheck_empty_domain(): constrainer = SomeNotInSetConstraint(set("abc")) v1, v2 = variables = [Variable("v1"), Variable("v2")] domains = {v1: Domain(["a"]), v2: Domain(["b"])} assert constrainer(variables, domains, {v1: "a"}) assert not constrainer(variables, domains, {v1: "a"}, True)
def test_forwardcheck_empty_domain(): constrainer = SomeNotInSetConstraint(set('abc')) v1, v2 = variables = [Variable('v1'), Variable('v2')] domains = {v1: Domain(['a']), v2: Domain(['b'])} assert constrainer(variables, domains, {v1: 'a'}) assert not constrainer(variables, domains, {v1: 'a'}, True)
def __init__(self, title, professor): """. PARAMETERS TYPE Potential Arguments ----------------------------------------------- title string 'csc', 'phy' professor string 'DrShade' """ Variable.__init__(self, title) self.title = title self.professor = professor
def test_forwardcheck(): constrainer = SomeNotInSetConstraint(set('abc'), n=2) v1, v2, v3 = variables = [Variable('v1'), Variable('v2'), Variable('v3')] domains = {v1: Domain(['a']), v2: Domain(['b', 'y']), v3: Domain(['c', 'z'])} assert constrainer(variables, domains, {v1: 'a'}) assert ['a'] == list(domains[v1]) assert ['b', 'y'] == list(domains[v2]) assert ['c', 'z'] == list(domains[v3]) assert constrainer(variables, domains, {v1: 'a'}, True) assert ['a'] == list(domains[v1]) assert ['y'] == list(domains[v2]) assert ['z'] == list(domains[v3])
def test_forwardcheck_exact(): constrainer = SomeNotInSetConstraint(set('abc'), n=2, exact=True) v1, v2, v3 = variables = [Variable('v1'), Variable('v2'), Variable('v3')] assignments = {v1: 'a'} domains = {v1: Domain(['a', 'x']), v2: Domain(['b', 'y']), v3: Domain(['c', 'z'])} assert constrainer(variables, domains, assignments) assert constrainer(variables, domains, assignments, True) assert 'b' not in domains[v2] assert 'y' in domains[v2] assert 'c' not in domains[v3] assert 'z' in domains[v3] domains = {v1: Domain(['a', 'x']), v2: Domain(['b', 'y']), v3: Domain(['c'])} assert constrainer(variables, domains, assignments) assert not constrainer(variables, domains, assignments, True)
def test_forwardcheck(): constrainer = SomeNotInSetConstraint(set("abc"), n=2) v1, v2, v3 = variables = [Variable("v1"), Variable("v2"), Variable("v3")] domains = { v1: Domain(["a"]), v2: Domain(["b", "y"]), v3: Domain(["c", "z"]) } assert constrainer(variables, domains, {v1: "a"}) assert ["a"] == list(domains[v1]) assert ["b", "y"] == list(domains[v2]) assert ["c", "z"] == list(domains[v3]) assert constrainer(variables, domains, {v1: "a"}, True) assert ["a"] == list(domains[v1]) assert ["y"] == list(domains[v2]) assert ["z"] == list(domains[v3])
def test_exact(): constrainer = SomeNotInSetConstraint(set('abc'), n=2, exact=True) v1, v2, v3 = variables = [Variable('v1'), Variable('v2'), Variable('v3')] assignments = {v1: 'a', v2: 'y', v3: 'z'} assert constrainer(variables, {}, assignments) assignments = {v1: 'a', v2: 'y'} assert constrainer(variables, {}, assignments) assignments = {v1: 'a', v2: 'b', v3: 'z'} assert not constrainer(variables, {}, assignments) assignments = {v1: 'a', v2: 'b'} assert not constrainer(variables, {}, assignments) assignments = {v1: 'a', v2: 'b', v3: 'c'} assert not constrainer(variables, {}, assignments) assignments = {v1: 'x', v2: 'y', v3: 'z'} assert not constrainer(variables, {}, assignments)
def test_exact(): constrainer = SomeNotInSetConstraint(set("abc"), n=2, exact=True) v1, v2, v3 = variables = [Variable("v1"), Variable("v2"), Variable("v3")] assignments = {v1: "a", v2: "y", v3: "z"} assert constrainer(variables, {}, assignments) assignments = {v1: "a", v2: "y"} assert constrainer(variables, {}, assignments) assignments = {v1: "a", v2: "b", v3: "z"} assert not constrainer(variables, {}, assignments) assignments = {v1: "a", v2: "b"} assert not constrainer(variables, {}, assignments) assignments = {v1: "a", v2: "b", v3: "c"} assert not constrainer(variables, {}, assignments) assignments = {v1: "x", v2: "y", v3: "z"} assert not constrainer(variables, {}, assignments)
def test_forwardcheck_exact(): constrainer = SomeNotInSetConstraint(set("abc"), n=2, exact=True) v1, v2, v3 = variables = [Variable("v1"), Variable("v2"), Variable("v3")] assignments = {v1: "a"} domains = { v1: Domain(["a", "x"]), v2: Domain(["b", "y"]), v3: Domain(["c", "z"]) } assert constrainer(variables, domains, assignments) assert constrainer(variables, domains, assignments, True) assert "b" not in domains[v2] assert "y" in domains[v2] assert "c" not in domains[v3] assert "z" in domains[v3] domains = { v1: Domain(["a", "x"]), v2: Domain(["b", "y"]), v3: Domain(["c"]) } assert constrainer(variables, domains, assignments) assert not constrainer(variables, domains, assignments, True)
def test_empty_constraint(): constrainer = SomeNotInSetConstraint(set()) v1, v2 = variables = [Variable('v1'), Variable('v2')] assignments = {v1: 'a', v2: 'b'} assert constrainer(variables, {}, assignments)
def test_too_much_overlap(): constrainer = SomeNotInSetConstraint(set('ab')) v1, v2 = variables = [Variable('v1'), Variable('v2')] assignments = {v1: 'a', v2: 'b'} assert not constrainer(variables, {}, assignments)
def near_miss_encode(cs, thread_log, obj_id_log, obj_id_threadlist): klen = 5 near_miss_dict = {} #if LogEntry.objid_to_int['null'] in obj_id_log: #print("delete null key when filtering nearmiss") #del obj_id_log[LogEntry.objid_to_int['null']] progress = 0 for objid in obj_id_log: progress = progress + 1 log = obj_id_log[objid] if len(log) < 2 or LogEntry.int_to_objid[objid] == 'null': continue #print('processing ', progress,'/', len(obj_id_log),' objid ', LogEntry.int_to_objid[objid]) ex_entry = log[0] if len(obj_id_threadlist[ex_entry.object_id_]) < 2: continue objidstr = LogEntry.int_to_objid[objid] if len(objidstr) < 42 and '0000-0000-' in objidstr: continue #print('processing ', progress,'/', len(obj_id_log), " thread size ", len(obj_id_threadlist[ex_entry.object_id_])) for idx, end_log_entry in enumerate(log): for j in range(idx - 1, max(idx - klen-1,-1), -1): #for j in range(idx - 1, -1, -1): start_log_entry = log[j] start_tsc, end_tsc = start_log_entry.finish_tsc_, end_log_entry.start_tsc_ if not close_enough(start_tsc, end_tsc): break if not start_log_entry.is_conflict(end_log_entry): continue # very important here. dramatically reduce the overhead. #sig = find_signature(start_log_entry.location_, end_log_entry.location_) sig = find_signature(start_log_entry, end_log_entry) if sig in near_miss_dict and near_miss_dict[sig] > 10: continue if sig not in near_miss_dict: near_miss_dict[sig] = 0 near_miss_dict[sig] += 1 if sig not in cs.sig_cons: cs.sig_cons[sig] = [] if sig in cs.concurrent_sigs: print("Ignore concurrent op " + sig) continue # # We just encode constraints for call operations now # rel_log_original_list = [ #rel_log_list = [ log_entry for log_entry in thread_log[start_log_entry.thread_id_]. range_by(start_tsc, end_tsc, ltsc = False) if log_entry.is_candidate() ] # if already exists a confirmed rel inferred_rel = find_confirmed_rel(rel_log_original_list) #inferred_rel = False if inferred_rel: print("keep the windows by not inferring more because of containting the confirmed " + inferred_rel.description_) acq_log_original_list = [ log_entry for log_entry in thread_log[end_log_entry.thread_id_]. range_by(start_tsc, end_tsc, ltsc = False) if log_entry.is_candidate() ] #acq_sleep_log_list = [log_entry for log_entry in acq_log_list if log_entry.is_sleep_] rel_log_list = rel_log_original_list acq_log_list = acq_log_original_list #sleep refine algorithm here domi_sleep_entry = None index = -1 confirmed = False #''' if not inferred_rel : for i in range(len(rel_log_original_list)-1): log_entry = rel_log_original_list[i] if log_entry.is_sleep_ and log_entry.finish_tsc_ < end_tsc: index = i domi_sleep_entry = log_entry if index > -1: #print("Refine a original constraint") #if len(rel_nonsleep_log_list) == 1: # print("Confirm releasing", rel_nonsleep_log_list[0].description_) start_tsc = domi_sleep_entry.finish_tsc_ acq_shrinked_log_list = [ log_entry for log_entry in thread_log[end_log_entry.thread_id_]. range_by(start_tsc, end_tsc, ltsc = False) if log_entry.is_candidate() ] #acq_shrinked_sleep_list = [log_entry for log_entry in acq_log_list if log_entry.is_sleep_] #acq_shrinked_sleep_list = [log_entry for log_entry in acq_shrinked_log_list if log_entry.is_sleep_] #if len(acq_shrinked_sleep_list) == 0: ''' acq_mid_op_list = [ log_entry for log_entry in thread_log[end_log_entry.thread_id_]. range_by(domi_sleep_entry.finish_tsc_ - (domi_sleep_entry.finish_tsc_ - domi_sleep_entry.start_tsc_)/2, domi_sleep_entry.finish_tsc_, ltsc = False) #if log_entry.is_candidate() ] ''' acq_mid_op_list = find_mid_operations(thread_log[end_log_entry.thread_id_], domi_sleep_entry.start_tsc_, domi_sleep_entry.finish_tsc_) if len(acq_mid_op_list) == 0: rel_log_list = rel_log_original_list[index+1:] acq_log_list = acq_shrinked_log_list print("Refine a constraint by sleep before " + rel_log_list[0].description_) rel_nonsleep_log_list = [i for i in rel_log_list if not i.is_sleep_] if len(rel_nonsleep_log_list) == 1: confirmed = True Variable.release_var(rel_nonsleep_log_list[0]).set_confirmation() print("Confirm releasing", rel_nonsleep_log_list[0].description_) if len(acq_log_list) > 0: Variable.acquire_var(acq_log_list[0]).set_confirmation() # end of sleep refine algorithm #''' cs.sig_cons[sig].append([rel_log_list, acq_log_list, objid, start_log_entry, end_log_entry]) #cs.add_constraint(rel_log_list, acq_log_list, objid) #''' #print("near-miss count ", nm_cnt) if len(near_miss_dict) >0: print("MAX occurence ", max(near_miss_dict.values())) return cs
def find_confirmed_rel(rel_list): var_set = [Variable.release_var(log_entry) for log_entry in rel_list] var_confirmed_list = [v for v in var_set if v.is_confirmed_ and (v.infer_type == "rel")] if len(var_confirmed_list) > 0: return var_confirmed_list[0] return None
def test_empty_constraint(): constrainer = SomeNotInSetConstraint(set()) v1, v2 = variables = [Variable("v1"), Variable("v2")] assignments = {v1: "a", v2: "b"} assert constrainer(variables, {}, assignments)
def test_too_much_overlap(): constrainer = SomeNotInSetConstraint(set("ab")) v1, v2 = variables = [Variable("v1"), Variable("v2")] assignments = {v1: "a", v2: "b"} assert not constrainer(variables, {}, assignments)