def __init__(self, comp_def): super().__init__(comp_def.node.variable, comp_def) assert comp_def.algo.algo == "adsa" assert (comp_def.algo.mode == "min") or (comp_def.algo.mode == "max") self.mode = comp_def.algo.mode self.probability = comp_def.algo.param_value("probability") self.variant = comp_def.algo.param_value("variant") self.period = comp_def.algo.param_value("period") self.constraints = comp_def.node.constraints self.current_assignment = {} if self.variant == "B": # In DSA-B, we need to check if there are still some violated # constraints, for this we compute the best achievable cost for each # constraint: self.best_constraints_costs = { c.name: find_optimum(c, self.mode) for c in self.constraints } self._start_handle = None self._tick_handle = None
def __init__(self, comp_def: ComputationDef): super().__init__(comp_def.node.variable, comp_def) assert comp_def.algo.algo == "dsa" assert (comp_def.algo.mode == "min") or (comp_def.algo.mode == "max") self.mode = comp_def.algo.mode self.probability = comp_def.algo.param_value("probability") self.variant = comp_def.algo.param_value("variant") self.stop_cycle = comp_def.algo.param_value("stop_cycle") self.constraints = comp_def.node.constraints if comp_def.algo.param_value("p_mode") == "arity": n_count = sum(len(c.dimensions) - 1 for c in self.constraints) n = len(comp_def.node.neighbors) self.probability = 1 / n_count * 1.2 self.logger.debug( f"Using arity-based threshold : {self.probability} {n_count} {n}" ) # Maps for the values of our neighbors for the current and next cycle: self.current_cycle = {} self.next_cycle = {} if self.variant == "B": # In DSA-B, we need to check if there are still some violated # constraints, for this we compute the best achievable cost for each # constraint: self.best_constraints_costs = { c.name: find_optimum(c, self.mode) for c in self.constraints }
def __init__(self, variable, constraints, variant='B', probability=0.7, mode='min', logger=None, comp_def=None): """ :param variable a variable object for which this computation is responsible :param constraints: the list of constraints involving this variable :param variant: the variant of the DSA algorithm : 'A' for DSA-A, etc.. possible values avec 'A', 'B' and 'C' :param probability : the probability to change the value, used differently depending on the variant of DSA. See (Zhang, 2005) for details. :param mode: optimization mode, 'min' for minimization and 'max' for maximization. Defaults to 'min'. """ super().__init__(variable, comp_def) self._msg_handlers['dsa_value'] = self._on_value_msg self.logger = logger if logger is not None \ else logging.getLogger('pydcop.algo.dsa.'+variable.name) self.probability = probability self.variant = variant self.mode = mode self.constraints = list(constraints) self.__optimum_dict__ = { c.name: find_optimum(c, self.mode) for c in self.constraints } # some constraints might be unary, and our variable can have several # constraints involving the same variable self._neighbors = set([ v.name for c in constraints for v in c.dimensions if v != variable ]) self._neighbors_values = {} # Due to asynchronicity, at a turn n an agent can receive the value # of a neighbor for the turn n and the turn (n+1) before receiving # all neighbors' value for turn n. We need not to erase the value of # turn n self._postponed_messages = list()
def __init__(self, comp_def: ComputationDef): super().__init__(comp_def.node.variable, comp_def) assert comp_def.algo.algo == "dsa" assert (comp_def.algo.mode == "min") or (comp_def.algo.mode == "max") self.mode = comp_def.algo.mode self.probability = comp_def.algo.param_value("probability") self.variant = comp_def.algo.param_value("variant") self.stop_cycle = comp_def.algo.param_value("stop_cycle") self.constraints = comp_def.node.constraints # Maps for the values of our neighbors for the current and next cycle: self.current_cycle = {} self.next_cycle = {} if self.variant == "B": # In DSA-B, we need to check if there are still some violated # constraints, for this we compute the best achievable cost for each # constraint: self.best_constraints_costs = { c.name: find_optimum(c, self.mode) for c in self.constraints }