Floyd–Warshall
April 15th, 2010It 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
Easter holiday in Scotland
April 6th, 2010DrupalCamp Spain
March 1st, 2010Havel-Hakimi
February 19th, 2010The code is in catalan, but should be self-explanatory.
def comprova(nodes):
if sum(nodes) % 2 != 0:
print 'la suma se graus no es parell'
return 0
if max(nodes) > len(nodes)-1:
print 'hi ha un node de grau mes gran que el total de nodes'
return 0
if min(nodes) < 0:
print 'hi ha un node de grau negatiu'
return 0
if max(nodes) == 0:
print 'es un graf correcte'
return 0
return 1
# mostra de Butà un hidrocarbó amb fórmula C4H10
nodes = [4,4,4,4,1,1,1,1,1,1,1,1,1,1]
# mostra d'una definició de graf incorrecte
# nodes = [6,5,5,5,5,2,1,1]
while (comprova(nodes)):
print nodes
nodes2 = list(nodes)
nodes.sort()
nodes.reverse()
if nodes!=nodes2: print str(nodes) + " ordenat"
node = nodes.pop(0)
for i in range(node):
nodes[i]=nodes[i]-1
print nodes
if sum(nodes) % 2 != 0:
print ‘la suma se graus no es parell’
return 0
if max(nodes) > len(nodes)-1:
print ‘hi ha un node de grau mes gran que el total de nodes’
return 0
if min(nodes) < 0:
print ‘hi ha un node de grau negatiu’
return 0
if max(nodes) == 0:
print ‘es un graf correcte’
return 0
return 1
nodes = [7,5,4,3,2,2,2]
nodes = [7,6,5,4,4,3,2,1]
nodes = [5,5,3,2,2,1,1]
nodes = [4,3,2,2,2,2,1]
nodes = [6,5,5,5,5,2,1,1]
nodes = [4,4,4,4,1,1,1,1,1,1,1,1,1,1]
while (comprova(nodes)):
print nodes
nodes2 = list(nodes)
nodes.sort()
nodes.reverse()
if nodes!=nodes2: print str(nodes) + ” ordenat”
node = nodes.pop(0)
for i in range(node):
nodes[i]=nodes[i]-1
print nodes
Minotaur’s labyrinth
February 4th, 2010Terrassa Fast motion (Time-lapse)
February 2nd, 2010Spiders
February 1st, 2010Cologne
January 25th, 2010I went with Dani to Cologne. Thank God for the european low-cost airlines.
Athens
January 10th, 2010I’ve had some cultural days in Athens.








