Shortest Path Programs from Second Week


(I know there are too many files here, I thought it kept things simpler to split them up like this, but now I'm not so sure. Maybe at some point in the near future I'll recombine them a bit differently. Whatever I do, they will remain functionally the same, so don't worry about things changing significantly while you're working.)
  1. The data files cities.txt and roads.txt
  2. The utility and data handling files:
    1. Simple utilities utilities.c and utilities.h
    2. Data handlers data.c and data.h
    3. Special data structures for AI solutions aiutils.c and aiutils.h
    4. Solution extractors for AI solutions ai.c and ai.h
  3. The actual code for the algorithmic solution algorithmic.c and algorithmic.h
  4. The actual code for the basic (infinite) AI solution bai.c
  5. The actual code for the slightly improved (loop-free) AI solution sai.c
  6. The three main programs:
    1. To run the algorithmic solution mainalg.c
    2. To run the basic (infinite) AI solution mainbai.c
    3. To run the slightly improved (loop-free) AI solution mainsai.c

Note

Different computers and compilers have a nasty habit of doing things slightly differently even though they all claim to be standard. I have made all these files so that they can easily be adjustable for the two systems I usually use (GNU for BSD (a type of unix) on rabbit) and (WATCOM for Windows on a PC). All the adjustable bits have been squeezed into one tiny area inside utilities.h and utilities.c. If you find you need to make changes for your own favourite compiler, you should be able to make a similar adjustment in the same place.

Running It

To run these, first compile the all:
          cc -c *.c
Then (because there are three versions of the main program) either delete or hide the unwanted ones:
          rm mainbai.o mainsai.o
The link all the surviving object files:
          cc *.o -o run
Then run the program:
          run
(If your path is not set up correctly, just typeing "run" won't work, you'll have to type "./run" instead. If you find that annoying, correct your path and it'll go away.)

The above sequence will run the algorithmic solution. If you then want to see one of the AI solutions, either repeat all the steps (probably easiest but a little wasteful) or (if you want to be clever about it) remove the object file for the version of main that you just ran:
          rm mainalg.o
Create the object file for the version of main that you want to run now:
          cc -c mainbai.c
Link everything again:
          cc *.o -o run
and run it:
          run


All this deleting and relinking is annoying. I used to have all three versions of the program in one single main.c, which is a lot more convenient. When you run it it just asks wich version you want. Unfortunately, the program got unnecessarily big and ugly, so I went for the three separate versions instead.