I want to create an automaton supervisor. I was able to create the class of automata. However, when I am facing the case of fusion with automata, I do not know how to deal with it. For example, with the following automata:
ThedataI'musingis
donnees=("nomprob", # nome do problema
[("e1",True),("e2",True),("e3",True),("s1",False),("s2",False),("s3",False)], # eventos
("plant",[("S4",True,False),("S1",False,False),("S2",False,True)], # primeiros estados de autômatos
[("S4","S1",["e1","e2","e3"]),("S1","S2",["e1","e3"]),("S1","S4",["s1","s2","s3"]),("S2","S1",["s1","s2","s3"])]), # primeiras transições de autômatos
("spec",[("S0",True,False),("S1",False,False),("S2",False,True)], #segundos estados de autômatos
[("S0","S1",["e1","e2","e3"]),("S1","S2",["e1","e2","e3"]),("S1","S0",["s1","s2","s3"]),("S2","S1",["s1","s2","s3"])] # segundas transições de autômatos
)
)
And the method I'm modifying to create a checked automaton is:
def creerplantspec(self,donnees):
"""método para criar os autômatos sincronizados.
Args:
donnees (:obj:'list' of :obj:'str'): nome, eventos, transição e estados dos autômatos de sincronização.
Attributes :
plantspec (Automate): autômatos de especificações que queremos criar com um nome, eventos e estados.
"""
nom,donneesEtats,donneesTransitions=donnees
self.plantspec=Automate(nom,self)
for elt in donneesEtats :
nom,initial,final=elt
(self.spec+self.plant).ajouterEtat(nom,initial,final)
for elt in donneesTransitions:
nomDepart,nomArrivee,listeNomsEvt=elt
self.spec.ajouterTransition(nomDepart,nomArrivee,listeNomsEvt)
The full code can be found in github . I already thought about this algorithm:
for (Etat_s, Etat_p) in plant, spec:
we create a new state Etat_{s.name,p.name}
for (transition_s, transition_p) in Etat_s, Etat_p:
new state with the concatenation of the names of the ends of the transitions
if transitions' events are the same:
we add a transition from Etat_{s.name,p.name} to this last state
else if transition's are different
here I don't know
Minimum code constructing the automata:
If you need it, here is the code. He builds the automata, but does not merge them yet (and sorry for the French:)):
class Etat:
def __init__(self,nomDonne,initial=False,final=False):
self.nom=nomDonne
self.initial=initial
self.final=final
self.transitionsSortantes=[]
def __str__(self):
return'{}'.format(self.nom)
def __repr__(self) :
return 'Etat : {}'.format(self)
def ajouterTransitionSortante(self,transition):
self.transitionsSortantes.append(transition)
class Evenement:
def __init__(self,nomDonne,controle=False):
self.nom=nomDonne
self.controle=controle
def __str__(self):
return'{}'.format(self.nom)
def __repr__(self) :
return 'Evenement : {}'.format(self)
class Transition:
def __init__(self,depart,arrivee):
self.depart=depart
self.arrivee=arrivee
self.evenements=[]
self.depart.ajouterTransitionSortante(self)
def __str__(self):
return'({},{},{})'.format(self.depart,self.arrivee,self.evenements)
def __repr__(self) :
return 'Transition : {}'.format(self)
def enregistrerEvt(self,evt):
self.evenements.append(evt)
class Automate:
def __init__(self,nomDonne,probleme):
self.nom=nomDonne
self.probleme=probleme
self.etats=[]
self.etatNomme={} # cle : nom, valeur : obj
self.transitions=[]
def __str__(self):
return'{}'.format(self.nom)
def __repr__(self) :
return 'Automate : {}'.format(self)
def ajouterEtat(self,nom,initial,final):
objEtat=Etat(nom,initial,final)
self.etats.append(objEtat)
self.etatNomme[nom]=objEtat
def ajouterTransition(self,nomEtatDepart,nomEtatArrivee,listeNomsEvts):
objEtatDepart=self.etatNomme[nomEtatDepart]
objEtatArrivee=self.etatNomme[nomEtatArrivee]
objtrans=Transition(objEtatDepart,objEtatArrivee)
self.transitions.append(objtrans)
for nom in listeNomsEvts :
objEvt=self.probleme.evtNomme[nom]
objtrans.enregistrerEvt(objEvt)
def sAfficher(self):
print(self)
for etat in self.etats:
print (etat)
for etat in self.etats:
print (etat,etat.transitionsSortantes)
class Probleme:
def __init__(self,nomprob):
self.nom=nomprob
self.evts=[]
self.plant=None
self.spec=None
self.superviseur=None
self.plantspec=None
self.evtNomme={} # cle : nom, valeur : obj
def __str__(self):
return'{}'.format(self.nom)
def __repr__(self) :
return 'Probleme : {}'.format(self)
def ajouterEvenement(self,nom,controle):
objEvt=Evenement(nom,controle)
self.evts.append(objEvt)
self.evtNomme[nom]=objEvt
def creerPlant(self,donnees):
nom,donneesEtats,donneesTransitions=donnees
self.plant=Automate(nom,self)
for elt in donneesEtats :
nom,initial,final=elt
self.plant.ajouterEtat(nom,initial,final)
for elt in donneesTransitions:
nomDepart,nomArrivee,listeNomsEvt=elt
self.plant.ajouterTransition(nomDepart,nomArrivee,listeNomsEvt)
def creerspec(self,donnees):
nom,donneesEtats,donneesTransitions=donnees
self.spec=Automate(nom,self)
for elt in donneesEtats :
nom,initial,final=elt
self.spec.ajouterEtat(nom,initial,final)
for elt in donneesTransitions:
nomDepart,nomArrivee,listeNomsEvt=elt
self.spec.ajouterTransition(nomDepart,nomArrivee,listeNomsEvt)
def creerplantspec(self,donnees):
nom,donneesEtats,donneesTransitions=donnees
self.plantspec=Automate(nom,self)
for elt in donneesEtats :
nom,initial,final=elt
(self.spec+self.plant).ajouterEtat(nom,initial,final)
for elt in donneesTransitions:
nomDepart,nomArrivee,listeNomsEvt=elt
self.spec.ajouterTransition(nomDepart,nomArrivee,listeNomsEvt)
donnees=("nomprob",[("e1",True),("e2",True),("e3",True),("s1",False),("s2",False),("s3",False)],
("plant",[("S4",True,False),("S1",False,False),("S2",False,True)],
[("S4","S1",["e1","e2","e3"]),("S1","S2",["e1","e3"]),("S1","S4",["s1","s2","s3"]),("S2","S1",["s1","s2","s3"])]),
("spec",[("S0",True,False),("S1",False,False),("S2",False,True)],[("S0","S1",["e1","e2","e3"]),("S1","S2",["e1","e2","e3"]),("S1","S0",["s1","s2","s3"]),("S2","S1",["s1","s2","s3"])]))
nom,donneesEvts,donneesPlant,donneesSpec=donnees
monProbleme=Probleme(nom)
for elt in donneesEvts:
nom,controle=elt
monProbleme.ajouterEvenement(nom,controle)
monProbleme.creerPlant(donneesPlant)
monProbleme.plant.sAfficher()
monProbleme.creerspec(donneesSpec)
monProbleme.spec.sAfficher()
I'm checking out the ideas of applying de-morgan on it Amit said here . But I never implemented that. Anyway, I'm open to any idea of merging.