Exemplo n.º 1
0
    def on_new_automata(self, action, param):
        if(len(self.window.tab) > 5):
            print("[*] You exceed the opended pages limit")
        else: 
            print("[*] You created a new automata")
            a = Automaton()

            # Test Renderer
            from test_automata import automata_01
            automata_01(a)

            self.automaton = a
            self.lst_state = list(a.states)
            self.ar = AutomatonRender()

            # Creating Drawing Area
            self.darea = Gtk.DrawingArea()
            self.darea.connect("draw", self.on_draw)
            self.darea.set_events(Gdk.EventMask.BUTTON_MOTION_MASK |
                                Gdk.EventMask.BUTTON_PRESS_MASK
            )
            self.darea.connect("motion-notify-event", self.on_motion_notify)
            self.darea.connect("button-press-event", self.on_button_press)

            self.page = self.window.add_tab(self.darea, "automata")
Exemplo n.º 2
0
 def on_load_automata(self, action, param):
     dialog = Gtk.FileChooserDialog("Choose file", self.window, Gtk.FileChooserAction.OPEN,
                                    ("_Cancel", Gtk.ResponseType.CANCEL,
                                     "_Open", Gtk.ResponseType.ACCEPT)
                                    )
     result = dialog.run()
     if result == Gtk.ResponseType.ACCEPT:
         a = Automaton()
         self.elements.append(a)
         print("You loaded an automata:", dialog.get_filename())
         # TODO: load and create editor tab with a
         # a.load(dialog.get_filename())
     else:
         print("You CANCELED")
     dialog.destroy()
Exemplo n.º 3
0
#!/usr/bin/python

import os
import sys
cur_path = os.path.realpath(__file__)
base_path = os.path.dirname(os.path.dirname(cur_path))
sys.path.insert(1, base_path)

import pluggins

from machine.automaton import Automaton
g = Automaton()

Q0 = g.state_add('Q0', marked=False, initial=True)
Q1 = g.state_add('Q1', marked=False, initial=False)
Q2 = g.state_add('Q2', marked=True, initial=False)
Q3 = g.state_add('Q3', marked=False, initial=False)
Q4 = g.state_add('Q4', marked=True, initial=False)

e0 = g.event_add('e0', True, True)
e1 = g.event_add('e1', True, True)

t1 = g.transition_add(Q0, Q1, e0)
t2 = g.transition_add(Q0, Q3, e1)
t3 = g.transition_add(Q1, Q1, e0)
t4 = g.transition_add(Q1, Q2, e1)
t5 = g.transition_add(Q3, Q3, e0)
t6 = g.transition_add(Q3, Q4, e1)
t7 = g.transition_add(Q4, Q2, e1)
t8 = g.transition_add(Q4, Q1, e0)
t9 = g.transition_add(Q2, Q4, e1)
Exemplo n.º 4
0
def xmlParser(path):
    arquivo = path

    doc = parse(arquivo)
    xml = doc.documentElement

    data = xml.getElementsByTagName('data')

    for info in data:
        states = info.getElementsByTagName('state')
        events = info.getElementsByTagName('event')
        transitions = info.getElementsByTagName('transition')

    G = Automaton()
    stateDict = dict()
    eventDict = dict()

    for state in states:
        name = state.getElementsByTagName('name')[0].childNodes[0].data
        id = state.getAttribute('id')
        isInitial = False
        try:
            properties = state.getElementsByTagName("properties")[0]
            if (properties.getElementsByTagName("initial")[0]):
                isInitial = True
        except:
            pass
        isMarked = False
        try:
            properties = state.getElementsByTagName("properties")[0]
            if (properties.getElementsByTagName("marked")[0]):
                isMarked = True
        except:
            pass
        s = G.state_add(name, marked=isMarked, initial=isInitial)
        stateDict[id] = s

    for event in events:
        name = event.getElementsByTagName('name')[0].childNodes[0].data
        id = event.getAttribute('id')
        isObservable = False
        try:
            properties = event.getElementsByTagName("properties")[0]
            if (properties.getElementsByTagName("observable")[0]):
                observable = True
        except:
            pass
        isControllable = False
        try:
            properties = event.getElementsByTagName("properties")[0]
            if (properties.getElementsByTagName("controllable")[0]):
                controllable = True
        except:
            pass
        ev = G.event_add(name,
                         observable=isObservable,
                         controllable=isControllable)
        eventDict[id] = ev

    for transition in transitions:
        tEvent = transition.getAttribute('event')
        tSource = transition.getAttribute('source')
        tTarget = transition.getAttribute('target')
        ev = eventDict[tEvent]
        ss = stateDict[tSource]
        st = stateDict[tTarget]
        G.transition_add(ss, st, ev)

    return G
