Floyd–Warshall

April 15th, 2010

It was 2am and I had an exercice where I had to do a Floyd–Warshall algorithm over a graph to get the maximum cost among the minimum paths. The numbers on the paper began to blur and I found it way easier to copy the pseudocode from Wikipedia and translate into Python than to actually do it. Am I awesome? Is there something wrong with me?

Here you are.

#n = num of vertices
n = 7
#this is my little aproximation to infinity... didn't want to get into the docs
m = 1e1000
#this is the matrix that describes de graph
path = [[0,4,3,m,m,m,m],[4,0,4,6,m,6,m],[3,4,0,6,m,m,m],[m,6,6,0,4,4,6],[m,m,m,4,0,6,10],[m,6,m,4,6,0,2],[m,m,m,6,10,2,0]]
for k in xrange(n):
	for i in xrange(n):
		for j in xrange(n):
			path[i][j] = min ( path[i][j], path[i][k]+path[k][j] )
			print path

Minotaur’s labyrinth

February 4th, 2010

Minotaur’s labytinth in Python

Minotaure

Read the rest of this entry »