# Diffusion

In the switch network game we need a way to tell when an uninterrupted path exists from the power source to one of the timers, given that switches along the way can be open or closed, and given that the current can flow along many alternative paths. How can our program determine this?

Each wire segment, represented as agent, has a number of attributes including a voltage. A set of directly connected wire segments is called a node. Each wire segment in a node shares the same voltage. Nodes that are connected to either the + or – lead of the battery will assume the voltage of the lead that they are connected to, e.g., 12 volt or 0 volt. Nodes connected to resistors including bulbs will compute their voltage based on all the resistor values and voltages of other nodes that they are connected to through these resistors.

Specifically, the voltage u of a node connected to n other nodes with a voltage ui through resistors ri will be computed by following equation.If all the nodes and resistors are known, a global solution approach such as Gaussian elimination can be used to solve the resulting system of linear equations be used to determine the voltages of all nodes. But in a distributed simulation based on autonomous agents the Kirchhoff equation can be employed as part of diffusion process. Each node will continuously run the above Kirchhoff equation to gradually compute its voltage.

If the resistances between nodes are all the same, Equation 1 becomes simpler: the value of u becomes simply the average of the u values for the neighboring nodes. When each cell in a grid calculate the value of some attribute by averaging the attributes of its neighbors, the attribute values diffuse through the grid.

In the switch simulation, an switch blocks diffusion (it tells the wires connected to it that it has u=0). A closed switch acts like a piece of wire, and participates normally in the diffusion. As a result the diffusion pattern responds in the right way to changes in switch settings. If the player closes an open switch the diffusion values representing voltage converge quickly to their new values.