Here is the idea I had for a while. Different wiring model. Main advantage of this is that it uses by far less CPU time, virtually zero. Also, it is somewhat more realistic and easy to understand.
All wires, connected to each other, form a single "circuit". Circuit works as a single entity, no calculations per wire is needed until some wire is added or removed to circuit.
Circuit has following two parameters: resistance and capacity. Resistance is a sum of resistances of all wires in it. It is a number of EU that is consumed per cycle by circuit itself. Capacity is a minimum capacity of all wires in circuit. When more than this value of energy flow passes through, then weakest wire in it (one at random) burns out.
All machines that generate or consume energy have at most one In and at most one Out. They have "Normal" and "Maximum" values of power that they can provide or consume. I'll call them NormGen and MaxGen for generators of power and NormLoad and MaxLoad for consumers of power.
"Normal" is a "best scenario" power, between Norm and Max is OK, below Norm is undesired, more than Max is impossible.
Most machines have equal Max and Norm. Power storages have NormGen and NormLoad at zero. Machines that are not working at the moment have everything at zero, naturally.
Real energy provided and consumed is calculated this way.
0. If SumMaxGen < Resistance then circuit just does not work. Same when there is noconsumers or no generators. Otherwise resistance is subtracted from power: SumMaxGen -= Resistance; SumNormGen -= Resistance
Then one of four scenarios works:
1. If SumMaxGen < SumNormLoad, then Flow = SumMaxGen. Each generator works at their maximum, while each consumer receives energy proportionally to their NormLoad
2. Else if SumNormGen <= SumNormLoad <= SumMaxGen, then Flow = SumNormLoad. Each consumer works at normal power, and each generator provides their NormGen, and remaining power is taken proportionally to difference between MaxGen and NormGen
3. Else if SumNormLoad < SumNormGen <= SumMaxLoad, then Flow = SumNormGen. Each generator works at normal, while consumers take their Normoad and the rest proportionallly to difference between MaxLoad and NormLoad
4. Otherwise (that is, if SumMaxLoad < SumNormGen) each consumer works at max, while each generator provides energy proportionally to their NormGen, if they can, or their NormGen if they can't give less then NormGen. Flow is calculated accordingly.
These calculations are made only when circuit or some machine connected to it changes it's parameters, like generator running out of fuel or processor running out of raw materials. If machines are designed so they don't switch on and off too often, then calculation could be done only each 5 seconds or so at most.
Another side effect of this model is that machines work at more stable environment, so we can do less calculations for machines, using extrapolations. For example, if macerator have enough power and coal to work for 1 minute, then we can just forget about it for one minute, or until power flow changes, and then just convert coal to dust in bulk.
That's it. I don't have to carry it in my head any more, so I can put other things in it