When the cables and relays have the data required, the order in a sequence and linked to a generator I don't see the issue. You remove a cable, you gather its order and linked generator, then every cable with the same generator ID after it is switched off. You don't need a function, you run these actions on cable removed by whatever method.
You don't need to use functions here imo or any overlap checks. When you create a cable, you take its start point gen ID, this could be from a generator or relay, and on the destination point, you then create the cable and assign that gen ID to the destination whether it is a relay or machine. Also taking into account the number in the sequence since that matters as you have a mechanic where you can remove cables.