Beispiel #1
0
def setup():
    """
    Initialize binary circuit manager
    """
    mgr = BDD()
    mgr.configure(reordering=False)
    """
    Declare spaces and types
    """
    # Declare continuous state spaces
    pspace = DynamicCover(-2, 2)
    anglespace = DynamicCover(-np.pi, np.pi, periodic=True)
    # Declare discrete control spaces
    vspace = EmbeddedGrid(2, vmax / 2, vmax)
    angaccspace = EmbeddedGrid(3, -1.5, 1.5)
    """
    Declare interfaces
    """
    dubins_x = Interface(mgr, {
        'x': pspace,
        'theta': anglespace,
        'v': vspace
    }, {'xnext': pspace})
    dubins_y = Interface(mgr, {
        'y': pspace,
        'theta': anglespace,
        'v': vspace
    }, {'ynext': pspace})
    dubins_theta = Interface(mgr, {
        'theta': anglespace,
        'v': vspace,
        'omega': angaccspace
    }, {'thetanext': anglespace})

    return mgr, dubins_x, dubins_y, dubins_theta
Beispiel #2
0
from pytest import approx

import numpy as np
import funcy as fn

from redax.module import Interface, CompositeInterface
from redax.spaces import DynamicCover
from redax.synthesis import ControlPre, DecompCPre, ReachGame, SafetyGame, ReachAvoidGame
from redax.visualizer import scatter2D, plot3D, plot3D_QT, pixel2D
from redax.utils.overapprox import bloatbox

from redax.predicates.dd import BDD
mgr = BDD()
mgr.configure(reordering=True)

ts = .2
k = .1
g = 9.8


def dynamics(p, v, a):
    vsign = 1 if v > 0 else -1
    return p + v * ts, v + a * ts - vsign * k * (v**2) * ts - g * ts


pspace = DynamicCover(-10, 10)
vspace = DynamicCover(-16, 16)
aspace = DynamicCover(0, 20)

# Smaller component modules
pcomp = Interface(mgr, {'p': pspace, 'v': vspace}, {'pnext': pspace})
Beispiel #3
0
def setup(init=False):

    mgr = BDD()
    mgr.configure(
        reordering=False
    )  # Reordering causes too much time overhead for minimal gain.
    subsys = {}
    subsys['x'] = Interface(mgr, {
        'x': xspace,
        'vx': vxspace,
        'theta': thetaspace,
        't': thrust
    }, {'xnext': xspace})
    subsys['y'] = Interface(mgr, {
        'y': yspace,
        'vy': vyspace,
        'theta': thetaspace,
        't': thrust
    }, {'ynext': yspace})
    subsys['vx'] = Interface(
        mgr, {
            'vx': vxspace,
            'theta': thetaspace,
            'omega': omegaspace,
            't': thrust,
            's': side
        }, {'vxnext': vxspace})
    subsys['vy'] = Interface(
        mgr, {
            'vy': vyspace,
            'theta': thetaspace,
            'omega': omegaspace,
            't': thrust,
            's': side
        }, {'vynext': vyspace})
    subsys['theta'] = Interface(mgr, {
        'theta': thetaspace,
        'omega': omegaspace,
        's': side
    }, {'thetanext': thetaspace})
    subsys['omega'] = Interface(mgr, {
        'omega': omegaspace,
        's': side
    }, {'omeganext': omegaspace})

    # Coarse, but exhaustive abstraction of submodules.
    if init:
        iter_coarseness = {
            'x': {
                'x': 7,
                'vx': 5,
                'theta': 2
            },
            'y': {
                'y': 7,
                'vy': 5,
                'theta': 2
            },
            'vx': {
                'vx': 5,
                'theta': 4,
                'omega': 3
            },
            'vy': {
                'vy': 5,
                'theta': 4,
                'omega': 3
            },
            'theta': {
                'theta': 5,
                'omega': 4
            },
            'omega': {
                'omega': 4
            }
        }
        # iter_coarseness = {k: {k_: v_ + 1 for k_, v_ in v.items()} for k, v in iter_coarseness.items()}
        # iter_coarseness = sysview
        initabs_start = time.time()
        for i in states:
            print("Refining", i, "module")
            print("Iter Coarseness:", iter_coarseness[i])
            print("Recording Coarseness:",
                  {k: v
                   for k, v in sysview[i].items() if k in subsys[i].vars})
            subsys[i] = coarse_abstract(subsys[i], iter_coarseness[i],
                                        sysview[i])
            print(len(mgr), "manager nodes after first pass")
            subsys[i].check()
            print("Subsys", i, "ND ratio:", nd_ratio(subsys[i]))

            subsys[i] = coarse_abstract(subsys[i],
                                        iter_coarseness[i],
                                        sysview[i],
                                        shift_frac=0.5)
            print(len(mgr), "manager nodes after second pass")
            subsys[i].check()
            print("Subsys", i, "ND ratio:", nd_ratio(subsys[i]), "\n")

            mgr.reorder(
                order_heuristic(mgr, [
                    'x', 'y', 'vx', 'vy', 'theta', 'omega', 't', 's', 'xnext',
                    'ynext', 'vxnext', 'vynext', 'thetanext', 'omeganext'
                ]))

        print("Coarse Initial Abstraction Time (s): ",
              time.time() - initabs_start)

    return mgr, subsys