this is a deceptively complex math/geometry task.
If you google ‘Travelling salesman problem’ (as mentioned in the post link from Ewan) you will see what I mean.
Not the right answer for a Dynamo forum, but I have done something similar using QGIS (free/opensource)- which has algorithms specifically for working out nearest neighbours or shortest path. It is actually quite easy- just need some CAD lines, as shown in the example below.
You basically simplify using line to lines represent possible paths- and can calculate a distance matrix between points on the network, or a shortest path between points
There are some packages for Dynamo to use this information