@@ -0,0 +1,1433 @@
+from __future__ import print_function, division%0Afrom __future__ import absolute_import%0A%0Aimport pypsa%0A%0Aimport numpy as np%0A%0A%0Adef test_sclopf():%0A%0A%0A    csv_folder_name = %22../examples/scigrid-de/scigrid-with-load-gen-trafos/%22%0A%0A    network = pypsa.Network(csv_folder_name=csv_folder_name)%0A%0A    #test results were generated with GLPK and other solvers may differ%0A    solver_name = %22glpk%22%0A%0A    #There are some infeasibilities without line extensions%0A    for line_name in %5B%22316%22,%22527%22,%22602%22%5D:%0A        network.lines.loc%5Bline_name,%22s_nom%22%5D = 1200%0A%0A    network.now = network.snapshots%5B0%5D%0A%0A    #choose the contingencies%0A    branch_outages = network.lines.index%5B:3%5D%0A%0A    print(%22Performing security-constrained linear OPF:%22)%0A%0A    network.sclopf(branch_outages=branch_outages)%0A%0A%0A%0A    #For the PF, set the P to the optimised P%0A    network.generators_t.p_set.loc%5Bnetwork.now%5D = network.generators_t.p.loc%5Bnetwork.now%5D%0A    network.storage_units_t.p_set.loc%5Bnetwork.now%5D = network.storage_units_t.p.loc%5Bnetwork.now%5D%0A%0A    #Check no lines are overloaded with the linear contingency analysis%0A%0A    p0_test = network.lpf_contingency(branch_outages=branch_outages)%0A%0A    #check loading as per unit of s_nom in each contingency%0A%0A    max_loading = abs(p0_test.divide(network.passive_branches().s_nom,axis=0)).describe().loc%5B%22max%22%5D%0A%0A%0A    np.testing.assert_array_almost_equal(max_loading,np.ones((len(max_loading))))%0A%0A%0Aif __name__ == %22__main__%22:%0A    test_sclopf()%0A

Include unit test of Security-Constrained LOPF