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

Method sum_in

recipes/Python/578615_graph/recipe-578615.py:289–302  ·  view source on GitHub ↗

Return sum of all edges that point to vertex. >>> g = Graph(VertexType=WVertex) >>> g.add(1, [1, 2, 3]) >>> g.add(4, 1, 3) >>> g[1].sum_in(), g[3].sum_in(), g[4].sum_in() (4, 1, 0)

(self)

Source from the content-addressed store, hash-verified

287 __slots__ = []
288
289 def sum_in(self):
290 """Return sum of all edges that point to vertex.
291
292 >>> g = Graph(VertexType=WVertex)
293 >>> g.add(1, [1, 2, 3])
294 >>> g.add(4, 1, 3)
295 >>> g[1].sum_in(), g[3].sum_in(), g[4].sum_in()
296 (4, 1, 0)
297 """
298 g, t = self._graph, self._id
299 sum = 0
300 for h in self.in_vertices():
301 sum += g[h][t]
302 return sum
303
304 def sum_out(self):
305 """Return sum of all edges that leave from vertex.

Callers

nothing calls this directly

Calls 1

in_verticesMethod · 0.45

Tested by

no test coverage detected