Created
June 5, 2016 21:00
-
-
Save totetmatt/11d642708583579a0e21b208cfa83da7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.spark.graphx._ | |
import org.apache.spark.rdd.RDD | |
val r = scala.util.Random | |
class LayoutData( | |
xp: Double=0, | |
yp: Double=0, | |
dxp: Double=0, | |
dyp: Double=0, | |
old_dxp: Double=0, | |
old_dyp: Double=0, | |
massp:Double=1) extends java.io.Serializable { | |
var x:Double=xp | |
var y:Double=yp | |
var dx:Double = dxp | |
var dy:Double = dyp | |
var old_dx:Double = old_dxp | |
var old_dy:Double = old_dyp | |
var mass:Double = massp | |
} | |
class NodeData(labelp:String,layoutp:LayoutData)extends java.io.Serializable { | |
var label:String=labelp | |
var layout:LayoutData = layoutp | |
} | |
val vertexArray = Array( | |
(1L, new NodeData("Alice",new LayoutData(1,1)) ), | |
(2L, new NodeData("Bob",new LayoutData(2,2)) ), | |
(3L, new NodeData("Charlie",new LayoutData(3,3)) ), | |
(4L, new NodeData("David",new LayoutData(4,4)) ), | |
(5L, new NodeData("Ed",new LayoutData(5,5)) ), | |
(6L, new NodeData("Fran",new LayoutData(6,6)) ) | |
) | |
val edgeArray = Array( | |
Edge(2L, 1L, 7), | |
Edge(2L, 4L, 2), | |
Edge(3L, 2L, 4), | |
Edge(3L, 6L, 3), | |
Edge(4L, 1L, 1), | |
Edge(5L, 2L, 2), | |
Edge(5L, 3L, 8), | |
Edge(5L, 6L, 3) | |
) | |
val vertexRDD: RDD[(Long, NodeData)] = sc.parallelize(vertexArray) | |
val edgeRDD: RDD[Edge[Int]] = sc.parallelize(edgeArray) | |
val graph: Graph[NodeData, Int] = Graph(vertexRDD, edgeRDD) | |
graph.vertices.foreach(println) | |
graph.vertices.join(graph.degrees).foreach(A => A._2._1.layout.mass += A._2._2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment