mikeash.com: just this guy, you know?


by Michael Ash

Download ChemicalBurn (104K) Requires Mac OS X 10.4 or later.

ChemicalBurn is a screensaver that simulates a transportation network. Packages are generated with a destination, and attempt to find the fastest way there. Frequently used routes get faster, making them more popular. The result is a beautiful self-organizing network colorfully displayed on your screen.

ChemicalBurn is open source. You can view the source code on its GitHub page. ChemicalBurn is released under the MIT License.

New in 1.1.4:
• Fixed large memory leaks when running in 64-bit mode.

New in 1.1.3:
• Full compatibility with Mac OS X 10.6 Snow Leopard.

New in 1.1.2:
• Fixed two bugs which could cause the routing algorithm to fail, freezing or crashing the screensaver.

New in 1.1.1:
• Fixed deadlock in threading code, added watchdog thread to terminate gracefully in case of other deadlocks.

New in 1.1:
• ChemicalBurn is now multithreaded to take advantage of multicore and multiprocessor Macintoshes.

How it Works
Nodes are randomly generated on the screen. Initially, all connections are equally slow. Packages are generated randomly as the screensaver runs. Each package is generated at a random node, and has another random node set as its destination.

As packages flow through a connection, the connection is strengthened and becomes faster. A disused connection gradually weakens. This is analogous to real-life computer and transportation networks, where the connections with the most traffic get more infrastructure investment and become even faster.

The result is a self-organizing network with complex structure, as popular routes are reinforced with even more traffic, and hubs, rings, and other structures form spontaneously from the simple rules.

If enabled, nodes will be created and destroyed at random during the simulation. When a node is destroyed, it is not immediately removed from the network. Instead the node and its connections turns red, packages are forbidden from using that node in their routes and packages with the destroyed node as their destination are re-routed elsewhere. Once all packages are clear of the destroyed node, it is removed from the screen.

ChemicalBurn has several options to allow you to customize it and explore the consequences of different equations on the networks it forms.

Traffic Weighting
As more traffic flows through a connection, it reinforces and becomes faster. The relationship between the number of packages flowing and the speed of the connection can be changed.

Distance Weighting
Normally the length of a connection is just the distance between the two nodes, but this can be altered. This has the effect of changing the speed of longer connections compared to shorter ones. The settings are similar to Traffic Weighting with the exception of Bell, which is removed as it doesn't make sense here.

Create/Destroy Nodes at Random
If checked, nodes will be created and destroyed at random. The rate is adjusted to keep the total number of nodes close to the desired amount. If unchecked, the network will remain static except for the changes in connection weighting.

Package of Death
When unchecked, nodes are created and destroyed at random. When checked, nodes are created at random but destroyed using a special Package of Death. This package is displayed onscreen as a red triangle. Unlike other packages, it is never delivered, but when it reaches its destination it immediately chooses a new destination and keeps moving. Every node it touches is destroyed. Its speed is adjusted to keep the number of nodes close to the number desired.

Number of Nodes:
Sets the number of nodes visible on screen. If Create/Destroy Nodes at Random is checked, this number is merely approximate.

The number of nodes has a drastic effect on performance. Most of ChemicalBurn's time is spent finding the optimal route for the packages. This has to be done when a package is generated, and is redone every time the package reaches a new node, as conditions may have changed while it was in transit. The route-finding algorithm takes a time that is approximately proportional to the square of the number of nodes.

Worse, the number of route-finding operations increases as the number of nodes goes up. There are more packages generated, and each package needs individual route-finding. More nodes tends to have networks with more steps, which also increases the number of route-finding operations.

In the end, the CPU time spent is proportional to the cube or fourth power of the number of nodes. The default value of 100 runs well on my high-end G4. Increase it if you have a fast computer and like a busy screen. Decreasing it can drastically cut the amout of CPU power used while still presenting a very pretty screensaver.

Download ChemicalBurn (104K)

ChemicalBurn is © 2006 by Michael Ash. http://mikeash.com/

Hosted at DigitalOcean.