Example #1
0
    def test_numble(self):
        Numble = make_numble_class(Brick, Target, Want, Avail, Allowed,
                                   [Plus, Times])
        g = Graph(port_mates=port_mates)
        numble = Numble([4, 5, 6], 15)
        numble.build(g, None)

        #pg(g)

        ids = g.nodes_of_class(Target)
        self.assertEqual(len(ids), 1)
        targetid = ids[0]
        self.assertEqual(g.value_of(targetid), 15)

        ids = g.nodes_of_class(Want)
        self.assertEqual(len(ids), 1)
        wantid = ids[0]
        self.assertTrue(g.has_hop(wantid, 'taggees', targetid, 'tags'))

        brickids = g.nodes_of_class(Brick)
        self.assertEqual(len(brickids), 3)
        self.assertCountEqual([g.value_of(b) for b in brickids], [4, 5, 6])

        ids = g.nodes_of_class(Avail)
        self.assertEqual(len(ids), 3)
        for b in brickids:
            self.assertTrue(g.has_tag(b, Avail))

        operatorids = g.nodes_of_class(Operator)
        self.assertEqual(len(operatorids), 2)

        ids = g.nodes_of_class(Allowed)
        self.assertEqual(len(ids), 2)
        for o in operatorids:
            self.assertTrue(g.has_tag(o, Allowed))
Example #2
0
#                  NodeWithTag(Avail),
#                  Not(NodeWithTag(Assessment)))
#  => assess(node, target)
'''

#make_python(prog, debug=1)
exec(compile_fargish(prog, saveto='numbo5.gen.py'), globals())

Operator.is_duplicable = True  #HACK

Plus.expr_class = expr.Plus  #HACK
Plus.symbol = '+'  #HACK
Times.expr_class = expr.Times  #HACK
Times.symbol = '*'  #HACK

Numble = make_numble_class(Brick, Target, Want, Avail, Allowed,
                           [Plus, Times, Minus])

##### Hacks

Number.is_duplicable = True

Want.min_activation = 1.0

#tag_port_label = 'taggees'
#taggee_port_label = 'tags'
#
#@classmethod
#def cls_add_tag(cls, g, taggees):  # HACK
#    taggees = list(as_iter(taggees))
#    taggee_containers = intersection(
#        *[g.member_of(ee) for ee in as_iter(taggees)]