CodePudding user response:
I don't know the building Lord solved, I this give you an example:import org. Apache. Spark. {SparkConf, SparkContext}
The import org. Apache. Spark. The graphx. {EdgeDirection VertexId, Graph}
The import org. Apache. Spark. The graphx. Util. GraphGenerators
The object Pregel_SSSP {
Def main (args: Array [String]) {
Val conf=new SparkConf (). SetAppName (" Pregel_SSSP ")
Val sc=new SparkContext (conf)
//A graph with edge attributes containing distances
Val graph: a graph [Long, Double]=
GraphGenerators. LogNormalGraph (sc, numVertices=5). MapEdges (e=& gt; E.a TTR event. ToDouble)
Graph. Edges. Foreach (println)
Val sourceId: VertexId=0//The ultimate source
//Initialize the graph to that all are the except the root have short infinity.
Val initialGraph: Graph [(Double, List [VertexId]), Double]=Graph. MapVertices ((id, _)=& gt; If (id==sourceId) (0.0, List [VertexId] (sourceId)) else (Double PositiveInfinity, List [VertexId] ()))
Val SSSP=initialGraph. Pregel ((Double) PositiveInfinity, List [VertexId] ()), Int. J MaxValue, EdgeDirection. Out) (
//Vertex Program
(id, dist, newDist)=& gt; If (dist. _1 & lt; NewDist. _1) dist else newDist,
//Send Message
Triplet=& gt; {
If (triplet. SrcAttr. _1 & lt; Triplet. DstAttr. _1 - triplet. Attr) {
The Iterator ((triplet. DstId (triplet. SrcAttr. _1 + triplet. Attr, triplet. SrcAttr. _2: + triplet. DstId)))
} else {
The Iterator. Empty
}
},
//Merge Message
(a, b)=& gt; If (a. _1 & lt; B. _1) else b)
Println (SSSP. Are. Collect. MkString (" \ n "))
}
}
CodePudding user response:
Based on the spark 1.3CodePudding user response:
Hello, this is monophyletic shortest paths, parallel multi-source path, how can I try to write method calls, he then needs to point to production RDD, call monophyletic method to the map, but cannot nested RDD RDD, on the other hand, I can feel he must be parallel, because for every nodes monophyletic path and other irrelevant, just don't know how to parallel, urgent!!!CodePudding user response: