Skip to content
Snippets Groups Projects
Commit 1e5535cf authored by Dan Crankshaw's avatar Dan Crankshaw
Browse files

Added connected components back

parent 543a54df
No related branches found
No related tags found
No related merge requests found
...@@ -64,7 +64,7 @@ object Analytics extends Logging { ...@@ -64,7 +64,7 @@ object Analytics extends Logging {
* lowest vertex id in the connected component containing * lowest vertex id in the connected component containing
* that vertex. * that vertex.
*/ */
def connectedComponents[VD: Manifest, ED: Manifest](graph: Graph[VD, ED]) = { def connectedComponents[VD: Manifest, ED: Manifest](graph: Graph[VD, ED], numIter: Int) = {
val ccGraph = graph.mapVertices { case Vertex(vid, _) => vid } val ccGraph = graph.mapVertices { case Vertex(vid, _) => vid }
GraphLab.iterate(ccGraph)( GraphLab.iterate(ccGraph)(
...@@ -72,6 +72,7 @@ object Analytics extends Logging { ...@@ -72,6 +72,7 @@ object Analytics extends Logging {
(a: Vid, b: Vid) => math.min(a, b), // merge (a: Vid, b: Vid) => math.min(a, b), // merge
(v, a: Option[Vid]) => math.min(v.data, a.getOrElse(Long.MaxValue)), // apply (v, a: Option[Vid]) => math.min(v.data, a.getOrElse(Long.MaxValue)), // apply
(me_id, edge) => (edge.vertex(me_id).data < edge.otherVertex(me_id).data), // scatter (me_id, edge) => (edge.vertex(me_id).data < edge.otherVertex(me_id).data), // scatter
numIter,
gatherDirection = EdgeDirection.Both, scatterDirection = EdgeDirection.Both gatherDirection = EdgeDirection.Both, scatterDirection = EdgeDirection.Both
) )
} }
...@@ -157,38 +158,38 @@ object Analytics extends Logging { ...@@ -157,38 +158,38 @@ object Analytics extends Logging {
sc.stop() sc.stop()
} }
// case "cc" => { case "cc" => {
//
// var numIter = Int.MaxValue var numIter = Int.MaxValue
// var isDynamic = false var isDynamic = false
//
// options.foreach{ options.foreach{
// case ("numIter", v) => numIter = v.toInt case ("numIter", v) => numIter = v.toInt
// case ("dynamic", v) => isDynamic = v.toBoolean case ("dynamic", v) => isDynamic = v.toBoolean
// case (opt, _) => throw new IllegalArgumentException("Invalid option: " + opt) case (opt, _) => throw new IllegalArgumentException("Invalid option: " + opt)
// } }
//
// if(!isDynamic && numIter == Int.MaxValue) { if(!isDynamic && numIter == Int.MaxValue) {
// println("Set number of iterations!") println("Set number of iterations!")
// sys.exit(1) sys.exit(1)
// } }
// println("======================================") println("======================================")
// println("| Connected Components |") println("| Connected Components |")
// println("--------------------------------------") println("--------------------------------------")
// println(" Using parameters:") println(" Using parameters:")
// println(" \tDynamic: " + isDynamic) println(" \tDynamic: " + isDynamic)
// println(" \tNumIter: " + numIter) println(" \tNumIter: " + numIter)
// println("======================================") println("======================================")
//
// val sc = new SparkContext(host, "ConnectedComponents(" + fname + ")") val sc = new SparkContext(host, "ConnectedComponents(" + fname + ")")
// val graph = GraphLoader.textFile(sc, fname, a => 1.0F) val graph = GraphLoader.textFile(sc, fname, a => 1.0F)
// //val cc = Analytics.connectedComponents(graph, numIter) val cc = Analytics.connectedComponents(graph, numIter)
// // val cc = if(isDynamic) Analytics.dynamicConnectedComponents(graph, numIter) //val cc = if(isDynamic) Analytics.dynamicConnectedComponents(graph, numIter)
// // else Analytics.connectedComponents(graph, numIter) // else Analytics.connectedComponents(graph, numIter)
// println("Components: " + cc.vertices.map(_.data).distinct()) println("Components: " + cc.vertices.map(_.data).distinct())
//
// sc.stop() sc.stop()
// } }
// //
// case "shortestpath" => { // case "shortestpath" => {
// //
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment