예제 #1
0
파일: testAc.py 프로젝트: bkovitz/FARGish
 class Looker(AcNode):
     acs = [
         LookForTup([CTagged(Avail), CTagged(Avail)],
                    tupcond=NotTheArgsOf(Plus, 'operands'),
                    focal_point=InWorkspace),
         Raise(FoundTup, tup='nodes')
     ]
예제 #2
0
 def actions(self):
     badnode = self.g.look_for(
         #TODO 'and' these criteria
         OfClass(Block),
         CTagged(Avail),
         CTagged(NotGoodEnough),
         focal_point=self.g.ws)
     if badnode:
         return FuncAction(start_fixer_seq, badnode)
예제 #3
0
class OoMBigGapToWantedTagger(Persistent, AcNode):
    acs = [
        LookForTup([And(CTagged(OoM), CTagged(Want)),
                    CTagged(OoM)],
                   tupcond=CTupAnd(NotTheArgsOf(OoMBigGapToWanted, 'taggees'),
                                   TagValuesBigGap(OoM)),
                   focal_point=InWorkspace),
        DeTup(asgn_to=('node1', 'node2')),
        AddNode(OoMBigGapToWanted, wanted='node1', lesser='node2')
    ]
예제 #4
0
class OoMGreaterThanTagger(Persistent, AcNode):
    # TODO How do we anchor the tuple search on one node, e.g. the Target?
    acs = [
        LookForTup(
            [CTagged(OoM), CTagged(OoM)],
            # TODO Somehow rewrite following line as NotTagged
            tupcond=CTupAnd(NotTheArgsOf(OoMGreaterThan, 'taggees'),
                            TagValuesGt(OoM)),
            focal_point=InWorkspace),
        DeTup(asgn_to=('node1', 'node2')),
        AddNode(OoMGreaterThan, greater='node1', lesser='node2')
    ]
예제 #5
0
class AddAllInGlom(AcNode):
    threshold = 1.0
    acs = [
        All(And(OfClass(Number), CTagged(Avail))),
        WithNameOverride(LookFor(And(OfClass(Plus), CTagged(Allowed)),
                                 focal_point=InWorkspace),
                         focal_point='opwithin'),
        AddNode(
            Proposal,
            action=ConsumeOperands(),
            proposed_operands='nodes',
            proposed_operator='node',
        )
    ]
예제 #6
0
class NoticeCouldMakeTimes(LateNoticer):
    min_support_for = 1.0
    acs = [
        OrBlock(
            LookForTup(
                [
                    And(CTagged(Avail), MinActivation(3.0)),
                    And(CTagged(Avail), MinActivation(3.0))
                ],
                tupcond=NotTheArgsOf(Times, 'source'),
                focal_point=InWorkspace,
            ), NeedOperands.from_env()),
        BuildOpResult(Times, operands='nodes')
    ]
예제 #7
0
 def go(self, g, actor):
     if not self.glom:
         raise NeedArg(self, 'glom')
     #old_members = as_set(g.members_of(self.glom))
     old_members = as_set(
         g.find_all(CTagged(Avail), subset=g.members_of(self.glom)))
     excluded = as_set(g.find_all(CTagged(Exclude), subset=old_members))
     new_members = old_members - excluded
     g.remove_node(self.glom)
     if new_members:
         g.add_node(Glom, new_members)
         g.new_state(self.actor, Completed)
     else:  # should signal failure  TODO
         print('REGLOM FAILED', self.glom, old_members, excluded,
               new_members)
예제 #8
0
 def go(self, g, actor):
     if not self.focal_point:
         raise NeedArg(self, 'focal_point')
     g.add_node(
         Proposal,
         ConsumeOperands(),
         consume_operands=g.find_all(OfClass(Number),
                                     CTagged(Avail),
                                     focal_point=self.focal_point),
         proposed_operator=g.look_for(
             OfClass(Plus),
             CTagged(Allowed),  # TODO 'and' these criteria
             focal_point=g.ws),
         member_of=g.ws)
     g.new_state(self.actor, Completed)
예제 #9
0
 def actions(self):
     #TODO 'and' these criteria
     node = self.g.look_for(CTagged(Avail),
                            NotTagged(Assessment),
                            focal_point=self.g.ws)
     if node:
         return assess(g, node, self.g.neighbor(self, 'target'))
예제 #10
0
class LookForOperands(OneShot, AcNode):
    # TODO If no operands, raise an alarm
    acs = [
        All(CTagged(Avail), focal_point=MyContext),
        Boost(),
        RemoveBlockedTag()
    ]
예제 #11
0
class DiffIsWantedTagger(AcNode):
    acs = [
        LookForTup([Diff, CTagged(Want)],
                   tupcond=CTupAnd(NotTheArgsOf(DiffIsWanted, 'taggees'),
                                   TupSameValue()),
                   focal_point=InWorkspace),
        AddNode(DiffIsWanted, taggees='nodes', completion_of='this')
    ]
예제 #12
0
class NoticeCouldMakeMinus(AcNode):
    min_support_for = 1.0
    acs = [
        OrBlock(
            LookForTup(
                [
                    And(CTagged(Avail), MinActivation(0.0)),
                    And(CTagged(Avail), MinActivation(0.0))
                ],
                tupcond=CTupAnd(NotTheArgsOf(Minus, 'source'), GreaterThan()),
                focal_point=InWorkspace,
            ), NeedOperands.from_env()),
        DeTup(asgn_to=('minuend', 'subtrahend')),
        BuildOpResult(Minus,
                      minuend='minuend',
                      subtrahend='subtrahend',
                      completion_of='this')
    ]
예제 #13
0
class AllBricksAvail(Tag, HasUpdate, ActiveNode):
    update_action: Actions = Ac.as_action([
        All(OfClass(Brick), focal_point=MyContext),
        AcNot(AllAre(CTagged(Avail))),
        SelfDestruct()
    ])

    def actions(self):
        pass
예제 #14
0
파일: testAc.py 프로젝트: bkovitz/FARGish
    def test_do_notice_and_tag(self):
        # Tests running Ac objects directly. Normally, though, you only run
        # Ac objects from inside an AcNode.
        g = NumboGraph(Numble([4, 5, 6], 15))
        targetid = 1  # HACK

        env = Ac.run(g, All(OfClass(Brick), focal_point=g.ws), actor=targetid)
        nodes = map(g.as_node, env['nodes'])
        self.assertCountEqual(nodes, [Brick(4), Brick(5), Brick(6)])

        # Should fail because All is missing a 'focal_point' arg.
        try:
            env = Ac.run(g, All(OfClass(Brick)), actor=targetid)
        except NeedArg as exc:
            self.assertEqual(
                exc, NeedArg(ac=All(OfClass(Brick)), name='focal_point'))
        else:
            self.fail("Missing 'focal_point' failed to raise AcNeedArg.")

        env = Ac.run(
            g, [All(OfClass(Brick), focal_point=g.ws),
                AllAre(CTagged(Avail))],
            actor=targetid)
        nodes = map(g.as_node, env['nodes'])
        self.assertCountEqual(nodes, [Brick(4), Brick(5), Brick(6)])

        env = Ac.run(g, [
            All(OfClass(Brick), focal_point=g.ws),
            AllAre(CTagged(Avail)),
            TagWith(AllBricksAvail, taggees='nodes')
        ],
                     actor=targetid)
        result = list(g.as_nodes(env['result']))

        self.assertEqual(len(result), 1)
        tag = result[0]
        self.assertEqual(tag.__class__, AllBricksAvail)
        self.assertTrue(g.has_tag(nodes, tag))
예제 #15
0
파일: testAc.py 프로젝트: bkovitz/FARGish
    def test_noticer(self):
        g = NumboGraph(Numble([4, 5, 6], 15))

        noticer = g.add_node(AdHocAcNode, [
            All(OfClass(Brick), focal_point=g.ws),
            AllAre(CTagged(Avail)),
            TagWith(AllBricksAvail, taggees='nodes')
        ],
                             member_of=g.ws)

        self.assertEqual(noticer.state, Start)
        self.assertTrue(noticer.can_go())
        self.assertIn(noticer.id, g.as_nodeids(g.active_nodes()))
        g.do_timestep(actor=noticer)
        tag = g.as_node(first(g.new_nodes))
        self.assertEqual(tag.__class__, AllBricksAvail)
        self.assertEqual(noticer.state, Completed)
        self.assertFalse(noticer.can_go())
        self.assertNotIn(noticer.id, g.as_nodeids(g.active_nodes()))
예제 #16
0
파일: testAc.py 프로젝트: bkovitz/FARGish
 class NoticeSolved(AcNode):
     acs = [
         LookFor(CTagged(Avail), cond=EqualValue('node', 'target')),
         Raise(NumboSuccess, node='node', target='target')
     ]
예제 #17
0
 def current_soln(self) -> str:
     '''The candidate solution (partial or complete) that the model is
     currently considering.'''
     return ', '.join(
         str(self.expr_in_progress(node))
         for node in self.find_all(CTagged(Avail), focal_point=self.ws))
예제 #18
0
class NoticeAllBricksAreAvail(Persistent, AcNode):
    acs = [
        All(OfClass(Brick)),  # missing 'focal_point' argument
        AllAre(CTagged(Avail)),
        TagWith(AllBricksAvail, taggees='nodes')
    ]
예제 #19
0
class NoticeSolved(Persistent, AcNode):
    acs = [
        LookFor(OfClass(Target), asgn_to='target'),
        LookFor(CTagged(Avail), cond=EqualValue('node', 'target')),
        Raise(NumboSuccess, node='node', target='target')
    ]