Analysis and Application of Optimization Techniques to Power System Security and Electricity Markets