Last active
October 19, 2017 04:52
-
-
Save redwrasse/2ea9a65ece6bdcbd8d82b3318e8f4c04 to your computer and use it in GitHub Desktop.
Maximum value in the Pregel formalism in Spark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Maximum value algorithm: at each iteration each | |
* node sends to its neighbors the largest value it | |
* has ever seen. | |
*/ | |
package graphalgorithms | |
import org.apache.spark.graphx._ | |
object MaxValue { | |
val MAX_ITERATIONS = 100 | |
def run(g: Graph[Int, Int]): Graph[Int, Int] = { | |
val mergeMsg = (a:Int, b: Int) => math.max(a, b) | |
val activeDirection = EdgeDirection.Either | |
val numIterations = MAX_ITERATIONS | |
val initialMsg = Integer.MIN_VALUE | |
val vprog = (vid: VertexId, vd: Int, a: Int) => math.max(vd, a) | |
val sendMsg = (etr: EdgeTriplet[Int, Int]) => { | |
val a = math.max(etr.srcAttr, etr.dstAttr) | |
Iterator((etr.srcId, a), (etr.dstId, a)) | |
} | |
Pregel(g, initialMsg, numIterations)( | |
vprog, sendMsg, mergeMsg) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment