Function Repository Resource:

# WeightedDistanceGraph

Given vertices, return a complete graph with edge weights equal to edge lengths

Contributed by: Ed Pegg Jr
 ResourceFunction["WeightedDistanceGraph"][vert] given the list of vertices vert, returns a graph where edges are vertex pairs weighted by their Euclidean distance.

## Examples

### Basic Examples

The output based on the Kreisel–Kurz integral heptagon looks like a random complete graph:

 In[1]:=
 Out[2]=

The graph has edge weights:

 In[3]:=
 Out[3]=

### Scope

The Wolfram Language has several graph functions that work on point sets that do not return weighted graphs. Operations on graphs without proper weighting can return unexpected results:

 In[4]:=
 Out[4]=

With weights given to edges, a method like Kruskal’s algorithm can work as expected:

 In[5]:=
 Out[6]=

With weights given to edges, a method like Prim’s algorithm can work as expected:

 In[7]:=
 Out[7]=

### Possible Issues

Using weighted graphs for finding a minimal spanning tree does not scale up well for larger graphs:

 In[8]:=
 Out[8]=

In these cases it is better to go right to the algorithm, which is several thousand times faster:

 In[9]:=
 In[10]:=
 Out[10]=

## Requirements

Wolfram Language 11.3 (March 2018) or above