|
Adventures in Trainz Artificial Intelligence
By John D'Angelo
“Open the pod bay doors, Hal…I said open the pod bay doors, Hal…Hal?”
Remember those words from the movie 2001? That was an example of artificial intelligence going crazy! I remember reading a book quite a few years ago by David Heiserman dealing with robotics and artificial intelligence. Using his book, I wrote a program in BASIC to create a little artificial life form that wandered about the computer screen, bumping into the edges of the screen and turning away from the barrier. Artificial intelligence, also known as AI has really advanced since those early days, and today you can hear someone say “Geoff, go to the right of that signal…. No, no, the RIGHT!” Good old artificial intelligence, it REALLY keeps you on your toes!
Sometimes the computer-brained engineer can do things that boggle the human mind and, to tell the truth, I am STILL experiencing days when I say to myself “Geeeez, I never thought he’d do THAT!”
Although I am not a programmer and have not seen the code for the Trainz programs, I can say that there are basic AI instructions that have been programmed in for the engineer to follow when running under AI control. I think these three instructions are embedded in the program:
- If you are traveling along and the left lane becomes available, take it.
- If you are traveling to a destination, take the shortest route.
- Look ahead to the next signal to determine your speed.
All three directives are quite logical to the programmers, yet sometimes they can generate unexpected results.
One of the basic reasons why I have experienced some unusual situations with Trainz AI is that I live in the United States and the folks who created the Trainz program live in Australia. Don’t get me wrong, I think Australians are great, and are very much like us Americans, but they just drive on the wrong side of the road. Of course they would say that it is we who drive on the wrong side of the road!
Our railroads follow the same procedure as our roads and on tracks with two lanes; trains will normally pass each other on the right. Australian and UK railroads normally will pass on the left. When a locomotive is driven in manual mode and the switches are thrown by you, the artificial intelligence is not called into play. If you decide that you want to let the computer run the train and the routing, that’s where things can get interesting!
With rule one active in the programming, I found that on long two tracked runs where I wanted the trains to pass to the right of each other, they sometimes didn’t behave. In one case, before they came close to each other, one train had a crossover available so that it could take the left lane. It would switch over and proceed on the left track because the signaling had not yet detected the other train. Eventually they would meet on that track and sit facing each other while generating exclamation marks all over the place, essentially saying “What do we do now?”
In this example of one problem that I had, the crossovers were there so that trains running in each direction could stop at a single platform station. The train running on the eastbound track could cross over to the station track, pick up the passengers and then cross back onto its own route again. See figure 1.
Figure 1.
The green boxes represent the approach signals. Without “fixing” the programming, an eastbound train would take the crossover to the station platform, load the passengers, but then continue eastward on the westbound track without taking the next crossover to the eastbound track! A westbound train that was scheduled to stop at the station would come and stop at the platform, load the passengers, but then take the crossover to the eastbound track and continue going west on that track. The problem was being caused by that embedded instruction to take the left-hand track.
The way I corrected this problem was to use the Track Direction Marker device found in the Add Trackmark menu in Surveyor.
Track Direction Marker.
The Track Direction Marker is a yellow marker and you adjust it to point out the direction of travel that is allowed. In the above screen shot, the marker has been placed so the oncoming train will not cross over to the left-hand track. An additional marker has been placed at the other end to keep a train from going along the left track after it completes the station stop in the other direction. The marker locations are shown in figure 2.
Figure 2.
Using this system I have successfully had trains come from east and west and load their passengers and then proceed on the proper track. In close meets, where both trains need to go to the station platform, one train will be held properly by the outbound approach signal until the first train has cleared the station area.
The second rule, although it is quite logical, can also result in some strange actions by your driver. I have had trains suddenly run backwards to a destination on a model of an HO style loop railroad, because the distance to the destination was a bit shorter if the train ran in reverse. Obviously the rule really was created with a more true-to-life point-to-point track plan in mind, but many people still enjoy creating loop style routes.
Another effect of this rule, that I discovered on my George’s Gorge route, was when I sent the train to the Eastville portal, the train left the main line and ran through the industrial track at the Hillside Mines yard instead of proceeding along on the main line.
Taking the industrial track
The reason why the train took the industrial track instead of staying on the main line was because the route bends to the right. Taking the industrial track was the shorter way to go. It worked, but I really preferred that the train stay on the main line.
One method I used to correct the backwards running train and the train that departed from the main line was to use markers. The markers are red in color and do not control the direction of the train, but they give a reference position on the track. You can place a marker on the track and then instruct the driver to go to a destination via that marker or even stop at that marker.
I personally like to use an interlocking tower or signal box in conjunction with markers. Terry Franks (Tafweb) has a number of great looking signal boxes available from his web site. One of the features his signal boxes have that I really like is that they can be named. I use an alphabetical naming system for my interlocking towers, starting from the west of the route they are labeled A, then B, then C, etc. I give the tower a name based on the letter. Tower “G” would be the letter of the tower I would place here and I named it “George.” The tower was placed on the main line past where the turnoff to the industrial siding was.
I then placed two markers on the main line in front of the tower, one on the eastbound track; the other on the westbound track. I named the markers TGE and TGW, (Tower George East, Tower George West).
George Tower with markers.
When programming the instructions to the driver, I programmed him to drive via the TGE marker to the Eastville portal.
Programming the driver.
Now the train will stay on the main line as it passes through the Hillside Mine area. The markers and tower can also be used on a large loop route, between two distant stations to ensure the train will move forward via the marker to the destination.
The final rule of the group allows the engineer to slow down in anticipation of a red signal. The Trainz signaling system is based on a system called “look ahead.” Signals are normally red until the train approaches. As the train gets closer the signal will change from red to yellow and finally to green, if the path ahead is clear. I had found that for some reason on another route of mine that the train was slowing down to half speed on long runs that were clear. It should have been cruising at the posted speed limit, since there were no trains ahead, but under the AI control, the driver went at the caution speed.
Train running at caution speed.
I think the problem here was that the signal looks down the track for a shorter distance than the AI driver looks ahead. The driver was looking far ahead to a signal that had not detected the train yet, and was still in the default red condition. Seeing red in the distance, the driver slowed to caution speed. The rule makes good sense, when you look at the conditions involved; you just need to understand what is happening and how to work within the rule’s parameters. The fix for me was quite simple. I just placed additional signals along the route so the AI driver did not have a long non-signal distance to contend with. From then on, the AI driver was able to move along at the posted speed as long as the track was clear ahead.
Train now running properly (note the green signal).
I hope this article has been of use to you and helps you to enjoy running your trains more. It’s also a good idea to keep your drivers happy!
John
More Articles:
[Visit the VR Reading Room.]
If you want to be notified when a new article arrives, join the VR-News group at Yahoo. This group is purely for notification. Anyone can join; only the moderator can post.
�2006 John D'Angelo. All rights reserved.
If you want to be notified when a new article arrives, join the VR-News group at Yahoo. This group is purely for notification. Anyone can join; only the moderator can post.
�2006 Alfred Barten. All rights reserved.
|