def add(self, action):
        transitions = []

        for relation in self.machine.graph.transitions:
            if isinstance(relation.right,
                          Stop) and (relation.label == 0
                                     or isinstance(relation.left, Start)):
                a = Action(action=action)
                if relation.label == 0:
                    transitions.append(
                        MachineRelation(left=relation.left, right=a, label=0))
                else:
                    transitions.append(
                        MachineRelation(left=relation.left, right=a))
                transitions.append(
                    MachineRelation(left=a,
                                    right=self.machine.graph.get_stop(),
                                    label=0))
            else:
                transitions.append(relation)
        res = MachineGraph(transitions=transitions)

        for vertex in res.get_special_vertices(Action):
            # print("::", res.graph.action_vertex_label_mapping[vertex])
            if not res.vertex_mapping[
                    vertex] and not res.vertex_reverse_mapping[vertex]:
                continue
            if 1 not in res.action_vertex_label_mapping[vertex]:
                res.transitions.append(
                    MachineRelation(left=vertex, right=res.get_stop(),
                                    label=1))

        self.machine = RandomMachine(graph=MachineGraph(
            transitions=transitions))
Пример #2
0
def add_action_transitions(transitions):
    res = MachineGraph(transitions=transitions)
    stop = res.get_stop()
    for vertex in res.get_special_vertices(Action):
        if not res.vertex_mapping[vertex] and not res.vertex_reverse_mapping[
                vertex]:
            continue
        if 1 not in res.action_vertex_label_mapping[vertex]:
            res.transitions.append(
                MachineRelation(left=vertex, right=stop, label=1))
    return res.transitions