Ejemplo n.º 1
0
def test_abstract_the_dynamics_dual():
    """test_abstract_the_dynamics using dual-simulation algorithm"""
    dom = pc.box2poly([[0.0, 10.0], [0.0, 20.0]])
    ppp = define_partition(dom)
    sys = define_dynamics(dom)
    logger.info(sys)

    disc_options = {'N': 3, 'trans_length': 2, 'min_cell_volume': 1.5}

    ab = abstract.discretize(ppp,
                             sys,
                             plotit=False,
                             save_img=False,
                             simu_type='dual',
                             **disc_options)
    assert ab.ppp.compute_adj()

    [sys_dyn, cont_partition, part] = define_dynamics_dual()
    disc_options = {'N': 1, 'trans_length': 1000, 'min_cell_volume': 0.0}
    ab_2 = abstract.discretize(cont_partition,
                               sys_dyn,
                               simu_type='dual',
                               **disc_options)

    table = np.zeros([len(part), 1])
    for i in ab_2.ppp.regions:
        for j in range(len(part)):
            if i == part[j]:
                table[j] = 1
    assert np.sum(table) == len(part)
Ejemplo n.º 2
0
def test_transient_regions():
    """drift is too strong, so no self-loop must exist
    
    This bug caused when running union is taken between Presets
    during solve_feasible, as happened with old use_all_horizon,
    cf:
        - 5b1e9681918739b276a221fcc1fd6eebfd058ce3
        - f5f4934ab9d21062f633eef3861ad935c3d3b54b
    """
    dom = pc.box2poly([[0.0, 4.0], [0.0, 3.0]])

    def cont_predicates():
        p = dict()
        p['safe'] = pc.box2poly([[0.5, 3.5], [0.5, 2.5]])

        ppp = abstract.prop2part(dom, p)
        ppp, new2old_reg = abstract.part2convex(ppp)
        ppp.plot()
        return ppp

    def drifting_dynamics():
        A = np.array([[1.0, 0.0], [0.0, 1.0]])

        B = np.array([[1.0], [0.0]])

        U = pc.box2poly([[0.0, 1.0]])

        K = np.array([[-100.0], [0.0]])

        sys = hybrid.LtiSysDyn(A, B, None, K, U, None, dom)
        return sys

    ppp = cont_predicates()
    sys = drifting_dynamics()
    logger.info(sys)

    with assert_raises(ValueError):
        ab = abstract.discretize(ppp,
                                 sys,
                                 N=1,
                                 use_all_horizon=True,
                                 trans_length=1)

    ab = abstract.discretize(ppp,
                             sys,
                             N=1,
                             use_all_horizon=False,
                             trans_length=1)

    logger.debug(ab.ts)
    self_loops = {i for i, j in ab.ts.transitions() if i == j}
    logger.debug('self loops at states: ' + str(self_loops))

    assert (not self_loops)
Ejemplo n.º 3
0
def test_transient_regions():
    """drift is too strong, so no self-loop must exist
    
    This bug caused when running union is taken between Presets
    during solve_feasible, as happened with old use_all_horizon,
    cf:
        - 5b1e9681918739b276a221fcc1fd6eebfd058ce3
        - f5f4934ab9d21062f633eef3861ad935c3d3b54b
    """
    dom = pc.box2poly([[0.0, 4.0], [0.0, 3.0]])

    def cont_predicates():
        p = dict()
        p["safe"] = pc.box2poly([[0.5, 3.5], [0.5, 2.5]])

        ppp = abstract.prop2part(dom, p)
        ppp, new2old_reg = abstract.part2convex(ppp)
        ppp.plot()
        return ppp

    def drifting_dynamics():
        A = np.array([[1.0, 0.0], [0.0, 1.0]])

        B = np.array([[1.0], [0.0]])

        U = pc.box2poly([[0.0, 1.0]])

        K = np.array([[-100.0], [0.0]])

        sys = hybrid.LtiSysDyn(A, B, None, K, U, None, dom)
        return sys

    ppp = cont_predicates()
    sys = drifting_dynamics()
    logger.info(sys)

    with assert_raises(ValueError):
        ab = abstract.discretize(ppp, sys, N=1, use_all_horizon=True, trans_length=1)

    ab = abstract.discretize(ppp, sys, N=1, use_all_horizon=False, trans_length=1)

    logger.debug(ab.ts)
    self_loops = {i for i, j in ab.ts.transitions() if i == j}
    logger.debug("self loops at states: " + str(self_loops))

    assert not self_loops
