Lets say I have an array of vertices and I want to create edges from them in a way that each vertex connects to the next x vertices. x could have any integer value. Is there a way to do that with Spark?
This is what I have with Scala so far:
//array that holds the edges
var edges = Array.empty[Edge[Double]]
for(j <- 0 to vertices.size - 2) {
for(i <- 1 to x) {
if((j+i) < vertices.size) {
//add edge
edges = edges ++ Array(Edge(vertices(j)._1, vertices(j+i)._1, 1.0))
//add inverse edge, we want both directions
edges = edges ++ Array(Edge(vertices(j+i)._1, vertices(j)._1, 1.0))
}
}
}
where vertices variable is an array of (Long, String). But the whole process is of course sequential.
Edit:
For example, if I have vertices as such: Hello
, World
, and
, Planet
cosmos
. I need the following edges: Hello -> World
, World -> Hello
, Hello -> and
, and -> Hello
, Hello
-> Planet
, Planet -> Hello
, World -> and
, and -> World
, World -> Planet
, Planet -> World
, World -> cosmos
, cosmos -> World
, and so on.