aboutsummaryrefslogtreecommitdiff
path: root/docs/graphx-programming-guide.md
diff options
context:
space:
mode:
authorAnkur Dave <ankurdave@gmail.com>2014-01-13 21:02:09 -0800
committerAnkur Dave <ankurdave@gmail.com>2014-01-13 21:02:38 -0800
commit59e4384e19b0d7390259fa42daae95ae6f12f793 (patch)
tree6d2f1c76c540b111c6a42890db7095d876dfef3c /docs/graphx-programming-guide.md
parentc6023bee60cee06b3dd31bb8253da6e07862c13d (diff)
downloadspark-59e4384e19b0d7390259fa42daae95ae6f12f793.tar.gz
spark-59e4384e19b0d7390259fa42daae95ae6f12f793.tar.bz2
spark-59e4384e19b0d7390259fa42daae95ae6f12f793.zip
Fix Pregel SSSP example in programming guide
Diffstat (limited to 'docs/graphx-programming-guide.md')
-rw-r--r--docs/graphx-programming-guide.md22
1 files changed, 14 insertions, 8 deletions
diff --git a/docs/graphx-programming-guide.md b/docs/graphx-programming-guide.md
index 76de26c7cd..91cc5b69cc 100644
--- a/docs/graphx-programming-guide.md
+++ b/docs/graphx-programming-guide.md
@@ -511,7 +511,7 @@ In the following example we use the `mapReduceTriplets` operator to compute the
more senior followers of each user.
{% highlight scala %}
-// Import Random graph generation library
+// Import random graph generation library
import org.apache.spark.graphx.util.GraphGenerators
// Create a graph with "age" as the vertex property. Here we use a random graph for simplicity.
val graph: Graph[Double, Int] =
@@ -643,18 +643,23 @@ iterations, and the edge direction in which to send messages (by default along o
second argument list contains the user defined functions for receiving messages (the vertex program
`vprog`), computing messages (`sendMsg`), and combining messages `mergeMsg`.
-We can use the Pregel operator to express computation such single source shortest path in the
-following example.
+We can use the Pregel operator to express computation such as single source
+shortest path in the following example.
{% highlight scala %}
-val graph: Graph[String, Double] // A graph with edge attributes containing distances
-val sourceId: VertexId = 42 // The ultimate source
+import org.apache.spark.graphx._
+// Import random graph generation library
+import org.apache.spark.graphx.util.GraphGenerators
+// A graph with edge attributes containing distances
+val graph: Graph[Int, Double] =
+ GraphGenerators.logNormalGraph(sc, numVertices = 100).mapEdges(e => e.attr.toDouble)
+val sourceId: VertexID = 42 // The ultimate source
// Initialize the graph such that all vertices except the root have distance infinity.
-val initialGraph = graph.mapVertices((id, _) => if (id == shourceId) 0.0 else Double.PositiveInfinity)
+val initialGraph = graph.mapVertices((id, _) => if (id == sourceId) 0.0 else Double.PositiveInfinity)
val sssp = initialGraph.pregel(Double.PositiveInfinity)(
- (id, dist, newDist) => math.min(dist, newDist) // Vertex Program
+ (id, dist, newDist) => math.min(dist, newDist), // Vertex Program
triplet => { // Send Message
- if(triplet.srcAttr + triplet.attr < triplet.dstAttr) {
+ if (triplet.srcAttr + triplet.attr < triplet.dstAttr) {
Iterator((triplet.dstId, triplet.srcAttr + triplet.attr))
} else {
Iterator.empty
@@ -662,6 +667,7 @@ val sssp = initialGraph.pregel(Double.PositiveInfinity)(
},
(a,b) => math.min(a,b) // Merge Message
)
+println(sssp.vertices.collect.mkString("\n"))
{% endhighlight %}
# Graph Builders