Friday, 15 December 2017

Rebuilding 470Router to suit me

As I have mentioned, I have been working on a software project to complete my Open University degree. This project was named 470Router - 470 after the code for the OU course - TM470 - and Router as it was intended to be used to create freight car routings for my model railroad. Well, I finished the degree (got a 2.2 and was awarded a B.Sc. Hons) and went off to do other things (mostly building some plastic scale model cars - Gentle Scale Modelling).

Now, I am back onto my model railroad I thought that I would review what I was doing for the software now that I wasn't under time pressure and the need to meet the OU module project requirements. It turned out that, although the software worked, it didn't do a very good job of building way freights. This is quite a complex procedure which has to take account of industry requirements in the towns, collecting empties, delivering loads, gathering everything back up and delivering empty cars back to their home roads. The software that I had developed didn't even look at that last element.

I spent a few days pondering over the state of the project and decided that the logic was way too complex. I had to think of a solution and it came to me - Car Cards! What, you say, back to bits of paper? Not quite. What I had in mind was to develop a set of virtual car cards. The basic problem of the existing software was that everything was run off the car and the industry. There was nothing that summarised the situation for any one car shipment. This is what a car card does perfectly. Therefore, I expanded the database to include a set of car cards. They look like this:

carType boxcar
town Sunset
target Creamery
State e
waitTime 2
destination home
id 1
timeOnSite 0
currentCarID PRR:81146

All of the above data is static (doesn't change) except for the currentCarID which records which car, if any, is using that car card currently and the timeOnSite which counts down the holding time at the industry.

Changing to Car Cards meant that I could implement some of the logic for the routing in a simpler way. I no longer had to deduce what was going on by looking at the industry data, the car data, etc. The whole picture could be deduced from the card. Most of the fields are obvious. However, a few need some explanation. The destination being designated as "home" means - refer to the actual car to see where it gets sent after this card is complete. For an NYC box car, this would be Hartford - as this is our nearest access point theNew York Central (although you could argue for Boston, given that the B&A was wholly owned). A Canadian Pacific car could be sent to either Hartford or Boston as both would give access to the CP system. This field can also be used to hold the ID of another card. This provides for a double trip - a reefer goes to the ice house and then, in this field, it gets redirected to a user of a loaded refrigerator car.  We know that the car is currently at the Creamery because there is an entry in the currentCarID. PRR:81146 is a Pennsylvania Railroad boxcar currently being loaded (we know this because the State field is "e" indicating that the car events are started with a delivery of this car, empty to the Creamery).

The timeOnSite field gets set to the wait time on arrival at the Creamery. There is a cycle of trains representing a single day. At the end of this cycle, the timeOnSite fields for each car is reduced by1 until it reaches 0, in which case the car is regarded as ready for collection.

On collection, the car is assessed for its next move. I, currently,  make no provision for multiple destinations. Loaded cars are collected by the next way freight and shipped in the direction of the train. Hence, loaded cars can go to Hartford or Boston depending on the route of the freight train. Empty cars are assessed against their "home" designation. All SNE (home road cars) are placed in the Sunset yard for further allocation. All other empty cars are shipped to their "home" as described above.

So far, this is meeting my needs. I accept that there is much more that I can do with this but, having spent a lot of time on this, I want to run some trains before hitting the keyboard again.