Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spark
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cs525-sp18-g07
spark
Commits
59e4384e
Commit
59e4384e
authored
11 years ago
by
Ankur Dave
Browse files
Options
Downloads
Patches
Plain Diff
Fix Pregel SSSP example in programming guide
parent
c6023bee
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docs/graphx-programming-guide.md
+14
-8
14 additions, 8 deletions
docs/graphx-programming-guide.md
with
14 additions
and
8 deletions
docs/graphx-programming-guide.md
+
14
−
8
View file @
59e4384e
...
...
@@ -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
R
andom graph generation library
// Import
r
andom 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 == s
h
ourceId) 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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment