Merge
This commit is contained in:
parent
3767f69745
commit
f5987060a4
BIN
MPSI/obligatoire/TP_BDD/TP BDD.pdf
Normal file
BIN
MPSI/obligatoire/TP_BDD/TP BDD.pdf
Normal file
Binary file not shown.
22152
MPSI/obligatoire/TP_BDD/mondial-mysql.sql
Normal file
22152
MPSI/obligatoire/TP_BDD/mondial-mysql.sql
Normal file
File diff suppressed because it is too large
Load Diff
12
MPSI/obligatoire/TP_GoL/Pipfile
Normal file
12
MPSI/obligatoire/TP_GoL/Pipfile
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[[source]]
|
||||||
|
name = "pypi"
|
||||||
|
url = "https://pypi.org/simple"
|
||||||
|
verify_ssl = true
|
||||||
|
|
||||||
|
[dev-packages]
|
||||||
|
|
||||||
|
[packages]
|
||||||
|
pygame = "*"
|
||||||
|
|
||||||
|
[requires]
|
||||||
|
python_version = "3.7"
|
53
MPSI/obligatoire/TP_GoL/Pipfile.lock
generated
Normal file
53
MPSI/obligatoire/TP_GoL/Pipfile.lock
generated
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
{
|
||||||
|
"_meta": {
|
||||||
|
"hash": {
|
||||||
|
"sha256": "e172a3e30534a9a0b74742497b40f2ab196a0890d1cb082eb481fb89e384456e"
|
||||||
|
},
|
||||||
|
"pipfile-spec": 6,
|
||||||
|
"requires": {
|
||||||
|
"python_version": "3.7"
|
||||||
|
},
|
||||||
|
"sources": [
|
||||||
|
{
|
||||||
|
"name": "pypi",
|
||||||
|
"url": "https://pypi.org/simple",
|
||||||
|
"verify_ssl": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"default": {
|
||||||
|
"pygame": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:0480fe82cd41a43e3eea497fa2c059c72ac54cb5d003d5aa2ed06a04541c384e",
|
||||||
|
"sha256:136a3b5711d9ec369a0407e4e08ffced3ba61aa41059e9280ffffa79c8614f65",
|
||||||
|
"sha256:2622b9dd95f445c887a36a57eade42c672598589f69a8052ccdb8eeeffa4dbb1",
|
||||||
|
"sha256:301c6428c0880ecd4a9e3951b80e539c33863b6ff356a443db1758de4f297957",
|
||||||
|
"sha256:396320aa29a925feed0b64639f77ce1418722ea7f536b4e4936083dd8d4c4535",
|
||||||
|
"sha256:398c42b605ecc514e62f68f1944a2d21e247938309f598de6cb0ad3c207324a8",
|
||||||
|
"sha256:4aaff572a273a32e70ec3593d213e59ab11c183a9916616562247930f17a5447",
|
||||||
|
"sha256:4e1065577f1b29111113be5deb2ea88553551a5e1cf33e0c08fa32768f285809",
|
||||||
|
"sha256:5f052dc2975a399aa1830c1f04c5f72856aa416bf3cd4b31375a058015a5c620",
|
||||||
|
"sha256:68ea43e51150316b9fb08e251209d4e2b4e76a340b5b6fc8cdf1a898c78f7e5b",
|
||||||
|
"sha256:698433a9fcefca0527244dc44dff9503eb26157494730b1cc80e6e4dbb246e92",
|
||||||
|
"sha256:6f714986f7987f10cb94f1be0753318e341a7ea6b12d66f37a4d5d6dd4695023",
|
||||||
|
"sha256:73cd9df328c7e72638dbcc1d18e7155225faed880a53db6bad90d1d7c0a71dfd",
|
||||||
|
"sha256:7876d1f29f66d3d7cac46479503891ee1ef409b0fbce54b0d74f3a6b33a46dba",
|
||||||
|
"sha256:854e87b8b2b76e3ed11d64985fcfdd7af919659503de99fc2b0a717b314c3cf0",
|
||||||
|
"sha256:8da13704ad45b7d5de8a8cca135a7f44c7fc6aa9f691abe7b0392468a34a8013",
|
||||||
|
"sha256:9ce22fb72298ea33dbb3a1c6c60a4a4e19d9698df6f3f5782eba4dada7b7736d",
|
||||||
|
"sha256:a37b6c59e7b8feadc51db5197052b86ceb6443f9fb2a6f7d6527620e707c558c",
|
||||||
|
"sha256:a6e8d2f99dbe1dfe72d0c019693c14d93c410f702d0b04ec9a81b36dacd55a23",
|
||||||
|
"sha256:a9ac862dd7159861f2c6443b0029089e1c0c4ec762a8074022914ec52fe4dfac",
|
||||||
|
"sha256:ae1bc3e78ed28f20878e7ca2c98663a6634e9c00d7746d39413fc18e907dc162",
|
||||||
|
"sha256:be7e70f91bd4eb35ae081062f16bf434619b3292358d9b061f8159ddc570c7f0",
|
||||||
|
"sha256:c895cf9c1b6d1cbba8cb8cc3f5427febcf8aa41a9333697741abeea1c537a350",
|
||||||
|
"sha256:e3e7e4a09dfd8b03663222d6bcadec9fef021404f4d9eecf56825342e039dfc1",
|
||||||
|
"sha256:f1f5714d2c23f6a64ef2ac4fcd36a2dd2689da85978d951a99a6ae5dfdf9bdbc",
|
||||||
|
"sha256:fa788f775680fc5d268ab00a2da29c9a22830032cfab732730298a2952cd87f3"
|
||||||
|
],
|
||||||
|
"index": "pypi",
|
||||||
|
"version": "==1.9.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"develop": {}
|
||||||
|
}
|
26
MPSI/obligatoire/TP_GoL/README
Normal file
26
MPSI/obligatoire/TP_GoL/README
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
Le simulateur utilise pygame, pour l'installer :
|
||||||
|
pip install pygame
|
||||||
|
une fois fait, pour lancer le simulateur, executez le main.py en tant que script (Ca permet à Pyzo de lancer le script dans le bon dossier)
|
||||||
|
|
||||||
|
Comment l'utiliser :
|
||||||
|
|
||||||
|
Les touches :
|
||||||
|
PARTOUT :
|
||||||
|
ESPACE : Met en pause le jeu
|
||||||
|
C : Diminuer la fréquence de mise à jour des cellules
|
||||||
|
V : Augmenter la fréquence de mise à jour des cellules
|
||||||
|
Q : Quitter
|
||||||
|
Suppr : Effacer la grille
|
||||||
|
D : Activer le mode débogage (Affiche les compteurs des cellules à l'itération précédente)
|
||||||
|
M : Basculer en mode Clavier / Basculer en mode Souris
|
||||||
|
Mode Souris :
|
||||||
|
Clic gauche : Changer l'état de la cellule selectionnée (rester appuyé pour en changer plusieurs)
|
||||||
|
Clic droit / Clic molette (glisser) : Changer la zone visible de la grille
|
||||||
|
Molette vers le haut : Zoomer
|
||||||
|
Molette vers le bas : Dézoomer
|
||||||
|
Mode Clavier :
|
||||||
|
Touches directionnelles (Flèches) : Déplacer le pointeur (cadre jaune)
|
||||||
|
T : changer l'état de la cellule selectionnée
|
||||||
|
|
||||||
|
À propos :
|
||||||
|
La grille est infinie, et par défaut, le mode souris est activé. Le mode clavier est incomplet mais permet de faire des actions basique.
|
BIN
MPSI/obligatoire/TP_GoL/assets/alive_cell.png
Normal file
BIN
MPSI/obligatoire/TP_GoL/assets/alive_cell.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 756 B |
BIN
MPSI/obligatoire/TP_GoL/assets/alive_cell.xcf
Normal file
BIN
MPSI/obligatoire/TP_GoL/assets/alive_cell.xcf
Normal file
Binary file not shown.
BIN
MPSI/obligatoire/TP_GoL/assets/cell.xcf
Normal file
BIN
MPSI/obligatoire/TP_GoL/assets/cell.xcf
Normal file
Binary file not shown.
BIN
MPSI/obligatoire/TP_GoL/assets/dead_cell.png
Normal file
BIN
MPSI/obligatoire/TP_GoL/assets/dead_cell.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 753 B |
BIN
MPSI/obligatoire/TP_GoL/assets/dead_cell.xcf
Normal file
BIN
MPSI/obligatoire/TP_GoL/assets/dead_cell.xcf
Normal file
Binary file not shown.
BIN
MPSI/obligatoire/TP_GoL/assets/highlight.png
Normal file
BIN
MPSI/obligatoire/TP_GoL/assets/highlight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 831 B |
BIN
MPSI/obligatoire/TP_GoL/assets/highlight.xcf
Normal file
BIN
MPSI/obligatoire/TP_GoL/assets/highlight.xcf
Normal file
Binary file not shown.
274
MPSI/obligatoire/TP_GoL/main.py
Normal file
274
MPSI/obligatoire/TP_GoL/main.py
Normal file
@ -0,0 +1,274 @@
|
|||||||
|
import pygame
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
import random
|
||||||
|
"""
|
||||||
|
Game of Life Simulator
|
||||||
|
"""
|
||||||
|
|
||||||
|
#Partie Calculatoire
|
||||||
|
RULES = {"B":3, "O":3, "U":2}
|
||||||
|
NEIGHBOURS = [(i,j) for i in (-1,0,1) for j in (-1,0,1) if (i,j) != (0,0)]
|
||||||
|
|
||||||
|
def relative(offset, cell):
|
||||||
|
"""
|
||||||
|
Fonction permettant d'obtenir une coordonnée absolue à partir d'une origine(offset) et de coordonnées relative(cell).
|
||||||
|
"""
|
||||||
|
return tuple(cell[i] + offset[i] for i in range(len(cell)))
|
||||||
|
|
||||||
|
def difference(origin, cell):
|
||||||
|
"""
|
||||||
|
Fonction permettant d'obtenir les coordonnées de cell en fixant origin comme origine
|
||||||
|
"""
|
||||||
|
return tuple(cell[i] - origin[i] for i in range(len(cell)))
|
||||||
|
|
||||||
|
def scale(cell, factor):
|
||||||
|
return tuple(int(cell[i]*factor) for i in range(len(cell)))
|
||||||
|
class Grid:
|
||||||
|
"""
|
||||||
|
Classe gérant les calculs liés à l'évolution d'une grille infinie selon le Jeu de la vie
|
||||||
|
"""
|
||||||
|
def __init__(self):
|
||||||
|
self.alive_cells = set({(i, 0) for i in range(500)})
|
||||||
|
self.active_cells = dict()
|
||||||
|
self.old_cells = set()
|
||||||
|
|
||||||
|
def tick(self):
|
||||||
|
self.old_cells.clear()
|
||||||
|
self.old_cells.update(self.alive_cells)
|
||||||
|
self.active_cells.clear()
|
||||||
|
#On s'assure que les cellules vivantes soient considérés comme actives
|
||||||
|
for cell in self.alive_cells:
|
||||||
|
self.active_cells.update({cell:0})
|
||||||
|
#On met à jour les voisins des cellules vivantes, c'est à dire incrémenter leur compteur
|
||||||
|
for cell in self.alive_cells:
|
||||||
|
for neighbour in NEIGHBOURS:
|
||||||
|
self.incr_counter(relative(cell, neighbour))
|
||||||
|
#On applique les règles du jeu selon le compteur des cellules actives
|
||||||
|
for cell in self.active_cells:
|
||||||
|
if RULES["U"] <= self.active_cells[cell] <= RULES["O"]:
|
||||||
|
if self.active_cells[cell] == RULES["B"]:
|
||||||
|
self.alive_cells.add(cell)
|
||||||
|
else:
|
||||||
|
self.alive_cells.discard(cell)
|
||||||
|
|
||||||
|
|
||||||
|
def incr_counter(self, cell):
|
||||||
|
if cell in self.active_cells:
|
||||||
|
self.active_cells[cell] +=1
|
||||||
|
else:
|
||||||
|
self.active_cells.update({cell:1})
|
||||||
|
|
||||||
|
|
||||||
|
#Interface Graphique
|
||||||
|
|
||||||
|
pygame.init()
|
||||||
|
size = width, height = 1025,1025
|
||||||
|
screen = pygame.display.set_mode(size, flags=pygame.RESIZABLE)
|
||||||
|
DEBUG = False #Affichage de variables de débogage à l'écran
|
||||||
|
TICK_RATE = 10 #Fréquence de rafraîchissement du jeu
|
||||||
|
FRAME_RATE = 60 #Fréquence de rafraîchissement de l'interface
|
||||||
|
camera = [0, 0] #Permettant choisir quelle zone de la grille on visualise
|
||||||
|
true_camera = camera
|
||||||
|
MOUSE = True #Mode souris : On pointe avec les cellules avec la souris et pas les flèches directionnelles
|
||||||
|
grid = Grid() #On initialise une grille
|
||||||
|
#On charge les assets
|
||||||
|
source_assets = {
|
||||||
|
"alive_cell": pygame.image.load("assets/alive_cell.png"),
|
||||||
|
"dead_cell": pygame.image.load("assets/dead_cell.png"),
|
||||||
|
"highlight": pygame.image.load("assets/highlight.png")}
|
||||||
|
|
||||||
|
SCALE = .25 #Facteur de taille variable (zoom)
|
||||||
|
CELL_SIDE = int(source_assets["highlight"].get_rect().width * SCALE) #Mesure en pixel d'un côté d'une cellule
|
||||||
|
assets = {asset:pygame.transform.scale(source_assets[asset],(CELL_SIDE,CELL_SIDE)) for asset in source_assets}
|
||||||
|
font = pygame.font.SysFont(pygame.font.get_default_font(), CELL_SIDE)
|
||||||
|
class Unit(pygame.sprite.Sprite):
|
||||||
|
"""
|
||||||
|
Classe représentant une unité d'affichage (cellule)
|
||||||
|
Il est à noter que cette unité peut représenter différentes cellules en fonction de camera
|
||||||
|
"""
|
||||||
|
def __init__(self, offset):
|
||||||
|
super().__init__()
|
||||||
|
self.offset = offset
|
||||||
|
|
||||||
|
def draw(self, screen, camera, grid):
|
||||||
|
self.image = assets[("dead_cell","alive_cell")[relative(camera, self.offset) in grid.alive_cells]]
|
||||||
|
self.position = self.image.get_rect()
|
||||||
|
self.position.x = self.offset[0]*CELL_SIDE #On positionne la cellule sur l'écran
|
||||||
|
self.position.y = self.offset[1]*CELL_SIDE #On positionne la cellule sur l'écran
|
||||||
|
screen.blit(self.image, self.position) #On dessine la cellule
|
||||||
|
if DEBUG and relative(camera, self.offset) in grid.active_cells:
|
||||||
|
text = font.render(str(grid.active_cells[relative(camera, self.offset)]), False, (0,255,0))
|
||||||
|
posi = text.get_rect()
|
||||||
|
posi.center = self.position.center
|
||||||
|
screen.blit(text, posi)
|
||||||
|
|
||||||
|
class Pointer(pygame.sprite.Sprite):
|
||||||
|
"""
|
||||||
|
Classe représentant le pointeur de cellule sélectionnée (pour l'éditer)
|
||||||
|
"""
|
||||||
|
def __init__(self, pos):
|
||||||
|
super().__init__()
|
||||||
|
self.pos = pos
|
||||||
|
|
||||||
|
def draw(self, screen, camera, grid):
|
||||||
|
self.image = assets["highlight"]
|
||||||
|
self.position = self.image.get_rect()
|
||||||
|
self.position.x = self.pos[0]*CELL_SIDE #On positionne le pointeur sur l'écran
|
||||||
|
self.position.y = self.pos[1]*CELL_SIDE #On positionne le pointeur sur l'écran
|
||||||
|
screen.blit(self.image, self.position) #On dessine le pointeur
|
||||||
|
|
||||||
|
def draw_grid(screen, camera, grid, units):
|
||||||
|
for unit in units:
|
||||||
|
units[unit].draw(screen, camera, grid)
|
||||||
|
|
||||||
|
#Boucle principale
|
||||||
|
def get_units():
|
||||||
|
return {(i,j):Unit((i,j)) for i in range(width//(CELL_SIDE) +1) for j in range(height//(CELL_SIDE) +1)}
|
||||||
|
units = get_units() #Liste de cellules à afficher à l'écran
|
||||||
|
relatives = {unit:relative(camera, unit) for unit in units}
|
||||||
|
pointer = Pointer((0,0)) #Permettant de sélectionner une cellule précisément pour l'éditer
|
||||||
|
running = True
|
||||||
|
pause = True
|
||||||
|
last_tick = time.time()
|
||||||
|
last_frame = time.time()
|
||||||
|
KEYSDOWN = set()
|
||||||
|
MOUSEBUTTONSDOWN = set()
|
||||||
|
visited_cells = set()
|
||||||
|
drag_origin = (0,0) #Position du curseur à la préssion du bouton du milieu de la souris
|
||||||
|
last_pointer_move = time.time()
|
||||||
|
redraw = True
|
||||||
|
while running:
|
||||||
|
frame = (last_frame + 1/FRAME_RATE) - time.time() < 0
|
||||||
|
if frame:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.VIDEORESIZE:
|
||||||
|
size = width, height = event.size
|
||||||
|
screen =screen = pygame.display.set_mode(size,
|
||||||
|
flags=pygame.RESIZABLE)
|
||||||
|
units = get_units()
|
||||||
|
redraw = True
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
sys.exit()
|
||||||
|
if event.type == pygame.KEYDOWN:
|
||||||
|
KEYSDOWN.add(event.key)
|
||||||
|
if event.key in [275,276,273,274] and not MOUSE: #Touches directionnelles pour déplacer le pointeur
|
||||||
|
new_pos = list(pointer.pos)
|
||||||
|
exec("new_pos" + ("[0]+","[0]-","[1]-","[1]+")[[275,276,273,274].index(event.key)] + "=1")
|
||||||
|
if pointer.pos in units: units[pointer.pos].draw(screen, camera, grid)
|
||||||
|
pointer.pos = tuple(new_pos)
|
||||||
|
last_pointer_move = time.time()
|
||||||
|
if event.key == 116 and not MOUSE: #T: Changer l'état d'une cellule
|
||||||
|
if relative(camera, pointer.pos) in grid.alive_cells:
|
||||||
|
grid.alive_cells.discard(relative(camera, pointer.pos))
|
||||||
|
else:
|
||||||
|
grid.alive_cells.add(relative(camera, pointer.pos))
|
||||||
|
visited_cells.add(relative(camera, pointer.pos))
|
||||||
|
if event.type == pygame.KEYUP:
|
||||||
|
print(event.key)
|
||||||
|
if event.key in KEYSDOWN:
|
||||||
|
if event.key == 32: #ESPACE : pause
|
||||||
|
pause = not pause
|
||||||
|
if event.key in (109,59): #M : Mode souris
|
||||||
|
MOUSE = not MOUSE
|
||||||
|
if event.key == 100: #D : Mode de déboggage
|
||||||
|
DEBUG = not DEBUG
|
||||||
|
if event.key in (113,97): #Q : Quitter
|
||||||
|
sys.exit()
|
||||||
|
if event.key == 127: #Suppr : Effacer la grille
|
||||||
|
grid.alive_cells.clear()
|
||||||
|
redraw = True
|
||||||
|
if event.key == 99: #C: Diminuer le TICK_RATE
|
||||||
|
TICK_RATE = TICK_RATE/2
|
||||||
|
if event.key == 118: #V : Augmenter le TICK_RATE
|
||||||
|
TICK_RATE = TICK_RATE*2
|
||||||
|
if event.key == 116 and not MOUSE: #T: Changer l'état d'une cellule
|
||||||
|
visited_cells.clear()
|
||||||
|
if event.key == 114 : #R : Remplir aléatoirement l'écran
|
||||||
|
redraw = True
|
||||||
|
for unit in units:
|
||||||
|
if random.randint(0,3) == 0:
|
||||||
|
grid.alive_cells.add(relatives[unit])
|
||||||
|
else:
|
||||||
|
grid.alive_cells.discard(relatives[unit])
|
||||||
|
KEYSDOWN.discard(event.key)
|
||||||
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
|
if MOUSE:
|
||||||
|
if event.button in (2,3): #Bouton de la molette / Clic droit : Glisser
|
||||||
|
print(event.pos)
|
||||||
|
true_camera = camera
|
||||||
|
drag_origin = event.pos
|
||||||
|
if event.button == 1: #Clic gauche : Éditer la cellule selectionnée
|
||||||
|
if relative(camera, pointer.pos) in grid.alive_cells:
|
||||||
|
grid.alive_cells.discard(relative(camera, pointer.pos))
|
||||||
|
else:
|
||||||
|
grid.alive_cells.add(relative(camera, pointer.pos))
|
||||||
|
visited_cells.add(relative(camera, pointer.pos))
|
||||||
|
MOUSEBUTTONSDOWN.add(event.button)
|
||||||
|
if event.type == pygame.MOUSEBUTTONUP:
|
||||||
|
if event.button in (2,3):
|
||||||
|
camera = difference(scale(difference(drag_origin, event.pos), 1/CELL_SIDE), true_camera)
|
||||||
|
redraw = True
|
||||||
|
if event.button == 1:
|
||||||
|
visited_cells.clear()
|
||||||
|
if event.button == 4: #Molette vers le haut #Zoom
|
||||||
|
if CELL_SIDE*2 <= min(size):
|
||||||
|
SCALE *= 2 #Facteur de taille variable (zoom)
|
||||||
|
CELL_SIDE = int(source_assets["highlight"].get_rect().width * SCALE) #Mesure en pixel d'un côté d'une cellule
|
||||||
|
assets = {asset:pygame.transform.scale(source_assets[asset],(CELL_SIDE,CELL_SIDE)) for asset in source_assets}
|
||||||
|
units = get_units() #Liste de cellules à afficher à l'écran
|
||||||
|
font = pygame.font.SysFont(pygame.font.get_default_font(), CELL_SIDE)
|
||||||
|
redraw = True
|
||||||
|
if event.button == 5: #Molette vers le bas #"Dézoom"
|
||||||
|
if CELL_SIDE/2 >= 3:
|
||||||
|
SCALE *= 1/2 #Facteur de taille variable (zoom)
|
||||||
|
CELL_SIDE = int(source_assets["highlight"].get_rect().width * SCALE) #Mesure en pixel d'un côté d'une cellule
|
||||||
|
assets = {asset:pygame.transform.scale(source_assets[asset],(CELL_SIDE,CELL_SIDE)) for asset in source_assets}
|
||||||
|
units = get_units() #Liste de cellules à afficher à l'écran
|
||||||
|
font = pygame.font.SysFont(pygame.font.get_default_font(), CELL_SIDE)
|
||||||
|
redraw = True
|
||||||
|
print(event.button)
|
||||||
|
MOUSEBUTTONSDOWN.discard(event.button)
|
||||||
|
if event.type == pygame.MOUSEMOTION:
|
||||||
|
if 2 in MOUSEBUTTONSDOWN or 3 in MOUSEBUTTONSDOWN:
|
||||||
|
camera = difference(scale(difference(drag_origin, event.pos), 1/CELL_SIDE),true_camera)
|
||||||
|
redraw = True
|
||||||
|
if MOUSE:
|
||||||
|
if pointer.pos in units: units[pointer.pos].draw(screen, camera, grid)
|
||||||
|
pointer.pos = scale(event.pos, 1/CELL_SIDE)
|
||||||
|
if 1 in MOUSEBUTTONSDOWN:
|
||||||
|
if pointer.pos in units: units[pointer.pos].draw(screen, camera, grid)
|
||||||
|
pointer.pos = scale(event.pos, 1/CELL_SIDE)
|
||||||
|
if relative(camera, pointer.pos) not in visited_cells:
|
||||||
|
if relative(camera, pointer.pos) in grid.alive_cells:
|
||||||
|
grid.alive_cells.discard(relative(camera, pointer.pos))
|
||||||
|
else:
|
||||||
|
grid.alive_cells.add(relative(camera, pointer.pos))
|
||||||
|
visited_cells.add(relative(camera, pointer.pos))
|
||||||
|
if not MOUSE and (time.time() - (last_pointer_move + 5/FRAME_RATE) > 0):
|
||||||
|
for key in KEYSDOWN:
|
||||||
|
if key in [275,276,273,274]:
|
||||||
|
new_pos = list(pointer.pos)
|
||||||
|
exec("new_pos" + ("[0]+","[0]-","[1]-","[1]+")[[275,276,273,274].index(event.key)] + "=1")
|
||||||
|
if pointer.pos in units: units[pointer.pos].draw(screen, camera, grid)
|
||||||
|
pointer.pos = tuple(new_pos)
|
||||||
|
last_pointer_move = time.time()
|
||||||
|
if redraw:
|
||||||
|
relatives = {unit:relative(camera, unit) for unit in units}
|
||||||
|
draw_grid(screen, camera, grid, units)
|
||||||
|
redraw = False
|
||||||
|
if (last_tick + 1/TICK_RATE) - time.time() < 0:
|
||||||
|
last_tick = time.time()
|
||||||
|
if not pause:
|
||||||
|
grid.tick()
|
||||||
|
if True:
|
||||||
|
for unit in units:
|
||||||
|
if (relatives[unit] in grid.alive_cells) != (relatives[unit] in grid.old_cells):
|
||||||
|
units[unit].draw(screen, camera, grid)
|
||||||
|
if frame:
|
||||||
|
if pointer.pos in units:
|
||||||
|
units[pointer.pos].draw(screen, camera, grid)
|
||||||
|
pointer.draw(screen, camera, grid)
|
||||||
|
pygame.display.flip()
|
||||||
|
last_frame = time.time()
|
||||||
|
time.sleep(max(0,min((last_frame + 1/FRAME_RATE) - time.time(), (last_tick + 1/TICK_RATE) - time.time()))) #On attend avant la prochaine image / le prochain tick pour ne pas surcharger le CPU inutilement
|
684
MPSI/spe/cours/chemins
Normal file
684
MPSI/spe/cours/chemins
Normal file
@ -0,0 +1,684 @@
|
|||||||
|
0 -> 1 en 1. :
|
||||||
|
0 -> 1
|
||||||
|
0 -> 0 -> 1
|
||||||
|
0 -> 1 -> 1
|
||||||
|
0 -> 0 -> 1 -> 1
|
||||||
|
|
||||||
|
0 -> 2 en 2. :
|
||||||
|
0 -> 2
|
||||||
|
0 -> 0 -> 2
|
||||||
|
0 -> 2 -> 2
|
||||||
|
0 -> 0 -> 2 -> 2
|
||||||
|
|
||||||
|
0 -> 3 en 2. :
|
||||||
|
0 -> 1 -> 3
|
||||||
|
0 -> 0 -> 1 -> 3
|
||||||
|
0 -> 1 -> 3 -> 3
|
||||||
|
0 -> 0 -> 1 -> 3 -> 3
|
||||||
|
|
||||||
|
0 -> 4 en 4. :
|
||||||
|
0 -> 2 -> 4
|
||||||
|
0 -> 0 -> 2 -> 4
|
||||||
|
0 -> 2 -> 4 -> 4
|
||||||
|
0 -> 0 -> 2 -> 4 -> 4
|
||||||
|
|
||||||
|
0 -> 5 en 6. :
|
||||||
|
0 -> 1 -> 3 -> 5
|
||||||
|
0 -> 0 -> 1 -> 3 -> 5
|
||||||
|
0 -> 1 -> 3 -> 5 -> 5
|
||||||
|
0 -> 0 -> 1 -> 3 -> 5 -> 5
|
||||||
|
|
||||||
|
0 -> 6 en 3. :
|
||||||
|
0 -> 1 -> 3 -> 6
|
||||||
|
0 -> 0 -> 1 -> 3 -> 6
|
||||||
|
0 -> 1 -> 3 -> 6 -> 6
|
||||||
|
0 -> 0 -> 1 -> 3 -> 6 -> 6
|
||||||
|
|
||||||
|
0 -> 7 en 18. :
|
||||||
|
0 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8 -> 7
|
||||||
|
0 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8 -> 7 -> 7
|
||||||
|
0 -> 0 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8 -> 7
|
||||||
|
0 -> 0 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8 -> 7 -> 7
|
||||||
|
|
||||||
|
0 -> 8 en 17. :
|
||||||
|
0 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8
|
||||||
|
0 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8 -> 8
|
||||||
|
0 -> 0 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8
|
||||||
|
0 -> 0 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8 -> 8
|
||||||
|
|
||||||
|
0 -> 9 en 6. :
|
||||||
|
0 -> 1 -> 3 -> 6 -> 9
|
||||||
|
0 -> 0 -> 1 -> 3 -> 6 -> 9
|
||||||
|
0 -> 1 -> 3 -> 6 -> 9 -> 9
|
||||||
|
0 -> 0 -> 1 -> 3 -> 6 -> 9 -> 9
|
||||||
|
|
||||||
|
0 -> 10 en 9. :
|
||||||
|
0 -> 1 -> 3 -> 6 -> 9 -> 10
|
||||||
|
0 -> 0 -> 1 -> 3 -> 6 -> 9 -> 10
|
||||||
|
0 -> 1 -> 3 -> 6 -> 9 -> 10 -> 10
|
||||||
|
0 -> 0 -> 1 -> 3 -> 6 -> 9 -> 10 -> 10
|
||||||
|
|
||||||
|
1 -> 0 en 17. :
|
||||||
|
1 -> 3 -> 6 -> 9 -> 10 -> 0
|
||||||
|
1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 0
|
||||||
|
1 -> 1 -> 3 -> 6 -> 9 -> 10 -> 0
|
||||||
|
1 -> 1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 0
|
||||||
|
|
||||||
|
1 -> 2 en 19. :
|
||||||
|
1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2
|
||||||
|
1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2 -> 2
|
||||||
|
1 -> 1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2
|
||||||
|
1 -> 1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2 -> 2
|
||||||
|
|
||||||
|
1 -> 3 en 1. :
|
||||||
|
1 -> 3
|
||||||
|
1 -> 1 -> 3
|
||||||
|
1 -> 3 -> 3
|
||||||
|
1 -> 1 -> 3 -> 3
|
||||||
|
|
||||||
|
1 -> 4 en 21. :
|
||||||
|
1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4
|
||||||
|
1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4 -> 4
|
||||||
|
1 -> 1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4
|
||||||
|
1 -> 1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4 -> 4
|
||||||
|
|
||||||
|
1 -> 5 en 5. :
|
||||||
|
1 -> 3 -> 5
|
||||||
|
1 -> 1 -> 3 -> 5
|
||||||
|
1 -> 3 -> 5 -> 5
|
||||||
|
1 -> 1 -> 3 -> 5 -> 5
|
||||||
|
|
||||||
|
1 -> 6 en 2. :
|
||||||
|
1 -> 3 -> 6
|
||||||
|
1 -> 1 -> 3 -> 6
|
||||||
|
1 -> 3 -> 6 -> 6
|
||||||
|
1 -> 1 -> 3 -> 6 -> 6
|
||||||
|
|
||||||
|
1 -> 7 en 17. :
|
||||||
|
1 -> 3 -> 6 -> 9 -> 10 -> 8 -> 7
|
||||||
|
1 -> 3 -> 6 -> 9 -> 10 -> 8 -> 7 -> 7
|
||||||
|
1 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8 -> 7
|
||||||
|
1 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8 -> 7 -> 7
|
||||||
|
|
||||||
|
1 -> 8 en 16. :
|
||||||
|
1 -> 3 -> 6 -> 9 -> 10 -> 8
|
||||||
|
1 -> 3 -> 6 -> 9 -> 10 -> 8 -> 8
|
||||||
|
1 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8
|
||||||
|
1 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8 -> 8
|
||||||
|
|
||||||
|
1 -> 9 en 5. :
|
||||||
|
1 -> 3 -> 6 -> 9
|
||||||
|
1 -> 1 -> 3 -> 6 -> 9
|
||||||
|
1 -> 3 -> 6 -> 9 -> 9
|
||||||
|
1 -> 1 -> 3 -> 6 -> 9 -> 9
|
||||||
|
|
||||||
|
1 -> 10 en 8. :
|
||||||
|
1 -> 3 -> 6 -> 9 -> 10
|
||||||
|
1 -> 1 -> 3 -> 6 -> 9 -> 10
|
||||||
|
1 -> 3 -> 6 -> 9 -> 10 -> 10
|
||||||
|
1 -> 1 -> 3 -> 6 -> 9 -> 10 -> 10
|
||||||
|
|
||||||
|
2 -> 0 en 19. :
|
||||||
|
2 -> 3 -> 6 -> 9 -> 10 -> 0
|
||||||
|
2 -> 3 -> 6 -> 9 -> 10 -> 0 -> 0
|
||||||
|
2 -> 2 -> 3 -> 6 -> 9 -> 10 -> 0
|
||||||
|
2 -> 2 -> 3 -> 6 -> 9 -> 10 -> 0 -> 0
|
||||||
|
2 -> 4 -> 6 -> 9 -> 10 -> 0
|
||||||
|
2 -> 4 -> 6 -> 9 -> 10 -> 0 -> 0
|
||||||
|
2 -> 2 -> 4 -> 6 -> 9 -> 10 -> 0
|
||||||
|
2 -> 2 -> 4 -> 6 -> 9 -> 10 -> 0 -> 0
|
||||||
|
|
||||||
|
2 -> 1 en 8. :
|
||||||
|
2 -> 3 -> 5 -> 1
|
||||||
|
2 -> 3 -> 5 -> 1 -> 1
|
||||||
|
2 -> 2 -> 3 -> 5 -> 1
|
||||||
|
2 -> 2 -> 3 -> 5 -> 1 -> 1
|
||||||
|
|
||||||
|
2 -> 3 en 3. :
|
||||||
|
2 -> 3
|
||||||
|
2 -> 2 -> 3
|
||||||
|
2 -> 3 -> 3
|
||||||
|
2 -> 2 -> 3 -> 3
|
||||||
|
|
||||||
|
2 -> 4 en 2. :
|
||||||
|
2 -> 4
|
||||||
|
2 -> 2 -> 4
|
||||||
|
2 -> 4 -> 4
|
||||||
|
2 -> 2 -> 4 -> 4
|
||||||
|
|
||||||
|
2 -> 5 en 7. :
|
||||||
|
2 -> 3 -> 5
|
||||||
|
2 -> 2 -> 3 -> 5
|
||||||
|
2 -> 3 -> 5 -> 5
|
||||||
|
2 -> 2 -> 3 -> 5 -> 5
|
||||||
|
|
||||||
|
2 -> 6 en 4. :
|
||||||
|
2 -> 3 -> 6
|
||||||
|
2 -> 2 -> 3 -> 6
|
||||||
|
2 -> 4 -> 6
|
||||||
|
2 -> 2 -> 4 -> 6
|
||||||
|
2 -> 3 -> 6 -> 6
|
||||||
|
2 -> 2 -> 3 -> 6 -> 6
|
||||||
|
2 -> 4 -> 6 -> 6
|
||||||
|
2 -> 2 -> 4 -> 6 -> 6
|
||||||
|
|
||||||
|
2 -> 7 en 19. :
|
||||||
|
2 -> 3 -> 6 -> 9 -> 10 -> 8 -> 7
|
||||||
|
2 -> 3 -> 6 -> 9 -> 10 -> 8 -> 7 -> 7
|
||||||
|
2 -> 2 -> 3 -> 6 -> 9 -> 10 -> 8 -> 7
|
||||||
|
2 -> 2 -> 3 -> 6 -> 9 -> 10 -> 8 -> 7 -> 7
|
||||||
|
2 -> 4 -> 6 -> 9 -> 10 -> 8 -> 7
|
||||||
|
2 -> 4 -> 6 -> 9 -> 10 -> 8 -> 7 -> 7
|
||||||
|
2 -> 2 -> 4 -> 6 -> 9 -> 10 -> 8 -> 7
|
||||||
|
2 -> 2 -> 4 -> 6 -> 9 -> 10 -> 8 -> 7 -> 7
|
||||||
|
|
||||||
|
2 -> 8 en 18. :
|
||||||
|
2 -> 3 -> 6 -> 9 -> 10 -> 8
|
||||||
|
2 -> 3 -> 6 -> 9 -> 10 -> 8 -> 8
|
||||||
|
2 -> 2 -> 3 -> 6 -> 9 -> 10 -> 8
|
||||||
|
2 -> 2 -> 3 -> 6 -> 9 -> 10 -> 8 -> 8
|
||||||
|
2 -> 4 -> 6 -> 9 -> 10 -> 8
|
||||||
|
2 -> 4 -> 6 -> 9 -> 10 -> 8 -> 8
|
||||||
|
2 -> 2 -> 4 -> 6 -> 9 -> 10 -> 8
|
||||||
|
2 -> 2 -> 4 -> 6 -> 9 -> 10 -> 8 -> 8
|
||||||
|
|
||||||
|
2 -> 9 en 7. :
|
||||||
|
2 -> 3 -> 6 -> 9
|
||||||
|
2 -> 2 -> 3 -> 6 -> 9
|
||||||
|
2 -> 4 -> 6 -> 9
|
||||||
|
2 -> 2 -> 4 -> 6 -> 9
|
||||||
|
2 -> 3 -> 6 -> 9 -> 9
|
||||||
|
2 -> 2 -> 3 -> 6 -> 9 -> 9
|
||||||
|
2 -> 4 -> 6 -> 9 -> 9
|
||||||
|
2 -> 2 -> 4 -> 6 -> 9 -> 9
|
||||||
|
|
||||||
|
2 -> 10 en 10. :
|
||||||
|
2 -> 3 -> 6 -> 9 -> 10
|
||||||
|
2 -> 2 -> 3 -> 6 -> 9 -> 10
|
||||||
|
2 -> 4 -> 6 -> 9 -> 10
|
||||||
|
2 -> 2 -> 4 -> 6 -> 9 -> 10
|
||||||
|
2 -> 3 -> 6 -> 9 -> 10 -> 10
|
||||||
|
2 -> 2 -> 3 -> 6 -> 9 -> 10 -> 10
|
||||||
|
2 -> 4 -> 6 -> 9 -> 10 -> 10
|
||||||
|
2 -> 2 -> 4 -> 6 -> 9 -> 10 -> 10
|
||||||
|
|
||||||
|
3 -> 0 en 16. :
|
||||||
|
3 -> 6 -> 9 -> 10 -> 0
|
||||||
|
3 -> 6 -> 9 -> 10 -> 0 -> 0
|
||||||
|
3 -> 3 -> 6 -> 9 -> 10 -> 0
|
||||||
|
3 -> 3 -> 6 -> 9 -> 10 -> 0 -> 0
|
||||||
|
|
||||||
|
3 -> 1 en 5. :
|
||||||
|
3 -> 5 -> 1
|
||||||
|
3 -> 5 -> 1 -> 1
|
||||||
|
3 -> 3 -> 5 -> 1
|
||||||
|
3 -> 3 -> 5 -> 1 -> 1
|
||||||
|
|
||||||
|
3 -> 2 en 18. :
|
||||||
|
3 -> 6 -> 9 -> 10 -> 0 -> 2
|
||||||
|
3 -> 6 -> 9 -> 10 -> 0 -> 2 -> 2
|
||||||
|
3 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2
|
||||||
|
3 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2 -> 2
|
||||||
|
|
||||||
|
3 -> 4 en 20. :
|
||||||
|
3 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4
|
||||||
|
3 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4 -> 4
|
||||||
|
3 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4
|
||||||
|
3 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4 -> 4
|
||||||
|
|
||||||
|
3 -> 5 en 4. :
|
||||||
|
3 -> 5
|
||||||
|
3 -> 3 -> 5
|
||||||
|
3 -> 5 -> 5
|
||||||
|
3 -> 3 -> 5 -> 5
|
||||||
|
|
||||||
|
3 -> 6 en 1. :
|
||||||
|
3 -> 6
|
||||||
|
3 -> 3 -> 6
|
||||||
|
3 -> 6 -> 6
|
||||||
|
3 -> 3 -> 6 -> 6
|
||||||
|
|
||||||
|
3 -> 7 en 16. :
|
||||||
|
3 -> 6 -> 9 -> 10 -> 8 -> 7
|
||||||
|
3 -> 6 -> 9 -> 10 -> 8 -> 7 -> 7
|
||||||
|
3 -> 3 -> 6 -> 9 -> 10 -> 8 -> 7
|
||||||
|
3 -> 3 -> 6 -> 9 -> 10 -> 8 -> 7 -> 7
|
||||||
|
|
||||||
|
3 -> 8 en 15. :
|
||||||
|
3 -> 6 -> 9 -> 10 -> 8
|
||||||
|
3 -> 6 -> 9 -> 10 -> 8 -> 8
|
||||||
|
3 -> 3 -> 6 -> 9 -> 10 -> 8
|
||||||
|
3 -> 3 -> 6 -> 9 -> 10 -> 8 -> 8
|
||||||
|
|
||||||
|
3 -> 9 en 4. :
|
||||||
|
3 -> 6 -> 9
|
||||||
|
3 -> 3 -> 6 -> 9
|
||||||
|
3 -> 6 -> 9 -> 9
|
||||||
|
3 -> 3 -> 6 -> 9 -> 9
|
||||||
|
|
||||||
|
3 -> 10 en 7. :
|
||||||
|
3 -> 6 -> 9 -> 10
|
||||||
|
3 -> 3 -> 6 -> 9 -> 10
|
||||||
|
3 -> 6 -> 9 -> 10 -> 10
|
||||||
|
3 -> 3 -> 6 -> 9 -> 10 -> 10
|
||||||
|
|
||||||
|
4 -> 0 en 17. :
|
||||||
|
4 -> 6 -> 9 -> 10 -> 0
|
||||||
|
4 -> 6 -> 9 -> 10 -> 0 -> 0
|
||||||
|
4 -> 4 -> 6 -> 9 -> 10 -> 0
|
||||||
|
4 -> 4 -> 6 -> 9 -> 10 -> 0 -> 0
|
||||||
|
|
||||||
|
4 -> 1 en 18. :
|
||||||
|
4 -> 6 -> 9 -> 10 -> 0 -> 1
|
||||||
|
4 -> 6 -> 9 -> 10 -> 0 -> 1 -> 1
|
||||||
|
4 -> 4 -> 6 -> 9 -> 10 -> 0 -> 1
|
||||||
|
4 -> 4 -> 6 -> 9 -> 10 -> 0 -> 1 -> 1
|
||||||
|
|
||||||
|
4 -> 2 en 19. :
|
||||||
|
4 -> 6 -> 9 -> 10 -> 0 -> 2
|
||||||
|
4 -> 6 -> 9 -> 10 -> 0 -> 2 -> 2
|
||||||
|
4 -> 4 -> 6 -> 9 -> 10 -> 0 -> 2
|
||||||
|
4 -> 4 -> 6 -> 9 -> 10 -> 0 -> 2 -> 2
|
||||||
|
|
||||||
|
4 -> 3 en 19. :
|
||||||
|
4 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3
|
||||||
|
4 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 3
|
||||||
|
4 -> 4 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3
|
||||||
|
4 -> 4 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 3
|
||||||
|
|
||||||
|
4 -> 5 en 23. :
|
||||||
|
4 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 5
|
||||||
|
4 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 5 -> 5
|
||||||
|
4 -> 4 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 5
|
||||||
|
4 -> 4 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 5 -> 5
|
||||||
|
|
||||||
|
4 -> 6 en 2. :
|
||||||
|
4 -> 6
|
||||||
|
4 -> 4 -> 6
|
||||||
|
4 -> 6 -> 6
|
||||||
|
4 -> 4 -> 6 -> 6
|
||||||
|
|
||||||
|
4 -> 7 en 17. :
|
||||||
|
4 -> 6 -> 9 -> 10 -> 8 -> 7
|
||||||
|
4 -> 6 -> 9 -> 10 -> 8 -> 7 -> 7
|
||||||
|
4 -> 4 -> 6 -> 9 -> 10 -> 8 -> 7
|
||||||
|
4 -> 4 -> 6 -> 9 -> 10 -> 8 -> 7 -> 7
|
||||||
|
|
||||||
|
4 -> 8 en 16. :
|
||||||
|
4 -> 6 -> 9 -> 10 -> 8
|
||||||
|
4 -> 6 -> 9 -> 10 -> 8 -> 8
|
||||||
|
4 -> 4 -> 6 -> 9 -> 10 -> 8
|
||||||
|
4 -> 4 -> 6 -> 9 -> 10 -> 8 -> 8
|
||||||
|
|
||||||
|
4 -> 9 en 5. :
|
||||||
|
4 -> 6 -> 9
|
||||||
|
4 -> 4 -> 6 -> 9
|
||||||
|
4 -> 6 -> 9 -> 9
|
||||||
|
4 -> 4 -> 6 -> 9 -> 9
|
||||||
|
|
||||||
|
4 -> 10 en 8. :
|
||||||
|
4 -> 6 -> 9 -> 10
|
||||||
|
4 -> 4 -> 6 -> 9 -> 10
|
||||||
|
4 -> 6 -> 9 -> 10 -> 10
|
||||||
|
4 -> 4 -> 6 -> 9 -> 10 -> 10
|
||||||
|
|
||||||
|
5 -> 0 en 18. :
|
||||||
|
5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 0
|
||||||
|
5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 0
|
||||||
|
5 -> 5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 0
|
||||||
|
5 -> 5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 0
|
||||||
|
|
||||||
|
5 -> 1 en 1. :
|
||||||
|
5 -> 1
|
||||||
|
5 -> 1 -> 1
|
||||||
|
5 -> 5 -> 1
|
||||||
|
5 -> 5 -> 1 -> 1
|
||||||
|
|
||||||
|
5 -> 2 en 20. :
|
||||||
|
5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2
|
||||||
|
5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2 -> 2
|
||||||
|
5 -> 5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2
|
||||||
|
5 -> 5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2 -> 2
|
||||||
|
|
||||||
|
5 -> 3 en 2. :
|
||||||
|
5 -> 1 -> 3
|
||||||
|
5 -> 1 -> 3 -> 3
|
||||||
|
5 -> 5 -> 1 -> 3
|
||||||
|
5 -> 5 -> 1 -> 3 -> 3
|
||||||
|
|
||||||
|
5 -> 4 en 22. :
|
||||||
|
5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4
|
||||||
|
5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4 -> 4
|
||||||
|
5 -> 5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4
|
||||||
|
5 -> 5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4 -> 4
|
||||||
|
|
||||||
|
5 -> 6 en 3. :
|
||||||
|
5 -> 1 -> 3 -> 6
|
||||||
|
5 -> 5 -> 1 -> 3 -> 6
|
||||||
|
5 -> 1 -> 3 -> 6 -> 6
|
||||||
|
5 -> 5 -> 1 -> 3 -> 6 -> 6
|
||||||
|
|
||||||
|
5 -> 7 en 18. :
|
||||||
|
5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8 -> 7
|
||||||
|
5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8 -> 7 -> 7
|
||||||
|
5 -> 5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8 -> 7
|
||||||
|
5 -> 5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8 -> 7 -> 7
|
||||||
|
|
||||||
|
5 -> 8 en 17. :
|
||||||
|
5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8
|
||||||
|
5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8 -> 8
|
||||||
|
5 -> 5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8
|
||||||
|
5 -> 5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 8 -> 8
|
||||||
|
|
||||||
|
5 -> 9 en 6. :
|
||||||
|
5 -> 1 -> 3 -> 6 -> 9
|
||||||
|
5 -> 5 -> 1 -> 3 -> 6 -> 9
|
||||||
|
5 -> 1 -> 3 -> 6 -> 9 -> 9
|
||||||
|
5 -> 5 -> 1 -> 3 -> 6 -> 9 -> 9
|
||||||
|
|
||||||
|
5 -> 10 en 9. :
|
||||||
|
5 -> 1 -> 3 -> 6 -> 9 -> 10
|
||||||
|
5 -> 5 -> 1 -> 3 -> 6 -> 9 -> 10
|
||||||
|
5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 10
|
||||||
|
5 -> 5 -> 1 -> 3 -> 6 -> 9 -> 10 -> 10
|
||||||
|
|
||||||
|
6 -> 0 en 15. :
|
||||||
|
6 -> 9 -> 10 -> 0
|
||||||
|
6 -> 9 -> 10 -> 0 -> 0
|
||||||
|
6 -> 6 -> 9 -> 10 -> 0
|
||||||
|
6 -> 6 -> 9 -> 10 -> 0 -> 0
|
||||||
|
|
||||||
|
6 -> 1 en 16. :
|
||||||
|
6 -> 9 -> 10 -> 0 -> 1
|
||||||
|
6 -> 9 -> 10 -> 0 -> 1 -> 1
|
||||||
|
6 -> 6 -> 9 -> 10 -> 0 -> 1
|
||||||
|
6 -> 6 -> 9 -> 10 -> 0 -> 1 -> 1
|
||||||
|
|
||||||
|
6 -> 2 en 17. :
|
||||||
|
6 -> 9 -> 10 -> 0 -> 2
|
||||||
|
6 -> 9 -> 10 -> 0 -> 2 -> 2
|
||||||
|
6 -> 6 -> 9 -> 10 -> 0 -> 2
|
||||||
|
6 -> 6 -> 9 -> 10 -> 0 -> 2 -> 2
|
||||||
|
|
||||||
|
6 -> 3 en 17. :
|
||||||
|
6 -> 9 -> 10 -> 0 -> 1 -> 3
|
||||||
|
6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 3
|
||||||
|
6 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3
|
||||||
|
6 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 3
|
||||||
|
|
||||||
|
6 -> 4 en 19. :
|
||||||
|
6 -> 9 -> 10 -> 0 -> 2 -> 4
|
||||||
|
6 -> 9 -> 10 -> 0 -> 2 -> 4 -> 4
|
||||||
|
6 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4
|
||||||
|
6 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4 -> 4
|
||||||
|
|
||||||
|
6 -> 5 en 21. :
|
||||||
|
6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 5
|
||||||
|
6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 5 -> 5
|
||||||
|
6 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 5
|
||||||
|
6 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 5 -> 5
|
||||||
|
|
||||||
|
6 -> 7 en 15. :
|
||||||
|
6 -> 9 -> 10 -> 8 -> 7
|
||||||
|
6 -> 9 -> 10 -> 8 -> 7 -> 7
|
||||||
|
6 -> 6 -> 9 -> 10 -> 8 -> 7
|
||||||
|
6 -> 6 -> 9 -> 10 -> 8 -> 7 -> 7
|
||||||
|
|
||||||
|
6 -> 8 en 14. :
|
||||||
|
6 -> 9 -> 10 -> 8
|
||||||
|
6 -> 9 -> 10 -> 8 -> 8
|
||||||
|
6 -> 6 -> 9 -> 10 -> 8
|
||||||
|
6 -> 6 -> 9 -> 10 -> 8 -> 8
|
||||||
|
|
||||||
|
6 -> 9 en 3. :
|
||||||
|
6 -> 9
|
||||||
|
6 -> 6 -> 9
|
||||||
|
6 -> 9 -> 9
|
||||||
|
6 -> 6 -> 9 -> 9
|
||||||
|
|
||||||
|
6 -> 10 en 6. :
|
||||||
|
6 -> 9 -> 10
|
||||||
|
6 -> 6 -> 9 -> 10
|
||||||
|
6 -> 9 -> 10 -> 10
|
||||||
|
6 -> 6 -> 9 -> 10 -> 10
|
||||||
|
|
||||||
|
7 -> 0 en 19. :
|
||||||
|
7 -> 6 -> 9 -> 10 -> 0
|
||||||
|
7 -> 6 -> 9 -> 10 -> 0 -> 0
|
||||||
|
7 -> 7 -> 6 -> 9 -> 10 -> 0
|
||||||
|
7 -> 7 -> 6 -> 9 -> 10 -> 0 -> 0
|
||||||
|
|
||||||
|
7 -> 1 en 20. :
|
||||||
|
7 -> 6 -> 9 -> 10 -> 0 -> 1
|
||||||
|
7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 1
|
||||||
|
7 -> 7 -> 6 -> 9 -> 10 -> 0 -> 1
|
||||||
|
7 -> 7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 1
|
||||||
|
|
||||||
|
7 -> 2 en 21. :
|
||||||
|
7 -> 6 -> 9 -> 10 -> 0 -> 2
|
||||||
|
7 -> 6 -> 9 -> 10 -> 0 -> 2 -> 2
|
||||||
|
7 -> 7 -> 6 -> 9 -> 10 -> 0 -> 2
|
||||||
|
7 -> 7 -> 6 -> 9 -> 10 -> 0 -> 2 -> 2
|
||||||
|
|
||||||
|
7 -> 3 en 21. :
|
||||||
|
7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3
|
||||||
|
7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 3
|
||||||
|
7 -> 7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3
|
||||||
|
7 -> 7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 3
|
||||||
|
|
||||||
|
7 -> 4 en 23. :
|
||||||
|
7 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4
|
||||||
|
7 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4 -> 4
|
||||||
|
7 -> 7 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4
|
||||||
|
7 -> 7 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4 -> 4
|
||||||
|
|
||||||
|
7 -> 5 en 25. :
|
||||||
|
7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 5
|
||||||
|
7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 5 -> 5
|
||||||
|
7 -> 7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 5
|
||||||
|
7 -> 7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 5 -> 5
|
||||||
|
|
||||||
|
7 -> 6 en 4. :
|
||||||
|
7 -> 6
|
||||||
|
7 -> 6 -> 6
|
||||||
|
7 -> 7 -> 6
|
||||||
|
7 -> 7 -> 6 -> 6
|
||||||
|
|
||||||
|
7 -> 8 en 18. :
|
||||||
|
7 -> 6 -> 9 -> 10 -> 8
|
||||||
|
7 -> 6 -> 9 -> 10 -> 8 -> 8
|
||||||
|
7 -> 7 -> 6 -> 9 -> 10 -> 8
|
||||||
|
7 -> 7 -> 6 -> 9 -> 10 -> 8 -> 8
|
||||||
|
|
||||||
|
7 -> 9 en 7. :
|
||||||
|
7 -> 6 -> 9
|
||||||
|
7 -> 7 -> 6 -> 9
|
||||||
|
7 -> 6 -> 9 -> 9
|
||||||
|
7 -> 7 -> 6 -> 9 -> 9
|
||||||
|
|
||||||
|
7 -> 10 en 10. :
|
||||||
|
7 -> 6 -> 9 -> 10
|
||||||
|
7 -> 7 -> 6 -> 9 -> 10
|
||||||
|
7 -> 6 -> 9 -> 10 -> 10
|
||||||
|
7 -> 7 -> 6 -> 9 -> 10 -> 10
|
||||||
|
|
||||||
|
8 -> 0 en 20. :
|
||||||
|
8 -> 7 -> 6 -> 9 -> 10 -> 0
|
||||||
|
8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 0
|
||||||
|
8 -> 8 -> 7 -> 6 -> 9 -> 10 -> 0
|
||||||
|
8 -> 8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 0
|
||||||
|
|
||||||
|
8 -> 1 en 21. :
|
||||||
|
8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 1
|
||||||
|
8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 1
|
||||||
|
8 -> 8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 1
|
||||||
|
8 -> 8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 1
|
||||||
|
|
||||||
|
8 -> 2 en 22. :
|
||||||
|
8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 2
|
||||||
|
8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 2 -> 2
|
||||||
|
8 -> 8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 2
|
||||||
|
8 -> 8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 2 -> 2
|
||||||
|
|
||||||
|
8 -> 3 en 22. :
|
||||||
|
8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3
|
||||||
|
8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 3
|
||||||
|
8 -> 8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3
|
||||||
|
8 -> 8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 3
|
||||||
|
|
||||||
|
8 -> 4 en 24. :
|
||||||
|
8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4
|
||||||
|
8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4 -> 4
|
||||||
|
8 -> 8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4
|
||||||
|
8 -> 8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 2 -> 4 -> 4
|
||||||
|
|
||||||
|
8 -> 5 en 26. :
|
||||||
|
8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 5
|
||||||
|
8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 5 -> 5
|
||||||
|
8 -> 8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 5
|
||||||
|
8 -> 8 -> 7 -> 6 -> 9 -> 10 -> 0 -> 1 -> 3 -> 5 -> 5
|
||||||
|
|
||||||
|
8 -> 6 en 5. :
|
||||||
|
8 -> 7 -> 6
|
||||||
|
8 -> 7 -> 6 -> 6
|
||||||
|
8 -> 8 -> 7 -> 6
|
||||||
|
8 -> 8 -> 7 -> 6 -> 6
|
||||||
|
|
||||||
|
8 -> 7 en 1. :
|
||||||
|
8 -> 7
|
||||||
|
8 -> 7 -> 7
|
||||||
|
8 -> 8 -> 7
|
||||||
|
8 -> 8 -> 7 -> 7
|
||||||
|
|
||||||
|
8 -> 9 en 8. :
|
||||||
|
8 -> 7 -> 6 -> 9
|
||||||
|
8 -> 8 -> 7 -> 6 -> 9
|
||||||
|
8 -> 7 -> 6 -> 9 -> 9
|
||||||
|
8 -> 8 -> 7 -> 6 -> 9 -> 9
|
||||||
|
|
||||||
|
8 -> 10 en 11. :
|
||||||
|
8 -> 7 -> 6 -> 9 -> 10
|
||||||
|
8 -> 8 -> 7 -> 6 -> 9 -> 10
|
||||||
|
8 -> 7 -> 6 -> 9 -> 10 -> 10
|
||||||
|
8 -> 8 -> 7 -> 6 -> 9 -> 10 -> 10
|
||||||
|
|
||||||
|
9 -> 0 en 12. :
|
||||||
|
9 -> 10 -> 0
|
||||||
|
9 -> 10 -> 0 -> 0
|
||||||
|
9 -> 9 -> 10 -> 0
|
||||||
|
9 -> 9 -> 10 -> 0 -> 0
|
||||||
|
|
||||||
|
9 -> 1 en 13. :
|
||||||
|
9 -> 10 -> 0 -> 1
|
||||||
|
9 -> 10 -> 0 -> 1 -> 1
|
||||||
|
9 -> 9 -> 10 -> 0 -> 1
|
||||||
|
9 -> 9 -> 10 -> 0 -> 1 -> 1
|
||||||
|
|
||||||
|
9 -> 2 en 14. :
|
||||||
|
9 -> 10 -> 0 -> 2
|
||||||
|
9 -> 10 -> 0 -> 2 -> 2
|
||||||
|
9 -> 9 -> 10 -> 0 -> 2
|
||||||
|
9 -> 9 -> 10 -> 0 -> 2 -> 2
|
||||||
|
|
||||||
|
9 -> 3 en 14. :
|
||||||
|
9 -> 10 -> 0 -> 1 -> 3
|
||||||
|
9 -> 10 -> 0 -> 1 -> 3 -> 3
|
||||||
|
9 -> 9 -> 10 -> 0 -> 1 -> 3
|
||||||
|
9 -> 9 -> 10 -> 0 -> 1 -> 3 -> 3
|
||||||
|
|
||||||
|
9 -> 4 en 16. :
|
||||||
|
9 -> 10 -> 0 -> 2 -> 4
|
||||||
|
9 -> 10 -> 0 -> 2 -> 4 -> 4
|
||||||
|
9 -> 9 -> 10 -> 0 -> 2 -> 4
|
||||||
|
9 -> 9 -> 10 -> 0 -> 2 -> 4 -> 4
|
||||||
|
|
||||||
|
9 -> 5 en 18. :
|
||||||
|
9 -> 10 -> 0 -> 1 -> 3 -> 5
|
||||||
|
9 -> 10 -> 0 -> 1 -> 3 -> 5 -> 5
|
||||||
|
9 -> 9 -> 10 -> 0 -> 1 -> 3 -> 5
|
||||||
|
9 -> 9 -> 10 -> 0 -> 1 -> 3 -> 5 -> 5
|
||||||
|
|
||||||
|
9 -> 6 en 15. :
|
||||||
|
9 -> 10 -> 0 -> 1 -> 3 -> 6
|
||||||
|
9 -> 10 -> 0 -> 1 -> 3 -> 6 -> 6
|
||||||
|
9 -> 9 -> 10 -> 0 -> 1 -> 3 -> 6
|
||||||
|
9 -> 9 -> 10 -> 0 -> 1 -> 3 -> 6 -> 6
|
||||||
|
|
||||||
|
9 -> 7 en 12. :
|
||||||
|
9 -> 10 -> 8 -> 7
|
||||||
|
9 -> 10 -> 8 -> 7 -> 7
|
||||||
|
9 -> 9 -> 10 -> 8 -> 7
|
||||||
|
9 -> 9 -> 10 -> 8 -> 7 -> 7
|
||||||
|
|
||||||
|
9 -> 8 en 11. :
|
||||||
|
9 -> 10 -> 8
|
||||||
|
9 -> 10 -> 8 -> 8
|
||||||
|
9 -> 9 -> 10 -> 8
|
||||||
|
9 -> 9 -> 10 -> 8 -> 8
|
||||||
|
|
||||||
|
9 -> 10 en 3. :
|
||||||
|
9 -> 10
|
||||||
|
9 -> 9 -> 10
|
||||||
|
9 -> 10 -> 10
|
||||||
|
9 -> 9 -> 10 -> 10
|
||||||
|
|
||||||
|
10 -> 0 en 9. :
|
||||||
|
10 -> 0
|
||||||
|
10 -> 0 -> 0
|
||||||
|
10 -> 10 -> 0
|
||||||
|
10 -> 10 -> 0 -> 0
|
||||||
|
|
||||||
|
10 -> 1 en 10. :
|
||||||
|
10 -> 0 -> 1
|
||||||
|
10 -> 0 -> 1 -> 1
|
||||||
|
10 -> 10 -> 0 -> 1
|
||||||
|
10 -> 10 -> 0 -> 1 -> 1
|
||||||
|
|
||||||
|
10 -> 2 en 11. :
|
||||||
|
10 -> 0 -> 2
|
||||||
|
10 -> 0 -> 2 -> 2
|
||||||
|
10 -> 10 -> 0 -> 2
|
||||||
|
10 -> 10 -> 0 -> 2 -> 2
|
||||||
|
|
||||||
|
10 -> 3 en 11. :
|
||||||
|
10 -> 0 -> 1 -> 3
|
||||||
|
10 -> 0 -> 1 -> 3 -> 3
|
||||||
|
10 -> 10 -> 0 -> 1 -> 3
|
||||||
|
10 -> 10 -> 0 -> 1 -> 3 -> 3
|
||||||
|
|
||||||
|
10 -> 4 en 13. :
|
||||||
|
10 -> 0 -> 2 -> 4
|
||||||
|
10 -> 0 -> 2 -> 4 -> 4
|
||||||
|
10 -> 10 -> 0 -> 2 -> 4
|
||||||
|
10 -> 10 -> 0 -> 2 -> 4 -> 4
|
||||||
|
|
||||||
|
10 -> 5 en 15. :
|
||||||
|
10 -> 0 -> 1 -> 3 -> 5
|
||||||
|
10 -> 0 -> 1 -> 3 -> 5 -> 5
|
||||||
|
10 -> 10 -> 0 -> 1 -> 3 -> 5
|
||||||
|
10 -> 10 -> 0 -> 1 -> 3 -> 5 -> 5
|
||||||
|
|
||||||
|
10 -> 6 en 12. :
|
||||||
|
10 -> 0 -> 1 -> 3 -> 6
|
||||||
|
10 -> 0 -> 1 -> 3 -> 6 -> 6
|
||||||
|
10 -> 10 -> 0 -> 1 -> 3 -> 6
|
||||||
|
10 -> 10 -> 0 -> 1 -> 3 -> 6 -> 6
|
||||||
|
|
||||||
|
10 -> 7 en 9. :
|
||||||
|
10 -> 8 -> 7
|
||||||
|
10 -> 8 -> 7 -> 7
|
||||||
|
10 -> 10 -> 8 -> 7
|
||||||
|
10 -> 10 -> 8 -> 7 -> 7
|
||||||
|
|
||||||
|
10 -> 8 en 8. :
|
||||||
|
10 -> 8
|
||||||
|
10 -> 8 -> 8
|
||||||
|
10 -> 10 -> 8
|
||||||
|
10 -> 10 -> 8 -> 8
|
||||||
|
|
||||||
|
10 -> 9 en 15. :
|
||||||
|
10 -> 0 -> 1 -> 3 -> 6 -> 9
|
||||||
|
10 -> 0 -> 1 -> 3 -> 6 -> 9 -> 9
|
||||||
|
10 -> 10 -> 0 -> 1 -> 3 -> 6 -> 9
|
||||||
|
10 -> 10 -> 0 -> 1 -> 3 -> 6 -> 9 -> 9
|
||||||
|
|
BIN
MPSI/spe/cours/floyd_warshall
Executable file
BIN
MPSI/spe/cours/floyd_warshall
Executable file
Binary file not shown.
BIN
MPSI/spe/cours/floyd_warshall.cmi
Normal file
BIN
MPSI/spe/cours/floyd_warshall.cmi
Normal file
Binary file not shown.
BIN
MPSI/spe/cours/floyd_warshall.cmx
Normal file
BIN
MPSI/spe/cours/floyd_warshall.cmx
Normal file
Binary file not shown.
112
MPSI/spe/cours/floyd_warshall.ml
Normal file
112
MPSI/spe/cours/floyd_warshall.ml
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
let ii = infinity;;
|
||||||
|
|
||||||
|
let g = [|
|
||||||
|
(* 0 1 2 3 4 5 6 7 8 9 10*)
|
||||||
|
(*0*) [|0.;1.;2.;ii;ii;ii;ii;ii;ii;ii;ii|];
|
||||||
|
(*1*) [|ii;0.;ii;1.;ii;ii;ii;ii;ii;ii;ii|];
|
||||||
|
(*2*) [|ii;ii;0.;3.;2.;ii;ii;ii;ii;ii;ii|];
|
||||||
|
(*3*) [|ii;ii;ii;0.;ii;4.;1.;ii;ii;ii;ii|];
|
||||||
|
(*4*) [|ii;ii;ii;ii;0.;ii;2.;ii;ii;ii;ii|];
|
||||||
|
(*5*) [|ii;1.;ii;ii;ii;0.;ii;ii;ii;ii;ii|];
|
||||||
|
(*6*) [|ii;ii;ii;ii;ii;ii;0.;ii;ii;3.;ii|];
|
||||||
|
(*7*) [|ii;ii;ii;ii;ii;ii;4.;0.;ii;ii;ii|];
|
||||||
|
(*8*) [|ii;ii;ii;ii;ii;ii;ii;1.;0.;ii;ii|];
|
||||||
|
(*9*) [|ii;ii;ii;ii;ii;ii;ii;ii;ii;0.;3.|];
|
||||||
|
(*10*)[|9.;ii;ii;ii;ii;ii;ii;ii;8.;ii;0.|];|];;
|
||||||
|
|
||||||
|
let copie_matrice m =
|
||||||
|
let p = Array.length m and q = Array.length m.(0) in
|
||||||
|
let c = Array.make_matrix p q m.(0).(0) in
|
||||||
|
for i = 0 to p-1 do
|
||||||
|
for j = 0 to q-1 do
|
||||||
|
c.(i).(j) <- m.(i).(j)
|
||||||
|
done;
|
||||||
|
done;
|
||||||
|
c;;
|
||||||
|
|
||||||
|
let ecraser_matrice m1 m2 =
|
||||||
|
let p = Array.length m2 and q = Array.length m2.(0) in
|
||||||
|
for i = 0 to p-1 do
|
||||||
|
for j = 0 to q-1 do
|
||||||
|
m1.(i).(j) <- m2.(i).(j)
|
||||||
|
done;
|
||||||
|
done;;
|
||||||
|
|
||||||
|
let floyd_warshall g =
|
||||||
|
let n = Array.length g in
|
||||||
|
(* w^(k) pour k=-1 *)
|
||||||
|
let w = copie_matrice g in
|
||||||
|
for k = 0 to n-1 do
|
||||||
|
(* mise ŕ jour de w^(k) *)
|
||||||
|
let c = Array.make_matrix n n 0. in
|
||||||
|
for i = 0 to n-1 do
|
||||||
|
for j = 0 to n-1 do
|
||||||
|
c.(i).(j) <- min w.(i).(j) (w.(i).(k)+.w.(k).(j))
|
||||||
|
done;
|
||||||
|
done;
|
||||||
|
ecraser_matrice w c;
|
||||||
|
done;
|
||||||
|
(* on retourne w^(n-1) *)
|
||||||
|
w;;
|
||||||
|
|
||||||
|
|
||||||
|
let transfo_matrice m =
|
||||||
|
let p = Array.length m and q = Array.length m.(0) in
|
||||||
|
let c = Array.make_matrix p q (m.(0).(0),[[(0,0)]]) in
|
||||||
|
for i = 0 to p-1 do
|
||||||
|
for j = 0 to q-1 do
|
||||||
|
c.(i).(j) <- (m.(i).(j), [[(i,j)]])
|
||||||
|
done;
|
||||||
|
done;
|
||||||
|
c;;
|
||||||
|
|
||||||
|
let rec joindre_chemins l1 l2 =
|
||||||
|
let rec aux chemin li = match li with
|
||||||
|
| [] -> []
|
||||||
|
| h::t -> (chemin@h)::(aux chemin t) in
|
||||||
|
match l1 with
|
||||||
|
| [] -> []
|
||||||
|
| h::t -> (aux h l2)@(joindre_chemins t l2);;
|
||||||
|
|
||||||
|
let floyd_warshall_complet g =
|
||||||
|
let n = Array.length g in
|
||||||
|
(* w^(k) pour k=-1 *)
|
||||||
|
let w = transfo_matrice g in
|
||||||
|
for k = 0 to n-1 do
|
||||||
|
(* mise ŕ jour de w^(k) *)
|
||||||
|
let c = Array.make_matrix n n w.(0).(0) in
|
||||||
|
for i = 0 to n-1 do
|
||||||
|
for j = 0 to n-1 do
|
||||||
|
let ((db,cb), (ds,cs), (dt,ct)) = (w.(i).(j), w.(i).(k), w.(k).(j)) in
|
||||||
|
if db = ds +. dt then
|
||||||
|
if db <> infinity then
|
||||||
|
c.(i).(j) <- (db,cb@(joindre_chemins cs ct))
|
||||||
|
else
|
||||||
|
c.(i).(j) <- (db, cb)
|
||||||
|
else if db > ds +. dt then
|
||||||
|
c.(i).(j) <- (ds +. dt, joindre_chemins cs ct)
|
||||||
|
else
|
||||||
|
c.(i).(j) <- (db, cb);
|
||||||
|
done;
|
||||||
|
done;
|
||||||
|
ecraser_matrice w c;
|
||||||
|
done;
|
||||||
|
(* on retourne w^(n-1) *)
|
||||||
|
w;;
|
||||||
|
|
||||||
|
open Format;;
|
||||||
|
let tous_les_chemins g =
|
||||||
|
let mat = floyd_warshall_complet g in
|
||||||
|
|
||||||
|
let rec affiche_chemin last l = match l with
|
||||||
|
| [] -> printf "%d\n" last
|
||||||
|
| (i,j)::t -> (printf "%d -> " i); affiche_chemin j t in
|
||||||
|
|
||||||
|
for i = 0 to Array.length mat - 1 do
|
||||||
|
for j = 0 to Array.length mat.(0) -1 do
|
||||||
|
if i<>j then
|
||||||
|
let (d,c) = mat.(i).(j) in printf "%d -> %d en %F :\n" i j d; List.iter (fun li -> printf " "; affiche_chemin j li) c;
|
||||||
|
print_newline ()
|
||||||
|
done
|
||||||
|
done;;
|
||||||
|
tous_les_chemins g;;
|
BIN
MPSI/spe/cours/floyd_warshall.o
Normal file
BIN
MPSI/spe/cours/floyd_warshall.o
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user