頂点の配列があり、各頂点が次の x 頂点に接続する方法でそれらからエッジを作成したいとしましょう。x には任意の整数値を指定できます。Sparkでそれを行う方法はありますか?
これは私がScalaでこれまでに持っているものです:
//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))
}
}
}
ここで、頂点変数は (Long, String) の配列です。しかし、プロセス全体はもちろんシーケンシャルです。
編集:
たとえば、次のような頂点があるとHello
します。次の辺が必要です: , , , , -> , , , , , ,など。World
and
Planet
cosmos
Hello -> World
World -> Hello
Hello -> and
and -> Hello
Hello
Planet
Planet -> Hello
World -> and
and -> World
World -> Planet
Planet -> World
World -> cosmos
cosmos -> World