Created
February 4, 2016 19:19
-
-
Save marctrem/9273b232ff720eb18aa9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
''' | |
The MIT License (MIT) | |
Copyright (c) 2015 Marc-André Tremblay | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. | |
''' | |
def print_soil(node_names, nodes): | |
fsmName = 'aDates' | |
initialState = node_names[0] | |
finalState = node_names[-1] | |
print('--\n-- Automate\n--\n') | |
print('!create %s:Automate' % fsmName) | |
print('!set %s.alphabet := Set{\'%s\'}' % (fsmName, "','".join(map(str, range(10))))) | |
print() | |
print('--\n-- États\n--\n') | |
for k in states: | |
print('!create %s:Etat' % k) | |
print('!insert (%s, %s) into DefiniSur' % (fsmName, k)) | |
print() | |
print('--\n-- Transitions\n--\n') | |
for k, v in states.items(): | |
if len(v) > 0: | |
print('-- Transition%s pour état %s' % ('' if len(v) == 1 else 's', k)) | |
for k2, v2 in v.items(): | |
transitionName = "trans_%s_%s" % (k, k2) | |
print('!create %s:Transition' % transitionName) | |
print('!insert (%s, %s) into Contient' % (fsmName, transitionName)) | |
print('!set %s.symboles := Set{\'%s\'}' % (transitionName, "','".join(v2))) | |
print('!insert (%s, %s) into EstSourceDe' % (k, transitionName)) | |
print('!insert (%s, %s) into EstCibleDe' % (k2, transitionName)) | |
print() | |
print() | |
print('--\n-- État initial et final\n--\n') | |
print('!insert (%s, %s) into DebuteDans' % (fsmName, initialState)) | |
print('!insert (%s, %s) into AccepteDans' % (fsmName, finalState)) | |
valid_dates = ['29022000', '31022011', '01011901', '31122099'] | |
invalid_dates = ['00042015', '31042015', '29022015', '01011900', '01012100'] | |
print() | |
for x in valid_dates: | |
print('? %s.accepte(\'%s\')' % (fsmName, x)) | |
for x in invalid_dates: | |
print('? %s.accepte(\'%s\') = false' % (fsmName, x)) | |
# Définir le graph | |
state_names = ["etatInitial", | |
"jourCaractere1_1", | |
"jourCaractere1_2", | |
"jourCaractere1_3", | |
"jourCaractere1_4", | |
"jourCaractere2_1", | |
"jourCaractere2_2", | |
"jourCaractere2_3", | |
"jourCaractere2_4", | |
"moisCaractere1_1", | |
"moisCaractere1_2", | |
"moisCaractere1_3", | |
"moisCaractere1_4", | |
"moisCaractere1_5", | |
"moisCaractere1_6", | |
"moisCaractere2_1", | |
"moisCaractere2_2", | |
"anneeCaractere1_1", | |
"anneeCaractere1_2", | |
"anneeCaractere1_3", | |
"anneeCaractere1_4", | |
"anneeCaractere2_1", | |
"anneeCaractere2_2", | |
"anneeCaractere2_3", | |
"anneeCaractere2_4", | |
"anneeCaractere3_1", | |
"anneeCaractere3_2", | |
"anneeCaractere3_3", | |
"anneeCaractere3_4", | |
"anneeCaractere3_5", | |
"etatFinal"] | |
# Nous associons chaque état sortant à chaque état ainsi que le symbole permettant de l'atteindre | |
# { etat_entrant : { etat_sortant: ['symbole', ...] | |
# etat_sortant2: ['autre_symbole', ...}} | |
states = { | |
state_names[0]: { | |
state_names[1]: ['2'], | |
state_names[2]: ['1'], | |
state_names[3]: ['0'], | |
state_names[4]: ['3'], | |
}, | |
state_names[1]: { | |
state_names[5]: ['0', '1', '2', '3', '4', '5', '6', '7', '8'], | |
state_names[6]: ['9'], | |
}, | |
state_names[2]: { | |
state_names[5]: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], | |
}, | |
state_names[3]: { | |
state_names[5]: ['1', '2', '3', '4', '5', '6', '7', '8', '9'], | |
}, | |
state_names[4]: { | |
state_names[7]: ['0'], | |
state_names[8]: ['1'], | |
}, | |
state_names[6]: { | |
state_names[11]: ['0'], | |
state_names[10]: ['1'], | |
}, | |
state_names[5]: { | |
state_names[9]: ['0'], | |
state_names[10]: ['1'], | |
}, | |
state_names[7]: { | |
state_names[10]: ['1'], | |
state_names[12]: ['0'], | |
}, | |
state_names[8]: { | |
state_names[14]: ['0'], | |
state_names[13]: ['1'], | |
}, | |
state_names[8]: { | |
state_names[14]: ['0'], | |
state_names[13]: ['1'], | |
}, | |
state_names[11]: { | |
state_names[16]: ['2'], | |
state_names[15]: ['1', '3', '4', '5', '6', '7', '8', '9'], | |
}, | |
state_names[9]: { | |
state_names[15]: ['1', '2', '3', '4', '5', '6', '7', '8', '9'], | |
}, | |
state_names[10]: { | |
state_names[15]: ['0', '1', '2'], | |
}, | |
state_names[12]: { | |
state_names[15]: ['1', '3', '4', '5', '6', '7', '8', '9'], | |
}, | |
state_names[14]: { | |
state_names[15]: ['1', '3', '5', '7', '8'], | |
}, | |
state_names[13]: { | |
state_names[15]: ['0', '2'], | |
}, | |
state_names[16]: { | |
state_names[19]: ['2'], | |
state_names[20]: ['1'], | |
}, | |
state_names[15]: { | |
state_names[17]: ['2'], | |
state_names[18]: ['1'], | |
}, | |
state_names[19]: { | |
state_names[23]: ['0'], | |
}, | |
state_names[20]: { | |
state_names[24]: ['9'], | |
}, | |
state_names[17]: { | |
state_names[21]: ['0'], | |
}, | |
state_names[18]: { | |
state_names[22]: ['9'], | |
}, | |
state_names[23]: { | |
state_names[28]: ['1', '3', '5', '7', '9'], | |
state_names[27]: ['0', '2', '4', '6', '8'], | |
}, | |
state_names[24]: { | |
state_names[28]: ['1', '3', '5', '7', '9'], | |
state_names[27]: ['2', '4', '6', '8'], | |
state_names[29]: ['0'], | |
}, | |
state_names[21]: { | |
state_names[25]: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], | |
}, | |
state_names[22]: { | |
state_names[25]: ['1', '2', '3', '4', '5', '6', '7', '8', '9'], | |
state_names[26]: ['0'], | |
}, | |
state_names[28]: { | |
state_names[30]: ['2', '6'], | |
}, | |
state_names[27]: { | |
state_names[30]: ['0', '4', '8'], | |
}, | |
state_names[29]: { | |
state_names[30]: ['4', '8'], | |
}, | |
state_names[25]: { | |
state_names[30]: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'], | |
}, | |
state_names[26]: { | |
state_names[30]: ['1', '2', '3', '4', '5', '6', '7', '8', '9'], | |
}, | |
state_names[30]: {} | |
} | |
if __name__ == '__main__': | |
print_soil(state_names, states) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment