As mentioned in a previous post, this isn't really about the shortest route, more the efficient use of the available drivers, which is a quite difficult to quantify.
People should really give the TSP a rest here as a potential solution. Your problem is only roughly related to a TSP this is more a traditional spanning tree or shortest path problem through a directed graph. However, like the TSP an exact solution for this may be extremely difficult to formulate. Graph theory algorithms can likely make a reasonable heuristic giving good solutions. For someone who has linear programming experience I think this would be extremely hard to formulate as an LP (if even possible) and you would probably have to write code to write your formulations prior to passing to an LP solver. I think if you look at my Djikstra algorithm I have most of the data structure components to formulate something that can give a feasible solution. Most likely provide simple heuristics like nearest neighbor to get a reasonable solution. Then from there consider improving algorithms.
I'm trying to get my head around using the following data to create the shortest route between 2 places in a map using VBA in either excel or access. ID Name Connection 1 Connection 2 1 Location1 2 2 Location2 3 4 3 Location3 2 4 Location4 2 5 5 Location5 3 5 So...
www.access-programmers.co.uk
See if I understand the setup
1. I believe it is a multi objective problem
Minimize number of dead ends (stranded drivers)
While minimizing total distance travel
Also it has to be feasible so the total vehicles to move <= Number of drivers * 8 trips
2. Contraints
Driver trips <= 8
3. Inputs. Number of drivers, routes to move number of vehicles.
Things that complicate this is that you can piggyback drivers if a driver arrives at a location with N vechicles required to arrive but some number <N that are leaving.
I will give this a try to formulate this using a spanning algorithm with possibly improving algorithms
Normally you want to do these types of problems using arrays for speed. But I think you need to store a lot of information and inputs so I would do it as a full oop implementation.
The data structure do to this represents a directed graph storing Vertices and Edges. In this case the Vertex are the locations and the edges are the paths between the location.
Class Edge:
--LocationStart (points to a vertex)
--LocationEnd (pointer to a vertex)
--NumberVehicles
Class Edges
-- CollectionEdges - collection class of edges
Class Vertex (Location, Postcode)
--Vertex Name (postcode name)
--TotalCarsToShip (not really needed for the algorithm but store anyways)
--CarsLeftToShip (running count)
--CarsLeftToArrive (runnimgCount)
--PiggyBacks (number of drivers awaiting for piggyback)
--ArrivalEdges (collection of arrival information)
Class Vertices
--Collection class of vertex
Class RoutingProblem
-- AllEdges
--AllVertices
--AllShipments
methods in here to drive the problem
Class Shipment
-DriverID
-VertexStart
-VertextStop
-DriverOrPiggyback
Class Shipments
custom collection recording all movements
I am unclear on starting locations put until that is clear I will assume a driver can start anywhere, but I do think this is important.
Here is an extremely rough algorithm, but I think once I start playing with it I can figure out how to iterate it. After each shipment update the Shipments class which holds the record of all movements to report the plan.
1. Pick a driver and assign starting point
2. Span edges picking nearest neighbor to pick next route. If nearest neighbor is a dead end pick the next nearest neighbor
decrease cars left to ship by 1
decrease cars left to arrive at next node by 1
update the edges number of vehicles by 1
3. "Move" to next vertex you selected
4. Verify that Number to ship >= number to arrive. If Number to ship <= to number to arrive leave driver at node by
updating piggybacks by 1
4a. If you left a piggyback then start routing next driver
4b. if no piggyback left then continue with that driver
5. If the next node has piggybacks determine if the number to left to ship - piggybacks <= Number to arrive (then assign a piggyback) and pick next node. Now next node has to have driver + piggybacks <= Number to ship or it is a dead end.
This gets really complicated in my opinion
Assume Vertex A has 3 vehicles to ship but 5 arriving. So there needs to be 2 piggybacks. There is no easy algorithm to figure out if 3 people (a driver and 2 piggybacks) go to B or if 2 go to B (driver and 1 piggyback) and 2 go to C (driver and 1 piggyback) or all the other possibilities.
I think I would apply the rule if there is a piggyback take them immediately. Then let the last driver take additional.
Once a drive completes 8 trips they are complete
To add complexity I think I would try to code a rollback. If a driver hits a dead end, roll back one vertex and try another path. If all those are exhausted roll back two vertices and span from there. Keep doing until all conditions exhausted and pick the best of the dead end solutions.
Similar to how the dijkstra works.
Questions
1. Is a dead end only when a driver gets stranded or does a driver have to make it back to the start?
2. Can the drivers start anywhere or is there a cost? If you have to drive them to the starts then you may want to send large groups to a location that has a lot to deliver.
After typing this I think you could leverage the flory warshall algorithm i demo here
I'm trying to get my head around using the following data to create the shortest route between 2 places in a map using VBA in either excel or access. ID Name Connection 1 Connection 2 1 Location1 2 2 Location2 3 4 3 Location3 2 4 Location4 2 5 5 Location5 3 5 So...
www.access-programmers.co.uk
You could then start with all potential 8 trip (and less) tours. This would have every start and every path to every end point. Then you could rank these by distance. You send a driver on the best tour. Once all vehicles are delivered from a location all tours that include that location get removed from consideration. I still have to wrap my head around planning for piggybacking to next location, but I think that is a good start.