1
$\begingroup$

I'd like to plot a complete Graph and then compute the Minimum spanning tree of it. I already can make a complete graph out of a list that countrydata gives me:

centerCoordinates = CountryData["Asia", "CenterCoordinates"];
completeGraphAsia = 
 GraphPlot[Table[1, {centerCoordinates}, {centerCoordinates}], 
  Method -> "RandomEmbedding", VertexLabeling -> True]

I tried to make a minimum spanning tree out of it, but it didn't really work... obviously, because the Kruskal MST expects a graph variable, but I couldn't figure out how else to do it:

KruskalMST = MinimumSpanningTree[completeAsia];

Any help appreciated :)

Thank you!

$\endgroup$
  • 1
    $\begingroup$ Please try: g = CompleteGraph[Length@centerCoordinates, VertexLabels -> "Name"] and FindSpanningTree[g, VertexLabels -> "Name"] $\endgroup$ – Mr.Wizard Jun 28 '15 at 10:52
  • $\begingroup$ Thanks @Mr.Wizard unfortunately those two commands crashes mathematica in my case. $\endgroup$ – kimsay Jun 28 '15 at 11:19
  • $\begingroup$ @Mr.Wizard,,,I obviously spent too much time...but posted to illustrate relations between diffierent functions...remain disappointed with `GeoBackground`` issues which I have sent email to Wolfram about... $\endgroup$ – ubpdqn Jun 28 '15 at 11:23
2
$\begingroup$

Just for illustration (and not dealing with distance or other edge weighting):

centerCoordinates = CountryData["Asia", "CenterCoordinates"];
asianames = CountryData["Asia", "Name"];
v = Length[centerCoordinates];
g = CompleteGraph[v, 
   VertexCoordinates -> (Reverse /@ centerCoordinates), 
   EdgeStyle -> Directive[LightGray, Opacity[0.2]], VertexSize -> 1];
st = FindSpanningTree[g, 
   VertexCoordinates -> (Reverse /@ centerCoordinates), 
   EdgeStyle -> Thick];
rules = Thread[Range[v] -> asianames];
hg = HighlightGraph[g, st, GraphHighlightStyle -> "Thick", 
  VertexLabels -> rules]
rcc = Thread[Range[v] -> (Reverse /@ centerCoordinates)];
GeoGraphics[{Red, Line /@ List @@@ (EdgeList[st] /. rcc)}, 
GeoRange -> EntityClass["Country", "Asia"]]

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.