def build_FTS(index):
    # build test FTS
    # simple test
    if index == 0:
        ts = FTS()
        ts.atomic_propositions.add_from({'a', 'b', 'c', 'd'})
        ts.states.add_from([('q1', {
            'ap': {'a'}
        }), ('q2', {
            'ap': {'a'}
        }), ('q3', {
            'ap': {'b'}
        }), ('q4', {
            'ap': {'b'}
        }), ('q5', {
            'ap': {'b'}
        }), ('q6', {
            'ap': {'c'}
        }), ('q7', {
            'ap': {'d'}
        })])
        ts.transitions.add('q1', 'q3')
        ts.transitions.add('q1', 'q4')
        ts.transitions.add('q3', 'q6')
        ts.transitions.add('q4', 'q6')
        ts.transitions.add('q2', 'q4')
        ts.transitions.add('q2', 'q5')
        ts.transitions.add('q5', 'q7')
        ts.transitions.add('q6', 'q6')
        ts.transitions.add('q7', 'q7')
    # FTS generated by continuous system
    elif index == 1:
        input_bound = 1.0
        cont_state_space = box2poly([[-1, 1], [-1, 1]])
        A = np.array([[0.5, 1.0], [0.75, -1.0]])
        B = np.array([[1, 0.], [0., 1]])
        U = input_bound * np.array([[-1., 1.], [-1., 1.]])
        U = box2poly(U)
        sys_dyn = hybrid.LtiSysDyn(A, B, None, None, U, None, cont_state_space)
        cont_props = {}
        cont_props['a'] = box2poly([[-0.5, 0.5], [-0.5, 0.5]])
        cont_props['b'] = box2poly([[-1, -0.5], [-1, 1]])
        cont_props['c'] = box2poly([[-0.5, 1], [0.5, 1]])
        cont_props['d'] = box2poly([[0.5, 1], [-1, 0.5]])
        cont_props['e'] = box2poly([[-0.5, 0.5], [-1, -0.5]])
        cont_partition = prop2part(cont_state_space, cont_props)
        sys = discretize(cont_partition,
                         sys_dyn,
                         closed_loop=False,
                         conservative=True,
                         trans_length=1,
                         N=1,
                         use_all_horizon=False,
                         min_cell_volume=0.0,
                         abs_tol=1e-7)
        ts = sys.ts
    return ts
Ejemplo n.º 5
0
def test_abstract_the_dynamics():
    dom = pc.box2poly([[0.0, 10.0], [0.0, 20.0]])
    ppp = define_partition(dom)
    sys = define_dynamics(dom)
    logger.info(sys)

    disc_options = {"N": 3, "trans_length": 2, "min_cell_volume": 1.5}

    ab = abstract.discretize(ppp, sys, plotit=False, save_img=False, **disc_options)
    assert ab.ppp.compute_adj()
    assert ab.ppp.is_partition()
Ejemplo n.º 6
0
def test_abstract_the_dynamics():
    dom = pc.box2poly([[0.0, 10.0], [0.0, 20.0]])
    ppp = define_partition(dom)
    sys = define_dynamics(dom)
    logger.info(sys)
    
    disc_options = {'N':3, 'trans_length':2, 'min_cell_volume':1.5}
    
    ab = abstract.discretize(ppp, sys, plotit=False,
                             save_img=False, **disc_options)
    assert(ab.ppp.compute_adj() )
    assert(ab.ppp.is_partition() )
Ejemplo n.º 7
0
# Build piecewise affine system from its subsystems
sys_dyn = PwaSysDyn(subsystems, cont_state_space)
# @pwasystem_end@

# Continuous proposition
cont_props = {}
cont_props['home'] = box2poly([[0., 1.], [0., 1.]])
cont_props['lot'] = box2poly([[2., 3.], [1., 2.]])

# Compute the proposition preserving partition
# of the continuous state space
cont_partition = prop2part(cont_state_space, cont_props)
disc_dynamics = discretize(
    cont_partition, sys_dyn, closed_loop=True,
    N=8, min_cell_volume=0.1, plotit=plotting,
    cont_props=cont_props
)

# Specifications

# Environment variables and assumptions
env_vars = {'park'}
env_init = set()                # empty set
env_prog = '!park'
env_safe = set()                # empty set

# System variables and requirements
sys_vars = {'X0reach'}

# []<>home
Ejemplo n.º 8
0
# @partition_section@
# Define atomic propositions for relevant regions of state space
cont_props = {}
cont_props['home'] = box2poly([[0., 1.], [0., 1.]])
cont_props['lot'] = box2poly([[2., 3.], [1., 2.]])

# Compute the proposition preserving partition of the continuous state space
cont_partition = prop2part(cont_state_space, cont_props)
plot_partition(cont_partition) if show else None
# @partition_section_end@

# @discretize_section@
# Given dynamics & proposition-preserving partition, find feasible transitions
disc_dynamics = discretize(cont_partition,
                           sys_dyn,
                           closed_loop=True,
                           N=8,
                           min_cell_volume=0.1,
                           plotit=show)
# @discretize_section_end@

# Visualize transitions in continuous domain (optional)
plot_partition(disc_dynamics.ppp, disc_dynamics.ts,
               disc_dynamics.ppp2ts) if show else None

# Specifications
# Environment variables and assumptions
env_vars = {'park'}
env_init = set()  # empty set
env_prog = '!park'
env_safe = set()  # empty set
Ejemplo n.º 9
0
# @partition_section@
# Define atomic propositions for relevant regions of state space
cont_props = {}
cont_props['home'] = box2poly([[0., 1.], [0., 1.]])
cont_props['lot'] = box2poly([[2., 3.], [1., 2.]])

# Compute the proposition preserving partition of the continuous state space
cont_partition = prop2part(cont_state_space, cont_props)
plot_partition(cont_partition, show=visualize)
# @partition_section_end@

# @discretize_section@
# Given dynamics & proposition-preserving partition, find feasible transitions
disc_dynamics = discretize(
    cont_partition, sys_dyn, closed_loop=True,
    N=8, min_cell_volume=0.1, plotit=visualize
)
# @discretize_section_end@

"""Visualize transitions in continuous domain (optional)"""
plot_partition(disc_dynamics.ppp, disc_dynamics.ts,
               disc_dynamics.ppp2ts, show=visualize)

"""Specifications"""
# Environment variables and assumptions
env_vars = {'park'}
env_init = set()                # empty set
env_prog = '!park'
env_safe = set()                # empty set

# System variables and requirements
Ejemplo n.º 10
0
# Define atomic propositions for relevant regions of state space
cont_props = {}
cont_props['home'] = shrinkPoly(box2poly([[0., 1.], [0., 1.]]),epsilon)
cont_props['lot'] = shrinkPoly(box2poly([[2., 3.], [1., 2.]]),epsilon)

# Compute the proposition preserving partition of the continuous state space
cont_partition = prop2part(cont_state_space, cont_props)
plot_partition(cont_partition) if show else None
cont_partition = shrinkPartition(cont_partition, epsilon)
plot_partition(cont_partition) if show else None
# @partition_section_end@

# @discretize_section@
# Given dynamics & proposition-preserving partition, find feasible transitions
disc_dynamics = discretize(
    cont_partition, sys_dyn_hat, closed_loop=True, conservative=True,
    N=1, min_cell_volume=0.01, plotit=show, trans_length=3
)
# @discretize_section_end@

"""Visualize transitions in continuous domain (optional)"""
plot_partition(disc_dynamics.ppp, disc_dynamics.ts,
               disc_dynamics.ppp2ts) if show else None

"""Specifications"""
# Environment variables and assumptions
env_vars = {'park'}
env_init = set()                # empty set
env_prog = '!park'
env_safe = set()                # empty set

# System variables and requirements
Ejemplo n.º 11
0
def test_find_controller_non_convex():
    """Test that it is enough that one polytope in the target region is
     reachable"""
    # Continuous state space
    cont_state_space = pc.box2poly([[0., 1.], [0., 2.]])

    # System dynamics (continuous state, discrete time): simple double integrator
    # but no reversing.
    h = 1.0
    A = np.array([[1.0, h], [0., 1.0]])
    B = np.array([[h**2 / 2.0], [h]])
    E = None

    # Available control, no disturbances. Can brake or accelerate.
    U = pc.box2poly(np.array([[-1., 1.]]))
    W = None

    # Construct the LTI system describing the dynamics
    sys_dyn = hybrid.LtiSysDyn(A, B, E, None, U, W, cont_state_space)

    # Define atomic propositions for relevant regions of state space
    cont_props = dict()
    cont_props['target'] = pc.box2poly([[0., 1.], [0., 2.]])

    # Compute the proposition preserving partition of the continuous state space
    # noinspection PyTypeChecker
    cont_partition = abstract.prop2part(cont_state_space, cont_props)

    # Abstraction
    disc_dynamics = abstract.discretize(cont_partition,
                                        sys_dyn,
                                        closed_loop=False,
                                        conservative=True,
                                        N=1,
                                        min_cell_volume=0.01,
                                        plotit=False,
                                        simu_type='bi',
                                        trans_length=1)

    # Setup a start point and a target point in a region that are problematic
    c_start_state = np.array([0.5, 0.0])
    c_end_desired = np.array([1.0, 2.0])
    # Find the discrete states of the start state and the target region
    d_start_state = abstract.find_discrete_state(c_start_state,
                                                 disc_dynamics.ppp)
    d_end_state = abstract.find_discrete_state(c_end_desired,
                                               disc_dynamics.ppp)
    # Try to find a control policy
    u = abstract.find_controller.get_input(x0=c_start_state,
                                           ssys=sys_dyn,
                                           abstraction=disc_dynamics,
                                           start=d_start_state,
                                           end=d_end_state,
                                           ord=1,
                                           mid_weight=5)
    assert 0.5 <= u <= 1.0, "u was " + str(u)
    # Try to find a control policy in the other direction and ascertain
    # an error is thrown
    assert_raises(Exception,
                  abstract.find_controller.get_input,
                  x0=c_end_desired,
                  ssys=sys_dyn,
                  abstraction=disc_dynamics,
                  start=d_end_state,
                  end=d_start_state,
                  ord=1,
                  mid_weight=5)
Ejemplo n.º 12
0
    )

    print("------ System Label State Space & partition")
    sys_dyn = hybrid.LtiSysDyn(A, B, E, None, U, W, X)

    cpartition = prop2part(X, cprops)
    if verbose == 1:
        sys.stdout.flush()
        print(" (Verbose) ")
        print(cpartition)
        sys.stdout.flush()

    disc_dynamics = discretize(cpartition,
                               sys_dyn,
                               closed_loop=True,
                               conservative=False,
                               N=5,
                               min_cell_volume=0.1,
                               remove_trans=True)

    save_png(disc_dynamics.ts, name="dynamics")
    states = [
        state for (state, label) in disc_dynamics.ts.states.find(
            with_attr_dict={'ap': {'init'}})
    ]
    disc_dynamics.ts.states.initial |= states

    print(
        "----------------------------------\n  Make GR(1) specification \n----------------------------------"
    )
    (ctrl_modes, grspec) = transform2control(disc_dynamics.ts, statevar='ctrl')
def build_FTS(index):
    # build test FTS
    # simple test
    if index == 0:
        ts = FTS()
        ts.atomic_propositions.add_from({'a', 'b', 'c', 'd'})
        ts.states.add_from([('q1', {
            'ap': {'a'}
        }), ('q2', {
            'ap': {'a'}
        }), ('q3', {
            'ap': {'b'}
        }), ('q4', {
            'ap': {'b'}
        }), ('q5', {
            'ap': {'b'}
        }), ('q6', {
            'ap': {'c'}
        }), ('q7', {
            'ap': {'d'}
        })])
        ts.transitions.add('q1', 'q3')
        ts.transitions.add('q1', 'q4')
        ts.transitions.add('q3', 'q6')
        ts.transitions.add('q4', 'q6')
        ts.transitions.add('q2', 'q4')
        ts.transitions.add('q2', 'q5')
        ts.transitions.add('q5', 'q7')
        ts.transitions.add('q6', 'q6')
        ts.transitions.add('q7', 'q7')
    # FTS generated by continuous system
    elif index == 1:
        # Problem parameters
        input_bound = 1.0
        # Continuous state space
        cont_state_space = box2poly([[-1, 1], [-1, 1]])
        # Continuous dynamics
        # (continuous-state, discrete-time)
        A = np.array([[0.5, 1.0], [0.75, -1.0]])
        B = np.array([[1, 0.], [0., 1]])
        # Available control, possible disturbances
        U = input_bound * np.array([[-1., 1.], [-1., 1.]])
        # Convert to polyhedral representation
        U = box2poly(U)
        # Construct the LTI system describing the dynamics
        sys_dyn = hybrid.LtiSysDyn(A, B, None, None, U, None, cont_state_space)
        # @dynamics_section_end@
        # @partition_section@
        # Define atomic propositions for relevant regions of state space
        cont_props = {}
        cont_props['a'] = box2poly([[-0.5, 0.5], [-0.5, 0.5]])
        cont_props['b'] = box2poly([[-1, -0.5], [-1, 1]])
        cont_props['c'] = box2poly([[-0.5, 1], [0.5, 1]])
        cont_props['d'] = box2poly([[0.5, 1], [-1, 0.5]])
        cont_props['e'] = box2poly([[-0.5, 0.5], [-1, -0.5]])
        # Compute the proposition preserving partition of the continuous state space
        cont_partition = prop2part(cont_state_space, cont_props)
        # @partition_section_end@
        # @discretize_section@
        # Given dynamics & proposition-preserving partition, find feasible transitions
        sys = discretize(cont_partition,
                         sys_dyn,
                         closed_loop=False,
                         conservative=True,
                         trans_length=1,
                         N=1,
                         use_all_horizon=False,
                         min_cell_volume=0.0,
                         abs_tol=1e-7)
        ts = sys.ts
    return ts
Ejemplo n.º 14
0
    U = box2poly(U)
    W = box2poly(W)

    # Construct the LTI system describing the dynamics
    sys_dyn = hybrid.LtiSysDyn(A, B, E, None, U, W, cont_state_space)

    # Define atomic propositions for relevant regions of state space
    cont_props = {}
    cont_props['home'] = box2poly([[0., 1.], [0., 1.]])
    cont_props['lot'] = box2poly([[2., 3.], [1., 2.]])

    # Compute proposition preserving partition of the continuous state space
    cont_partition = prop2part(cont_state_space, cont_props)

    pwa = discretize(
        cont_partition, sys_dyn, closed_loop=True,
        N=8, min_cell_volume=0.1, plotit=False
    )

    """Specifications"""
    # Environment variables and assumptions
    env_vars = {'park'}
    env_init = set()                # empty set
    env_prog = '!park'
    env_safe = set()                # empty set

    # System variables and requirements
    sys_vars = {'X0reach'}
    sys_init = {'X0reach'}
    sys_prog = {'home'}               # []<>home
    sys_safe = {'(X(X0reach) <-> lot) || (X0reach && !park)'}
    sys_prog |= {'X0reach'}
Ejemplo n.º 15
0
def specify_discretize_synthesize():
    """Return PWA partition and controller, dump them to pickle files."""
    # Problem parameters
    input_bound = 1.0
    uncertainty = 0.01

    # Continuous state space
    cont_state_space = box2poly([[0., 3.], [0., 2.]])

    # Continuous dynamics
    A = np.array([[1.0, 0.], [0., 1.0]])
    B = np.array([[0.1, 0.], [0., 0.1]])
    E = np.array([[1., 0.], [0., 1.]])

    # Available control, possible disturbances
    U = input_bound * np.array([[-1., 1.], [-1., 1.]])
    W = uncertainty * np.array([[-1., 1.], [-1., 1.]])

    # Convert to polyhedral representation
    U = box2poly(U)
    W = box2poly(W)

    # Construct the LTI system describing the dynamics
    sys_dyn = hybrid.LtiSysDyn(A, B, E, None, U, W, cont_state_space)

    # Define atomic propositions for relevant regions of state space
    cont_props = {}
    cont_props['home'] = box2poly([[0., 1.], [0., 1.]])
    cont_props['lot'] = box2poly([[2., 3.], [1., 2.]])

    # Compute proposition preserving partition of the continuous state space
    cont_partition = prop2part(cont_state_space, cont_props)

    pwa = discretize(
        cont_partition, sys_dyn, closed_loop=True,
        N=8, min_cell_volume=0.1, plotit=False)

    """Specifications"""
    # Environment variables and assumptions
    env_vars = {'park'}
    env_init = set()
    env_prog = '!park'
    env_safe = set()

    # System variables and requirements
    sys_vars = {'X0reach'}
    sys_init = {'X0reach'}
    sys_prog = {'home'}  # []<>home
    sys_safe = {'(X(X0reach) <-> lot) || (X0reach && !park)'}
    sys_prog |= {'X0reach'}

    # Create the specification
    specs = spec.GRSpec(env_vars, sys_vars, env_init, sys_init,
                        env_safe, sys_safe, env_prog, sys_prog)
    specs.qinit = '\A \E'
    specs.moore = False
    specs.plus_one = False

    """Synthesize"""
    ctrl = synth.synthesize(
        specs, sys=pwa.ts, ignore_sys_init=True, solver='gr1c')

    # store the result for future use
    if len(BUILDDIR) > 0 and not os.path.exists(BUILDDIR):
        os.mkdir(BUILDDIR)
    pickle.dump(ctrl, open(BUILDDIR + 'FSM.p', 'wb'))
    pickle.dump(pwa, open(BUILDDIR + 'AbstractPwa.p', 'wb'))
    return pwa, ctrl
