Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def PowerGraph(graph: Graph[V,E],
- gatherf: Edge[V,E] => A,
- sumf: (A, A) => A,
- applyf: ((Id,V), A) => V,
- signalf: Edge[V,E]=> Bool,
- maxIter: Int): Graph[V,E] = {
- // Extend the vertex data to include isActive
- var glGraph = graph.mapVertices((Id,v) => (id, (true,v)))
- // Loop while there are active vertices
- var i = 0
- var nActive = g.numVertices
- while (i < maxIter && nActive > 0) {
- // Execute the gather phase
- val acc = glGraph.filterE(e => e.dst.isActive).aggregateNeighbors(gatherf, sumf)
- // Execute the apply phase.
- glGraph = glGraph.updateVertices(acc, applyf)
- // Execute the Scatter Phase
- val active = glGraph.filter(e=>e.src.isActive).aggregateNeighbors(scatterf, (a,b)=> a||b)
- // Update activity status of vertices
- glGraph = glGraph.updateVertices(active,
- ((id, (old,v)), active)=>(id,(active,v)))
- // Count the number of active vertices
- nActive = glGraph.vertices.map(v => v.isActive).reduce((a,b) => a + b)
- i = i + 1
- }
- // Return the graph (without active flag)
- return glGraph.mapVertices(v => (v.id, v.data))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement