Ejemplo n.º 1
0
    def test_cover(self):
        covered = BitCondition.cover(self.bitstring1, .5)
        self.assertTrue(covered(covered))
        self.assertTrue(covered(self.bitstring1))

        covered = BitCondition.cover(self.bitstring1, 0)
        self.assertTrue(covered.mask.count() == len(self.bitstring1))

        covered = BitCondition.cover(self.bitstring1, 1)
        self.assertTrue(covered.mask.count() == 0)
Ejemplo n.º 2
0
    def cover(self, situation, existing_actions):
        """Create a new rule that matches the given situation and return it. Preferentially choose an action that is
        not present in the existing actions, if possible."""

        condition = BitCondition.cover(situation, self._parameters.wildcard_probability)
        action_candidates = ((set(existing_actions) - self._parameters.possible_actions) or
                             self._parameters.possible_actions)
        action = random.choice(list(action_candidates))
        metadata = RuleMetadata(self._time_stamp, self._parameters)
        return condition, action, metadata