Ejemplo n.º 16
0
# cprops["fullGas"] = box2poly([[0, 100], [0, 100], [-5, 5], [-5, 5], [90, 100]])

cpartition = prop2part(X, cprops)
if verbose == 1:
    print("partition before refinement")
    print(cpartition)

# plot_partition(cpartition)

print(
    "---------------------------------\n System partition State Space \n----------------------------------"
)

disc_dynamics = discretize(cpartition,
                           sys_dyn,
                           N=10,
                           min_cell_volume=100,
                           closed_loop=True)  #, conservative=True)

print(disc_dynamics.ppp)
# states = [state for (state, label) in disc_dynamics.ts.states.find(with_attr_dict={'ap': {'inA'}})]
# disc_dynamics.ts.states.initial |= states

print(
    "----------------------------------\n Define specification \n----------------------------------"
)

# Specifications
# Environment variables and assumptions
env_vars = set()
# env_vars['gasEmpty'] = 'boolean'
Ejemplo n.º 17
0
def specify_discretize_synthesize():
    """Return PWA partition and controller, dump them to pickle files."""
    # Problem parameters
    input_bound = 1.0
    uncertainty = 0.01

    # Continuous state space
    cont_state_space = box2poly([[0., 3.], [0., 2.]])

    # Continuous dynamics
    A = np.array([[1.0, 0.], [0., 1.0]])
    B = np.array([[0.1, 0.], [0., 0.1]])
    E = np.array([[1., 0.], [0., 1.]])

    # Available control, possible disturbances
    U = input_bound * np.array([[-1., 1.], [-1., 1.]])
    W = uncertainty * np.array([[-1., 1.], [-1., 1.]])

    # Convert to polyhedral representation
    U = box2poly(U)
    W = box2poly(W)

    # Construct the LTI system describing the dynamics
    sys_dyn = hybrid.LtiSysDyn(A, B, E, None, U, W, cont_state_space)

    # Define atomic propositions for relevant regions of state space
    cont_props = {}
    cont_props['home'] = box2poly([[0., 1.], [0., 1.]])
    cont_props['lot'] = box2poly([[2., 3.], [1., 2.]])

    # Compute proposition preserving partition of the continuous state space
    cont_partition = prop2part(cont_state_space, cont_props)

    pwa = discretize(cont_partition,
                     sys_dyn,
                     closed_loop=True,
                     N=8,
                     min_cell_volume=0.1,
                     plotit=False)
    """Specifications"""
    # Environment variables and assumptions
    env_vars = {'park'}
    env_init = set()
    env_prog = '!park'
    env_safe = set()

    # System variables and requirements
    sys_vars = {'X0reach'}
    sys_init = {'X0reach'}
    sys_prog = {'home'}  # []<>home
    sys_safe = {'(X(X0reach) <-> lot) || (X0reach && !park)'}
    sys_prog |= {'X0reach'}

    # Create the specification
    specs = spec.GRSpec(env_vars, sys_vars, env_init, sys_init, env_safe,
                        sys_safe, env_prog, sys_prog)
    specs.qinit = '\A \E'
    specs.moore = False
    specs.plus_one = False
    """Synthesize"""
    ctrl = synth.synthesize(specs,
                            sys=pwa.ts,
                            ignore_sys_init=True,
                            solver='gr1c')

    # store the result for future use
    if len(BUILDDIR) > 0 and not os.path.exists(BUILDDIR):
        os.mkdir(BUILDDIR)
    pickle.dump(ctrl, open(BUILDDIR + 'FSM.p', 'wb'))
    pickle.dump(pwa, open(BUILDDIR + 'AbstractPwa.p', 'wb'))
    return pwa, ctrl
