Friday, July 14, 2006

Fist thing finds me trying to track down a strange bug. The whole system is ment to run of one random seed, so that by changing one number you get a similar, but different city. I ran into problems becuase I kept getting different cities for the same number, and traced the problem into the Voronoi routine.

The strange thing is computer programs should be deterministic - given the same input they shuld create the same output, there is nothing else they can do unless some outside system changes something. After checking that there were no calls to Random in the Voronoi package I checked there was only one thread running at a given time. Both looked ok. After more digging it turned out that the Java library HashMap was to blame.

I guess some optimisation in java reuses objects, and this in someway sets up HashMap so it is different every time. The return order of a HashMap is also non-deterministic aka 'different every time'. Switching to a LinkedHashMap fixes the problem with minimal (programmer) overhead.

No comments:

Post a Comment