Optimizing Control of Distributed Cyber-Physical Systems