Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. graph = (Uncompress@*FromCharacterCode@*
  2. Flatten@*(ImageData[#1, "Byte"] &)@*Import)[
  3. "https://ooo.0o0.ooo/2017/02/27/58b427c17047e.png"]
  4.  
  5. weightGraph =
  6. Graph[graph,
  7. EdgeWeight ->
  8. Thread[EdgeList[graph] -> EuclideanDistance @@@ (EdgeList[graph])]]
  9.  
  10. clusters =
  11. FindClusters[VertexList[weightGraph], 8,
  12. DistanceFunction -> (EuclideanDistance[#1, #2] +
  13. GraphDistance[weightGraph, #, #2] &), Method -> "KMedoids"];
  14. Graph[weightGraph,
  15. VertexStyle ->
  16. Catenate[Thread /@ Tuples[clusters -> {Unevaluated@RandomColor[]}]],
  17. VertexSize -> {"Scaled", 0.02}]
  18.  
  19. edges = Select[
  20. Subsets[TakeLargestBy[EdgeList[weightGraph],
  21. EuclideanDistance @@ # &, 20], {7}],
  22. Length[ConnectedComponents[EdgeDelete[weightGraph, #]]] == 8 &]
  23.  
  24. edge7 = First[
  25. MinimalBy[
  26. edges, (g = ConnectedGraphComponents[EdgeDelete[weightGraph, #]];
  27. Total[MapThread[
  28. Function[{graph, ver}, GraphDistance[graph, #] & /@ ver], {g,
  29. VertexList /@ g}], 3]) &]]
  30.  
  31. EdgeDelete[weightGraph, edge7]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement