예제 #1
0
    def test_query_slipnet_for_delegate(self) -> None:
        graph = Graph.with_features(
            Consumer.make_table(range(1, 20), range(1, 20),
                                [plus, minus, times]))
        fm = FARGModel(slipnet=Slipnet(graph))
        ca = fm.build(self.pons_start_canvas())
        cr0 = fm.build(CellRef(ca, 0))

        # succeed

        codelet = QuerySlipnetForDelegate(qargs=(QBeforeFromAvails(),
                                                 QAfter(15),
                                                 SearchFor(Consumer)))

        #t0 = process_time()
        fm.run_codelet_and_follow_ups(codelet, {'source': cr0})
        #print('RUN1', process_time() - t0)
        delegate = fm.the(Consumer)
        self.assertIsNotNone(delegate)

        # fail

        codelet = QuerySlipnetForDelegate(qargs=(QBeforeFromAvails(),
                                                 QAfter(15),
                                                 SearchFor(DummyAgent)))

        #t0 = process_time()
        with self.assertRaises(NoResultFromSlipnet):
            fm.run_codelet_and_follow_ups(codelet, {'source': cr0})
예제 #2
0
import matplotlib.pyplot as plt  # type: ignore[import]

from FARGModel import FARGModel, FARGException, SolvedPuzzle, CellRef, \
    Agent, Codelet, Fizzle, log_pulse
from Log import lenable, ldisable, trace, lo
from Propagator import LogAdjustedDeltas
from Graph import Graph, Before, After
from Slipnet import Slipnet
from Agents import Want, Consumer, VariantMakerFromAvails
from Codelets import RaiseException
from Canvas import StepCanvas, Step
from Equation import plus, minus, times
from util import pr, pts, short

eqn_graph = Graph.with_features(
    Consumer.make_table(range(1, 21), range(1, 21), [plus, minus, times])
)  #.add_edges(MutualInhibition((Feature, Operator, Equation, int), weight=-5.0))

desnaggers_graph = Graph.with_features([VariantMakerFromAvails()])

ca: StepCanvas
cr0: CellRef
cr1: CellRef
cr2: CellRef
cr3: CellRef
wa: Want


def run(bricks: Sequence[int],
        target: int,
        seed: int = 1,