Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- graph = (Uncompress@*FromCharacterCode@*
- Flatten@*(ImageData[#1, "Byte"] &)@*Import)[
- "https://ooo.0o0.ooo/2017/02/27/58b427c17047e.png"]
- weightGraph =
- Graph[graph,
- EdgeWeight ->
- Thread[EdgeList[graph] -> EuclideanDistance @@@ (EdgeList[graph])]]
- clusters =
- FindClusters[VertexList[weightGraph], 8,
- DistanceFunction -> (EuclideanDistance[#1, #2] +
- GraphDistance[weightGraph, #, #2] &), Method -> "KMedoids"];
- Graph[weightGraph,
- VertexStyle ->
- Catenate[Thread /@ Tuples[clusters -> {Unevaluated@RandomColor[]}]],
- VertexSize -> {"Scaled", 0.02}]
- edges = Select[
- Subsets[TakeLargestBy[EdgeList[weightGraph],
- EuclideanDistance @@ # &, 20], {7}],
- Length[ConnectedComponents[EdgeDelete[weightGraph, #]]] == 8 &]
- edge7 = First[
- MinimalBy[
- edges, (g = ConnectedGraphComponents[EdgeDelete[weightGraph, #]];
- Total[MapThread[
- Function[{graph, ver}, GraphDistance[graph, #] & /@ ver], {g,
- VertexList /@ g}], 3]) &]]
- EdgeDelete[weightGraph, edge7]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement