def propagate(self, control, changes): with util.Timer("Propagation-{}".format(str(self.id))): for lit in changes: for internal_lit in TimeAtomToSolverLit.grab_id(lit): for prop_func in self.watch_to_tc[Signatures.convert_to_untimed_lit(internal_lit)]: if prop_func(control, internal_lit) is None: return
def main(self, prg, files): with util.Timer(StatNames.UNTILSOLVE_TIMER_MSG.value): for name in files: prg.load(name) self.__handler = TheoryHandler(self.watch_type, self.lock_ng, self.use_ids) add_theory(prg) with util.Timer(StatNames.GROUND_TIMER_MSG.value): prg.ground([("base", [])]) print("clingo grounding done") self.__handler.register(prg) prg.solve(on_statistics=self.__on_stats)
def propagate(self, control, changes): with util.Timer("Propagation-{}".format(str(self.id))): for lit in changes: for internal_lit in TimeAtomToSolverLit.grab_id(lit): # Check meta_ta to see the reason we check if untimed lit is in the mapping untimed_lit = Signatures.convert_to_untimed_lit(internal_lit) if untimed_lit in self.watch_to_tc: if self.watch_to_tc[untimed_lit].propagate(control, (internal_lit, lit)) is None: return
def finish_prop_func(self): self.func_str = "{}\n{}\n{}".format( prop_template_t_atom_start.format(f_name="prop_test", t_atom=self.t_atom), "\n".join(self.if_blocks), prop_template_end) with util.Timer("exec"): exec(self.func_str, globals()) self.propagate_func = types.MethodType(prop_test, self) self.func_str = None
def propagate(self, control, changes): with util.Timer("Propagation-{}".format(str(self.id))): for lit in changes: for internal_lit in TimeAtomToSolverLit.grab_id(lit): # have to check if untimed lit is in the mapping because it is possible that the # solver lit is associated with internal literals that are not relevant to this # propagator. This is only needed for this and Conseq since the mapping directly # gives the function. On other propagator types then mapping returns an empty list # and hence it does not loop at all untimed_lit = Signatures.convert_to_untimed_lit(internal_lit) if untimed_lit in self.watch_to_tc: if self.watch_to_tc[untimed_lit].propagate(control, internal_lit) is None: return
def propagate(self, control, changes): with util.Timer("Propagation-{}".format(str(self.id))): for lit in changes: for tc in set(self.watch_to_tc[lit]): result = tc.propagate(control, lit) if result is None: return for delete, add in result: self.watch_to_tc[delete].remove(tc) self.watch_to_tc[add].add(tc) if len(self.watch_to_tc[add]) == 1: # if the size is 1 then it contains only the new tc # so it wasn't watched before control.add_watch(add) if self.watch_to_tc[delete] == []: control.remove_watch(delete)
def build_prop_function(self): func_str = prop_template_start.format(f_name="prop_test", size=Signatures.fullsig_size) for info in self.t_atom_info: sign, untimed_lit, time_mod = info.sign, info.untimed_lit, info.time_mod grab_lit_str = [] for other_info in self.t_atom_names: grab_lit = check_mapping.format( untimed_lit=other_info.untimed_lit, time_mod=other_info.time_mod, sign=other_info.sign) grab_lit_str.append(grab_lit) ng_str = "ng = [{}]".format(", ".join(grab_lit_str)) if self.size > 2: func_str += if_template.format(untimed_lit=untimed_lit, t_mod=time_mod, min=self.min_time, max=self.max_time, ng=ng_str) else: func_str += if_template_size2.format(untimed_lit=untimed_lit, t_mod=time_mod, min=self.min_time, max=self.max_time, ng=ng_str) func_str += prop_template_end with util.Timer("exec"): exec(func_str, globals()) self.propagate_func = types.MethodType(prop_test, self) return self.propagate_func
def propagate(self, control, changes): with util.Timer("Propagation-{}".format(str(self.id))): for lit in changes: for tc, at in set(self.watch_to_tc[lit]): res = tc.propagate(control, (lit, at)) if res is None: return ng, check = res if not ng: # if ng is empty continue if check == ConstraintCheck.NONE: # only update watches if ng was not unit or conflict for ng_lit in ng: if ng_lit != lit: if (tc, at) in self.watch_to_tc[ng_lit]: second_watch = ng_lit break new_watch = get_replacement_watch(ng, [lit, second_watch], control) if new_watch is not None: self.watch_to_tc[lit].remove((tc, at)) self.watch_to_tc[new_watch].add((tc, at))
def propagate(self, control, changes): with util.Timer("Propagation-{}".format(str(self.id))): for lit in changes: for tc in self.watch_to_tc[lit]: if tc.propagate(control, lit) is None: return