I would set variable/boolean "hasPower" for each Cable, Relay and Generator.
Generator would have power set 1 by default.
If Cable overlaps Generator & Generator hasPower==1, set Cable hasPower 1.
If Cable overlaps Relay & Cable hasPower==1 & Relay hasPower==0, set Relay hasPower 1.
If Cable overlaps Relay & Cable hasPower==0 & Relay hasPower==1, set Cable hasPower 1.
Things get problematic when you want to add shorts:
If Cable overlaps Relay & Cable hasPower==1 & Relay hasPower==1, run function "ElectricShort".
This would be set immeadetly when unpowered Cable is overlapping with powered Relay. To tackle this, power cable could be split in two + & - side and check for those instead.
If you do not want to run this all the time, put it into function and set it for each Cable.
But in this case the function has to run from cable starting from generator first!
Haven't tested it, but this is how I would start making it.