Optimal operation & security analysis of power systems with flexible resources