What Was I Thinking?
June 12, 2002
Traveling Salesman

First, credit where credit is due. The basic graphics engine I got from "Learn Computer Game Programming with DirectX 7.0" by Ian Parberry. That is, setting up DirectX, the sprite drawing routines, Windows message pump, that sort of thing. The line drawing algorithm is the Bresenham algorithm, which I downloaded from GameDev.net. Using those tools to the ends displayed here is pretty much my creation.

To use the program, find and open up the file "Settings.txt." There are four numbers inside.
1. The number of points to be randomly generated. There's not much point in using less than three, and the program is written for a maximum of 100.
2. The number of simultaneous paths to be calculated. This is a number from 1 to 4. The theory was that every path would eventually converge on the same ideal solution, so the fewer different colors you see on the screen, the better the answer. In practice, this really just slows things down without accomplishing much, although it is nice to look at, what with the multiple colors and all.
3.& 4. These numbers allow you to manipulate the random factor. The first number is the value the random number generator must roll under. The second number is the range of values the random number generator will roll against. The range is 1 to value #4. If value #3 is zero, there will be no randomness. Value #4 can be any amount up to roughly 4 billion, but keep it to 8 digits or less to avoid a memory leak, and value #3 should be less than value #4.

THERE IS NO SAFETY NET BUILT IN TO CHECK THESE VALUES. I AM NOT RESPONSIBLE IF YOU BREAK SOMETHING.

Choose the settings you want, making sure there is a newline after the last number. Do not leave a blank line between any numbers, and do not put any text in the file next to the numbers. Also, don't put commas in the numbers.

Then, run the program. The points will be randomly generated, the connection lines drawn, and the optimization automatically started.

If you run this program without a randomness factor, odds are very good it will get stuck in a configuration that is less than ideal, but that looks good to the program. If the random factor is too high, any progress made by the program via the application of the rules will be overwhelmed. It's a balancing act. I find two plus one per 20 points, over a range of 300 is a ratio that produces good results.

As yet, there is no way to tell the program a series of points you want it to work with. Nor is there any way to save a particular layout so you can come back to it later. You can, however, hit Alt-Tab to cycle out of the program and let it run in the background while you do other things.

To end the program, hit Escape.

There are two numbers in the upper left corner of the screen. The upper number is the total length of the blue path. If you are running a single path, it will be the blue one. The lower number is the length of the shortest path so far discovered.

There are three views, which you cycle through by clicking the mouse. The default view shows all the paths currently being optimized, as well as the current best path. One mouseclick brings you to the ideal path, in grey. Only the shortest path, whose length is the lower number in the upper left of the screen, is displayed. Click again, and only the paths in progress are displayed, without the ideal path being shown.

The program runs in 800x600 resolution. I believe that if your computer can't handle such resolution, the program will end itself.

The graphics files are in no way protected. If you don't like the color scheme, go in and change it. I won't stop you. They were created with Windows' Paint program. Just make sure you put anything you change in the same location as the old graphics.

Don't claim this as your own work (as if you would want to). To the extent I am allowed by law, I reserve copyrights and any other rights that might be lyin' around not doin' nothin'.

Download Traveling Salesman


Warning: include(/home/sekimori/public_html/david/sidebar.php) [function.include]: failed to open stream: No such file or directory in /home/sekimori/public_html/david/archives/cat_programs.php on line 113

Warning: include() [function.include]: Failed opening '/home/sekimori/public_html/david/sidebar.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/sekimori/public_html/david/archives/cat_programs.php on line 113