def _calc_paths():
 def dump():
  for i in sws:
   for j in sws:
    a = path_map[i][j][0]
    if (a is None):
     a = '*'
    print a,
   print
 sws = switches.values()
 path_map.clear()
 for k in sws:
  for (j, port) in adjacency[k].iteritems():
   if (port is None):
    continue
   path_map[k][j] = (1, None)
  path_map[k][k] = (0, None)
 for k in sws:
  for i in sws:
   for j in sws:
    if (path_map[i][k][0] is not None):
     if (path_map[k][j][0] is not None):
      ikj_dist = (path_map[i][k][0] + path_map[k][j][0])
      if ((path_map[i][j][0] is None) or (ikj_dist < path_map[i][j][0])):
       path_map[i][j] = (ikj_dist, k)

def _calc_paths ( ) : def dump ( ) : for i in sws : for j in sws : a = path_map [ i ] [ j ] [ 0 ] if ( a is None ) : a = '*' print a , print sws = switches . values ( ) path_map . clear ( ) for k in sws : for ( j , port ) in adjacency [ k ] . iteritems ( ) : if ( port is None ) : continue path_map [ k ] [ j ] = ( 1 , None ) path_map [ k ] [ k ] = ( 0 , None ) for k in sws : for i in sws : for j in sws : if ( path_map [ i ] [ k ] [ 0 ] is not None ) : if ( path_map [ k ] [ j ] [ 0 ] is not None ) : ikj_dist = ( path_map [ i ] [ k ] [ 0 ] + path_map [ k ] [ j ] [ 0 ] ) if ( ( path_map [ i ] [ j ] [ 0 ] is None ) or ( ikj_dist < path_map [ i ] [ j ] [ 0 ] ) ) : path_map [ i ] [ j ] = ( ikj_dist , k )
essentially floyd-warshall algorithm .