예제 #1
0
def build_belief_base():
    # There must be one color in each position
    belief_base(red[0] + "v" + green[0] + "v" + yellow[0] + "v" + blue[0])
    belief_base(red[1] + "v" + green[1] + "v" + yellow[1] + "v" + blue[1])
    belief_base(red[2] + "v" + green[2] + "v" + yellow[2] + "v" + blue[2])
    belief_base(red[3] + "v" + green[3] + "v" + yellow[3] + "v" + blue[3])

    # There can only be one color in each position
    belief_base()
    def test_contraction(self):
        b = belief_base()
        for i in ['p', 'q', 'r']:
            expand(b, i)
        r = belief_base()
        expand(r, 'r')
        contract(b, 'p^q', 'full-meet')
        self.assertEqual(b, r)

        b = belief_base()
        for i in ['p', 'q', '~pvr', 'r']:
            expand(b, i)
        r = belief_base()
        for i in ['q', 'rv~p']:
            expand(r, i)
        contract(b, 'r', 'maxichoice')
        self.assertEqual(b, r)

        b = belief_base()
        for i in ['p', '~pvr', 'r', 'p^q']:
            expand(b, i)
        r = belief_base()
        expand(r, 'rv~p')
        contract(b, 'r', 'partial-meet')
        self.assertEqual(b, r)

        b = belief_base()
        for i in ['p', 'q', 'r']:
            expand(b, i)
        r = belief_base()
        for i in ['q', 'r']:
            expand(r, i)
        contract(b, 'p^q', 'partial-meet')
        self.assertEqual(b, r)
    def test_revision(self):
        b = belief_base()
        for i in ['p', 'q', 'r']:
            expand(b, i)
        r = belief_base()
        for i in ['p', 'q', 'r', 'p^q']:
            expand(r, i)
        revise(b, 'p^q', 'maxichoice')
        self.assertEqual(b, r)

        b = belief_base()
        for i in ['p^q', 'r']:
            expand(b, i)
        r = belief_base()
        for i in ['~p', 'r']:
            expand(r, i)
        revise(b, '~p', 'full-meet')
        self.assertEqual(b, r)
 def test_entails(self):
     b = belief_base('p')
     self.assertTrue(entails(b, 'p'))
     self.assertFalse(entails(b, 'q'))
     expand(b, 'q')
     self.assertTrue(entails(b, 'p^q'))
     expand(b, 'r')
     self.assertFalse(entails(b, '(r^~p)'))
     self.assertTrue(entails(
         b, 'p^q^r^(~rvp)'))  # raises error due to remove function
예제 #5
0
from belief_revision_engine import cnf, belief_base, entails, expand, contract, revise

b = belief_base()
for beliefs in ['p', 'q^r']:
    expand(b, beliefs)
print("b is: {}".format(b))
revise(b, 'p^q')
print("after revision, b is: {}".format(b))
print("entails p? {}".format(entails(b, 'p')))
expand(b, '~p^q')
contract(b, 'p', 'full-meet')
print("after contraction, b is: {}".format(b))
print("entails p? {}".format(entails(b, 'p')))