Beispiel #1
0
def main():
    """Synthesize two Moore components, assemble, and simulate them."""
    # synthesize
    foo_spec = specify_component_foo()
    bar_spec = specify_component_bar()
    synthesize_some_controller('bar', 'foo', foo_spec)
    synthesize_some_controller('foo', 'bar', bar_spec)
    # assemble
    foo = steps.AutomatonStepper(foo_spec)
    bar = steps.AutomatonStepper(bar_spec)
    sch = steps.Scheduler(2)
    asm = steps.Assembly()
    asm.machines = dict(scheduler=sch, foo=foo, bar=bar)
    # history
    n_steps = 20
    asm.init()
    print(asm.state)
    for _ in range(n_steps):
        asm.step()
        print(asm.state)
    # plotting
    plot_machines(asm)
    plt.xlabel('behavior states')
    plt.show()
Beispiel #2
0
def test_step():
    aut = trl.Automaton()
    aut.declare_variables(x='bool', y=(1, 3))
    aut.varlist = dict(env=['x'], sys=['y'])
    aut.prime_varlists()
    aut.init['impl_sys'] = 'True'
    action = aut.add_expr("x /\ (~ x') /\ (y = 2) /\ (y' = 3)")
    aut.action['impl'] = action
    stepper = steps.AutomatonStepper(aut)
    # `action` enabled at `state`
    state = dict(x=True, y=2)
    next_values = stepper.step(state)
    d = dict(x=False, y=3)
    assert next_values == d, (next_values, d)
    # `action` not enabled at `state`
    state = dict(x=True, y=1)
    with nt.assert_raises(ValueError):
        stepper.step(state)