Exemple #1
0
def is_final_sink(node: Node):
    flagged_nodes = node.transitions.get(LABEL_TRUE)
    if flagged_nodes is None:
        return False

    return index_of(lambda node_flag: node_flag[0] == node and node_flag[1], flagged_nodes)\
           is not None
Exemple #2
0
    def get_architecture_trans_assumption(self, label,
                                          sys_state_vector) -> str:
        """ It handles 'is_active' and 'tok' variables in the specification. """

        #TODO: here I can add G(tok -> !prev) for the hub abstraction instead of specifying this on LTL level

        active_signals = list(
            filter(lambda s: s in label, self._is_active_signals))
        assert len(active_signals
                   ) <= 1, 'spec cannot contain > 1 is_active as conjunction'

        index_of_prev = index_of(lambda s: s in label,
                                 self._sends_prev_signals)
        assert index_of_prev is None or self.nof_processes == 1, \
            'using prev in the spec is not supported; prev in async hub abstraction works with local properties only'

        if not active_signals and not index_of_prev:
            return ''

        if active_signals:
            #: :type: QuantifiedSignal
            active = active_signals[0]
            proc_index = active.binding_indices[0]
        else:
            proc_index = self._sends_prev_signals[
                index_of_prev].binding_indices[0]
            assert self.nof_processes == 1, 'should come here only in the case of async hub'

        sends_prev_signal = _filter_by_proc(proc_index,
                                            self._sends_prev_signals)[0]

        value_by_sched, _ = build_signals_values(self._sched_signals, label)

        if self.nof_processes > 1:
            sends_prev_value = self._get_wrapped_prev_expr(
                proc_index, sys_state_vector, value_by_sched)
        else:
            #async_hub
            value_by_signal, _ = build_signals_values([sends_prev_signal],
                                                      label)
            sends_prev_value = value_by_signal[sends_prev_signal]

        if not active_signals:
            return sends_prev_value

        value_by_proc = self._build_label_from_proc_index(proc_index)

        value_by_signal = add_dicts(
            value_by_sched, value_by_proc,
            {sends_prev_signal: sends_prev_value},
            {self.state_arg_name: sys_state_vector[proc_index]})

        is_active_func_desc = self._get_desc_is_active(proc_index)

        func = self.underlying_solver.call_func(is_active_func_desc,
                                                value_by_signal)

        return func
Exemple #3
0
def is_absorbing(node):
    true_label = Label({})

    sets_of_flagged_nodes = node.transitions.get(true_label)
    if sets_of_flagged_nodes is None:
        return False

    all_next_flagged_nodes = chain(*sets_of_flagged_nodes)
    return index_of(lambda node_flag: node_flag[0] == node, all_next_flagged_nodes) is not None
Exemple #4
0
def is_absorbing(node):
    true_label = Label({})

    sets_of_flagged_nodes = node.transitions.get(true_label)
    if sets_of_flagged_nodes is None:
        return False

    all_next_flagged_nodes = chain(*sets_of_flagged_nodes)
    return index_of(lambda node_flag: node_flag[0] == node,
                    all_next_flagged_nodes) is not None
Exemple #5
0
def is_dead_end(state):
    if state is DEAD_END:
        return True

    if Label({}) in state.transitions:
        next_states_set_list = state.transitions[Label({})]
        assert len(next_states_set_list) == 1
        next_states_set = next_states_set_list[0]

        if index_of(lambda node_flag: node_flag[0] == state and node_flag[1], next_states_set) is not None:
            return True

    return False
def is_quantified_property(property) -> Bool:  # TODO: does not allow embedded forall quantifiers
    """ Return True iff the property has quantified indices.
        Numbers cannot be used as quantification indices.
    """
    for e in property.assumptions + property.guarantees:
        if isinstance(e, ForallExpr):
            binding_indices = e.arg1
            if index_of(lambda bi: isinstance(bi, str), binding_indices) is not None:
                return True
        else:
            assert e.__class__ in [ForallExpr, BinOp, UnaryOp, Bool], 'unknown class'

    return False
Exemple #7
0
    def get_architecture_trans_assumption(self, label, sys_state_vector) -> str:
        """ It handles 'is_active' and 'tok' variables in the specification. """

        #TODO: here I can add G(tok -> !prev) for the hub abstraction instead of specifying this on LTL level

        active_signals = list(filter(lambda s: s in label, self._is_active_signals))
        assert len(active_signals) <= 1, 'spec cannot contain > 1 is_active as conjunction'

        index_of_prev = index_of(lambda s: s in label, self._sends_prev_signals)
        assert index_of_prev is None or self.nof_processes == 1, \
            'using prev in the spec is not supported; prev in async hub abstraction works with local properties only'

        if not active_signals and not index_of_prev:
            return ''

        if active_signals:
            #: :type: QuantifiedSignal
            active = active_signals[0]
            proc_index = active.binding_indices[0]
        else:
            proc_index = self._sends_prev_signals[index_of_prev].binding_indices[0]
            assert self.nof_processes == 1, 'should come here only in the case of async hub'

        sends_prev_signal = _filter_by_proc(proc_index, self._sends_prev_signals)[0]

        value_by_sched, _ = build_signals_values(self._sched_signals, label)

        if self.nof_processes > 1:
            sends_prev_value = self._get_wrapped_prev_expr(proc_index,
                                                           sys_state_vector,
                                                           value_by_sched)
        else:
            #async_hub
            value_by_signal, _ = build_signals_values([sends_prev_signal], label)
            sends_prev_value = value_by_signal[sends_prev_signal]

        if not active_signals:
            return sends_prev_value

        value_by_proc = self._build_label_from_proc_index(proc_index)

        value_by_signal = add_dicts(value_by_sched,
                                    value_by_proc,
                                    {sends_prev_signal: sends_prev_value},
                                    {self.state_arg_name:sys_state_vector[proc_index]})

        is_active_func_desc = self._get_desc_is_active(proc_index)

        func = self.underlying_solver.call_func(is_active_func_desc, value_by_signal)

        return func
Exemple #8
0
def is_dead_end(state):
    if state is DEAD_END:
        return True

    if Label({}) in state.transitions:
        next_states_set_list = state.transitions[Label({})]
        assert len(next_states_set_list) == 1
        next_states_set = next_states_set_list[0]

        if index_of(lambda node_flag: node_flag[0] == state and node_flag[1],
                    next_states_set) is not None:
            return True

    return False
Exemple #9
0
def is_quantified_property(
        property) -> Bool:  #TODO: does not allow embedded forall quantifiers
    """ Return True iff the property has quantified indices.
        Numbers cannot be used as quantification indices.
    """
    for e in property.assumptions + property.guarantees:
        if isinstance(e, ForallExpr):
            binding_indices = e.arg1
            if index_of(lambda bi: isinstance(bi, str),
                        binding_indices) is not None:
                return True
        else:
            assert e.__class__ in [ForallExpr, BinOp, UnaryOp,
                                   Bool], 'unknown class'

    return False
def is_absorbing(node):
    flagged_nodes = node.transitions.get(LABEL_TRUE)
    if flagged_nodes is None:
        return False

    return index_of(lambda node_flag: node_flag[0] == node, flagged_nodes) is not None