U = box2poly(U)
W = box2poly(W)
# Construct the LTI system describing the dynamics
sys_dyn = hybrid.LtiSysDyn(A, B, E, None, U, W, cont_state_space)
# Define atomic propositions for relevant regions of state space
cont_props = {}
cont_props['home'] = box2poly([[0., 1.], [0., 1.]])
cont_props['lot'] = box2poly([[2., 3.], [1., 2.]])
# Compute the proposition preserving partition of
# the continuous state space
cont_partition = prop2part(cont_state_space, cont_props)
plot_partition(cont_partition) if show else None
# Given dynamics & proposition-preserving partition,
# find feasible transitions
disc_dynamics = discretize(
    cont_partition, sys_dyn, closed_loop=False,
    conservative=True,
    N=5, min_cell_volume=0.1, plotit=show)
# Visualize transitions in continuous domain (optional)
plot_partition(disc_dynamics.ppp, disc_dynamics.ts,
               disc_dynamics.ppp2ts) if show else None
#
# Specification
# Environment variables and assumptions
env_vars = {'park'}
env_init = set()
env_prog = '!park'
env_safe = set()
# System variables and requirements
sys_vars = {'X0reach'}
sys_init = {'X0reach'}
sys_prog = {'home'}  # []<>home
Ejemplo n.º 19
0
# Compute the proposition preserving partition of the continuous state space
cont_partition = prop2part(cont_state_space, cont_props)
plot_partition(cont_partition)
# @partition_section_end@

# @discretize_section@
# Given dynamics & proposition-preserving partition, find feasible transitions
disc_params = {
    'closed_loop': True,
    'N': 8,
    'min_cell_volume': 0.1,
    'plotit': visualize,
    'conservative': False
}
disc_dynamics = discretize(cont_partition, sys_dyn, **disc_params)
# @discretize_section_end@
"""Visualize transitions in continuous domain (optional)"""
plot_partition(disc_dynamics.ppp, disc_dynamics.ts, disc_dynamics.ppp2ts)
"""Specifications"""
# Environment variables and assumptions
env_vars = {'park'}
env_init = set()  # empty set
env_prog = '!park'
env_safe = set()  # empty set

# System variables and requirements
sys_vars = {'X0reach'}
sys_init = {'X0reach'}
sys_prog = {'home'}  # []<>home
sys_safe = {'(X(X0reach) <-> lot) || (X0reach && !park)'}
Ejemplo n.º 20
0
# @partition_section@
# Define atomic propositions for relevant regions of state space
cont_props = {}
cont_props['home'] = box2poly([[0., 1.], [0., 1.]])
cont_props['lot'] = box2poly([[2., 3.], [1., 2.]])

# Compute the proposition preserving partition of the continuous state space
cont_partition = prop2part(cont_state_space, cont_props)
plot_partition(cont_partition)
# @partition_section_end@

# @discretize_section@
# Given dynamics & proposition-preserving partition, find feasible transitions
disc_params = {'closed_loop':True, 'N':8, 'min_cell_volume':0.1,
               'plotit':visualize, 'conservative':False}
disc_dynamics = discretize(cont_partition, sys_dyn, **disc_params)
# @discretize_section_end@

"""Visualize transitions in continuous domain (optional)"""
plot_partition(disc_dynamics.ppp, disc_dynamics.ts,
               disc_dynamics.ppp2ts)

"""Specifications"""
# Environment variables and assumptions
env_vars = {'park'}
env_init = set()                # empty set
env_prog = '!park'
env_safe = set()                # empty set

# System variables and requirements
sys_vars = {'X0reach'}
Ejemplo n.º 21
0
U = box2poly(U)
W = box2poly(W)
# Construct the LTI system describing the dynamics
sys_dyn = hybrid.LtiSysDyn(A, B, E, None, U, W, cont_state_space)
# Define atomic propositions for relevant regions of state space
cont_props = {}
cont_props['home'] = box2poly([[0., 1.], [0., 1.]])
cont_props['lot'] = box2poly([[2., 3.], [1., 2.]])
# Compute the proposition preserving partition of
# the continuous state space
cont_partition = prop2part(cont_state_space, cont_props)
plot_partition(cont_partition) if show else None
# Given dynamics & proposition-preserving partition,
# find feasible transitions
disc_dynamics = discretize(
    cont_partition, sys_dyn, closed_loop=False,
    conservative=True,
    N=5, min_cell_volume=0.1, plotit=show)
