Developing an Optimized Intelligent Security Framework for Cyber-Physical Systems