Ejemplo n.º 1
0
    def test_join_bothsamevar(self):
        x1 = Variable('x1', ['a', 'b', 'c'])
        u1 = NAryMatrixRelation([x1], np.array([1, 2, 3], np.int8))
        u2 = NAryMatrixRelation([x1], np.array([1, 2, 3], np.int8))

        # x1 = Variable('x1', ['a', 'b', 'c'])
        # u1 = dpop.NAryRelation([x1], np.array([1, 2, 3], np.int8))

        self.assertEqual(u1.get_value_for_assignment(['b']), 2)

        u_j = dpop.join_utils(u1, u2)

        self.assertEqual(u_j.arity, 1)
        self.assertEqual(u_j.get_value_for_assignment(['a']), 2)
        self.assertEqual(u_j.get_value_for_assignment(['b']), 4)
        self.assertEqual(u_j.get_value_for_assignment(['c']), 6)
Ejemplo n.º 2
0
    def _eff_cost(self, rel: NAryMatrixRelation, val) -> float:
        """
        Compute the effective cost of a constraint with combining its base
        cost with the associated modifier value (i.e. the weight of the
        constraint at the current step)
        :param rel: a constraint given as NAryMatrixRelation.
        :param val: the value of the agent's variablefor which to compute the
        _eff_cost
        :return: the effective cost of the constraint for the current
        assignment.
        """
        # Keep only the variables present in the relation rel
        global_asgt = self._neighbors_values.copy()
        global_asgt[self.name] = val
        asgt = filter_assignment_dict(global_asgt, rel.dimensions)

        c = rel.get_value_for_assignment(asgt)
        modifier = self._get_modifier_for_assignment(rel, asgt)
        if self._modifier_mode == 'A':
            c += modifier
        else:  # modifier_mode == 'M'
            c *= modifier

        return c