Exemplo n.º 1
0
    def test_biImpl(self):
        formula = BiImpl(Atom("a"), Atom("b"))

        pc = PrimeCompilator(formula)
        result = self.sortedResult(pc.compile())
        # result = (sorted(result[0], key=lambda i: str(i)), sorted(result[1], key=lambda i: str(i)))

        self.assertEqual(result[0], [['a', 'b'], [Not('a'), Not('b')]])
        self.assertEqual(result[1], [[Not('a'), 'b'], [Not('b'), 'a']])
Exemplo n.º 2
0
    def test_paper_formula_negated(self):

        # Then again using only mhs
        pc = PrimeCompilator(
            Or(
                And(
                    Or(And(Atom("a"), Atom("b")), And(Atom("a"),
                                                      Not(Atom("b")))),
                    Atom("c")), And(Atom("b"), Atom("c"))).getNegation())

        result = self.sortedResult(pc.compile())
        # result = (sorted(result[0], key=lambda i: str(i)), sorted(result[1], key=lambda i: str(i)))

        self.assertEqual(result,
                         ([[Not('a'), Not('b')], [Not('c')]],
                          [[Not('a'), Not('c')], [Not('b'), Not('c')]]))
Exemplo n.º 3
0
    def test_paper_formula(self):

        # Then again using only mhs
        pc = PrimeCompilator(
            Or(
                And(
                    Or(And(Atom("a"), Atom("b")), And(Atom("a"),
                                                      Not(Atom("b")))),
                    Atom("c")), And(Atom("b"), Atom("c"))))

        result = pc.compile()

        result = self.sortedResult(result)
        self.assertEqual(
            result, ([[Atom('a'), Atom('c')], [Atom('b'), Atom('c')]
                      ], [[Atom('a'), Atom('b')], [Atom('c')]]))
Exemplo n.º 4
0
    def test_DoubleEffectPrinciple_performance(self):
        endo_actions = ["a" + str(i) for i in range(6)]
        consequences = {
            "c1": True,
            "c2": False,
            "c3": True,
            "c4": False,
            "c5": True
        }
        consequence_literals = [
            Atom(name) if truth_value else Not(Atom(name))
            for name, truth_value in consequences.items()
        ]

        formulae = [
            Formula.makeConjunction([Not(Bad(Atom(a))) for a in endo_actions])
        ]
        formulae += [
            Formula.makeConjunction(
                [Impl(Bad(Atom(c)), Not(Goal(Atom(c))))
                 for c in consequences] + [
                     Impl(Bad(Not(Atom(c))), Not(Goal(Not(Atom(c)))))
                     for c in consequences
                 ])
        ]
        formulae += [
            Formula.makeDisjunction(
                [And(Good(Atom(c)), Goal(Atom(c))) for c in consequences] + [
                    And(Good(Not(Atom(c))), Goal(Not(Atom(c))))
                    for c in consequences
                ])
        ]
        formulae += [
            Formula.makeConjunction([
                Impl(Bad(Atom(c)), Not(Instrumental(Atom(c))))
                for c in consequences
            ] + [
                Impl(Bad(Not(Atom(c))), Not(Instrumental(Not(Atom(c)))))
                for c in consequences
            ])
        ]
        formulae += [Gt(U(Formula.makeConjunction(consequence_literals)), 0)]

        formula = Formula.makeConjunction(formulae)

        compilator = PrimeCompilator(formula)
        compilator.compile()
Exemplo n.º 5
0
    def test_DoNolHarm_performance(self):
        consequences = {
            "co1": True,
            "co2": False,
            "co3": True,
            "co4": False,
            "co5": False,
            "co6": False
        }

        formulae = [
            Formula.makeConjunction([
                Impl(Bad(Atom(c)), Not(Caused(Atom(c)))) for c in consequences
            ] + [
                Impl(Bad(Not(Atom(c))), Not(Caused(Not(Atom(c)))))
                for c in consequences
            ])
        ]

        formula = Formula.makeConjunction(formulae)

        compilator = PrimeCompilator(formula)
        compilator.compile()
Exemplo n.º 6
0
    def test_AvoidAvoidableHarm_performance(self):
        consequences = {
            "co1": True,
            "co2": False,
            "co3": True,
            "co4": False,
            "co5": True
        }

        formulae = [
            Formula.makeConjunction([
                Impl(And(Bad(Atom(c)), Finally(Atom(c))),
                     Not(Avoidable(Atom(c)))) for c in consequences
            ] + [
                Impl(And(Bad(Not(Atom(c))), Finally(Not(Atom(c)))),
                     Not(Avoidable(Not(Atom(c))))) for c in consequences
            ])
        ]

        formula = Formula.makeConjunction(formulae)

        compilator = PrimeCompilator(formula)
        compilator.compile()
Exemplo n.º 7
0
    def test_DoNoInstrumentalHarm_performance(self):
        consequences = {
            "c1": True,
            "c2": False,
            "c3": True,
            "c4": False,
            "c5": False,
            "c6": False
        }

        formulae = [
            Formula.makeConjunction([
                Impl(Bad(Atom(c)), Not(Instrumental(Atom(c))))
                for c in consequences
            ] + [
                Impl(Bad(Not(Atom(c))), Not(Instrumental(Not(Atom(c)))))
                for c in consequences
            ])
        ]

        formula = Formula.makeConjunction(formulae)

        compilator = PrimeCompilator(formula)
        compilator.compile()
Exemplo n.º 8
0
    def test_non_boolean(self):
        pc = PrimeCompilator(Good(Atom("a")))
        result = self.sortedResult(pc.compile())

        self.assertEqual(result, ([[Good('a')]], [[Good('a')]]))
Exemplo n.º 9
0
 def test_disjunction(self):
     pc = PrimeCompilator(Formula.makeDisjunction(["a", "b", "c", "d"]))
     result = self.sortedResult(pc.compile())
     self.assertEqual(
         result, ([["a"], ["b"], ["c"], ["d"]], [["a", "b", "c", "d"]]))
Exemplo n.º 10
0
    def test_empty(self):
        pc = PrimeCompilator(And(Atom("a"), Not(Atom('a'))))

        result = self.sortedResult(pc.compile())

        self.assertEqual(result, ([], []))  # not satisfiable
Exemplo n.º 11
0
 def test_basic_2(self):
     pc = PrimeCompilator(Or("a", And("b", "c")))
     result = self.sortedResult(pc.compile())
     self.assertEqual(result,
                      ([["a"], ["b", "c"]], [["a", "b"], ["a", "c"]]))
Exemplo n.º 12
0
    def test_basic_negated(self):
        pc = PrimeCompilator(Not(Atom("a")))

        result = self.sortedResult(pc.compile())
        self.assertEqual(result, ([[Not('a')]], [[Not('a')]]))
Exemplo n.º 13
0
    def test_basic(self):
        pc = PrimeCompilator(Atom("a"))

        result = self.sortedResult(pc.compile())
        self.assertEqual(result, ([['a']], [['a']]))