Exemplo n.º 1
0
    def preprocess(self):

        # Project the initial state
        new_init = PDKB(self.init.depth, self.init.agents, self.init.props)
        rmls = self.init.rmls
        for ag in self.agent_projection:
            rmls = project(rmls, ag)
        new_init.rmls = rmls
        self.init = new_init

        self.orig_cond_count = 0
        self.comp_cond_count = 0

        # Expand and project the action's effects with derived conditional effects
        for act in self.domain.actions:

            self.orig_cond_count += sum([
                len(act.effs[i][0]) + len(act.effs[i][1])
                for i in range(len(act.effs))
            ])
            act.expand()
            self.comp_cond_count += sum([
                len(act.effs[i][0]) + len(act.effs[i][1])
                for i in range(len(act.effs))
            ])

            for ag in self.agent_projection:
                act.project_effects(ag)

            if self.agent_projection:
                # We project the precondition separately since we are in the
                #  perspective of the final agent
                act.project_pre(self.agent_projection[-1])
Exemplo n.º 2
0
def test1():
    print "\n----\n"

    l1 = Literal('p')
    l2 = Belief(2, Belief(1, l1))
    l3 = Belief(2, neg(Belief(1, neg(l1))))
    l4 = neg(l3)

    l5 = neg(Belief(1, neg(Belief(2, l1))))
    l6 = neg(Belief(1, neg(Belief(2, Possible(3, Belief(4, l1))))))

    print "KD closure operation:"
    print "%s -> %s" % (str(l2), str(map(str, kd_closure(l2))))
    print "%s -> %s" % (str(l3), str(map(str, kd_closure(l3))))

    print "\n----\n"

    kb = PDKB(2, [1,2], map(Literal, ['p', 'q']))
    kb.add_rml(l2)
    print "Initial KB:"
    print kb
    print "\nClosing..."
    kb.logically_close()
    print kb

    print "\n----\n"

    kb.add_rml(l4)
    print "Initial Closed KB:"
    kb.logically_close()
    print kb
    print "\nConsistent: %s" % str(kb.is_consistent())

    print "\n----\n"

    kb = PDKB(2, [1,2], map(Literal, ['p', 'q']))
    kb.add_rml(Belief(1, Literal('p')))
    kb.add_rml(Belief(2, Literal('q')))
    kb.add_rml(Belief(1, Belief(2, Literal('q'))))
    kb.add_rml(neg(Belief(1, Literal('q'))))
    print "Initial KB:"
    print kb
    print "\n...projecting on agent 1\n"
    print project(kb.rmls, 1)

    print "\n----\n"
Exemplo n.º 3
0
    def preprocess(self):

        # Project the initial state
        new_init = PDKB(self.init.depth, self.init.agents, self.init.props)
        rmls = self.init.rmls
        for ag in self.agent_projection:
            rmls = project(rmls, ag)
        new_init.rmls = rmls
        self.init = new_init

        # Expand and project the action's effects with derived conditional effects
        for act in self.domain.actions:
            act.expand()
            for ag in self.agent_projection:
                act.project_effects(ag)

            if self.agent_projection:
                # We project the precondition separately since we are in the
                #  perspective of the final agent
                act.project_pre(self.agent_projection[-1])