CIS 554 Clojure 3: Vehicle Routing
Fall 2014, David Matuszek

# Purposes of this assignment

• Introduce you to STM (Software Transactional Memory)

# General idea of the assignment

You are in charge of a small fleet of delivery vehicles. Each day there are deliveries to make to a number of locations. Your task: Given the locations that must be visited, produce routes for each vehicle that minimizes the total distance traveled.

# Details

A location is represented by a pair of integers, `[x y]`. To keep things relatively simple, the distance between two locations` [x1 y1]` and` [x2 y2]` will be the Manhattan distance, that is, `abs(x1 - x2) + abs(y1 - y2)`.

Each vehicle will start at a central location, `[0 0]`, make deliveries to some number of locations, and return to the central location. The problem is to decide which locations each vehicle will visit, and the order in which to visit those locations, so as to minimize the total distance traveled by all the vehicles.

This is an NP-complete problem, that is, a perfect solution requires exponential time--time which you will not have. Therefore, the assignment is to start with one or more (probably extremely bad) route assignments, and by trial and error, gradually improve the route assignments until you have something reasonable.

I will add one additional constraint to this problem, namely, that every vehicle should visit the same number of locations, plus or minus one (because the number of locations may not be a multiple of the number of vehicles).

## Use of STM

You should use STM to keep track of the following data: For each vehicle, which locations it visits, and in which order; and the total distance traveled by all vehicles. Each time a better solution is found, use a transaction to replace the previous best known solution, and print the new best distance, along with which vehicle found it.

You should have several agents each working on the complete problem, vying with one another to produce better and better solutions. You can use additional "helper" agents if that seems desirable or useful.

## Plan of attack

Here's what I would do; you might prefer a different approach.

I would assign the locations to the vehicles, possibly randomly, possibly a little more intelligently. Then I would find a best route through those locations for each vehicle--this is the Traveling Salesman problem, which itself is NP-hard, but I'll keep the number of locations per vehicle fairly small.

After that I would randomly swap a pair of locations between two vehicles, find the best route for each, and see if that is an improvement; if not, put the locations back where they were in the respective routes.

At any point my agents might take the current best plan, rather than the one they have been working to improve, and use that as a new starting point.

This approach depends on trying a very large number of possible route assignments. You are welcome to use heuristics to do a more intelligent job, but begin by "doing the simplest thing that could possibly work" and, if you have time and inclination, improving on that solution.

## Approximate numbers

While your program should accept any inputs, you can expect numbers in these ranges:

• Four to eight vehicles.
• Four to eight locations per vehicle (hence, 16 to 64 locations to visit).
• Four to eight agents working on the main problem. You can set this number yourself, but it should be easy to modify.
• `x-y` coordinates between -100 and 100.