Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Given vertices, get a complete graph with edge weights equal to edge lengths
ResourceFunction["WeightedDistanceGraph"][vert] given the list of vertices vert, returns a graph where edges are vertex pairs weighted by their Euclidean distance. |
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]= | ![]() |
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]= | ![]() |
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]= | ![]() |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License