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.)
- The data files
cities.txt and roads.txt
- The utility and data handling files:
- Simple utilities
utilities.c and utilities.h
- Data handlers
data.c and data.h
- Special data structures for AI solutions
aiutils.c and aiutils.h
- Solution extractors for AI solutions
ai.c and ai.h
- The actual code for the algorithmic solution
algorithmic.c and algorithmic.h
- The actual code for the basic (infinite) AI solution
bai.c
- The actual code for the slightly improved (loop-free) AI solution
sai.c
- The three main programs:
- To run the algorithmic solution mainalg.c
- To run the basic (infinite) AI solution mainbai.c
- 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.