Commit 0b3097fb authored by Guillaume Sabbagh's avatar Guillaume Sabbagh
Browse files

Rafistolage de Foncteur aléatoire

parent 1836adee
......@@ -364,49 +364,75 @@ class FoncteurAleatoire(Foncteur):
if categorie_cible == None:
categorie_cible = GrapheCompositionAleatoire()
categorie_indexante.transformer_graphviz()
categorie_cible.transformer_graphviz()
app_obj = dict()
app_morph = dict()
fleches_a_mapper = set(categorie_indexante[categorie_indexante.objets,categorie_indexante.objets])
while len(fleches_a_mapper) > 0:
def tentative_de_mapper(app_obj,app_morph,fleches_a_mapper,categorie_indexante,categorie_cible) -> Union[Tuple[dict,dict,set],None]:
app_obj = copy.copy(app_obj)
app_morph = copy.copy(app_morph)
fleches_a_mapper = copy.copy(fleches_a_mapper)
fleche = fleches_a_mapper.pop()
if not fleche.is_identite:
if fleche.source != fleche.cible:
sources_image_possibles = categorie_cible.objets
cibles_image_possibles = categorie_cible.objets
if fleche.source in app_obj:
sources_image_possibles = {app_obj[fleche.source]}
if fleche.cible in app_obj:
cibles_image_possibles = {app_obj[fleche.cible]}
image = random.choice(list(categorie_cible(sources_image_possibles,cibles_image_possibles)))
if len([f for f in categorie_cible(sources_image_possibles,cibles_image_possibles) if f.source != f.cible or f.is_identite]) == 0:
return None
image = random.choice([f for f in categorie_cible(sources_image_possibles,cibles_image_possibles) if f.source != f.cible or f.is_identite])
app_morph[fleche] = image
app_obj[fleche.source] = image.source
app_obj[fleche.cible] = image.cible
else:
image = random.choice([categorie_cible.identite(obj) for obj in categorie_cible.objets])
#on essaie de map un cycle
sources_cibles_image_possibles = {app_obj[fleche.source]} if fleche.source in app_obj else categorie_cible.objets
image = random.choice([categorie_cible.identite(o) for o in sources_cibles_image_possibles])#random.choice([f for o in sources_cibles_image_possibles for l in categorie_cible({o},{o}) for f in l])
app_morph[fleche] = image
app_obj[fleche.source] = image.source
while True:
for fleche in fleches_a_mapper:
declencher = False
sources_image_possibles = categorie_cible.objets
cibles_image_possibles = categorie_cible.objets
if fleche.cible in app_obj:
cibles_image_possibles = app_obj[fleche.cible]
declencher = True
if fleche.source in app_obj:
sources_image_possibles = app_obj[fleche.source]
declencer = True
if declencher:
fleches_a_mapper -= {fleche}
# image = random.choice([f for f in fleches_cibles if f.cible in ])
if fleche.source != fleche.cible:
declencher = False
sources_image_possibles = categorie_cible.objets
cibles_image_possibles = categorie_cible.objets
if fleche.cible in app_obj:
cibles_image_possibles = {app_obj[fleche.cible]}
declencher = True
if fleche.source in app_obj:
sources_image_possibles = {app_obj[fleche.source]}
declencer = True
if declencher:
fleches_a_mapper -= {fleche}
if len([f for f in categorie_cible(sources_image_possibles,cibles_image_possibles) if f.source != f.cible or f.is_identite]) == 0:
return None
image = random.choice([f for f in categorie_cible(sources_image_possibles,cibles_image_possibles) if f.source != f.cible or f.is_identite])
app_morph[fleche] = image
app_obj[fleche.source] = image.source
app_obj[fleche.cible] = image.cible
break
elif fleche.source in app_obj:
#on essaie de map un cycle
image = categorie_cible.identite(app_obj[fleche.source])#random.choice(list(categorie_cible({app_obj[fleche.source]},{app_obj[fleche.source]})))
app_morph[fleche] = image
app_obj[fleche.source] = image.source
else:
break
return app_obj,app_morph,fleches_a_mapper
app_obj = {m.source:app_morph[m].source for m in app_morph if m.is_identite}
fleches_a_mapper = {f for f in categorie_indexante[categorie_indexante.objets,categorie_indexante.objets] if not f.is_identite}
while len(fleches_a_mapper) > 0:
res = tentative_de_mapper(app_obj,app_morph,fleches_a_mapper,categorie_indexante,categorie_cible)
if res != None:
app_obj,app_morph,fleches_a_mapper = res
for obj in categorie_indexante.objets:
if obj not in app_obj:
app_obj[obj] = random.choice(list(categorie_cible.objets))
app_morph[categorie_indexante.identite(obj)] = categorie_cible.identite(app_obj[obj])
Foncteur.__init__(self,categorie_indexante,categorie_cible,app_obj,app_morph)
def test_FoncteurAleatoire():
......@@ -419,6 +445,6 @@ def test_FoncteurAleatoire():
if __name__ == '__main__':
test_GrapheCompositionAleatoire()
# test_GrapheCompositionAleatoire()
# test_MonoideGC()
# test_FoncteurAleatoire()
\ No newline at end of file
test_FoncteurAleatoire()
\ No newline at end of file
TOUJOURS_VERIFIER_COHERENCE = 0 # booléen qui indique si on doit toujours vérifier la cohérence des structures qu'on construit
TOUJOURS_VERIFIER_COHERENCE = 1 # booléen qui indique si on doit toujours vérifier la cohérence des structures qu'on construit
TOUJOURS_VERIFIER_COHERENCE_COMPOSEE = 1
DEBUG_LOI_DE_COMPOSITION = False
GRAPHVIZ_ENABLED = True # booléen qui indique s'il faut charger la bibliothèque graphviz
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment