Exemple #1
0
def single_recurrence_goal(target, z_next, within, players, ij, aut):
    """Development harness for parameterized assumption construction."""
    assert 'scheduler' not in players
    print('single recurrence goal: {ij}'.format(ij=ij))
    i, j = ij
    assert i >= 0, i
    assert j >= 0, j
    phase = '{i}_{j}'.format(i=i, j=j)
    _masks.add_masks_and_hidden_vars(aut, phase=phase)
    # define players that assumptions will be generated for
    # players outside `team` are treated as the team's environment
    player, *team = players
    print('player: {p}'.format(p=player))
    print('team: {t}'.format(t=team))
    # define what the component observes
    aut.observe(player, [player])
    # eliminate hidden vars from target
    inv = aut.global_inv
    vis_z = observable(z_next, inv, inv, aut)
    vis_target = observable(target, inv, inv, aut)
    y = vis_target
    # print('vis_target')
    # print_slice(vis_target, aut)
    yold = None
    # iterate over assumption generation,
    # which is effectively the least fixpoint Y
    trap = aut.true
    etas = list()
    while y != yold:
        # print('Y iteration')
        yold = y
        # can others help as a team ?
        attr, trap, eta_team = make_pinfo_assumption(
            y, vis_z, within, player, team, aut)
        etas.append(eta_team)
        within_new = inv & trap
        z_next_new = aut.true
        ij_new = (i, j + 1)
        # decompose team
        if len(team) > 1:
            single_recurrence_goal(
                ~ eta_team, z_next_new, within_new,
                team, ij_new, aut)
        y = attr | trap
    # print('Y')
    # print_slice(y, aut)
    # \A vars:  (Inv /\ ~ Target)  =>  Y
    aut.observe(player, [player])
    proj_inv = maybe(inv, inv, aut)
    u = y | ~ proj_inv
    qvars = aut.vars_of_all_players
    u = aut.forall(qvars, u)
    # print('Maybe(Inv) => Y')
    # print_slice(u, aut)
    # u = y | target | ~ inv
    # u = aut.forall(qvars, u)
    # print('Inv  =>  (Y \/ Target)')
    # print_slice(u, aut)
    # print('end: {ij}========\n'.format(ij=ij))
    return y
def iterate_recurrence_goals(z, players, aut):
    within = aut.global_inv
    player = players[0]
    k_players = len(players) - 1
    n_goals = len(aut.win[player]['[]<>'])
    for i in range(n_goals):
        for j in range(k_players):
            phase = '{i}_{j}'.format(i=i, j=j)
            _masks.add_masks_and_hidden_vars(aut, phase=phase)
    z_new = list(z)
    for i, goal in enumerate(aut.win[player]['[]<>']):
        print('recurrence goal: {i}'.format(i=i))
        # declare at top to propagate to copied automata
        # caution: overwrites parameter maps
        ij = (i, 0)
        i_next = (i + 1) % n_goals
        z_next = z[i_next]
        y = single_recurrence_goal(goal, z_next, within, players, ij, aut)
        z_new[i] &= y
    return z_new
def main(aut):
    """Decompose specification into a contract."""
    inv = _closure.closure(aut.players, aut)
    assert not (aut.support(inv) & aut.masks)
    assert_type_invariant_implies_type_hints(inv, aut)
    fname = 'inv_bdd.pdf'
    dump_bdd_using_autoref(inv, fname)
    _closure.print_state_space_statistics(inv, aut)
    s = dumps_expr(inv, aut, use_types=True)
    print('\nshared invariant Inv:\n')
    print(s)
    fname = 'Invariant.tla'
    utils.dump_as_tla(s, fname)
    #
    # for charging station example
    # sys_player = 'station'
    # vrs = ['pos_x', 'pos_y']  # hide these variables
    #
    # for landing gear example
    # sys_player = 'autopilot'
    # vrs = ['door']
    # _closure.hide_vars_from_sys(vrs, inv, sys_player, aut)
    #
    # for charging station example
    # sys_player = 'robot'
    # players = ['robot', 'station']
    #
    # for autopilot example
    # sys_player = 'autopilot'
    # players = ['autopilot', 'gear_module', 'door_module']

    sys_player = 'environment'
    vrs = ['room1', 'room2']
    _closure.hide_vars_from_sys(vrs, inv, sys_player, aut)
    # sys_player = 'rob1'
    # vrs = ['pos2','goTo2']
    # _closure.hide_vars_from_sys(vrs, inv, sys_player, aut)
    # sys_player = 'rob2'
    # vrs = ['pos1','goTo1']
    # _closure.hide_vars_from_sys(vrs, inv, sys_player, aut)

    sys_player = 'environment'
    players = ['environment', 'rob1', 'rob2']

    aut.global_inv = inv  # global full-info invariant
    aut_unzipped = _closure.unzip(inv, aut.players, aut)
    # configure mask parameters
    initial_phase = 0
    phase = '{i}_0'.format(i=initial_phase)
    _masks.add_masks_and_hidden_vars(aut_unzipped, phase=phase)
    aut_unzipped.observe(sys_player, [sys_player])
    # require initial condition
    param_inv = parametric_predicate(inv, aut_unzipped)
    param_z = outer_fixpoint(players, aut_unzipped)
    z = param_z[initial_phase]
    u = z | ~param_inv
    qvars = aut.vars_of_all_players
    u = aut_unzipped.forall(qvars, u)
    # BDD stats
    stats = aut.bdd.statistics()
    s = utils.format_stats(stats)
    print(s)