Contingency analysis and mitigation