# Visualize transitions in continuous domain (optional)
plot_partition(disc_dynamics.ppp, disc_dynamics.ts,
               disc_dynamics.ppp2ts) if show else None
#
# Specification
# Environment variables and assumptions
env_vars = {'park'}
env_init = set()
env_prog = '!park'
env_safe = set()
# System variables and requirements
sys_vars = {'X0reach'}
sys_init = {'X0reach'}
sys_prog = {'home'}  # []<>home
Ejemplo n.º 22
0
cprops = {}
cprops["l"] = box2poly([[60., 65]])
cprops["g"] = box2poly([[goal - epsilon, goal + epsilon]])
cprops["init"] = box2poly([[76., 78.]])
cprops["h"] = box2poly([[80., 85]])

cpartition = prop2part(X, cprops)
if verbose == 1:
    print("partition before refinement")
    print(cpartition)
#  ----------------------------------\n System partition State Space \n----------------------------------

disc_dynamics = discretize(cpartition,
                           sys_dyn,
                           closed_loop=True,
                           conservative=True,
                           N=5,
                           min_cell_volume=0.1)

# part, ssys, N=10, min_cell_volume=0.1,
#   closed_loop=True, conservative=False,
#   max_numpoly=5, use_all_horizon=False,
#   trans_length=1, remove_trans=False,
#   abs_tol=1e-7,
#   plotit=False, save_img=False, cont_props=None,
#   plot_every=1

states = [
    state for (state, label) in disc_dynamics.ts.states.find(
        with_attr_dict={'ap': {'init'}})
]
Ejemplo n.º 23
0
cont_props = {}
cont_props['home'] = box2poly([[0., 1.], [0., 1.]])
cont_props['lot'] = box2poly([[2., 3.], [1., 2.]])

# Compute the proposition preserving partition
# of the continuous state space
cont_partition = prop2part(cont_state_space, cont_props)
if plotting:
    ax = cont_partition.plot()
    cont_partition.plot_props(ax=ax)
    ax.figure.savefig('spec_ppp.pdf')

disc_dynamics = discretize(cont_partition,
                           sys_dyn,
                           closed_loop=True,
                           N=8,
                           min_cell_volume=0.1,
                           plotit=plotting,
                           save_img=True,
                           cont_props=cont_props)
if plotting:
    ax = disc_dynamics.plot(show_ts=True)
    ax.figure.savefig('abs_pwa.pdf')
    disc_dynamics.ts.save('ts.pdf')

# Specifications

# Environment variables and assumptions
env_vars = {'park'}
env_init = set()  # empty set
env_prog = '!park'
env_safe = set()  # empty set
Ejemplo n.º 24
0
cont_props['home'] = shrinkPoly(box2poly([[0., 1.], [0., 1.]]), epsilon)
cont_props['lot'] = shrinkPoly(box2poly([[2., 3.], [1., 2.]]), epsilon)

# Compute the proposition preserving partition of the continuous state space
cont_partition = prop2part(cont_state_space, cont_props)
plot_partition(cont_partition) if show else None
cont_partition = shrinkPartition(cont_partition, epsilon)
plot_partition(cont_partition) if show else None
# @partition_section_end@

# @discretize_section@
# Given dynamics & proposition-preserving partition, find feasible transitions
disc_dynamics = discretize(cont_partition,
                           sys_dyn_hat,
                           closed_loop=True,
                           conservative=True,
                           N=1,
                           min_cell_volume=0.01,
                           plotit=show,
                           trans_length=3)
# @discretize_section_end@
"""Visualize transitions in continuous domain (optional)"""
plot_partition(disc_dynamics.ppp, disc_dynamics.ts,
               disc_dynamics.ppp2ts) if show else None
"""Specifications"""
# Environment variables and assumptions
env_vars = {'park'}
env_init = set()  # empty set
env_prog = '!park'
env_safe = set()  # empty set

# System variables and requirements