Group Abstract Group Abstract

Message Boards Message Boards

Subpaths in a Graph

Posted 10 years ago
POSTED BY: Bruce Colletti
Posted 10 years ago

Tech Support said to check out FindClusters (really neat). It works for this example whose output correctly groups the arcs into the associated subpaths:

L = {{1, 2}, {3, 4}, {2, 1}, {4, 5}, {9, 10}, {5, 8}};
FindClusters[L, DistanceFunction -> (Abs[Last@#1 - First@#2] &)]

{{{1, 2}, {2, 1}}, {{3, 4}, {4, 5}, {5, 8}}, {{9, 10}}}

Unfortunately, it fails for this example that puts all arcs into one list:

L = {{1, 2}, {3, 4}, {2, 1}, {4, 5}, {7, 8}, {5, 6}, {8, 9}, {11, 12}, {12, 13}, {13, 14}, {16, 17}, {30, 50}};
FindClusters[L, DistanceFunction -> (Abs[Last@#1 - First@#2] &)]

{{{1, 2}, {3, 4}, {2, 1}, {4, 5}, {7, 8}, {5, 6}, {8, 9}, {11, 12}, {12, 13}, {13, 14}, {16, 17}, {30, 50}}}

How could DistanceFunction be modified to correctly handle both examples?

POSTED BY: Bruce Colletti
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard