本文整理汇总了Python中pypower.t.t_is.t_is函数的典型用法代码示例。如果您正苦于以下问题:Python t_is函数的具体用法?Python t_is怎么用?Python t_is使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了t_is函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: t_makeLODF
def t_makeLODF(quiet=False):
"""Tests for C{makeLODF}.
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
ntests = 31
t_begin(ntests, quiet)
tdir = dirname(__file__)
casefile = join(tdir, 't_auction_case')
verbose = 0#not quiet
## load case
ppc = loadcase(casefile)
ppopt = ppoption(VERBOSE=verbose, OUT_ALL=0)
r = rundcopf(ppc, ppopt)
baseMVA, bus, gen, branch = r['baseMVA'], r['bus'], r['gen'], r['branch']
_, bus, gen, branch = ext2int1(bus, gen, branch)
## compute injections and flows
F0 = branch[:, PF]
## create some PTDF matrices
H = makePTDF(baseMVA, bus, branch, 0)
## create some PTDF matrices
try:
LODF = makeLODF(branch, H)
except ZeroDivisionError:
pass
## take out non-essential lines one-by-one and see what happens
ppc['bus'] = bus
ppc['gen'] = gen
branch0 = branch
outages = r_[arange(12), arange(13, 15), arange(16, 18),
[19], arange(26, 33), arange(34, 41)]
for k in outages:
ppc['branch'] = branch0.copy()
ppc['branch'][k, BR_STATUS] = 0
r, _ = rundcpf(ppc, ppopt)
baseMVA, bus, gen, branch = \
r['baseMVA'], r['bus'], r['gen'], r['branch']
F = branch[:, PF]
t_is(LODF[:, k], (F - F0) / F0[k], 6, 'LODF[:, %d]' % k)
t_end()
开发者ID:charlie0389,项目名称:PYPOWER,代码行数:49,代码来源:t_makeLODF.py
示例2: t_hasPQcap
def t_hasPQcap(quiet=False):
"""Tests for C{hasPQcap}.
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
t_begin(4, quiet)
## generator data
# bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf
gen = array([
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, 0, 12, 0, 2, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, -15, 12, -15, 2, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, -12, 0, -2, 0, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, -12, 15, -2, 15, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, -12, 12, -2, 2, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, 0, 12, 0, 8, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, -15, 12, -15, 8, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, -12, 0, -8, 0, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, -12, 15, -8, 15, 0, 0, 0, 0, 0],
[1, 10, 0, 10, -10, 1, 100, 1, 10, 2, 0, 20, -12, 12, -8, 8, 0, 0, 0, 0, 0]
])
t = 'hasPQcap(gen)'
t_is(hasPQcap(gen), [0,1,1,1,1,1,1,0,1,0,0], 12, t)
t = 'hasPQcap(gen, \'B\')'
t_is(hasPQcap(gen, 'B'), [0,1,1,1,1,1,1,0,1,0,0], 12, t)
t = 'hasPQcap(gen, \'U\')'
t_is(hasPQcap(gen, 'U'), [0,1,1,1,0,1,0,0,1,0,0], 12, t)
t = 'hasPQcap(gen, \'L\')'
t_is(hasPQcap(gen, 'L'), [0,1,0,1,1,1,1,0,0,0,0], 12, t)
t_end()
开发者ID:charlie0389,项目名称:PYPOWER,代码行数:37,代码来源:t_hasPQcap.py
示例3: t_auction_pips
def t_auction_pips(quiet=False):
"""Tests for code in auction.py, using PIPS solver.
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
n_tests = 183
t_begin(n_tests, quiet)
try:
from pypower.extras.smartmarket import runmkt
except ImportError:
t_skip(n_tests, 'smartmarket code not available')
return
ppopt = ppoption
ppopt['OPF_VIOLATION'] = 1e-7
ppopt['PDIPM_GRADTOL'] = 1e-6
ppopt['PDIPM_COMPTOL'] = 1e-7
ppopt['PDIPM_COSTTOL'] = 5e-9
ppopt['OPF_ALG'] = 560
ppopt['OUT_ALL_LIM'] = 1
ppopt['OUT_BRANCH'] = 0
ppopt['OUT_SYS_SUM'] = 0
ppopt['OUT_ALL'] = 0
ppopt['VERBOSE'] = 0
q = array([
[12, 24, 24],
[12, 24, 24],
[12, 24, 24],
[12, 24, 24],
[12, 24, 24],
[12, 24, 24],
[10, 10, 10],
[10, 10, 10],
[10, 10, 10],
])
##----- one offer block marginal @ $50 -----
p = array([
[20, 50, 60],
[20, 40, 70],
[20, 42, 80],
[20, 44, 90],
[20, 46, 75],
[20, 48, 60],
[100, 70, 60],
[100, 50, 20],
[100, 60, 50]
])
t = 'one marginal offer @ $50, auction_type = 5'
MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \
runmkt('t_auction_case', q, p, 1150, 100, [], [], mpopt)
cq5 = cq.copy()
cp5 = cp.copy()
i2e = bus.bus_i
e2i = sparse((max(i2e), 1))
e2i[i2e] = range(bus.size())
G = find( isload(gen) == False ) ## real generators
L = find( isload(gen) ) ## dispatchable loads
Gbus = e2i[gen.gen_bus[G]]
Lbus = e2i[gen.gen_bus[L]]
Qfudge = zeros(p.shape)
Qfudge[L, :] = \
diag(gen.Qg[L] / gen.Pg[L] * bus.lam_Q[Lbus]) * ones(p[L :].shape)
t_is( cq[G[0], 1:3], [23.32, 0], 2, t )
t_is( cp[G[0], :], 50, 4, t )
t_is( cq[L[1], 0:2], [10, 0], 2, t )
t_is( cp[L[1], :], 54.0312, 4, t )
t_is( cp[G, 0], bus.lam_P[Gbus], 8, [t, ' : gen prices'] )
t_is( cp[L, 0], bus.lam_P[Lbus] + Qfudge[L, 0], 8, [t, ' : load prices'] )
lao_X = p(G[0], 1) / bus.lam_P[Gbus[0], LAM_P]
fro_X = p(G(5), 2) / bus.lam_P[Gbus[5], LAM_P]
lab_X = p(L(2), 1) / (bus.lam_P[Lbus[2]] + Qfudge[L[2], 0])
frb_X = p(L(1), 1) / (bus.lam_P[Lbus[1]] + Qfudge[L[1], 0])
t_is( lao_X, 1, 4, 'lao_X')
t_is( fro_X, 1.1324, 4, 'fro_X')
t_is( lab_X, 1.0787, 4, 'lab_X')
t_is( frb_X, 0.9254, 4, 'frb_X')
t = 'one marginal offer @ $50, auction_type = 1'
MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \
runmkt('t_auction_case', q, p, 1110, 100, [], [], mpopt)
cp1 = cp.copy()
t_is( cq, cq5, 8, [t, ' : quantities'] )
t_is( cp, cp5, 6, [t, ' : prices'] )
t = 'one marginal offer @ $50, auction_type = 2'
MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \
runmkt('t_auction_case', q, p, 1120, 100, [], [], mpopt)
cp2 = cp.copy()
t_is( cq, cq5, 8, [t, ' : quantities'] )
t_is( cp[G, :], cp5[G, :] * fro_X, 8, [t, ' : gen prices'] )
t_is( cp[L[0:1], :], cp5[L[0:1], :] * fro_X, 8, [t, ' : load 1,2 prices'] )
t_is( cp[L[2], :], 60, 5, [t, ' : load 3 price'] ) ## clipped by accepted bid
#.........这里部分代码省略.........
开发者ID:AdrianBajdiuk,项目名称:PowerGridResillience,代码行数:101,代码来源:t_auction_pips.py
示例4: t_modcost
def t_modcost(quiet=False):
"""Tests for code in C{modcost}.
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
n_tests = 80
t_begin(n_tests, quiet)
## generator cost data
# 1 startup shutdown n x1 y1 ... xn yn
# 2 startup shutdown n c(n-1) ... c0
gencost0 = array([
[2, 0, 0, 3, 0.01, 0.1, 1, 0, 0, 0, 0, 0],
[2, 0, 0, 5, 0.0006, 0.005, 0.04, 0.3, 2, 0, 0, 0],
[1, 0, 0, 4, 0, 0, 10, 200, 20, 600, 30, 1200],
[1, 0, 0, 4, -30, -2400, -20, -1800, -10, -1000, 0, 0]
])
gencost = modcost(gencost0, 5, 'SCALE_F')
##----- POLYSHIFT -----
t = 'modcost SCALE_F - quadratic'
t_is(totcost(gencost, array([0, 0, 0, 0])) / 5, [1, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([1, 0, 0, 0])) / 5, [1.11, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([2, 0, 0, 0])) / 5, [1.24, 2, 0, 0], 8, t)
t = 'modcost SCALE_F - 4th order polynomial'
t_is(totcost(gencost, array([0, 0, 0, 0])) / 5, [1, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([0, 1, 0, 0])) / 5, [1, 2.3456, 0, 0], 8, t)
t_is(totcost(gencost, array([0, 2, 0, 0])) / 5, [1, 2.8096, 0, 0], 8, t)
t = 'modcost SCALE_F - pwl (gen)'
t_is(totcost(gencost, array([0, 0, 5, 0 ])) / 5, [1, 2, 100, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 10, 0])) / 5, [1, 2, 200, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 15, 0])) / 5, [1, 2, 400, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 20, 0])) / 5, [1, 2, 600, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 25, 0])) / 5, [1, 2, 900, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 30, 0])) / 5, [1, 2, 1200, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 35, 0])) / 5, [1, 2, 1500, 0], 8, t)
t = 'modcost SCALE_F - pwl (load)'
t_is(totcost(gencost, array([0, 0, 0, -5 ])) / 5, [1, 2, 0, -500], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -10])) / 5, [1, 2, 0, -1000], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -15])) / 5, [1, 2, 0, -1400], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -20])) / 5, [1, 2, 0, -1800], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -25])) / 5, [1, 2, 0, -2100], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -30])) / 5, [1, 2, 0, -2400], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -35])) / 5, [1, 2, 0, -2700], 8, t)
gencost = modcost(gencost0, 2, 'SCALE_X')
t = 'modcost SCALE_X - quadratic'
t_is(totcost(gencost, array([0, 0, 0, 0]) * 2), [1, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([1, 0, 0, 0]) * 2), [1.11, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([2, 0, 0, 0]) * 2), [1.24, 2, 0, 0], 8, t)
t = 'modcost SCALE_X - 4th order polynomial'
t_is(totcost(gencost, array([0, 0, 0, 0]) * 2), [1, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([0, 1, 0, 0]) * 2), [1, 2.3456, 0, 0], 8, t)
t_is(totcost(gencost, array([0, 2, 0, 0]) * 2), [1, 2.8096, 0, 0], 8, t)
t = 'modcost SCALE_X - pwl (gen)'
t_is(totcost(gencost, array([0, 0, 5, 0 ]) * 2), [1, 2, 100, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 10, 0]) * 2), [1, 2, 200, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 15, 0]) * 2), [1, 2, 400, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 20, 0]) * 2), [1, 2, 600, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 25, 0]) * 2), [1, 2, 900, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 30, 0]) * 2), [1, 2, 1200, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 35, 0]) * 2), [1, 2, 1500, 0], 8, t)
t = 'modcost SCALE_X - pwl (load)'
t_is(totcost(gencost, array([0, 0, 0, -5 ]) * 2), [1, 2, 0, -500], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -10]) * 2), [1, 2, 0, -1000], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -15]) * 2), [1, 2, 0, -1400], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -20]) * 2), [1, 2, 0, -1800], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -25]) * 2), [1, 2, 0, -2100], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -30]) * 2), [1, 2, 0, -2400], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -35]) * 2), [1, 2, 0, -2700], 8, t)
gencost = modcost(gencost0, 3, 'SHIFT_F')
t = 'modcost SHIFT_F - quadratic'
t_is(totcost(gencost, array([0, 0, 0, 0])) - 3, [1, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([1, 0, 0, 0])) - 3, [1.11, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([2, 0, 0, 0])) - 3, [1.24, 2, 0, 0], 8, t)
t = 'modcost SHIFT_F - 4th order polynomial'
t_is(totcost(gencost, array([0, 0, 0, 0])) - 3, [1, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([0, 1, 0, 0])) - 3, [1, 2.3456, 0, 0], 8, t)
t_is(totcost(gencost, array([0, 2, 0, 0])) - 3, [1, 2.8096, 0, 0], 8, t)
t = 'modcost SHIFT_F - pwl (gen)'
t_is(totcost(gencost, array([0, 0, 5, 0 ])) - 3, [1, 2, 100, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 10, 0])) - 3, [1, 2, 200, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 15, 0])) - 3, [1, 2, 400, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 20, 0])) - 3, [1, 2, 600, 0], 8, t)
#.........这里部分代码省略.........
开发者ID:charlie0389,项目名称:PYPOWER,代码行数:101,代码来源:t_modcost.py
示例5: t_opf_ipopt
def t_opf_ipopt(quiet=False):
"""Tests for IPOPT-based AC optimal power flow.
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
num_tests = 101
t_begin(num_tests, quiet)
tdir = dirname(__file__)
casefile = join(tdir, 't_case9_opf')
verbose = 0#not quiet
t0 = 'IPOPT : '
ppopt = ppoption(OPF_VIOLATION=1e-6, PDIPM_GRADTOL=1e-8,
PDIPM_COMPTOL=1e-8, PDIPM_COSTTOL=1e-9)
ppopt = ppoption(ppopt, OUT_ALL=0, VERBOSE=verbose, OPF_ALG=580)
## set up indices
ib_data = r_[arange(BUS_AREA + 1), arange(BASE_KV, VMIN + 1)]
ib_voltage = arange(VM, VA + 1)
ib_lam = arange(LAM_P, LAM_Q + 1)
ib_mu = arange(MU_VMAX, MU_VMIN + 1)
ig_data = r_[[GEN_BUS, QMAX, QMIN], arange(MBASE, APF + 1)]
ig_disp = array([PG, QG, VG])
ig_mu = arange(MU_PMAX, MU_QMIN + 1)
ibr_data = arange(ANGMAX + 1)
ibr_flow = arange(PF, QT + 1)
ibr_mu = array([MU_SF, MU_ST])
ibr_angmu = array([MU_ANGMIN, MU_ANGMAX])
## get solved AC power flow case from MAT-file
soln9_opf = loadmat(join(tdir, 'soln9_opf.mat'), struct_as_record=True)
## defines bus_soln, gen_soln, branch_soln, f_soln
bus_soln = soln9_opf['bus_soln']
gen_soln = soln9_opf['gen_soln']
branch_soln = soln9_opf['branch_soln']
f_soln = soln9_opf['f_soln'][0]
## run OPF
t = t0
r = runopf(casefile, ppopt)
bus, gen, branch, f, success = \
r['bus'], r['gen'], r['branch'], r['f'], r['success']
t_ok(success, [t, 'success'])
t_is(f, f_soln, 3, [t, 'f'])
t_is( bus[:, ib_data ], bus_soln[:, ib_data ], 10, [t, 'bus data'])
t_is( bus[:, ib_voltage], bus_soln[:, ib_voltage], 3, [t, 'bus voltage'])
t_is( bus[:, ib_lam ], bus_soln[:, ib_lam ], 3, [t, 'bus lambda'])
t_is( bus[:, ib_mu ], bus_soln[:, ib_mu ], 2, [t, 'bus mu'])
t_is( gen[:, ig_data ], gen_soln[:, ig_data ], 10, [t, 'gen data'])
t_is( gen[:, ig_disp ], gen_soln[:, ig_disp ], 3, [t, 'gen dispatch'])
t_is( gen[:, ig_mu ], gen_soln[:, ig_mu ], 3, [t, 'gen mu'])
t_is(branch[:, ibr_data ], branch_soln[:, ibr_data ], 10, [t, 'branch data'])
t_is(branch[:, ibr_flow ], branch_soln[:, ibr_flow ], 3, [t, 'branch flow'])
t_is(branch[:, ibr_mu ], branch_soln[:, ibr_mu ], 2, [t, 'branch mu'])
## run with automatic conversion of single-block pwl to linear costs
t = ''.join([t0, '(single-block PWL) : '])
ppc = loadcase(casefile)
ppc['gencost'][2, NCOST] = 2
r = runopf(ppc, ppopt)
bus, gen, branch, f, success = \
r['bus'], r['gen'], r['branch'], r['f'], r['success']
t_ok(success, [t, 'success'])
t_is(f, f_soln, 3, [t, 'f'])
t_is( bus[:, ib_data ], bus_soln[:, ib_data ], 10, [t, 'bus data'])
t_is( bus[:, ib_voltage], bus_soln[:, ib_voltage], 3, [t, 'bus voltage'])
t_is( bus[:, ib_lam ], bus_soln[:, ib_lam ], 3, [t, 'bus lambda'])
t_is( bus[:, ib_mu ], bus_soln[:, ib_mu ], 2, [t, 'bus mu'])
t_is( gen[:, ig_data ], gen_soln[:, ig_data ], 10, [t, 'gen data'])
t_is( gen[:, ig_disp ], gen_soln[:, ig_disp ], 3, [t, 'gen dispatch'])
t_is( gen[:, ig_mu ], gen_soln[:, ig_mu ], 3, [t, 'gen mu'])
t_is(branch[:, ibr_data ], branch_soln[:, ibr_data ], 10, [t, 'branch data'])
t_is(branch[:, ibr_flow ], branch_soln[:, ibr_flow ], 3, [t, 'branch flow'])
t_is(branch[:, ibr_mu ], branch_soln[:, ibr_mu ], 2, [t, 'branch mu'])
xr = r_[r['var']['val']['Va'], r['var']['val']['Vm'], r['var']['val']['Pg'],
r['var']['val']['Qg'], 0, r['var']['val']['y']]
t_is(r['x'], xr, 8, [t, 'check on raw x returned from OPF'])
## get solved AC power flow case from MAT-file
soln9_opf_Plim = loadmat(join(tdir, 'soln9_opf_Plim.mat'), struct_as_record=True)
## defines bus_soln, gen_soln, branch_soln, f_soln
bus_soln = soln9_opf_Plim['bus_soln']
gen_soln = soln9_opf_Plim['gen_soln']
branch_soln = soln9_opf_Plim['branch_soln']
f_soln = soln9_opf_Plim['f_soln'][0]
## run OPF with active power line limits
t = ''.join([t0, '(P line lim) : '])
ppopt1 = ppoption(ppopt, OPF_FLOW_LIM=1)
r = runopf(casefile, ppopt1)
bus, gen, branch, f, success = \
r['bus'], r['gen'], r['branch'], r['f'], r['success']
t_ok(success, [t, 'success'])
t_is(f, f_soln, 3, [t, 'f'])
t_is( bus[:, ib_data ], bus_soln[:, ib_data ], 10, [t, 'bus data'])
t_is( bus[:, ib_voltage], bus_soln[:, ib_voltage], 3, [t, 'bus voltage'])
t_is( bus[:, ib_lam ], bus_soln[:, ib_lam ], 3, [t, 'bus lambda'])
#.........这里部分代码省略.........
开发者ID:AdrianBajdiuk,项目名称:PowerGridResillience,代码行数:101,代码来源:t_opf_ipopt.py
示例6: t_pf
def t_pf(quiet=False):
"""Tests for power flow solvers.
@author: Ray Zimmerman (PSERC Cornell)
"""
t_begin(33, quiet)
tdir = dirname(__file__)
casefile = join(tdir, 't_case9_pf')
verbose = not quiet
ppopt = ppoption(VERBOSE=verbose, OUT_ALL=0)
## get solved AC power flow case from MAT-file
## defines bus_soln, gen_soln, branch_soln
soln9_pf = loadmat(join(tdir, 'soln9_pf.mat'), struct_as_record=False)
bus_soln = soln9_pf['bus_soln']
gen_soln = soln9_pf['gen_soln']
branch_soln = soln9_pf['branch_soln']
## run Newton PF
t = 'Newton PF : ';
ppopt = ppoption(ppopt, PF_ALG=1)
results, success = runpf(casefile, ppopt)
bus, gen, branch = results['bus'], results['gen'], results['branch']
t_ok(success, [t, 'success'])
t_is(bus, bus_soln, 6, [t, 'bus'])
t_is(gen, gen_soln, 6, [t, 'gen'])
t_is(branch, branch_soln, 6, [t, 'branch'])
## run fast-decoupled PF (XB version)
t = 'Fast Decoupled (XB) PF : ';
ppopt = ppoption(ppopt, PF_ALG=2)
results, success = runpf(casefile, ppopt)
bus, gen, branch = results['bus'], results['gen'], results['branch']
t_ok(success, [t, 'success'])
t_is(bus, bus_soln, 6, [t, 'bus'])
t_is(gen, gen_soln, 6, [t, 'gen'])
t_is(branch, branch_soln, 6, [t, 'branch'])
## run fast-decoupled PF (BX version)
t = 'Fast Decoupled (BX) PF : ';
ppopt = ppoption(ppopt, PF_ALG=3)
results, success = runpf(casefile, ppopt)
bus, gen, branch = results['bus'], results['gen'], results['branch']
t_ok(success, [t, 'success'])
t_is(bus, bus_soln, 6, [t, 'bus'])
t_is(gen, gen_soln, 6, [t, 'gen'])
t_is(branch, branch_soln, 6, [t, 'branch'])
## run Gauss-Seidel PF
t = 'Gauss-Seidel PF : ';
ppopt = ppoption(ppopt, PF_ALG=4)
results, success = runpf(casefile, ppopt)
bus, gen, branch = results['bus'], results['gen'], results['branch']
t_ok(success, [t, 'success'])
t_is(bus, bus_soln, 5, [t, 'bus'])
t_is(gen, gen_soln, 5, [t, 'gen'])
t_is(branch, branch_soln, 5, [t, 'branch'])
## get solved AC power flow case from MAT-file
## defines bus_soln, gen_soln, branch_soln
soln9_dcpf = loadmat(join(tdir, 'soln9_dcpf.mat'), struct_as_record=False)
bus_soln = soln9_dcpf['bus_soln']
gen_soln = soln9_dcpf['gen_soln']
branch_soln = soln9_dcpf['branch_soln']
## run DC PF
t = 'DC PF : '
results, success = rundcpf(casefile, ppopt)
bus, gen, branch = results['bus'], results['gen'], results['branch']
t_ok(success, [t, 'success'])
t_is(bus, bus_soln, 6, [t, 'bus'])
t_is(gen, gen_soln, 6, [t, 'gen'])
t_is(branch, branch_soln, 6, [t, 'branch'])
## check Qg distribution, when Qmin = Qmax
t = 'check Qg : '
ppopt = ppoption(ppopt, PF_ALG=1, VERBOSE=0)
ppc = loadcase(casefile)
ppc['gen'][0, [QMIN, QMAX]] = [20, 20]
results, success = runpf(ppc, ppopt)
bus, gen, branch = results['bus'], results['gen'], results['branch']
t_is(gen[0, QG], 24.07, 2, [t, 'single gen, Qmin = Qmax'])
ppc['gen'] = r_[array([ ppc['gen'][0, :] ]), ppc['gen']]
ppc['gen'][0, [QMIN, QMAX]] = [10, 10]
ppc['gen'][1, [QMIN, QMAX]] = [ 0, 50]
results, success = runpf(ppc, ppopt)
bus, gen, branch = results['bus'], results['gen'], results['branch']
t_is(gen[0:2, QG], [10, 14.07], 2, [t, '2 gens, Qmin = Qmax for one'])
ppc['gen'][0, [QMIN, QMAX]] = [10, 10]
ppc['gen'][1, [QMIN, QMAX]] = [-50, -50]
results, success = runpf(ppc, ppopt)
bus, gen, branch = results['bus'], results['gen'], results['branch']
t_is(gen[0:2, QG], [12.03, 12.03], 2, [t, '2 gens, Qmin = Qmax for both'])
ppc['gen'][0, [QMIN, QMAX]] = [0, 50]
ppc['gen'][1, [QMIN, QMAX]] = [0, 100]
#.........这里部分代码省略.........
开发者ID:Anastien,项目名称:PYPOWER,代码行数:101,代码来源:t_pf.py
示例7: t_pips
def t_pips(quiet=False):
"""Tests of pips NLP solver.
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
t_begin(60, quiet)
t = 'unconstrained banana function : '
## from MATLAB Optimization Toolbox's bandem.m
f_fcn = f2
x0 = array([-1.9, 2])
# solution = pips(f_fcn, x0, opt={'verbose': 2})
solution = pips(f_fcn, x0)
x, f, s, lam, out = solution["x"], solution["f"], solution["eflag"], \
solution["lmbda"], solution["output"]
t_is(s, 1, 13, [t, 'success'])
t_is(x, [1, 1], 13, [t, 'x'])
t_is(f, 0, 13, [t, 'f'])
t_is(out['hist'][-1]['compcond'], 0, 6, [t, 'compcond'])
t_ok(len(lam['mu_l']) == 0, [t, 'lam.mu_l'])
t_ok(len(lam['mu_u']) == 0, [t, 'lam.mu_u'])
t_is(lam['lower'], zeros(x.shape), 13, [t, 'lam[\'lower\']'])
t_is(lam['upper'], zeros(x.shape), 13, [t, 'lam[\'upper\']'])
t = 'unconstrained 3-d quadratic : '
## from http://www.akiti.ca/QuadProgEx0Constr.html
f_fcn = f3
x0 = array([0, 0, 0], float)
# solution = pips(f_fcn, x0, opt={'verbose': 2})
solution = pips(f_fcn, x0)
x, f, s, lam, out = solution["x"], solution["f"], solution["eflag"], \
solution["lmbda"], solution["output"]
t_is(s, 1, 13, [t, 'success'])
t_is(x, [3, 5, 7], 13, [t, 'x'])
t_is(f, -244, 13, [t, 'f'])
t_is(out['hist'][-1]['compcond'], 0, 6, [t, 'compcond'])
t_ok(len(lam['mu_l']) == 0, [t, 'lam.mu_l'])
t_ok(len(lam['mu_u']) == 0, [t, 'lam.mu_u'])
t_is(lam['lower'], zeros(x.shape), 13, [t, 'lam[\'lower\']'])
t_is(lam['upper'], zeros(x.shape), 13, [t, 'lam[\'upper\']'])
t = 'constrained 4-d QP : '
## from http://www.jmu.edu/docs/sasdoc/sashtml/iml/chap8/sect12.htm
f_fcn = f4
x0 = array([1.0, 0.0, 0.0, 1.0])
A = array([
[1.0, 1.0, 1.0, 1.0 ],
[0.17, 0.11, 0.10, 0.18]
])
l = array([1, 0.10])
u = array([1.0, Inf])
xmin = zeros(4)
# solution = pips(f_fcn, x0, A, l, u, xmin, opt={'verbose': 2})
solution = pips(f_fcn, x0, A, l, u, xmin)
x, f, s, lam, out = solution["x"], solution["f"], solution["eflag"], \
solution["lmbda"], solution["output"]
t_is(s, 1, 13, [t, 'success'])
t_is(x, array([0, 2.8, 0.2, 0]) / 3, 6, [t, 'x'])
t_is(f, 3.29 / 3, 6, [t, 'f'])
t_is(out['hist'][-1]['compcond'], 0, 6, [t, 'compcond'])
t_is(lam['mu_l'], array([6.58, 0]) / 3, 6, [t, 'lam.mu_l'])
t_is(lam['mu_u'], array([0, 0]), 13, [t, 'lam.mu_u'])
t_is(lam['lower'], array([2.24, 0, 0, 1.7667]), 4, [t, 'lam[\'lower\']'])
t_is(lam['upper'], zeros(x.shape), 13, [t, 'lam[\'upper\']'])
# H = array([
# [1003.1, 4.3, 6.3, 5.9],
# [ 4.3, 2.2, 2.1, 3.9],
# [ 6.3, 2.1, 3.5, 4.8],
# [ 5.9, 3.9, 4.8, 10.0]
# ])
# c = zeros(4)
# ## check with quadprog (for dev testing only)
# x, f, s, out, lam = quadprog(H,c,-A(2,:), -0.10, A(1,:), 1, xmin)
# t_is(s, 1, 13, [t, 'success'])
# t_is(x, [0 2.8 0.2 0]/3, 6, [t, 'x'])
# t_is(f, 3.29/3, 6, [t, 'f'])
# t_is(lam['eqlin'], -6.58/3, 6, [t, 'lam.eqlin'])
# t_is(lam.['ineqlin'], 0, 13, [t, 'lam.ineqlin'])
# t_is(lam['lower'], [2.24001.7667], 4, [t, 'lam[\'lower\']'])
# t_is(lam['upper'], [0000], 13, [t, 'lam[\'upper\']'])
t = 'constrained 2-d nonlinear : '
## from http://en.wikipedia.org/wiki/Nonlinear_programming#2-dimensional_example
f_fcn = f5
gh_fcn = gh5
hess_fcn = hess5
x0 = array([1.1, 0.0])
xmin = zeros(2)
# xmax = 3 * ones(2, 1)
# solution = pips(f_fcn, x0, xmin=xmin, gh_fcn=gh_fcn, hess_fcn=hess_fcn, opt={'verbose': 2})
solution = pips(f_fcn, x0, xmin=xmin, gh_fcn=gh_fcn, hess_fcn=hess_fcn)
x, f, s, lam, out = solution["x"], solution["f"], solution["eflag"], \
solution["lmbda"], solution["output"]
t_is(s, 1, 13, [t, 'success'])
t_is(x, [1, 1], 6, [t, 'x'])
t_is(f, -2, 6, [t, 'f'])
t_is(out['hist'][-1]['compcond'], 0, 6, [t, 'compcond'])
t_is(lam['ineqnonlin'], array([0, 0.5]), 6, [t, 'lam.ineqnonlin'])
#.........这里部分代码省略.........
开发者ID:AdrianBajdiuk,项目名称:PowerGridResillience,代码行数:101,代码来源:t_pips.py
示例8: t_loadcase
def t_loadcase(quiet=False):
"""Test that C{loadcase} works with an object as well as case file.
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
t_begin(240, quiet)
## compare result of loading from M-file file to result of using data matrices
tdir = dirname(__file__)
casefile = join(tdir, 't_case9_opf')
matfile = join(tdir, 't_mat9_opf')
pfcasefile = join(tdir, 't_case9_pf')
pfmatfile = join(tdir, 't_mat9_pf')
casefilev2 = join(tdir, 't_case9_opfv2')
matfilev2 = join(tdir, 't_mat9_opfv2')
pfcasefilev2 = join(tdir, 't_case9_pfv2')
pfmatfilev2 = join(tdir, 't_mat9_pfv2')
## read version 1 OPF data matrices
baseMVA, bus, gen, branch, areas, gencost = t_case9_opf()
## save as .mat file
savemat(matfile + '.mat', {'baseMVA': baseMVA, 'bus': bus, 'gen': gen,
'branch': branch, 'areas': areas, 'gencost': gencost}, oned_as='row')
## read version 2 OPF data matrices
ppc = t_case9_opfv2()
## save as .mat file
savemat(matfilev2 + '.mat', {'ppc': ppc}, oned_as='column')
## prepare expected matrices for v1 load
## (missing gen cap curve & branch ang diff lims)
tmp1 = (ppc['baseMVA'], ppc['bus'].copy(), ppc['gen'].copy(), ppc['branch'].copy(),
ppc['areas'].copy(), ppc['gencost'].copy())
tmp2 = (ppc['baseMVA'], ppc['bus'].copy(), ppc['gen'].copy(), ppc['branch'].copy(),
ppc['areas'].copy(), ppc['gencost'].copy())
## remove capability curves, angle difference limits
tmp1[2][1:3, [PC1, PC2, QC1MIN, QC1MAX, QC2MIN, QC2MAX]] = zeros((2,6))
tmp1[3][0, ANGMAX] = 360
tmp1[3][8, ANGMIN] = -360
baseMVA, bus, gen, branch, areas, gencost = tmp1
##----- load OPF data into individual matrices -----
t = 'loadcase(opf_PY_file_v1) without .py extension : '
baseMVA1, bus1, gen1, branch1, areas1, gencost1 = \
loadcase(casefile, False)
t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
t_is(bus1, bus, 12, [t, 'bus'])
t_is(gen1, gen, 12, [t, 'gen'])
t_is(branch1, branch, 12, [t, 'branch'])
t_is(areas1, areas, 12, [t, 'areas'])
t_is(gencost1, gencost, 12, [t, 'gencost'])
t = 'loadcase(opf_PY_file_v1) with .py extension : '
baseMVA1, bus1, gen1, branch1, areas1, gencost1 = \
loadcase(casefile + '.py', False)
t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
t_is(bus1, bus, 12, [t, 'bus'])
t_is(gen1, gen, 12, [t, 'gen'])
t_is(branch1, branch, 12, [t, 'branch'])
t_is(areas1, areas, 12, [t, 'areas'])
t_is(gencost1, gencost, 12, [t, 'gencost'])
t = 'loadcase(opf_MAT_file_v1) without .mat extension : '
baseMVA1, bus1, gen1, branch1, areas1, gencost1 = \
loadcase(matfile, False)
t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
t_is(bus1, bus, 12, [t, 'bus'])
t_is(gen1, gen, 12, [t, 'gen'])
t_is(branch1, branch, 12, [t, 'branch'])
t_is(areas1, areas, 12, [t, 'areas'])
t_is(gencost1, gencost, 12, [t, 'gencost'])
t = 'loadcase(opf_MAT_file_v1) with .mat extension : '
baseMVA1, bus1, gen1, branch1, areas1, gencost1 = \
loadcase(matfile + '.mat', False)
t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
t_is(bus1, bus, 12, [t, 'bus'])
t_is(gen1, gen, 12, [t, 'gen'])
t_is(branch1, branch, 12, [t, 'branch'])
t_is(areas1, areas, 12, [t, 'areas'])
t_is(gencost1, gencost, 12, [t, 'gencost'])
## prepare expected matrices for v2 load
baseMVA, bus, gen, branch, areas, gencost = tmp2
t = 'loadcase(opf_PY_file_v2) without .py extension : '
baseMVA1, bus1, gen1, branch1, areas1, gencost1 = \
loadcase(casefilev2, False)
t_is(baseMVA1, baseMVA, 12, [t, 'baseMVA'])
t_is(bus1, bus, 12, [t, 'bus'])
t_is(gen1, gen, 12, [t, 'gen'])
t_is(branch1, branch, 12, [t, 'branch'])
t_is(areas1, areas, 12, [t, 'areas'])
t_is(gencost1, gencost, 12, [t, 'gencost'])
t = 'loadcase(opf_PY_file_v2) with .py extension : '
baseMVA1, bus1, gen1, branch1, areas1, gencost1 = \
loadcase(casefilev2 + '.py', False)
#.........这里部分代码省略.........
开发者ID:charlie0389,项目名称:PYPOWER,代码行数:101,代码来源:t_loadcase.py
示例9: t_off2case
def t_off2case(quiet=False):
"""Tests for code in C{off2case}.
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
n_tests = 35
t_begin(n_tests, quiet)
## generator data
# bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf
gen0 = array([
[1, 10, 0, 60, -15, 1, 100, 1, 60, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[2, 10, 0, 60, -15, 1, 100, 1, 60, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[7, -30, -15, 0, -15, 1, 100, 1, 0, -30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[13, 10, 0, 60, -15, 1, 100, 1, 60, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[30, -30, 7.5, 7.5, 0, 1, 100, 1, 0, -30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
], float)
## generator cost data
# 1 startup shutdown n x1 y1 ... xn yn
# 2 startup shutdown n c(n-1) ... c0
gencost0 = array([
[1, 0, 0, 4, 0, 0, 12, 240, 36, 1200, 60, 2400],
[1, 100, 0, 4, 0, 0, 12, 240, 36, 1200, 60, 2400],
[1, 0, 0, 4, -30, 0, -20, 1000, -10, 2000, 0, 3000],
[1, 0, 0, 4, 0, 0, 12, 240, 36, 1200, 60, 2400],
[1, 0, 50, 4, -30, 0, -20, 1000, -10, 2000, 0, 3000]
], float)
try:
from pypower.extras.smartmarket import off2case
except ImportError:
t_skip(n_tests, 'smartmarket code not available')
return
t = 'isload()'
t_is(isload(gen0), array([0, 0, 1, 0, 1], bool), 8, t)
G = find( ~isload(gen0) )
L = find( isload(gen0) )
nGL = len(G) + len(L)
t = 'P offers only';
offers = {'P': {}}
offers['P']['qty'] = array([[25], [26], [27]], float)
offers['P']['prc'] = array([[10], [50], [100]], float)
gen, gencost = off2case(gen0, gencost0, offers)
gen1 = gen0.copy()
gen1[G, PMAX] = offers['P']['qty'].flatten()
gen1[L, GEN_STATUS] = 0
t_is( gen, gen1, 8, [t, ' - gen'] )
gencost1 = gencost0.copy()
gencost1[ix_(G, range(NCOST, NCOST + 9))] = c_[array([
[2, 0, 0, 25, 250],
[2, 0, 0, 26, 1300],
[2, 0, 0, 27, 2700],
]), zeros((3, 4))]
t_is( gencost, gencost1, 8, [t, ' - gencost'] )
offers['P']['qty'] = array([[25], [26], [0], [27], [0]], float)
offers['P']['prc'] = array([[10], [50], [0], [100], [0]], float)
gen, gencost = off2case(gen0, gencost0, offers)
t_is( gen, gen1, 8, [t, ' (all rows in offer) - gen'] )
t_is( gencost, gencost1, 8, [t, ' (all rows in offer) - gencost'] )
t = 'P offers only (GEN_STATUS=0 for 0 qty offer)';
offers['P']['qty'] = array([ [0], [26], [27]], float)
offers['P']['prc'] = array([[10], [50], [100]], float)
gen, gencost = off2case(gen0, gencost0, offers)
gen1 = gen0.copy()
gen1[G[1:3], PMAX] = offers['P']['qty'].flatten()[1:3]
gen1[G[0], GEN_STATUS] = 0
gen1[L, GEN_STATUS] = 0
t_is( gen, gen1, 8, [t, ' - gen'] )
gencost1 = gencost0.copy()
gencost1[ix_(G[1:3], range(NCOST, NCOST + 9))] = c_[array([
[2, 0, 0, 26, 1300],
[2, 0, 0, 27, 2700]
]), zeros((2, 4))]
t_is( gencost, gencost1, 8, [t, ' - gencost'] )
t = 'P offers, lim[\'P\'][\'max_offer\']';
offers['P']['qty'] = array([[25], [26], [27]], float)
offers['P']['prc'] = array([[10], [50], [100]], float)
lim = {'P': {'max_offer': 75}}
gen, gencost = off2case(gen0, gencost0, offers, lim=lim)
gen1 = gen0.copy()
gen1[G[:2], PMAX] = offers['P']['qty'].flatten()[:2, :]
gen1[r_[G[2], L], GEN_STATUS] = 0
t_is( gen, gen1, 8, [t, ' - gen'] )
gencost1 = gencost0.copy()
#.........这里部分代码省略.........
开发者ID:AdrianBajdiuk,项目名称:PowerGridResillience,代码行数:101,代码来源:t_off2case.py
示例10: t_runmarket
def t_runmarket(quiet=False):
"""Tests for code in C{runmkt}, C{smartmkt} and C{auction}.
@author: Ray Zimmerman (PSERC Cornell)
"""
n_tests = 20
t_begin(n_tests, quiet)
try:
from pypower.extras.smartmarket import runmarket
except ImportError:
t_skip(n_tests, 'smartmarket code not available')
t_end;
return
ppc = loadcase('t_auction_case')
ppopt = ppoption(OPF_ALG=560, OUT_ALL_LIM=1,
OUT_BRANCH=0, OUT_SYS_SUM=0)
ppopt = ppoption(ppopt, OUT_ALL=0, VERBOSE=1)
#ppopt = ppoption(ppopt, OUT_GEN=1, OUT_BRANCH=0, OUT_SYS_SUM=0)
offers = {'P': {}, 'Q': {}}
bids = {'P': {}, 'Q': {}}
offers['P']['qty'] = array([
[12, 24, 24],
[12, 24, 24],
[12, 24, 24],
[12, 24, 24],
[12, 24, 24],
[12, 24, 24]
])
offers['P']['prc'] = array([
[20, 50, 60],
[20, 40, 70],
[20, 42, 80],
[20, 44, 90],
[20, 46, 75],
[20, 48, 60]
])
bids['P']['qty'] = array([
[10, 10, 10],
[10, 10, 10],
[10, 10, 10]
])
bids['P']['prc'] = array([
[100, 70, 60],
# [100, 64.3, 20],
# [100, 30.64545, 0],
[100, 50, 20],
[100, 60, 50]
])
offers['Q']['qty'] = [ 60, 60, 60, 60, 60, 60, 0, 0, 0 ]
offers['Q']['prc'] = [ 0, 0, 0, 0, 0, 3, 0, 0, 0 ]
bids.Q['qty'] = [ 15, 15, 15, 15, 15, 15, 15, 12, 7.5 ]
# bids.Q['prc'] = [ 0, 0, 0, 0, 0, 0, 0, 83.9056, 0 ]
bids.Q['prc'] = [ 0, 0, 0, 0, 0, 0, 0, 20, 0 ]
t = 'marginal Q offer, marginal PQ bid, auction_type = 5'
mkt = {'auction_type': 5,
't': [],
'u0': [],
'lim': []}
r, co, cb, _, _, _, _ = runmarket(ppc, offers, bids, mkt, ppopt)
co5 = co.copy()
cb5 = cb.copy()
# [ co['P']['qty'] co['P']['prc'] ]
# [ cb['P']['qty'] cb['P']['prc'] ]
# [ co['Q']['qty'] co['Q']['prc'] ]
# [ cb['Q']['qty'] cb['Q']['prc'] ]
i2e = r['bus'][:, BUS_I]
e2i = sparse((max(i2e), 1))
e2i[i2e] = range(r['bus'].size)
G = find( isload(r['gen']) == 0 ) ## real generators
L = find( isload(r['gen']) ) ## dispatchable loads
Gbus = e2i[r['gen'][G, GEN_BUS]]
Lbus = e2i[r['gen'][L, GEN_BUS]]
t_is( co['P']['qty'], ones((6, 1)) * [12, 24, 0], 2, [t, ' : gen P quantities'] )
t_is( co['P']['prc'][0, :], 50.1578, 3, [t, ' : gen 1 P prices'] )
t_is( cb['P']['qty'], [[10, 10, 10], [10, 0.196, 0], [10, 10, 0]], 2, [t, ' : load P quantities'] )
t_is( cb['P']['prc'][1, :], 56.9853, 4, [t, ' : load 2 P price'] )
t_is( co['P']['prc'][:, 0], r['bus'][Gbus, LAM_P], 8, [t, ' : gen P prices'] )
t_is( cb['P']['prc'][:, 0], r['bus'][Lbus, LAM_P], 8, [t, ' : load P prices'] )
t_is( co['Q']['qty'], [4.2722, 11.3723, 14.1472, 22.8939, 36.7886, 12.3375, 0, 0, 0], 2, [t, ' : Q offer quantities'] )
t_is( co['Q']['prc'], [0, 0, 0, 0, 0, 3, 0.4861, 2.5367, 1.3763], 4, [t, ' : Q offer prices'] )
t_is( cb['Q']['qty'], [0, 0, 0, 0, 0, 0, 15, 4.0785, 5], 2, [t, ' : Q bid quantities'] )
t_is( cb['Q']['prc'], [0, 0, 0, 0, 0, 3, 0.4861, 2.5367, 1.3763], 4, [t, ' : Q bid prices'] )
t_is( co['Q']['prc'], r['bus'][[Gbus, Lbus], LAM_Q], 8, [t, ' : Q offer prices'] )
t_is( cb['Q']['prc'], co['Q']['prc'], 8, [t, ' : Q bid prices'] )
t = 'marginal Q offer, marginal PQ bid, auction_type = 0'
mkt['auction_type'] = 0
r, co, cb, _, _, _, _ = runmarket(ppc, offers, bids, mkt, ppopt)
#.........这里部分代码省略.........
开发者ID:Anastien,项目名称:PYPOWER,代码行数:101,代码来源:t_runmarket.py
示例11: t_opf_userfcns
def t_opf_userfcns(quiet=False):
"""Tests for userfcn callbacks (reserves/iflims) w/OPF.
Includes high-level tests of reserves and iflims implementations.
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
t_begin(38, quiet)
tdir = dirname(__file__)
casefile = join(tdir, 't_case30_userfcns')
verbose = 0#not quiet
ppopt = ppoption(OPF_VIOLATION=1e-6, PDIPM_GRADTOL=1e-8,
PDIPM_COMPTOL=1e-8, PDIPM_COSTTOL=1e-9)
ppopt = ppoption(ppopt, OUT_ALL=0, VERBOSE=verbose,
OPF_ALG=560, OPF_ALG_DC=200)
#ppopt = ppoption(ppopt, OUT_ALL=-1, VERBOSE=2, OUT_GEN=1)
## run the OPF with fixed reserves
t = 'fixed reserves : '
ppc = loadcase(casefile)
ppc = toggle_reserves(ppc, 'on')
r = runopf(ppc, ppopt)
t_ok(r['success'], [t, 'success'])
t_is(r['reserves']['R'], [25, 15, 0, 0, 19.3906, 0.6094], 4, [t, 'reserves.R'])
t_is(r['reserves']['prc'], [2, 2, 2, 2, 5.5, 5.5], 4, [t, 'reserves.prc'])
t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0.5, 0], 4, [t, 'reserves.mu.Pmax'])
t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 4, [t, 'reserves.mu.l'])
t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0], 4, [t, 'reserves.mu.u'])
t_ok('P' not in r['if'], [t, 'no iflims'])
t_is(r['reserves']['totalcost'], 177.8047, 4, [t, 'totalcost'])
t = 'toggle_reserves(ppc, \'off\') : ';
ppc = toggle_reserves(ppc, 'off')
r = runopf(ppc, ppopt)
t_ok(r['success'], [t, 'success'])
t_ok('R' not in r['reserves'], [t, 'no reserves'])
t_ok('P' not in r['if'], [t, 'no iflims'])
t = 'interface flow lims (DC) : '
ppc = loadcase(casefile)
ppc = toggle_iflims(ppc, 'on')
r = rundcopf(ppc, ppopt)
t_ok(r['success'], [t, 'success'])
t_is(r['if']['P'], [-15, 20], 4, [t, 'if.P'])
t_is(r['if']['mu']['l'], [4.8427, 0], 4, [t, 'if.mu.l'])
t_is(r['if']['mu']['u'], [0, 13.2573], 4, [t, 'if.mu.u'])
t_is(r['branch'][13, PF], 8.244, 3, [t, 'flow in branch 14'])
t_ok('R' not in r['reserves'], [t, 'no reserves'])
t = 'reserves + interface flow lims (DC) : '
ppc = loadcase(casefile)
ppc = toggle_reserves(ppc, 'on')
ppc = toggle_iflims(ppc, 'on')
r = rundcopf(ppc, ppopt)
t_ok(r['success'], [t, 'success'])
t_is(r['if']['P'], [-15, 20], 4, [t, 'if.P'])
t_is(r['if']['mu']['l'], [4.8427, 0], 4, [t, 'if.mu.l'])
t_is(r['if']['mu']['u'], [0, 38.2573], 4, [t, 'if.mu.u'])
t_is(r['reserves']['R'], [25, 15, 0, 0, 16.9, 3.1], 4, [t, 'reserves.R'])
t_is(r['reserves']['prc'], [2, 2, 2, 2, 5.5, 5.5], 4, [t, 'reserves.prc'])
t_is(r['reserves']['mu']['Pmax'], [0, 0, 0, 0, 0.5, 0], 4, [t, 'reserves.mu.Pmax'])
t_is(r['reserves']['mu']['l'], [0, 0, 1, 2, 0, 0], 4, [t, 'reserves.mu.l'])
t_is(r['reserves']['mu']['u'], [0.1, 0, 0, 0, 0, 0], 4, [t, 'reserves.mu.u'])
t_is(r['reserves']['totalcost'], 179.05, 4, [t, 'totalcost'])
t = 'interface flow lims (AC) : '
ppc = toggle_reserves(ppc, 'off')
r = runopf(ppc, ppopt)
t_ok(r['success'], [t, 'success'])
t_is(r['if']['P'], [-9.101, 21.432], 3, [t, 'if.P'])
t_is(r['if']['mu']['l'], [0, 0], 4, [t, 'if.mu.l'])
t_is(r['if']['mu']['u'], [0, 10.198], 3, [t, 'if.mu.u'])
t_ok('R' not in r['reserves'], [t, 'no reserves'])
t = 'interface flow lims (line out) : '
ppc = loadcase(casefile)
ppc = toggle_iflims(ppc, 'on')
ppc['branch'][11, BR_STATUS] = 0 ## take out line 6-10
r = rundcopf(ppc, ppopt)
t_ok(r['success'], [t, 'success'])
t_is(r['if']['P'], [-15, 20], 4, [t, 'if.P'])
t_is(r['if']['mu']['l'], [4.8427, 0], 4, [t, 'if.mu.l'])
t_is(r['if']['mu']['u'], [0, 13.2573], 4, [t, 'if.mu.u'])
t_is(r['branch'][13, PF], 10.814, 3, [t, 'flow in branch 14'])
t_ok('R' not in r['reserves'], [t, 'no reserves'])
# r['reserves']['R']
# r['reserves']['prc']
# r['reserves']['mu.Pmax']
# r['reserves']['mu']['l']
# r['reserves']['mu']['u']
# r['reserves']['totalcost']
#
# r['if']['P']
# r['if']['mu']['l']
# r['if']['mu']['u']
#.........这里部分代码省略.........
开发者ID:AdrianBajdiuk,项目名称:PowerGridResillience,代码行数:101,代码来源:t_opf_userfcns.py
示例12: t_makePTDF
def t_makePTDF(quiet=False):
"""Tests for C{makePTDF}.
@author: Ray Zimmerman (PSERC Cornell)
"""
ntests = 24
t_begin(ntests, quiet)
tdir = dirname(__file__)
casefile = join(tdir, 't_case9_opf')
verbose = 0#not quiet
## load case
ppopt = ppoption(VERBOSE=verbose, OUT_ALL=0)
r = rundcopf(casefile, ppopt)
baseMVA, bus, gen, branch = r['baseMVA'], r['bus'], r['gen'], r['branch']
_, bus, gen, branch = ext2int1(bus, gen, branch)
nb = bus.shape[0]
nbr = branch.shape[0]
ng = gen.shape[0]
## compute injections and flows
Cg = sparse((ones(ng), (gen[:, GEN_BUS], arange(ng))), (nb, ng))
Pg = Cg * gen[:, PG]
Pd = bus[:, PD]
P = Pg - Pd
ig = find(P > 0)
il = find(P <= 0)
F = branch[:, PF]
## create corresponding slack distribution matrices
e1 = zeros((nb, 1)); e1[0] = 1
e4 = zeros((nb, 1)); e4[3] = 1
D1 = eye(nb, nb) - dot(e1, ones((1, nb)))
D4 = eye(nb, nb) - dot(e4, ones((1, nb)))
Deq = eye(nb, nb) - ones((nb, 1)) / nb * ones((1, nb))
Dg = eye(nb) - matrix( Pd / sum(Pd) ).T * ones(nb)
Dd = eye(nb) - matrix( Pg / sum(Pg) ).T * ones(nb)
## create some PTDF matrices
H1 = makePTDF(baseMVA, bus, branch, 0)
H4 = makePTDF(baseMVA, bus, branch, 3)
Heq = makePTDF(baseMVA, bus, branch, ones(nb))
Hg = makePTDF(baseMVA, bus, branch, Pd)
Hd = makePTDF(baseMVA, bus, branch, Pg)
## matrices get properly transformed by slack dist matrices
t_is(H1, dot(H1, D1), 8, 'H1 == H1 * D1')
t_is(H4, dot(H1, D4), 8, 'H4 == H1 * D4')
t_is(Heq, dot(H1, Deq), 8, 'Heq == H1 * Deq')
t_is(Hg, dot(H1, Dg), 8, 'Hg == H1 * Dg')
t_is(Hd, dot(H1, Dd), 8, 'Hd == H1 * Dd')
t_is(H1, dot(Heq, D1), 8, 'H1 == Heq * D1')
t_is(H4, dot(Heq, D4), 8, 'H4 == Heq * D4')
t_is(Heq, dot(Heq, Deq), 8, 'Heq == Heq * Deq')
t_is(Hg, dot(Heq, Dg), 8, 'Hg == Heq * Dg')
t_is(Hd, dot(Heq, Dd), 8, 'Hd == Heq * Dd')
t_is(H1, dot(Hg, D1), 8, 'H1 == Hg * D1')
t_is(H4, dot(Hg, D4), 8, 'H4 == Hg * D4')
t_is(Heq, dot(Hg, Deq), 8, 'Heq == Hg * Deq')
t_is(Hg, dot(Hg, Dg), 8, 'Hg == Hg * Dg')
t_is(Hd, dot(Hg, Dd), 8, 'Hd == Hg * Dd')
## PTDFs can reconstruct flows
t_is(F, dot(H1, P), 3, 'Flow == H1 * P')
t_is(F, dot(H4, P), 3, 'Flow == H4 * P')
t_is(F, dot(Heq, P), 3, 'Flow == Heq * P')
t_is(F, dot(Hg, P), 3, 'Flow == Hg * P')
t_is(F, dot(Hd, P), 3, 'Flow == Hd * P')
## other
t_is(F, dot(Hg, Pg), 3, 'Flow == Hg * Pg')
t_is(F, dot(Hd, (-Pd)), 3, 'Flow == Hd * (-Pd)')
t_is(zeros(nbr), dot(Hg, (-Pd)), 3, 'zeros == Hg * (-Pd)')
t_is(zeros(nbr), dot(Hd, Pg), 3, 'zeros == Hd * Pg')
t_end()
开发者ID:Anastien,项目名称:PYPOWER,代码行数:77,代码来源:t_makePTDF.py
示例13: t_opf_dc_gurobi
def t_opf_dc_gurobi(quiet=False):
"""Tests for DC optimal power flow using Gurobi solver.
"""
algs = [0, 1, 2, 3, 4]
num_tests = 23 * len(algs)
t_begin(num_tests, quiet)
tdir = dirname(__file__)
casefile = join(tdir, 't_case9_opf')
if quiet:
verbose = False
else:
verbose = False
ppopt = ppoption('OUT_ALL', 0, 'VERBOSE', verbose);
ppopt = ppoption(ppopt, 'OPF_ALG_DC', 700);
## run DC OPF
if have_fcn('gurobipy'):
for k in range(len(algs)):
ppopt = ppoption(ppopt, 'GRB_METHOD', algs[k])
methods = [
'automatic',
'primal simplex',
'dual simplex',
'barrier',
'concurrent',
'deterministic concurrent',
]
t0 = 'DC OPF (Gurobi %s): ' % methods[k]
## set up indices
ib_data = r_[arange(BUS_AREA + 1), arange(BASE_KV, VMIN + 1)]
ib_voltage = arange(VM, VA + 1)
ib_lam = arange(LAM_P, LAM_Q + 1)
ib_mu = arange(MU_VMAX, MU_VMIN + 1)
ig_data = r_[[GEN_BUS, QMAX, QMIN], arange(MBASE, APF + 1)]
ig_disp = array([PG, QG, VG])
ig_mu = arange(MU_PMAX, MU_QMIN + 1)
ibr_data = arange(ANGMAX + 1)
ibr_flow = arange(PF, QT + 1)
ibr_mu = array([MU_SF, MU_ST])
#ibr_angmu = array([MU_ANGMIN, MU_ANGMAX])
## get solved DC power flow case from MAT-file
## defines bus_soln, gen_soln, branch_soln, f_soln
soln9_dcopf = loadmat(join(tdir, 'soln9_dcopf.mat'),
struct_as_record=True)
bus_soln, gen_soln, branch_soln, f_soln = \
soln9_dcopf['bus_soln'], soln9_dcopf['gen_soln'], \
soln9_dcopf['branch_soln'], soln9_dcopf['f_soln']
## run OPF
t = t0
r = rundcopf(casefile, ppopt)
bus, gen, branch, f, success = \
r['bus'], r['gen'], r['branch'], r['f'], r['success']
t_ok(success, [t, 'success'])
t_is(f, f_soln, 3, [t, 'f'])
t_is( bus[:, ib_data ], bus_soln[:, ib_data ], 10, [t, 'bus data'])
t_is( bus[:, ib_voltage], bus_soln[:, ib_voltage], 3, [t, 'bus voltage'
|
请发表评论