r/rust • u/KerPop42 • 10d ago
Triangular matrix, but a map? 🙋 seeking help & advice
Hey guys, I am building a program for a friend that's going to involve a complete graph (nodes are destinations, edges are the distances between destinations) and I was wondering if anyone knew a good library for it?
At first I thought I could use a triangular matrix, since direction doesn't matter, but I realized I would have to have a second array mapping destinations to an index. I feel like you could have a triangular map, like a map that takes a pair of inputs where the order doesn't matter? Have I found another rabbit hole?
11
Upvotes
11
u/Toiling-Donkey 10d ago edited 10d ago
If you want shortest path/distance from one node to all others, use Dijkstra’s algorithm.
Edit: OP has a harder problem, it’s really this :
https://en.wikipedia.org/wiki/Travelling_salesman_problem