If I have several nodes and the distances that they have between one another, how do get Mathematica to display this as a graph?

And also maybe define this graph in such a way that I can then use things like FindShortestTour.

So for a simple example say I had points A,B,C, where:

the distance from A to B is 10

the distance from A to C is 20

the distance from B to C is 15.



closed as off-topic by MarcoB, user9660, Silvia, Kuba, ubpdqn May 13 '16 at 8:25

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – MarcoB, Community, Silvia, ubpdqn
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    $\begingroup$ Welcome! What have you tried so far? $\endgroup$ – Yves Klett Mar 25 '16 at 21:39
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 0) Browse the common pitfalls question 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – Dr. belisarius Mar 25 '16 at 22:05

Here's a somewhat random example to get your started:

g = Graph[
  Range[4], {1 <-> 2, 1 <-> 3, 2 <-> 3, 2 <-> 4, 1 <-> 4}, 
  VertexLabels -> Thread[Range[4] -> CharacterRange["A", "D"]],
  EdgeWeight -> {10, 20, 15, 30, 10}, EdgeLabels -> "EdgeWeight"

Mathematica graphics

FindShortestPath[g, 3, 4]

(* Out:
  {3, 1, 4}
  {75, {1, 4, 2, 3, 1}}

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