Exemplo n.º 5
0
        self.current_state = row.transition.to_state
        self.list_box_clear()
        self.reset_list_box()

    def on_draw(self, wid, cr):
        self.ar.draw_partial(cr, self.automaton, self.current_state, forward_deep=self.forward_depth, backward_deep=self.backward_depth)

    def spin_event(self, event):
        self.forward_depth = self.forward_depth_spin.get_value_as_int()
        self.backward_depth = self.backward_depth_spin.get_value_as_int()
        self.darea.queue_draw()


# test
if __name__ == '__main__':
    g = Automaton()
    from test_automata import automata_01
    automata_01(g)

    simulator = Simulator(g)

    main_window = Gtk.Window()
    main_window.connect("delete-event", Gtk.main_quit)
    main_window.add(simulator.get_root_widget())
    
    main_window.show_all()
    Gtk.main()



Exemplo n.º 6
0
#!/usr/bin/python

import os
import sys
cur_path = os.path.realpath(__file__)
base_path = os.path.dirname(os.path.dirname(cur_path))
sys.path.insert(1, base_path)

import pluggins

from machine.automaton import Automaton

a = Automaton()

e1 = a.event_add('a', False, True)
e2 = a.event_add('b', True, True)
e3 = a.event_add('c', True, True)
s1 = a.state_add('q1', marked=True, initial=True)
s2 = a.state_add('q2', marked=True)

t1 = a.transition_add(s1, s2, e1)
t2 = a.transition_add(s2, s1, e2, probability=0.2)
a.transition_add(s1, s1, e2)
a.transition_add(s2, s2, e1)

t1.probability = 0.5

a.probabilitic_synchronization()

print(a)
print(t1.probabilistic_str())
Exemplo n.º 7
0
def create_automaton_01():
    a = Automaton()

    e1 = a.event_add('a', True, True)
    e2 = a.event_add('b', False, True)
    e3 = a.event_add('c', True, False)
    e4 = a.event_add('d', False, False)
    s1 = a.state_add('q1', x=100, y=150, marked=True, initial=True)
    s2 = a.state_add('q2', x=400, y=150, marked=True)
    s3 = a.state_add('q3', x=250, y=400, marked=True)
    s4 = a.state_add('q4', x=550, y=400, marked=True)
    s5 = a.state_add('q5', x=700, y=400, marked=True)

    a.transition_add(s1, s2, e1)
    a.transition_add(s2, s1, e2)
    a.transition_add(s1, s1, e2)
    a.transition_add(s2, s2, e1)
    a.transition_add(s1, s3, e3)
    a.transition_add(s2, s3, e3)
    a.transition_add(s3, s1, e1)
    a.transition_add(s3, s2, e2)
    t = a.transition_add(s3, s3, e3)
    # a.transition_remove(t)
    a.transition_add(s1, s2, e4)
    a.transition_add(s2, s1, e4)
    a.transition_add(s3, s4, e4)
    a.transition_add(s4, s5, e4)

    return a
Exemplo n.º 8
0
class ProbabilisticTransition:
    def __init__(self, *args, probability=1.0, **kwargs):
        self.probability = probability
        super().__init__(*args, **kwargs)

    @property
    def probability(self):
        return self._probability

    @probability.setter
    def probability(self, value):
        if isinstance(value, float) or isinstance(value, int):
            self._probability = value

    def probabilistic_str(self):
        return str(self) + ": ({probability})".format(
            probability=self.probability)


class ProbabilisticAutomaton:
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def probabilitic_synchronization(self, *args):
        pass


Transition.plugin_prepend(ProbabilisticTransition)
Automaton.plugin_prepend(ProbabilisticAutomaton)