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
19122af7
Commit
19122af7
authored
14 years ago
by
Ankur Dave
Browse files
Options
Downloads
Patches
Plain Diff
Update ShortestPath to work with controllable partitioning
parent
45ec9db8
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
bagel/src/main/scala/bagel/ShortestPath.scala
+5
-9
5 additions, 9 deletions
bagel/src/main/scala/bagel/ShortestPath.scala
with
5 additions
and
9 deletions
bagel/src/main/scala/bagel/ShortestPath.scala
+
5
−
9
View file @
19122af7
...
...
@@ -5,7 +5,6 @@ import spark.SparkContext._
import
scala.math.min
/*
object
ShortestPath
{
def
main
(
args
:
Array
[
String
])
{
if
(
args
.
length
<
4
)
{
...
...
@@ -26,7 +25,7 @@ object ShortestPath {
.
filter
(!
_
.
matches
(
"^\\s*#.*"
))
.
map
(
line
=>
line
.
split
(
"\t"
)))
val vertices: RDD[(String,
Either[
SPVertex
, SPMessage]
)] =
val
vertices
:
RDD
[(
String
,
SPVertex
)]
=
(
lines
.
groupBy
(
line
=>
line
(
0
))
.
map
{
case
(
vertexId
,
lines
)
=>
{
...
...
@@ -35,18 +34,16 @@ object ShortestPath {
new
SPEdge
(
targetId
,
edgeValue
.
toInt
)
}
(vertexId,
Left[SPVertex, SPMessage](
new SPVertex(vertexId, Int.MaxValue, outEdges, true))
)
(
vertexId
,
new
SPVertex
(
vertexId
,
Int
.
MaxValue
,
outEdges
,
true
))
}
})
val messages: RDD[(String,
Either[SPVertex,
SPMessage
]
)] =
val
messages
:
RDD
[(
String
,
SPMessage
)]
=
(
lines
.
filter
(
_
.
length
==
2
)
.
map
{
case
Array
(
vertexId
,
messageValue
)
=>
(vertexId,
Right[SPVertex, SPMessage](
new SPMessage(vertexId, messageValue.toInt))
)
(
vertexId
,
new
SPMessage
(
vertexId
,
messageValue
.
toInt
))
})
val graph: RDD[(String, Either[SPVertex, SPMessage])] = vertices ++ messages
System
.
err
.
println
(
"Read "
+
vertices
.
count
()+
" vertices and "
+
messages
.
count
()+
" messages."
)
...
...
@@ -55,7 +52,7 @@ object ShortestPath {
def
messageCombiner
(
minSoFar
:
Int
,
message
:
SPMessage
)
:
Int
=
min
(
minSoFar
,
message
.
value
)
val result = Pregel.run(sc,
graph
, numSplits, messageCombiner, () => Int.MaxValue, min _) {
val
result
=
Pregel
.
run
(
sc
,
vertices
,
messages
,
numSplits
,
messageCombiner
,
()
=>
Int
.
MaxValue
,
min
_
)
{
(
self
:
SPVertex
,
messageMinValue
:
Int
,
superstep
:
Int
)
=>
val
newValue
=
min
(
self
.
value
,
messageMinValue
)
...
...
@@ -83,4 +80,3 @@ object ShortestPath {
@serializable
class
SPVertex
(
val
id
:
String
,
val
value
:
Int
,
val
outEdges
:
Seq
[
SPEdge
],
val
active
:
Boolean
)
extends
Vertex
@serializable
class
SPEdge
(
val
targetId
:
String
,
val
value
:
Int
)
extends
Edge
@serializable
class
SPMessage
(
val
targetId
:
String
,
val
value
:
Int
)
extends
Message
*/
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