Competition And Optimization In Electricity Systems