def pre_check(f_network, reach, unreach, actions, actions_by_hitter,
              initial_state, start_node):
    reach_set = []
    unreach_set = []  # unsatisfied set
    L = {}
    dict_lcg = {}

    for i in reach + unreach:
        # Maybe ABAN can be replaced by logic programs
        [lcg_nodes, lcg_edges] = slcg(initial_state, actions, i)
        lcg_edges = cycle(lcg_nodes, lcg_edges, start_node, actions_by_hitter,
                          actions)
        dict_lcg[i] = [lcg_nodes, lcg_edges]
        L[i] = []
        for j in lcg_nodes:
            if j in reach + unreach:
                L[i].append(j)
        # res, _, _, _ = one_run_no_timer(copy.deepcopy(actions), copy.deepcopy(actions_by_hitter), initial_state, init_state="", start=i)
        res, _, _, _ = one_run_no_timer(actions,
                                        actions_by_hitter,
                                        initial_state,
                                        init_state="",
                                        start=i)
        if not res and i in reach:
            reach_set.append(i)
        if res and i in unreach:
            unreach_set.append(i)
    return reach_set, unreach_set, L, dict_lcg
Example #2
0
def specialize(f_network, process, actions, actions_by_hitter, initial_state, reach, unreach, to_revise, dict_lcg,
               scc_element):
    rev = [to_revise]
    modified = []
    for i in rev:
        res, _, x, lcg_edges = one_run_no_timer(actions, actions_by_hitter, initial_state, init_state="",
                                                start=i)  # reachability, iterations, sequence, used transition
        trans = []
        for l in actions[i]:
            if l in lcg_edges[i]:  # used transitions
                trans.append(l)
        # get the used transition
        # mark = False
        for j in unreach + scc_element:
            for k in trans:
                if j not in k[0] and j != (k[1], k[3]) and k in actions[i]:  # no self-regulation
                    temp = (tuple(list(k[0]) + [j]), k[1], k[2], k[3])
                    modified.append(temp)
                    actions[i].remove(k)
                    actions[i].append(temp)
                    for m in k[0]:
                        actions_by_hitter[m].remove(k)
                        actions_by_hitter[m].append(temp)
                    actions_by_hitter[j].append(temp)
        return actions, actions_by_hitter, modified
def overall(f_network, reach, unreach):
    for i in reach:
        if i in unreach:
            return None  # conflicted input
    [process, actions, actions_by_hitter, initial_state,
     start_node] = read_ban.read_ban(f_network)
    # acquire Re and Un
    [reach_set, unreach_set, L,
     dict_lcg] = pre_check(f_network, reach, unreach, actions,
                           actions_by_hitter, initial_state, start_node)
    # if there are unbreakable cycles, abandon
    if not reach_set and not unreach_set:
        return None
    modified = [1]
    while L and modified:
        modified = []
        scc = list(strongly_connected_components_path(L.keys(), L))
        cycles = copy.deepcopy(scc)
        for x in scc:
            if len(x) > 1:
                for element in x:
                    for succ in L[element]:
                        if succ in x and succ != element:
                            L[element].remove(succ)
            else:
                cycles.remove(x)
        # Get rid of self-dependencies in SLCGs
        L_sorted = dict(sorted(L.items(), key=lambda item: len(item[1])))
        for i in L_sorted:
            if i not in reach_set + unreach_set:
                L[i] = [i]
                continue
            # reconstruct lcg
            res, _, _, _ = one_run_no_timer(actions,
                                            actions_by_hitter,
                                            initial_state,
                                            init_state="",
                                            start=i)
            if (i in reach_set and res) or (i in unreach_set and not res):
                L[i] = [i]
                continue
            scc_element = []
            for j in cycles:
                if i in j:
                    scc_element = j
                    break
            if i in reach_set:
                pass
                # add transitions
            else:
                # delete transitions
                pass

            L[i] = [i]
            [reach_set, unreach_set, L,
             dict_lcg] = pre_check(f_network, reach, unreach, actions,
                                   actions_by_hitter, initial_state,
                                   start_node)
    return actions