Search code examples
scalaapache-sparkgraphspark-graphx

Implement a directed Graph as an undirected graph using GraphX


I have following directed graph as given by the nodes and edges below.

Nodes

1,2,3,4,5

Edges

(1,2),(1,3),(1,4),(2,5),(3,4),(3,5),(4,5)

How do I convert this directed graph to undirected graph Do I have to convert using built-in method. If there is build in method, what method is it?. Or, do I have to add edges manually in the dataset such as (1,2) to (2,1).


Solution

  • You don't need to convert your graph to an undirected graph. You'll simply have to treat it as an undirected graph (by simply ignoring the edge directions).

    For example, if you use collectNeighbors, you can make it act as an undirected graph by passing an EdgeDirection.Either as parameter.