Complexification.py 2.83 KB
Newer Older
 Guillaume Sabbagh committed Jun 22, 2021 1 ``````from Categorie import Categorie `````` Guillaume Sabbagh committed Jun 22, 2021 2 ``````from Foncteur import Foncteur `````` Guillaume Sabbagh committed Jun 22, 2021 3 ``````from Morphisme import Morphisme `````` 4 ``````from GrapheDeComposition import GC,MGC `````` Guillaume Sabbagh committed Jun 22, 2021 5 6 ``````from Diagramme import Diagramme, DiagrammeIdentite, Fleche from ChampActif import ChampActif,Cocone `````` 7 ``````from copy import copy `````` Guillaume Sabbagh committed Jun 22, 2021 8 ``````from TransformationNaturelle import TransfoNat `````` Guillaume Sabbagh committed Jun 22, 2021 9 ``````from typing import * `````` 10 11 12 13 14 `````` cat = GC(set("ABC")) f,g = [MGC('A','B','f'),MGC('A','C','g')] cat |= {f,g} `````` Guillaume Sabbagh committed Jun 22, 2021 15 16 ``````/!\ marche pas si les flèches ajoutées ajoute de nouveaux cocônes. Faire une boucle while. /!\ `````` 17 `````` `````` Guillaume Sabbagh committed Jun 22, 2021 18 ``````def modification(gc: GC, option_ajout:Tuple[Sequence[Any],Sequence[Morphisme]] = (set(),set()), option_elimination:Sequence[Diagramme] = set(), option_complex_agissante:Sequence[Diagramme] = set()) -> Tuple[GC,Foncteur]: `````` Guillaume Sabbagh committed Jun 22, 2021 19 `````` nouveau_gc = copy(gc) `````` Guillaume Sabbagh committed Jun 22, 2021 20 `````` fonct = Foncteur(gc,nouveau_gc,{o:o for o in gc.objets},{m:m for m in gc[gc.objets,gc.objets]}) `````` Guillaume Sabbagh committed Jun 22, 2021 21 22 23 24 `````` nouveaux_obj, nouvelles_fleches = option_ajout nouveau_gc |= set(nouveaux_obj) nouveau_gc |= set(nouvelles_fleches) nouveau_gc -= set(option_elimination) `````` Guillaume Sabbagh committed Jun 22, 2021 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 `````` for diag in option_complex_agissante: c_a = ChampActif(fonct@diag) c_a.transformer_graphviz() colimites = c_a.objets_colimites() if len(colimites) == 0: # S'il n'y avait pas de colimite, on la créé nouvel_objet = str(diag) while nouvel_objet in nouveau_gc.objets: nouvel_objet += "'" nouveau_gc |= {nouvel_objet} dico_index_jambe = dict() # {i:jambe} for i in diag.source.objets: jambe = MGC(diag(i),nouvel_objet) dico_index_jambe[i] = jambe nouveau_gc |= {jambe} for fleche_i in diag.source[diag.source.objets, diag.source.objets]: if dico_index_jambe[fleche_i.source] != dico_index_jambe[fleche_i.cible]@diag(fleche_i): MGC.identifier_morphismes(dico_index_jambe[fleche_i.cible]@diag(fleche_i),dico_index_jambe[fleche_i.source]) #ajouter les flèches vers les autres cocônes for cocone in c_a.objets: cocone = Cocone(cocone) nouvelle_fleche = MGC(nouvel_objet,cocone.nadir) for fleche_i in diag.source[diag.source.objets, diag.source.objets]: if dico_index_jambe[fleche_i.source] != cocone(fleche_i.cible)@diag(fleche_i): MGC.identifier_morphismes(cocone(fleche_i.cible)@diag(fleche_i),dico_index_jambe[fleche_i.source]) `````` Guillaume Sabbagh committed Jun 22, 2021 51 `````` `````` Guillaume Sabbagh committed Jun 22, 2021 52 `````` return nouveau_gc,fonct `````` Guillaume Sabbagh committed Jun 22, 2021 53 54 `````` cat.transformer_graphviz() `````` Guillaume Sabbagh committed Jun 22, 2021 55 56 57 ``````h = MGC('S','T','h') diag = DiagrammeIdentite(cat) cat2,fonct = modification(cat,({'S','T'},{h}),{},{diag}) `````` Guillaume Sabbagh committed Jun 22, 2021 58 ``````cat2.transformer_graphviz() `````` Guillaume Sabbagh committed Jun 22, 2021 59 60 61 62 63 64 65 66 67 ``````fonct.transformer_graphviz() diag = fonct@diag diag.transformer_graphviz() ChampActif(diag).transformer_graphviz() for cocone in ChampActif(diag).objets: Cocone(cocone).transformer_graphviz() ``````