An optimization based architecture for local systems managed by PLC devices