surete append
This commit is contained in:
parent
eefd9bdd48
commit
8c024db0f7
2 changed files with 127 additions and 0 deletions
69
surete/01_model_ascenseur.py
Normal file
69
surete/01_model_ascenseur.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
from enum import Enum
|
||||
from dataclasses import dataclass
|
||||
|
||||
class Etage(Enum):
|
||||
A = 0
|
||||
B = 1
|
||||
C = 2
|
||||
|
||||
@dataclass
|
||||
class Etat:
|
||||
ascenseur: Etage = Etage.A
|
||||
bouton_A: bool = False
|
||||
bouton_B: bool = False
|
||||
bouton_C: bool = False
|
||||
|
||||
def clone(self): return Etat(ascenseur=self.ascenseur, bouton_A=self.bouton_A, bouton_B=self.bouton_B, bouton_C=self.bouton_C)
|
||||
|
||||
def transition(etat: Etat, bouton_A: bool, bouton_B: bool, bouton_C: bool):
|
||||
if bouton_A: etat.bouton_A = True
|
||||
if bouton_B: etat.bouton_B = True
|
||||
if bouton_C: etat.bouton_C = True
|
||||
|
||||
if etat.bouton_A:
|
||||
ascenseur = Etage.A
|
||||
etat.bouton_A = False
|
||||
|
||||
elif etat.bouton_B:
|
||||
ascenseur = Etage.B
|
||||
etat.bouton_B = False
|
||||
|
||||
elif etat.bouton_C:
|
||||
ascenseur = Etage.C
|
||||
etat.bouton_C = False
|
||||
|
||||
return etat
|
||||
|
||||
def tout_bool():
|
||||
yield False
|
||||
yield True
|
||||
|
||||
def tout_etage():
|
||||
yield Etage.A
|
||||
yield Etage.B
|
||||
yield Etage.C
|
||||
|
||||
def tout_etat():
|
||||
for etage in tout_etage():
|
||||
for bouton_A in tout_bool():
|
||||
for bouton_B in tout_bool():
|
||||
for bouton_C in tout_bool():
|
||||
yield Etat(ascenseur=etage, bouton_A=bouton_A, bouton_B=bouton_B, bouton_C=bouton_C)
|
||||
|
||||
def tout_entree():
|
||||
for bouton_A in tout_bool():
|
||||
for bouton_B in tout_bool():
|
||||
for bouton_C in tout_bool():
|
||||
yield (bouton_A, bouton_B, bouton_C)
|
||||
|
||||
set_ = set()
|
||||
for etat in tout_etat():
|
||||
transition_map = {}
|
||||
for entree in tout_entree():
|
||||
res = transition(etat.clone(), *entree)
|
||||
if str(res) not in transition_map: transition_map[str(res)] = []
|
||||
set_.add(str(etat) + " + " + str(entree) + "\n=> " + str(transition(etat, *entree)))
|
||||
|
||||
|
||||
for line in set_:
|
||||
print(line + "\n")
|
Loading…
Add table
Add a link
Reference in a new issue