How to create a bipartite graph in GraphX

人走茶凉 提交于 2019-11-27 07:15:47

问题


I am able to build a graph using a vertexRDD and an edgeRDD via the GraphX API, no problem there. i.e.:

val graph: Graph[(String, Int), Int] = Graph(vertexRDD, edgeRDD)

However, I don't know where to start if I want to use two separate vertexRDD's instead of just one (a bipartite graph). Fore example, a graph containing shopper and product vertices.

My question is broad so I'm not expecting a detailed example, but rather a hint or nudge in the right direction. Any suggestions would be much appreciated.


回答1:


For example to model users and products as a bipartite graph we might do the following:

trait VertexProperty
case class UserProperty(val name: String) extends VertexProperty
case class ProductProperty(val name: String,
  val price: Double) extends VertexProperty

val users: RDD[(VertexId, VertexProperty)] = sc.parallelize(Seq(
  (1L, UserProperty("user1")), (2L, UserProperty("user2"))))

val products: RDD[(VertexId, VertexProperty)] = sc.parallelize(Seq(
  (1001L, ProductProperty("foo", 1.00)), (1002L, ProductProperty("bar", 3.99))))

val vertices = VertexRDD(users ++ products)

// The graph might then have the type:
val graph: Graph[VertexProperty, String] = null


来源:https://stackoverflow.com/questions/33241332/how-to-create-a-bipartite-graph-in-graphx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!