MCPcopy Create free account
hub / github.com/ActiveState/code / adj

Method adj

recipes/Python/579141_Simple_Graph_library/recipe-579141.py:473–499  ·  view source on GitHub ↗

G= { 0 : { 1 : 6, 2 : 4 } 1 : { 2 : 3, 5 : 7 } 2 : { 3 : 9, 4 : 1 } 3 : { 4 : 1 } 4 : { 5 : 5, 6 : 2 } 5 : { } 6 : { } } adj(G) >> { 0: {0: 0, 1: 6,

(self, missing=float('inf'))

Source from the content-addressed store, hash-verified

471 return tree
472
473 def adj(self, missing=float('inf')): # makes the adj dict will all possible cells, similar to matrix
474 """
475 G= { 0 : { 1 : 6, 2 : 4 }
476 1 : { 2 : 3, 5 : 7 }
477 2 : { 3 : 9, 4 : 1 }
478 3 : { 4 : 1 }
479 4 : { 5 : 5, 6 : 2 }
480 5 : { }
481 6 : { }
482 }
483
484 adj(G) >>
485 { 0: {0: 0, 1: 6, 2: 4, 3: inf, 4: inf, 5: inf, 6: inf},
486 1: {0: inf, 1: 0, 2: 3, 3: inf, 4: inf, 5: 7, 6: inf},
487 2: {0: inf, 1: inf, 2: 0, 3: 9, 4: 1, 5: inf, 6: inf},
488 3: {0: inf, 1: inf, 2: inf, 3: 0, 4: 1, 5: inf, 6: inf},
489 4: {0: inf, 1: inf, 2: inf, 3: inf, 4: 0, 5: 5, 6: 2},
490 5: {0: inf, 1: inf, 2: inf, 3: inf, 4: inf, 5: 0, 6: inf},
491 6: {0: inf, 1: inf, 2: inf, 3: inf, 4: inf, 5: inf, 6: 0}
492 }
493 """
494 vertices = self.v.keys()
495 return {v1:
496 {v2: 0 if v1 == v2 else self.v[v1].getNeighbours().get(v2, missing) for v2 in vertices
497 }
498 for v1 in vertices
499 }
500
501 def floyds(self):
502 """

Callers 4

floydsMethod · 0.95
reachabilityMethod · 0.95
dijkstraMethod · 0.95

Calls 3

keysMethod · 0.45
getMethod · 0.45
getNeighboursMethod · 0.45

Tested by

no test coverage detected