Ejemplo n.º 1
0
    def test_hardcoded_pons_asinorum(self):
        fm = FARGModel()
        ca = fm.build(SeqCanvas([SeqState((4, 5, 6), None)]))
        wa = fm.build(Want(15, canvas=ca, addr=0))
        wa.go(fm)  # Builds Consume objects and Detector

        for co in fm.ws_query(Consume, builder=wa):
            co.go(fm)

        bl = fm.ws_query1(Blocked)
        bl.go(fm)

        d9 = fm.ws_query1(Detector, target=9)
        d9.go(fm)

        co1 = fm.ws_query1(Consume, operands=(4, 5))
        co2 = fm.ws_query1(Consume, operands=(9, 6))
        aseq0 = fm.build(
            AgentSeq((co1, co2),
                     initial_kwargs=tupdict(source=CellRef(ca, 0),
                                            dest=CellRef(ca, 1))))
        aseq0.go(fm)  #This should not complain

        aseq = fm.ws_query1(AgentSeq)
        aseq.act(fm)

        d15 = fm.ws_query1(Detector, target=15)
        try:
            d15.go(fm)
            self.fail('Detector did not detect solution.')
        except SolvedNumble as exc:
            self.assertEqual(str(exc), '4 + 5 = 9; 9 + 6 = 15')
Ejemplo n.º 2
0
 def paint(self,
           fm: FARGModel,
           source: CellRef,
           dest: CellRef,
           builder: Union[Agent, None] = None,
           **ignored):
     #print('CPAINT', self)
     # TODO throw if any members/args are missing
     if builder is None:
         builder = self
     s0: SeqState = source.contents
     if s0 is None:
         return
     try:
         taken_avails, remaining_avails = s0.take_avails(self.operands)
     except ValuesNotAvail as exc:
         # TODO builder=self even if builder overridden by caller?
         #print('CNOT')
         fm.build(Blocked(taggee=self, reason=exc), builder=self)
         fm.downboost(self)
         return
     result = self.operator.call(*taken_avails)
     new_avails = tuple(remaining_avails) + (result, )
     delta = ArithDelta(tuple(taken_avails), result, self.operator)
     s1 = SeqState(new_avails, delta)
     return fm.paint_value(dest, s1, builder=builder)
Ejemplo n.º 3
0
    def consult_slipnet(self, fm: FARGModel):
        source = self.canvas.last_nonblank()
        #avails = self.canvas[self.addr].avails
        avails = source.contents.avails
        activations_in = {}
        for avail in avails:
            activations_in[Before(avail)] = 1.0
        activations_in[After(self.target)] = 0.1
        if all(avail > self.target for avail in avails):
            activations_in[Increase()] = 10.0

        exclude = Exclude(fm.neighbors(self))
        #source = CellRef(self.canvas, self.addr)
        agents = fm.pulse_slipnet(
            # GLOBAL constants in next line
            activations_in,
            k=20,
            type=Agent,
            num_get=1,
            filter=exclude)
        # TODO We need a way to get an Agent from the slipnet that means
        # something like "Just add what you have."
        #print('WANT got from slipnet:', [str(a) for a in agents]) #DIAG
        for agent in agents:
            if isinstance(agent, Consume):  #HACK
                agent = replace(agent, source=source)
            fm.build(agent, builder=self, init_a=0.1)
Ejemplo n.º 4
0
 def go(self, fm: FARGModel):
     # TODO Don't build these if they're already built
     fm.build(Detector(self.target, action=RaiseException(SolvedNumble)),
              builder=self)
     fm.build(GettingCloser.Tagger(target=self.target), builder=self)
     self.consult_slipnet(fm)
     self.update_support(fm)
     fm.sleep(self)
Ejemplo n.º 5
0
 def go(
     self, fm: FARGModel, **overrides
     #source: Union[CellRef, None]=None,
     #dest: Union[CellRef, None]=None,
     #builder: Union[Agent, None]=None
 ) -> CellRef:
     if overrides.get('source', None) is None:
         overrides['source'] = self.source
     if overrides.get('dest', None) is None:
         overrides['dest'] = overrides['source'].imaginary_next_cellref()
     result = self.paint(fm, **overrides)
     if result is not None:
         #fm.boost(self)
         fm.build(GoIsDone(taggee=self))
     return result
Ejemplo n.º 6
0
 def look(self, fm: FARGModel):
     # TODO Exclude nodes already tagged GettingCloser
     found = first(fm.search_ws(ImCell))
     #print('GettingCloser.Tagger FOUND', found)
     if found:
         weight = GettingCloser.calc_weight(found, self.target)
         if weight > 0.001:
             # TODO Indicate the Want node? The target?
             # TODO Indicate builder
             tag = fm.build(
                 GettingCloser(taggee=found,
                               target=self.target,
                               weight=weight))
             fm.add_mut_support(tag, found)
Ejemplo n.º 7
0
 def rebuild_with_blanks(self, fm: FARGModel, avail_operands: Tuple[Value],
                         unavail_operands: Tuple[Value]):
     print('REBU', self, avail_operands, unavail_operands)
     fm.build(replace(self, operands=avail_operands), builder=self)
Ejemplo n.º 8
0
 def on_build(self, fm: FARGModel):
     fm.build(self.source, builder=self)
     fm.build(self.dest, builder=self, edge_weight=1.0)