Exemplo n.º 1
0
def ppp2ts(part):
    """Derive transition system from proposition preserving partition.

    @param part: labeled polytopic partition from
        which to derive the transition system
    @type part: L{PropPreservingPartition}

    @return: C{(ts, state_map)}
        finite transition system labeled with propositions
        from the given partition, and map of
        polytope indices to transition system states.

    @rtype: (L{transys.FTS}, \C{dict})
    """
    # generate transition system and add transitions
    ofts = trs.FTS()

    adj = part.adj  #sp.lil_matrix
    n = adj.shape[0]
    ofts_states = range(n)
    ofts_states = trs.prepend_with(ofts_states, 's')

    ofts.states.add_from(ofts_states)

    ofts.transitions.add_adj(adj, ofts_states)

    # decorate TS with state labels
    atomic_propositions = set(part.prop_regions)
    ofts.atomic_propositions.add_from(atomic_propositions)
    for state, region in zip(ofts_states, part.regions):
        state_prop = region.props.copy()
        ofts.states.add(state, ap=state_prop)

    return (ofts, ofts_states)
Exemplo n.º 2
0
def ppp2ts(part):
    """Derive transition system from proposition preserving partition.

    @param part: labeled polytopic partition from
        which to derive the transition system
    @type part: L{PropPreservingPartition}

    @return: C{(ts, state_map)}
        finite transition system labeled with propositions
        from the given partition, and map of
        polytope indices to transition system states.

    @rtype: (L{transys.FTS}, \C{dict})
    """
    # generate transition system and add transitions
    ofts = trs.FTS()

    adj = part.adj #sp.lil_matrix
    n = adj.shape[0]
    ofts_states = range(n)
    ofts_states = trs.prepend_with(ofts_states, 's')

    ofts.states.add_from(ofts_states)

    ofts.transitions.add_adj(adj, ofts_states)

    # decorate TS with state labels
    atomic_propositions = set(part.prop_regions)
    ofts.atomic_propositions.add_from(atomic_propositions)
    for state, region in zip(ofts_states, part.regions):
        state_prop = region.props.copy()
        ofts.states.add(state, ap=state_prop)

    return (ofts, ofts_states)
Exemplo n.º 3
0
def test_only_mode_control():
    """Unrealizable due to non-determinism.

    Switched system with 2 modes: 'left', 'right'.
    Modes are controlled by the system.
    States are controlled by the environment.

    So only control over dynamics is through mode switching.
    Transitions are thus interpreted as non-deterministic.

    This can model uncertain outcomes in the real world,
    e.g., due to low quality actuators or
    bad low-level feedback controllers.
    """
    # Create a finite transition system
    env_sws = transys.FTS()
    env_sws.owner = 'env'

    env_sws.sys_actions.add_from({'right', 'left'})

    # str states
    n = 4
    states = transys.prepend_with(range(n), 's')

    env_sws.atomic_propositions.add_from(['home', 'lot'])

    # label TS with APs
    ap_labels = [set(), set(), {'home'}, {'lot'}]
    for i, label in enumerate(ap_labels):
        state = 's' + str(i)
        env_sws.states.add(state, ap=label)

    # mode1 transitions
    transmat1 = np.array([[0, 1, 0, 1], [0, 1, 0, 0], [0, 1, 0, 1],
                          [0, 0, 0, 1]])
    env_sws.transitions.add_adj(sp.lil_matrix(transmat1), states,
                                {'sys_actions': 'right'})

    # mode2 transitions
    transmat2 = np.array([[1, 0, 0, 0], [1, 0, 1, 0], [0, 0, 1, 0],
                          [1, 0, 1, 0]])
    env_sws.transitions.add_adj(sp.lil_matrix(transmat2), states,
                                {'sys_actions': 'left'})

    env_vars = {'park'}
    env_init = {'eloc = "s0"', 'park'}
    env_prog = {'!park'}
    env_safe = set()

    sys_vars = {'X0reach'}
    sys_init = {'X0reach'}
    sys_prog = {'home'}
    sys_safe = {'next(X0reach) <-> lot || (X0reach && !park)'}
    sys_prog |= {'X0reach'}

    specs = spec.GRSpec(env_vars, sys_vars, env_init, sys_init, env_safe,
                        sys_safe, env_prog, sys_prog)

    r = synth.is_realizable('gr1c', specs, env=env_sws, ignore_env_init=True)
    assert not r
###############################
# Switched system with 4 modes:
###############################

# In this scenario we have limited actions "left, right, up, down" with 
# certain (nondeterministic) outcomes

# Create a finite transition system
sys_sws = transys.FTS()

sys_sws.actions.add_from({'right','up','left','down'})

# str states
n = 6
states = transys.prepend_with(range(n), 's')
sys_sws.states.add_from(set(states) )
sys_sws.states.initial.add_from({'s0', 's3'})

sys_sws.atomic_propositions.add_from(['home','lot'])
state_labels = [{'home'}, set(), set(), set(), set(), {'lot'}]

# Add states and decorate TS with state labels (aka atomic propositions)
for state, label in zip(states, state_labels):
    sys_sws.states.add(state, ap=label)

# mode1 transitions
transmat1 = np.array([[0,1,0,0,1,0],
                      [0,0,1,0,0,1],
                      [0,0,1,0,0,0],
                      [0,1,0,0,1,0],
Exemplo n.º 5
0
# In this scenario we have limited actions "left, right, up, down" with
# uncertain (nondeterministics) outcomes (e.g., due to bad actuators or
# bad low-level feedback controllers)

# Only control over the dynamics is through mode switching
# Transitions should be interpreted as nondeterministic

# Create a finite transition system
env_sws = transys.FTS()
env_sws.owner = 'env'

env_sws.sys_actions.add_from({'right', 'up', 'left', 'down'})

# str states
n = 6
states = transys.prepend_with(range(n), 's')
env_sws.states.add_from(set(states))
env_sws.states.initial.add('s0')

env_sws.atomic_propositions.add_from(['home', 'lot'])
state_labels = [{'home'}, set(), set(), set(), set(), {'lot'}]

# Add states and decorate TS with state labels (aka atomic propositions)
for state, label in zip(states, state_labels):
    env_sws.states.add(state, ap=label)

# mode1 transitions
transmat1 = np.array([[0, 1, 0, 0, 1, 0], [0, 0, 1, 0, 0,
                                           1], [0, 0, 1, 0, 0, 0],
                      [0, 1, 0, 0, 1, 0], [0, 0, 1, 0, 0, 1],
                      [0, 0, 0, 0, 0, 1]])
Exemplo n.º 6
0
def test_only_mode_control():
    """Unrealizable due to non-determinism.
    
    Switched system with 2 modes: 'left', 'right'.
    Modes are controlled by the system.
    States are controlled by the environment.
    
    So only control over dynamics is through mode switching.
    Transitions are thus interpreted as non-deterministic.
    
    This can model uncertain outcomes in the real world,
    e.g., due to low quality actuators or
    bad low-level feedback controllers.
    """
    # Create a finite transition system
    env_sws = transys.OpenFTS()
    
    env_sws.sys_actions.add_from({'right','left'})
    
    # str states
    n = 4
    states = transys.prepend_with(range(n), 's')
    
    env_sws.atomic_propositions.add_from(['home','lot'])
    
    # label TS with APs
    ap_labels = [set(),set(),{'home'},{'lot'}]
    for i, label in enumerate(ap_labels):
        state = 's' + str(i)
        env_sws.states.add(state, ap=label)
    
    
    # mode1 transitions
    transmat1 = np.array([[0,1,0,1],
                          [0,1,0,0],
                          [0,1,0,1],
                          [0,0,0,1]])
    env_sws.transitions.add_adj(
        sp.lil_matrix(transmat1), states, {'sys_actions':'right'}
    )
                          
    # mode2 transitions
    transmat2 = np.array([[1,0,0,0],
                          [1,0,1,0],
                          [0,0,1,0],
                          [1,0,1,0]])
    env_sws.transitions.add_adj(
        sp.lil_matrix(transmat2), states, {'sys_actions':'left'}
    )
    
    env_vars = {'park'}
    env_init = {'eloc = 0', 'park'}
    env_prog = {'!park'}
    env_safe = set()
    
    sys_vars = {'X0reach'}
    sys_init = {'X0reach'}          
    sys_prog = {'home'}
    sys_safe = {'next(X0reach) <-> lot || (X0reach && !park)'}
    sys_prog |= {'X0reach'}
    
    specs = spec.GRSpec(env_vars, sys_vars, env_init, sys_init,
                        env_safe, sys_safe, env_prog, sys_prog)
    
    r = synth.is_realizable('gr1c', specs, env=env_sws, ignore_env_init=True)
    assert(not r)