Esempio n. 1
0
def test_build_I_matrices(case5):
    G, B, branch_map = case5.G, case5.B, case5.branch_map
    r, x = .01, .1
    g, b = z2y(r, x)
    Ireal = dok_matrix(
        [[0,  0, -b,  0],
         [b, 0,  0,  0],
         [0,  b,  b, -b],
         [0,  0,  0,  b]])
    Ireac = dok_matrix(
        [[0, 0, -g,  0],
         [g, 0,  0,  0],
         [0, g,  g, -g],
         [0, 0,  0,  g]])
    Ireal_hat, Ireac_hat = build_I_matrices(G, B, branch_map)
    assert_almost_equal(Ireal_hat.todense(), Ireal.todense())
    assert_almost_equal(Ireac_hat.todense(), Ireac.todense())
Esempio n. 2
0
def test_build_U_matrices(case5):
    G, B = case5.G, case5.B
    r, x = .01, .1
    g, b = z2y(r, x)
    S2 = 2**.5
    Ureal = dok_matrix(
        [[0., g*S2,    0,    0,       0],
         [0.,    0, g*S2,    0,       0],
         [0.,    0,    0, 3*g*S2,     0],
         [0.,    0,    0,    0,    g*S2]])
    Ureac = dok_matrix(
        [[0., -b*S2,     0,       0,     0],
         [0.,     0, -b*S2,       0,     0],
         [0.,     0,     0, -3*b*S2,     0],
         [0.,     0,     0,       0, -b*S2]])
    Ureal_hat, Ureac_hat = build_U_matrices(G, B)
    assert_almost_equal(Ureal_hat.todense(), Ureal.todense())
    assert_almost_equal(Ureac_hat.todense(), Ureac.todense())
Esempio n. 3
0
def test_build_contraint_matrix(case5):
    G, B, branch_map = case5.G, case5.B, case5.branch_map
    r, x = .01, .1
    g, b = z2y(r, x)
    S2 = 2**.5
    Areal = coo_matrix(
        [[0.,  g*S2,     0,      0,      0,  0,  0, -g,  0,  0,  0, -b,  0],
         [0.,     0,  g*S2,      0,      0, -g,  0,  0,  0,  b,  0,  0,  0],
         [0.,     0,     0, 3*g*S2,      0,  0, -g, -g, -g,  0,  b,  b, -b],
         [0.,     0,     0,      0,   g*S2,  0,  0,  0, -g,  0,  0,  0,  b]])
    Areac = coo_matrix(
        [[0., -b*S2,     0,       0,     0,  0,  0,  b,  0,  0,  0, -g,  0],
         [0.,     0, -b*S2,       0,     0,  b,  0,  0,  0,  g,  0,  0,  0],
         [0.,     0,     0, -3*b*S2,     0,  0,  b,  b,  b,  0,  g,  g, -g],
         [0.,     0,     0,       0, -b*S2,  0,  0,  0,  b,  0,  0,  0,  g]])
    Areal_hat, Areac_hat = build_constraint_matrix(G, B, branch_map)
    assert_almost_equal(Areal_hat.todense(), Areal.todense())
    assert_almost_equal(Areac_hat.todense(), Areac.todense())
Esempio n. 4
0
def test_z2y_normal():
    r, x = .02, .2
    g, b = z2y(r, x)
    ghat, bhat = 0.495049504950495, -4.9504950495049505
    assert_almost_equal(g, ghat)
    assert_almost_equal(b, bhat)
Esempio n. 5
0
def test_z2y_simple():
    r, x = 0, 1
    assert z2y(r, x) == (0, -1)