I trying to process the edges of a map. Each edge represents a path between two nodes as shown in the figure
From the map data I have, I am able to get this kind of data structure.
output: ArrayBuffer((1,4), (1,2), (2,4), (2,1), (2,3), (2,5), (3,2), (3,5), (4,1), (4,2), (5,2), (5,3))
The goal is to join connected segments/paths to calculate the combined length. The order of joining doesn't matter here as I only need to find the combined length after joining, to check if it satisfy a given condition. The possible joining segments could be:
>(1,2,3) [or even 3,2,1 as order doesn't matter]
>(1,2,5) or (5,2,1)
>(4,2,3) or (3,2,4)
>(4,2,5) or (5,2,4)
The problem here is: I should not consider paths like (1,2,4), (1,4), (3,2,5) or (3,5) as they are not feasible paths. I am trying to implement this in Spark using Scala as real data is huge map data. As I am new to this domain, any help would be greatly appreciated. P.S: I have the source from where I can get the length of each path/segment to add those lengths together after knowing which segments should be joined together.
UPDATE
processing each node for a given link gives me this: output:
ArrayBuffer((1,List()), (1,List(4, 2)), (2,List(4, 1)), (2,List(3, 5)), (3,List(2, 5)), (3,List()), (4,List(1, 2)), (4,List()), (5,List(2, 3)), (5,List()) (1,List())
because left node of this segment is not connected to any other segment and we can actually ignore all these single segments from our resulting structure. I got this final structure using scala map and flatmap function output:
ArrayBuffer((1,4), (1,2), (2,4), (2,1), (2,3), (2,5), (3,2), (3,5), (4,1), (4,2), (5,2), (5,3))