Beispiel #1
0
    def clean_out_map(self, out_map):
        clean_out_map = {}
        clean_out_map['outcome'] = out_map['outcome']

        clean_conditions = dict(
            (clean_variable(k), v) for k, v in out_map['condition'].items())
        clean_out_map['condition'] = clean_conditions

        return clean_out_map
    def clean_out_map(self, out_map):
        clean_out_map = {}
        clean_out_map['outcome'] = out_map['outcome']

        clean_conditions = dict((clean_variable(k), v)
                                for k, v in out_map['condition'].items())
        clean_out_map['condition'] = clean_conditions

        return clean_out_map
    def add_internal_state(self, label, class_decl):
        """
        Add an internal state to this concurrent state.

        Internal states are the classes that run in parallel.

        label: the name by which this internal state is referred to.
        class_decl: the class declaration for code generation. e.g. 'Foo()'
        """
        clean_label = clean_variable(label)
        if clean_label not in self.internal_states:
            self.internal_states[clean_label] = class_decl
Beispiel #4
0
    def add_internal_state(self, label, class_decl):
        """
        Add an internal state to this concurrent state.

        Internal states are the classes that run in parallel.

        label: the name by which this internal state is referred to.
        class_decl: the class declaration for code generation. e.g. 'Foo()'
        """
        clean_label = clean_variable(label)
        if clean_label not in self.internal_states:
            self.internal_states[clean_label] = class_decl
    def get_outcome_name(self, is_concurrent, state_name, condition):
        """Returns a name needed to transition to the next state.

        is_concurrent: Boolean, which equals if this state is a concurrent
                       state.
        state_name: The name of the next state in the automaton (e.g. "0")
        condition: A map from proposition to value needed for this outcome
                   to happen.
        If it's a concurrent state, combine the conditions in a meaningful way.
        """
        if not is_concurrent:
            (k, v) = condition.items()[0]
            return v

        # Output format is "key1_value1__key2_value2__key3_value3__..."
        outcome_str = "__".join(["{0}_{1}".format(clean_variable(k), v)
                                 for (k, v) in condition.items()])
        return outcome_str
def modify_names(all_out_vars, automata):
    """
    Make the state names human readable.

    We append "_X" to the state name for each output variable X that is true.
    """
    for state in automata:
        state.name = str(state.name) # sometimes they're ints

    old_name_to_new_name = {}
    for state in automata:
        new_name = state.name
        for i, val in enumerate(state.output_valuation):
            if val:
                new_name += "_" + clean_variable(all_out_vars[i])
        old_name_to_new_name[state.name] = new_name

    for state in automata:
        state.name = old_name_to_new_name[state.name]
        state.transitions = [old_name_to_new_name[n]
                             for n in state.transitions]

    return automata
Beispiel #7
0
def modify_names(all_out_vars, automata):
    """
    Make the state names human readable.

    We append "_X" to the state name for each output variable X that is true.
    """
    for state in automata:
        state.name = str(state.name)  # sometimes they're ints

    old_name_to_new_name = {}
    for state in automata:
        new_name = state.name
        for i, val in enumerate(state.output_valuation):
            if val:
                new_name += "_" + clean_variable(all_out_vars[i])
        old_name_to_new_name[state.name] = new_name

    for state in automata:
        state.name = old_name_to_new_name[state.name]
        state.transitions = [
            old_name_to_new_name[n] for n in state.transitions
        ]

    return automata