Saturday 25 November 2017

TrafficControl: Time Needed for Reading Network File and a Real Bug

In a previous blog post, I mentioned that it took more time to load a network file. The reason for the delay was that I compiled the program in debug mode. After compiling in debug mode, reading a large network file took some 20-25 seconds. The same operation takes 5 seconds on a release build. However, I'll need a test to benchmark such operations.

A real bug was found when defining an unit test case for the train load passenger method.

For a train with a capacity of 100, the test adds four passengers and later 100 passengers. The expected result is that four passengers will be denied.
The test tries to load more passengers than the train has capacity for. The expected verdict is that the train will be full and that the load method will return the number of passengers that were denied entry to the train.

The load function didn't consider the train capacity or the number of present passengers. This was fixed:

After the fix, the new testcase is passing.

The passenger handling is stubbed. In the future, the program needs to make the passengers plan their journey.

Saturday 18 November 2017

Trains: High Speed Trains... in Sweden???

No one who is reading my blog can question my passion for trains. A part of me would be very enthusiastic about entering a Thalys-like train at Malmö Central, reaching Stockholm two and a half hours later. Another part of me is looking at the numbers.

In two previous blog posts, I've seen that the population is much smaller for Sweden, compared with the lines in France, Germany, Spain and Japan.

Trafikverket (The Swedish Transport Administration) has made an economical assessment of the proposed high speed rail lines. That report saw significant advantages with high speed trains:
  • Increased capacity in the entire rail system, including existing lines.
  • Cargo trains won't slow down passenger trains.
  • Great reductions in travel time (36-64% reduction between Swedish towns along the line)
The value of the benefits were estimated to 150 billion SEK. However, the costs were estimated to be some 409 billion SEK. The return of investment would be 40%, a very poor prospect.

As the rail system in Sweden is already mature, the benefits of such a big project will smaller than the costs and the conclusion from the report is that high speed rail in Sweden will be too expensive.

I agree with that report. Such a project would starve out other investments that are necessary. The money should be used to build on the existing rail network, resolve bottle-necks and maintain the lines properly. High speed rail will starve out other, more efficient improvements.

Saturday 11 November 2017

TrafficControl: Crash When Using a Network Without Coordinates

In a previous blog post, I've seen that the program asserts when using a network without coordinates.

The assert is trigged when the train is in state "RUNNING":

After adding prints, I've seen that the issue comes when the train is in Train::runningState. The train tries to set the new position on the track using this->setTrackPosition.

The train is trying to get coordinates for a position on the track. But as the track has no coordinates, the code asserts.

The program is trying to act on the coordinateList that doesn't exist,
One solution can be to check if the coordinateList has length = 0. If that is the case, return 0. Also, the calling program should check if the track has coordinates. I'll add a boolean hasCoordinates to Track, and a corresponding get method.

The fix for train::setTrackPosition() is:

Saturday 4 November 2017

Trains: High Speed Trains... to Lyon???

In the first blog post about the planned 320 km/h high speed rail in Sweden, I calculated the population along the line from Lund to Järna (Malmö/Copenhagen to Stockholm).

Image credit: Wikimedia Commons
As of 2017, there are only four high speed lines of 320 km/h: Madrid to Barcelona, Paris (eastbound and westbound) and Dijon to Basel.

The following table compares some existing lines with the planned Swedish line. The populations are calculated within a 10 km and a 25 km radius from the stations. For the Swedish line, I exclude and include København in the calculations.

Start End Speed Stations Length Pop 10 km Pop 25 km
Malmö Stockholm 320 km/h 12 460 km 1,6 M/2,5 M 3 M/4,5 M
Paris Lyon 300 km/h 4 427 km 4,3 M 10 M
Paris Strasbourg 320 km/h 5 409 km 4,8 M 10 M
Madrid Barcelona 320 km/h 8 600 km 5,7 M 12 M
Tokyo Niigata 320 km/h 12/5 270 km 8,5 M 26 M

I also added the Japanese Joetshu Shinkanshen line, one of the smaller lines in the Shinksanshen network.

The proposed Swedish line will serve a much smaller population than the other lines. Also, that line has 12 stations, that will make the trains slower. One stop will take some five minutes, according to the time tables for the French/Spanish lines.

For the Paris/Strasbourg line, there are 17 departures per day in each direction. 13 of them doesn't stop between Paris and Strasbourg. A similar tradeoff will be necessary for the train operator in Sweden: Either stop at many stops, using the stations that are built but also making the train slower, or travel directly between Malmö/Copenhagen and Stockholm, passing several important stations without stopping.

Intermediate conclusion: 
Sweden has a much smaller population density and smaller cities than the European countries. The demand for travels will be much smaller than for the existing lines.