Exemple #1
0
class EvaluatorTests(unittest.TestCase):
    def setUp(self):
        f1 = TriangularFunction(
            Point(0, 0),
            Point(10, 0),
            Point(5, 1)
        )
        f2 = TriangularFunction(
            Point(5, 0),
            Point(15, 0),
            Point(10, 1)
        )

        agua_values = [
            ValueDefinition('Fria', f1),
            ValueDefinition('Tibia', f2)
        ]

        propina_values = [
            ValueDefinition('Poca', f1),
            ValueDefinition('Mucha', f2)
        ]

        self.variables = VariableCollection(
            (
                VariableDefinition('Agua', agua_values),
                VariableDefinition('Propina', propina_values)
                )
        )
        self.variables.add_input('Agua', 2.5)
        self.variables.add_input('Propina', 7.5)

        self.evaluator = RuleEvaluator()

    def test_one_var(self):
        result = self.evaluator.evaluate(self.variables, 'Agua = Fria')
        self.assertEqual(result, 0.5)

    def test_one_var_(self):
        result = self.evaluator.evaluate(self.variables, 'Agua = Tibia')
        self.assertEqual(result, 0)

    def test_OR(self):
        result = self.evaluator.evaluate(self.variables,
            'Agua = Fria or Agua = Tibia')
        self.assertEqual(result, 0.5)

    def test_AND(self):
        result = self.evaluator.evaluate(self.variables,
            'Agua = Fria and Agua = Tibia')
        self.assertEqual(result, 0)

    def test_NOT(self):
        result = self.evaluator.evaluate(self.variables,
            'not(Agua = Tibia)')
        self.assertEqual(result, 1)
Exemple #2
0
    def execute(self, input_values):
        """
        Metodo principal, encargado de toda la ejecucion del sistema

        """
        evaluator = RuleEvaluator()

        # Guardamos los valores iniciales que toman las variables de entrada
        for var, value in input_values.items():
            self.input_vars.add_input(var, value)

        # Evaluamos cada una de las reglas y truncamos c/ funcion
        for rule in self.rules:
            result = evaluator.evaluate(self.input_vars, rule.head)
            rule.output_var.truncate(result)
Exemple #3
0
    def setUp(self):
        f1 = TriangularFunction(
            Point(0, 0),
            Point(10, 0),
            Point(5, 1)
        )
        f2 = TriangularFunction(
            Point(5, 0),
            Point(15, 0),
            Point(10, 1)
        )

        agua_values = [
            ValueDefinition('Fria', f1),
            ValueDefinition('Tibia', f2)
        ]

        propina_values = [
            ValueDefinition('Poca', f1),
            ValueDefinition('Mucha', f2)
        ]

        self.variables = VariableCollection(
            (
                VariableDefinition('Agua', agua_values),
                VariableDefinition('Propina', propina_values)
                )
        )
        self.variables.add_input('Agua', 2.5)
        self.variables.add_input('Propina', 7.5)

        self.evaluator = RuleEvaluator()