Beispiel #1
0
def transition_directions_test():
    """
    unit test for correctness of abstracted transition directions, with:
    
      - uni-directional control authority
      - no disturbance
    """
    modes = []
    modes.append(('normal', 'fly'))
    modes.append(('refuel', 'fly'))
    env_modes, sys_modes = zip(*modes)

    cont_state_space = pc.box2poly([[0., 3.], [0., 2.]])
    pwa_sys = dict()
    pwa_sys[('normal', 'fly')] = hybrid.PwaSysDyn([subsys0()],
                                                  cont_state_space)
    pwa_sys[('refuel', 'fly')] = hybrid.PwaSysDyn([subsys1()],
                                                  cont_state_space)

    switched_dynamics = hybrid.SwitchedSysDyn(
        disc_domain_size=(len(env_modes), len(sys_modes)),
        dynamics=pwa_sys,
        env_labels=env_modes,
        disc_sys_labels=sys_modes,
        cts_ss=cont_state_space)

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

    ppp = abstract.prop2part(cont_state_space, cont_props)
    ppp, new2old = abstract.part2convex(ppp)

    N = 8
    trans_len = 1

    disc_params = {}
    for mode in modes:
        disc_params[mode] = {'N': N, 'trans_length': trans_len}

    swab = abstract.discretize_switched(ppp,
                                        switched_dynamics,
                                        disc_params,
                                        plot=True,
                                        show_ts=True,
                                        only_adjacent=False)

    ts = swab.modes[('normal', 'fly')].ts
    edges = {(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (1, 2), (1, 4),
             (1, 5), (2, 3), (2, 5), (2, 0), (3, 0), (4, 5), (5, 0)}

    logger.debug(set(ts.edges()).symmetric_difference(edges))
    assert (set(ts.edges()) == edges)

    ts = swab.ts

    assert (set(ts.edges()) == edges)
    for i, j in edges:
        assert (ts[i][j][0]['env_actions'] == 'normal')
        assert (ts[i][j][0]['sys_actions'] == 'fly')
Beispiel #2
0
def define_partition(dom):
    p = dict()
    p['a'] = pc.box2poly([[0.0, 10.0], [15.0, 18.0]])
    p['b'] = pc.box2poly([[0.0, 1.0], [0.0, 20.0]])

    ppp = abstract.prop2part(dom, p)
    ppp, new2old_reg = abstract.part2convex(ppp)
    return ppp
Beispiel #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 define_partition(dom):
    p = dict()
    p["a"] = pc.box2poly([[0.0, 10.0], [15.0, 18.0]])
    p["b"] = pc.box2poly([[0.0, 1.0], [0.0, 20.0]])

    ppp = abstract.prop2part(dom, p)
    ppp, new2old_reg = abstract.part2convex(ppp)
    return ppp
    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
Beispiel #6
0
def transition_directions_test():
    """Unit test for correctness of abstracted transition directions, with:

      - uni-directional control authority
      - no disturbance
    """
    modes = list()
    modes.append(('normal', 'fly'))
    modes.append(('refuel', 'fly'))
    env_modes, sys_modes = zip(*modes)
    # dynamics
    cont_state_space = pc.box2poly([[0.0, 3.0], [0.0, 2.0]])
    pwa_sys = dict()
    pwa_sys[('normal', 'fly')] = hybrid.PwaSysDyn([subsys0()],
                                                  cont_state_space)
    pwa_sys[('refuel', 'fly')] = hybrid.PwaSysDyn([subsys1()],
                                                  cont_state_space)
    switched_dynamics = hybrid.SwitchedSysDyn(
        disc_domain_size=(len(env_modes), len(sys_modes)),
        dynamics=pwa_sys,
        env_labels=env_modes,
        disc_sys_labels=sys_modes,
        cts_ss=cont_state_space)
    # propositions
    cont_props = dict()
    cont_props['home'] = pc.box2poly([[0.0, 1.0], [0.0, 1.0]])
    cont_props['lot'] = pc.box2poly([[2.0, 3.0], [1.0, 2.0]])
    # partition
    ppp = abstract.prop2part(cont_state_space, cont_props)
    ppp, new2old = abstract.part2convex(ppp)
    # configure discretization
    N = 8
    trans_len = 1
    disc_params = dict()
    for mode in modes:
        disc_params[mode] = dict(N=N, trans_length=trans_len)
    # discretize
    swab = abstract.discretize_switched(ppp,
                                        switched_dynamics,
                                        disc_params,
                                        plot=True,
                                        show_ts=True,
                                        only_adjacent=False)
    # assertions
    ts = swab.modes[('normal', 'fly')].ts
    edges = {(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (1, 2), (1, 4),
             (1, 5), (2, 3), (2, 5), (2, 0), (3, 0), (4, 5), (5, 0)}
    h = nx.MultiDiGraph()
    h.add_edges_from(edges)
    assert nx.is_isomorphic(ts, h)
    ts = swab.ts
    assert nx.is_isomorphic(ts, h)
    for _, _, d in ts.edges(data=True):
        assert d['env_actions'] == 'normal'
        assert d['sys_actions'] == 'fly'
Beispiel #7
0
pwa_normal = hybrid.PwaSysDyn([cont_dyn_normal], domain=cont_ss)
pwa_refuel = hybrid.PwaSysDyn([cont_dyn_refuel], domain=cont_ss)

dynamics_dict = {('normal', 'fly'): pwa_normal, ('refuel', 'fly'): pwa_refuel}

switched_dynamics = hybrid.SwitchedSysDyn(cts_ss=cont_ss,
                                          disc_domain_size=(len(env_modes),
                                                            len(sys_modes)),
                                          dynamics=dynamics_dict,
                                          env_labels=env_modes,
                                          disc_sys_labels=sys_modes)

## Create convex proposition preserving partition
ppp = abstract.prop2part(cont_ss, cont_props)
ppp, new2old = abstract.part2convex(ppp)

ax = ppp.plot_props()
ax.figure.savefig(imgpath + 'cprops.pdf')

ax = ppp.plot()
ax.figure.savefig(imgpath + 'ppp.pdf')

## Discretize to establish transitions
if os.name == "posix":
    start = os.times()[2]
    logger.info('start time: ' + str(start))
else:
    logger.info(
        'Timing currently only available for POSIX platforms (not Windows)')
msg = 'Found:\n'
msg += '\t Environment modes: ' + str(env_modes)
msg += '\t System modes: ' + str(sys_modes)

switched_dynamics = hybrid.SwitchedSysDyn(
    disc_domain_size=(len(env_modes), len(sys_modes)),
    dynamics=sys_dyn,
    env_labels=env_modes,
    disc_sys_labels=sys_modes,
    cts_ss=cont_state_space
)

print(switched_dynamics)

ppp = abstract.prop2part(cont_state_space, cont_props)
ppp, new2old = abstract.part2convex(ppp)

"""Discretize to establish transitions"""
start = time.time()

N = 8
trans_len=1

disc_params = {}
for mode in modes:
    disc_params[mode] = {'N':N, 'trans_length':trans_len}

swab = abstract.multiproc_discretize_switched(
    ppp, switched_dynamics, disc_params,
    plot=True, show_ts=True
)
def transition_directions_test():
    """
    unit test for correctness of abstracted transition directions, with:
    
      - uni-directional control authority
      - no disturbance
    """
    modes = []
    modes.append(("normal", "fly"))
    modes.append(("refuel", "fly"))
    env_modes, sys_modes = zip(*modes)

    cont_state_space = pc.box2poly([[0.0, 3.0], [0.0, 2.0]])
    pwa_sys = dict()
    pwa_sys[("normal", "fly")] = hybrid.PwaSysDyn([subsys0()], cont_state_space)
    pwa_sys[("refuel", "fly")] = hybrid.PwaSysDyn([subsys1()], cont_state_space)

    switched_dynamics = hybrid.SwitchedSysDyn(
        disc_domain_size=(len(env_modes), len(sys_modes)),
        dynamics=pwa_sys,
        env_labels=env_modes,
        disc_sys_labels=sys_modes,
        cts_ss=cont_state_space,
    )

    cont_props = {}
    cont_props["home"] = pc.box2poly([[0.0, 1.0], [0.0, 1.0]])
    cont_props["lot"] = pc.box2poly([[2.0, 3.0], [1.0, 2.0]])

    ppp = abstract.prop2part(cont_state_space, cont_props)
    ppp, new2old = abstract.part2convex(ppp)

    N = 8
    trans_len = 1

    disc_params = {}
    for mode in modes:
        disc_params[mode] = {"N": N, "trans_length": trans_len}

    swab = abstract.discretize_switched(
        ppp, switched_dynamics, disc_params, plot=True, show_ts=True, only_adjacent=False
    )

    ts = swab.modes[("normal", "fly")].ts
    edges = {
        (0, 0),
        (1, 1),
        (2, 2),
        (3, 3),
        (4, 4),
        (5, 5),
        (1, 2),
        (1, 4),
        (1, 5),
        (2, 3),
        (2, 5),
        (2, 0),
        (3, 0),
        (4, 5),
        (5, 0),
    }

    logger.debug(set(ts.edges()).symmetric_difference(edges))
    assert set(ts.edges()) == edges

    ts = swab.ts

    assert set(ts.edges()) == edges
    for i, j in edges:
        assert ts[i][j][0]["env_actions"] == "normal"
        assert ts[i][j][0]["sys_actions"] == "fly"