Esempio n. 1
0
def sync_trans(aut1, aut2, syc_events):

    sync_events = helper.extract_elems_from_trans(aut1.trans, 'event').union(
        helper.extract_elems_from_trans(aut2.trans, 'event'))
    sync_trans = set()
    for event in sync_events:
        if event not in aut1.events:
            for x in aut1.states:
                aut1.trans = aut1.trans | {auto.Transition(x, event, x)}
        if event not in aut2.events:
            for x in aut2.states:
                aut2.trans = aut2.trans | {auto.Transition(x, event, x)}
        for transition1 in auto.filter_trans_by_events(aut1.trans, {event}):
            for transition2 in auto.filter_trans_by_events(
                    aut2.trans, {event}):
                source = merge_label(
                    helper.extract_elems_from_trans({transition1},
                                                    'source').pop(),
                    helper.extract_elems_from_trans({tr2}, 'source').pop())
                target = merge_label(
                    helper.extract_elems_from_trans({transition1},
                                                    'target').pop(),
                    helper.extract_elems_from_trans({tr2}, 'target').pop())
                sync_trans.add(auto.Transition(source, event, target))

    return sync_trans
Esempio n. 2
0
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 20 11:05:39 2018

@author: Fredrik Möller
"""
import Automaton as auto

b1 = auto.Automaton(states={'a', 'b'},
                    init='a',
                    events={1},
                    trans={auto.Transition('a', 1, 'b')},
                    marked={'b'})
b2 = auto.Automaton(states={'c', 'd', 'e'},
                    init='c',
                    events={1, 2},
                    forbidden={},
                    trans={
                        auto.Transition('c', 1, 'd'),
                        auto.Transition('d', 2, 'e'),
                        auto.Transition('e', 1, 'c')
                    })

aut1 = b1
aut2 = b2
Esempio n. 3
0
def flip_trans(trans):
    """ Flips the direction of the transitions in the set"""
    return {auto.Transition(t.target, t.event, t.source) for t in trans}
def synch(aut1, aut2):
    """
    Returns the synchronous composition of two automata.
    
    :param aut1: Automaton
    :param aut2: Automaton
    """
    import helper as help
    import automaton as auto

    sync_events = help.extract_elems_from_trans(aut1.trans, 'event').union(
        help.extract_elems_from_trans(aut2.trans, 'event'))
    sync_trans = set()
    for event in sync_events:
        if event not in aut1.events:
            for y in aut1.states:
                aut1.trans = aut1.trans.union({auto.Transition(y, event, y)
                                               })  #for y in aut1.states

        if event not in aut2.events:
            for y in aut2.states:
                aut2.trans = aut2.trans.union({auto.Transition(y, event, y)
                                               })  #for y in aut1.states

    for event in sync_events:
        for transition1 in help.filter_trans_by_events(aut1.trans, {event}):
            for transition2 in help.filter_trans_by_events(
                    aut2.trans, {event}):
                source = help.merge_label(
                    help.extract_elems_from_trans({transition1},
                                                  'source').pop(),
                    help.extract_elems_from_trans({transition2},
                                                  'source').pop())
                target = help.merge_label(
                    help.extract_elems_from_trans({transition1},
                                                  'target').pop(),
                    help.extract_elems_from_trans({transition2},
                                                  'target').pop())
                sync_trans.add(auto.Transition(source, event, target))

    # initial states, as a "label" not set
    sync_init = help.merge_label(aut1.init, aut2.init)
    # states to be synchronized
    #sync_states=helper.cross_product(aut1.states,aut2.states)
    sync_states = help.cross_product(aut1.states, aut2.states)
    #sync_states=help.extract_elems_from_trans(sync_trans,'source').union(help.extract_elems_from_trans(sync_trans,'target'),{sync_init})
    # marked states, if no marked states in set --> all states are marked
    if len(aut1.marked) == 0:
        aut1.marked = aut1.states.copy()
    if len(aut2.marked) == 0:
        aut2.marked = aut2.states.copy()
    sync_marked = help.cross_product(aut1.marked, aut2.marked)
    sync_marked = sync_marked.intersection(sync_states)

    # forbidden states, forbidden states according to lecture notes
    sync_forbidden = help.cross_product(aut1.forbidden, aut2.states).union(
        help.cross_product(aut1.states, aut2.forbidden)) & sync_states

    reach_sync_states = reach(sync_events, sync_trans, {sync_init},
                              sync_forbidden)
    reach_sync_marked = sync_marked.intersection(reach_sync_states)
    reach_sync_states.update({sync_init})

    reach_trans = set()
    for element in sync_trans:
        if element.source.issubset(
                reach_sync_states) and element.target.issubset(
                    reach_sync_states):
            reach_trans.update({element})

    return auto.Automaton(states=reach_sync_states,
                          init=sync_init,
                          events=sync_events,
                          trans=reach_trans,
                          forbidden=sync_forbidden,
                          marked=reach_sync_marked)
    """
Esempio n. 5
0
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 13 15:20:37 2018

@author: Fredrik Möller
"""
#imports
import Automaton as auto

states = {'p11', 'p12'}
init = 'p11'
events = {'a', 'b'}
trans = {
    auto.Transition('p11', 'a', 'p12'),
    auto.Transition('p12', 'b', 'p11')
}
marked = {'p11', 'p12'}

start_states = states

p1 = auto.Automaton(states, init, events, trans, marked)

#coreachable_states = co_reach.coreach(events, trans,start_states, forbidden)
#print(coreachable_states)
Esempio n. 6
0
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 26 15:10:37 2018

@author: Fredrik Möller
"""

import synch1_1 as synch
import Automaton as auto

p1 = auto.Automaton(states={'p11', 'p12'},
                    init='p11',
                    events={'a', 'b'},
                    trans={
                        auto.Transition('p11', 'a', 'p12'),
                        auto.Transition('p12', 'b', 'p11')
                    },
                    marked={})

p2 = auto.Automaton(states={'p21', 'p22'},
                    init='p21',
                    events={'e', 'd', 'c'},
                    trans={
                        auto.Transition('p22', 'd', 'p21'),
                        auto.Transition('p22', 'e', 'p21'),
                        auto.Transition('p21', 'c', 'p22')
                    },
                    marked={})

sp1 = auto.Automaton(states={'sp11', 'sp12'},
                     init='sp11',