Esempio n. 1
0
def WarshallRoutage(g):
	plusgr = Graphe(g.sommets)
	plusgr.arcs = init(g.arcs)
	for i in range(1,len(plusgr.sommets)+1):
		for z in range(1,len(plusgr.sommets)+1):
			if (z,i) in plusgr.arcs:
				for y in range(1,len(plusgr.sommets)+1):
					if (z,y) not in plusgr.arcs and (i,y) in plusgr.arcs:
						plusgr.arcs[(z,y)]=plusgr.arcs[(z,i)]
	plusgr.AfficheMatrice()
Esempio n. 2
0
def Warshall(g):
	plusg = Graphe(g.sommets)
	plusg.arcs = dict(g.arcs)
	for i in range(1,len(plusg.sommets)+1):
		for z in range(1,len(plusg.sommets)+1):
			if (z,i) in plusg.arcs:
				for y in range(1,len(plusg.sommets)+1):
					if (i,y) in plusg.arcs:
						if not (z,y) in plusg.arcs:
							plusg.Ajouter_arc(z,y)
	plusg.AfficheMatrice()
Esempio n. 3
0
 def jouer(self, couleur):
     if self.graphe == None:
         Graphe(couleur, B_NO).ajoutSommet(self)
     elif self.graphe.couleur == LIBRE:
         self.graphe.couleur = couleur
         self.couleur = couleur
     for i in range(len(self.listeVoisin)):
         if self.listeVoisin[i].couleur == couleur and self.listeVoisin[
                 i].graphe != self.graphe:
             self.listeVoisin[i].graphe.fusion(self.graphe)
Esempio n. 4
0
def planning_cours(canvas, matiere, notion):
    global graphe
    global niveau

    print("niveau 24453", niveau)

    graphe = Graphe()
    graphe.cal_parcours(niveau)
    graphe.defintion_exercice(niveau, "normal", "")

    for k in range(len(L_dipso)):
        canvas.itemconfig(L_dipso[k] + 1, text=graphe.parcour_avec_exo[k].nom)
        canvas.tag_bind(L_dipso[k], '<ButtonPress-1>', onObjectClick2)
Esempio n. 5
0
def dijkstra(graphe, depart, arrive):
    file = fp.file_prioritaire(chemin.compare_chemin, etype=chemin)
    c = chemin()
    c.ajouter_point(depart, 0)
    file.enfile(c)
    print(file)
    i = depart
    c = file.defile()
    mat = graphe[2]
    n = gr.ordre(graphe)
    while i != arrive:
        for j in range(n):
            if mat[i][j] != 0:
                nc = c.copy()
                if not nc.contient(j):
                    nc.ajouter_point(j, mat[i][j])
                    file.enfile(nc)
        c = file.defile()
        i = c.dernier_point()
    return c
Esempio n. 6
0
    def __init__(self):

        self.taille = None
        self.joueurs = {
        }  #Stocke la configuration (IA ou joueur) de chacun des joueurs

        self.menu()

        self.coups = 0

        #matrice de sommets utilisée dans les graphes et taille n*n
        self.matriceSommets = []
        for i in range(self.taille):
            self.matriceSommets.append([])
        #on ajoute nos sommets
        for i in range(self.taille):
            for j in range(self.taille):
                self.matriceSommets[i].append(Sommet(i, j))

        #ici on ajoute pour tous les sommets qui touchent un bord dans un graphe avec son bord
        Graphe(LIBRE, B_HAUT_BLEU | B_GAUCHE_ROUGE).ajoutSommet(
            self.matriceSommets[0][0])
        Graphe(LIBRE, B_HAUT_BLEU | B_DROIT_ROUGE).ajoutSommet(
            self.matriceSommets[0][self.taille - 1])
        Graphe(LIBRE, B_BAS_BLEU | B_GAUCHE_ROUGE).ajoutSommet(
            self.matriceSommets[self.taille - 1][0])
        Graphe(LIBRE, B_BAS_BLEU | B_DROIT_ROUGE).ajoutSommet(
            self.matriceSommets[self.taille - 1][self.taille - 1])

        for i in range(self.taille):
            if i == 0:
                for j in range(1, self.taille - 1):
                    Graphe(LIBRE,
                           B_HAUT_BLEU).ajoutSommet(self.matriceSommets[i][j])
            elif i == self.taille - 1:
                for j in range(1, self.taille - 1):
                    Graphe(LIBRE,
                           B_BAS_BLEU).ajoutSommet(self.matriceSommets[i][j])
            else:
                Graphe(LIBRE,
                       B_GAUCHE_ROUGE).ajoutSommet(self.matriceSommets[i][0])
                Graphe(LIBRE, B_DROIT_ROUGE).ajoutSommet(
                    self.matriceSommets[i][self.taille - 1])

        #on va ajouter tous les voisins de tous les sommets
        for x in range(self.taille):
            for y in range(self.taille):
                if x != 0:
                    self.matriceSommets[x][y].ajoutVoisin(
                        self.matriceSommets[x - 1][y])
                if y != 0:
                    self.matriceSommets[x][y].ajoutVoisin(
                        self.matriceSommets[x][y - 1])
                    if x != self.taille - 1:
                        self.matriceSommets[x][y].ajoutVoisin(
                            self.matriceSommets[x + 1][y - 1])
                if x != self.taille - 1:
                    self.matriceSommets[x][y].ajoutVoisin(
                        self.matriceSommets[x + 1][y])
                if y != self.taille - 1:
                    if x != 0:
                        self.matriceSommets[x][y].ajoutVoisin(
                            self.matriceSommets[x - 1][y + 1])
                    self.matriceSommets[x][y].ajoutVoisin(
                        self.matriceSommets[x][y + 1])

        self.grille = Grille(Point(10, 30), self.taille, 40,
                             self.matriceSommets)

        self.tourActuel = ROUGE

        self.plateaux = {}
        if (self.taille <= 4):
            self.genererPlateaux()

        self.canvas = 0
        self.fenetre = 0
        self.commencer()
Esempio n. 7
0
f = open("Compare5000 p variable.txt", 'w')
f. write("Ordre,Glouton Matrice\n")

p = np.linspace(0.0001, 0.01, 5)
n = 5
for v in range(1, 1202, 100) :
    f.write(str(v) + ",")
    print(v)

    graphes = []
    for i in range(n) :
        matAdj = liens(p[i], v)
        points = np.arange(1, v+1)      #les points sont étiquetés de 1 à n
        graphe = [points.tolist(), [], matAdj]
        graphe = G.listeArretes(graphe)
        graphes.append(graphe)

    t1 = time.time()
    for i in range(n) :
        G.estConnexeGlouton(graphes[i])
    t2 = time.time()

    t3= time.time()
    for i in range(n) :
        G.estConnexe(graphes[i])
    t4 = time.time()

    f.write(str(20*(t2-t1)) + ' ' + str(20*(t4-t3)) + '\n')

f.close()
Esempio n. 8
0
        12, 31, 18
):  #Ordre du graphe --> Complexité quadratique (à partir de 10 ça devient long, au delà de 30 c'est très long et plus grand que 50 c'est turbo long)
    c = []  #Tableau utilisé pour afficher le graphique
    f = open("Dot - ordre " + str(n) + ".txt",
             'w')  #fichier pour stocker les résultats afin de les réutiliser
    f.write("Ordre " + str(n) + "\n")
    for i in range(k):
        print(str(i / k * 100) + "%")
        s = 0
        for j in range(
                t
        ):  #on crée t matices avec une probabilité de liens i afin de savoir la proportion de matrices connexes en foncttion de la probabilité de liens entre les noeuds
            matAdj = liens(p[i], n)
            points = np.arange(1, n + 1)  #les points sont étiquetés de 1 à n
            graphe = [points.tolist(), [], matAdj]
            graphe[1] = gr.listeArretes(graphe)
            if gr.estConnexeGlouton(graphe):
                s += 1
        c.append(s / t)
        f.write(str(p[i]) + " " + str(s / t) + "\n")

    c = np.array(c)
    plt.plot(p, c, label="Ordre " + str(n))
    plt.legend(loc="upper right")
    print("Ordre : " + str(n) + " : terminé\n")

    f.close()

plt.xlabel("Probabilité que deux noeuds soient liés")
plt.ylabel("Probabilité que le graphe soit connexe")
plt.title(