Пример #1
0
def test_load_case():
    casefile = CASE_DIRECTORY + 'case5_renumber_tree.m'
    vhat = 1
    i2e = [5, 1, 2, 3, 4]
    demands = [0, 1, 1, 1, 1]
    r, x = .01, .1
    g, b = z2y(r, x)
    n = len(demands)
    G = dok_matrix((n, n))
    B = dok_matrix((n, n))
    keys = [(0, 2), (0, 3), (1, 3), (3, 4)]
    for i, j in keys:
        G[i, j] = g
        G[j, i] = g
        B[i, j] = b
        B[j, i] = b
    c = load_case(casefile)
    assert c.demands == demands
    assert c.G == G
    assert c.B == B
    assert c.vhat == vhat
    assert c.i2e == i2e
Пример #2
0
def test_load_case():
    casefile = CASE_DIRECTORY + 'case5_renumber_tree.m'
    vhat = 1
    i2e = [5, 1, 2, 3, 4]
    demands = [0, 1, 1, 1, 1]
    r, x = .01, .1
    g, b = z2y(r, x)
    n = len(demands)
    G = dok_matrix((n, n))
    B = dok_matrix((n, n))
    keys = [(0, 2), (0, 3), (1, 3), (3, 4)]
    for i, j in keys:
        G[i, j] = g
        G[j, i] = g
        B[i, j] = b
        B[j, i] = b
    c = load_case(casefile)
    assert c.demands == demands
    assert c.G == G
    assert c.B == B
    assert c.vhat == vhat
    assert c.i2e == i2e
Пример #3
0
def test_load_branches_small(case5):
    demand_dict, root, _ = load_buses(case5)
    e2i, _, _ = renumber_buses(demand_dict, root)
    r, x = .01, .1
    g, b = z2y(r, x)
    n = len(e2i)
    Ghat = dok_matrix((n, n))
    Bhat = dok_matrix((n, n))
    keys = [(0, 2), (0, 3), (1, 3), (3, 4)]
    for i, j in keys:
        Ghat[i, j] = g
        Ghat[j, i] = g
        Bhat[i, j] = b
        Bhat[j, i] = b
    branch_list_hat = list(sorted(keys))
    branch_map_hat = {}
    for i, (fbus, tbus) in enumerate(branch_list_hat):
        branch_map_hat[(fbus, tbus)] = i
        branch_map_hat[(tbus, fbus)] = i
    G, B, branch_list, branch_map = load_branches(case5, e2i)
    assert_almost_equal(G.todense(), Ghat.todense())
    assert_almost_equal(B.todense(), Bhat.todense())
    assert branch_list == branch_list_hat
    assert branch_map == branch_map_hat
Пример #4
0
def test_load_branches_small(case5):
    demand_dict, root, _ = load_buses(case5)
    e2i, _, _ = renumber_buses(demand_dict, root)
    r, x = .01, .1
    g, b = z2y(r, x)
    n = len(e2i)
    Ghat = dok_matrix((n, n))
    Bhat = dok_matrix((n, n))
    keys = [(0, 2), (0, 3), (1, 3), (3, 4)]
    for i, j in keys:
        Ghat[i, j] = g
        Ghat[j, i] = g
        Bhat[i, j] = b
        Bhat[j, i] = b
    branch_list_hat = list(sorted(keys))
    branch_map_hat = {}
    for i, (fbus, tbus) in enumerate(branch_list_hat):
        branch_map_hat[(fbus, tbus)] = i
        branch_map_hat[(tbus, fbus)] = i
    G, B, branch_list, branch_map = load_branches(case5, e2i)
    assert_almost_equal(G.todense(), Ghat.todense())
    assert_almost_equal(B.todense(), Bhat.todense())
    assert branch_list == branch_list_hat
    assert branch_map == branch_map_hat