本文整理汇总了Python中pypower.t.t_begin.t_begin函数的典型用法代码示例。如果您正苦于以下问题:Python t_begin函数的具体用法?Python t_begin怎么用?Python t_begin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了t_begin函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: t_totcost
def t_totcost(quiet=False):
"""Tests for code in C{totcost}.
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
n_tests = 22
t_begin(n_tests, quiet)
## generator cost data
# 1 startup shutdown n x1 y1 ... xn yn
# 2 startup shutdown n c(n-1) ... c0
gencost = 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]
])
t = 'totcost - quadratic'
t_is(totcost(gencost, array([0, 0, 0, 0])), [1, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([1, 0, 0, 0])), [1.11, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([2, 0, 0, 0])), [1.24, 2, 0, 0], 8, t)
t = 'totcost - 4th order polynomial'
t_is(totcost(gencost, array([0, 0, 0, 0])), [1, 2, 0, 0], 8, t)
t_is(totcost(gencost, array([0, 1, 0, 0])), [1, 2.3456, 0, 0], 8, t)
t_is(totcost(gencost, array([0, 2, 0, 0])), [1, 2.8096, 0, 0], 8, t)
t = 'totcost - pwl (gen)'
t_is(totcost(gencost, array([0, 0, -10, 0 ])), [1, 2, -200, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 5, 0 ])), [1, 2, 100, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 10, 0])), [1, 2, 200, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 15, 0])), [1, 2, 400, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 20, 0])), [1, 2, 600, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 25, 0])), [1, 2, 900, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 30, 0])), [1, 2, 1200, 0], 8, t)
t_is(totcost(gencost, array([0, 0, 35, 0])), [1, 2, 1500, 0], 8, t)
t = 'totcost - pwl (load)'
t_is(totcost(gencost, array([0, 0, 0, 10 ])), [1, 2, 0, 1000], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -5 ])), [1, 2, 0, -500], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -10])), [1, 2, 0, -1000], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -15])), [1, 2, 0, -1400], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -20])), [1, 2, 0, -1800], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -25])), [1, 2, 0, -2100], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -30])), [1, 2, 0, -2400], 8, t)
t_is(totcost(gencost, array([0, 0, 0, -35])), [1, 2, 0, -2700], 8, t)
t_end()
开发者ID:AdrianBajdiuk,项目名称:PowerGridResillience,代码行数:51,代码来源:t_totcost.py
示例2: 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
示例3: 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
示例4: t_hessian
def t_hessian(quiet=False):
"""Numerical tests of 2nd derivative code.
@author: Ray Zimmerman (PSERC Cornell)
"""
t_begin(44, quiet)
## run powerflow to get solved case
ppopt = ppoption(VERBOSE=0, OUT_ALL=0)
results, _ = runpf(case30(), ppopt)
baseMVA, bus, gen, branch = \
results['baseMVA'], results['bus'], results['gen'], results['branch']
## switch to internal bus numbering and build admittance matrices
_, bus, gen, branch = ext2int1(bus, gen, branch)
Ybus, Yf, Yt = makeYbus(baseMVA, bus, branch)
Vm = bus[:, VM]
Va = bus[:, VA] * (pi / 180)
V = Vm * exp(1j * Va)
f = branch[:, F_BUS] ## list of "from" buses
t = branch[:, T_BUS] ## list of "to" buses
nl = len(f)
nb = len(V)
Cf = sparse((ones(nl), (range(nl), f)), (nl, nb)) ## connection matrix for line & from buses
Ct = sparse((ones(nl), (range(nl), t)), (nl, nb)) ## connection matrix for line & to buses
pert = 1e-8
##----- check d2Sbus_dV2 code -----
t = ' - d2Sbus_dV2 (complex power injections)'
lam = 10 * random.rand(nb)
num_Haa = zeros((nb, nb), complex)
num_Hav = zeros((nb, nb), complex)
num_Hva = zeros((nb, nb), complex)
num_Hvv = zeros((nb, nb), complex)
dSbus_dVm, dSbus_dVa = dSbus_dV(Ybus, V)
Haa, Hav, Hva, Hvv = d2Sbus_dV2(Ybus, V, lam)
for i in range(nb):
Vap = V.copy()
Vap[i] = Vm[i] * exp(1j * (Va[i] + pert))
dSbus_dVm_ap, dSbus_dVa_ap = dSbus_dV(Ybus, Vap)
num_Haa[:, i] = (dSbus_dVa_ap - dSbus_dVa).T * lam / pert
num_Hva[:, i] = (dSbus_dVm_ap - dSbus_dVm).T * lam / pert
Vmp = V.copy()
Vmp[i] = (Vm[i] + pert) * exp(1j * Va[i])
dSbus_dVm_mp, dSbus_dVa_mp = dSbus_dV(Ybus, Vmp)
num_Hav[:, i] = (dSbus_dVa_mp - dSbus_dVa).T * lam / pert
num_Hvv[:, i] = (dSbus_dVm_mp - dSbus_dVm).T * lam / pert
t_is(Haa.todense(), num_Haa, 4, ['Haa', t])
t_is(Hav.todense(), num_Hav, 4, ['Hav', t])
t_is(Hva.todense(), num_Hva, 4, ['Hva', t])
t_is(Hvv.todense(), num_Hvv, 4, ['Hvv', t])
##----- check d2Sbr_dV2 code -----
t = ' - d2Sbr_dV2 (complex power flows)'
lam = 10 * random.rand(nl)
# lam = [1 zeros(nl-1, 1)]
num_Gfaa = zeros((nb, nb), complex)
num_Gfav = zeros((nb, nb), complex)
num_Gfva = zeros((nb, nb), complex)
num_Gfvv = zeros((nb, nb), complex)
num_Gtaa = zeros((nb, nb), complex)
num_Gtav = zeros((nb, nb), complex)
num_Gtva = zeros((nb, nb), complex)
num_Gtvv = zeros((nb, nb), complex)
dSf_dVa, dSf_dVm, dSt_dVa, dSt_dVm, _, _ = dSbr_dV(branch, Yf, Yt, V)
Gfaa, Gfav, Gfva, Gfvv = d2Sbr_dV2(Cf, Yf, V, lam)
Gtaa, Gtav, Gtva, Gtvv = d2Sbr_dV2(Ct, Yt, V, lam)
for i in range(nb):
Vap = V.copy()
Vap[i] = Vm[i] * exp(1j * (Va[i] + pert))
dSf_dVa_ap, dSf_dVm_ap, dSt_dVa_ap, dSt_dVm_ap, Sf_ap, St_ap = \
dSbr_dV(branch, Yf, Yt, Vap)
num_Gfaa[:, i] = (dSf_dVa_ap - dSf_dVa).T * lam / pert
num_Gfva[:, i] = (dSf_dVm_ap - dSf_dVm).T * lam / pert
num_Gtaa[:, i] = (dSt_dVa_ap - dSt_dVa).T * lam / pert
num_Gtva[:, i] = (dSt_dVm_ap - dSt_dVm).T * lam / pert
Vmp = V.copy()
Vmp[i] = (Vm[i] + pert) * exp(1j * Va[i])
dSf_dVa_mp, dSf_dVm_mp, dSt_dVa_mp, dSt_dVm_mp, Sf_mp, St_mp = \
dSbr_dV(branch, Yf, Yt, Vmp)
num_Gfav[:, i] = (dSf_dVa_mp - dSf_dVa).T * lam / pert
num_Gfvv[:, i] = (dSf_dVm_mp - dSf_dVm).T * lam / pert
num_Gtav[:, i] = (dSt_dVa_mp - dSt_dVa).T * lam / pert
num_Gtvv[:, i] = (dSt_dVm_mp - dSt_dVm).T * lam / pert
t_is(Gfaa.todense(), num_Gfaa, 4, ['Gfaa', t])
t_is(Gfav.todense(), num_Gfav, 4, ['Gfav', t])
t_is(Gfva.todense(), num_Gfva, 4, ['Gfva', t])
t_is(Gfvv.todense(), num_Gfvv, 4, ['Gfvv', t])
t_is(Gtaa.todense(), num_Gtaa, 4, ['Gtaa', t])
t_is(Gtav.todense(), num_Gtav, 4, ['Gtav', t])
t_is(Gtva.todense(), num_Gtva, 4, ['Gtva', t])
t_is(Gtvv.todense(), num_Gtvv, 4, ['Gtvv', t])
##----- check d2Ibr_dV2 code -----
t = ' - d2Ibr_dV2 (complex currents)'
#.........这里部分代码省略.........
开发者ID:Anastien,项目名称:PYPOWER,代码行数:101,代码来源:t_hessian.py
示例5: t_dcline
def t_dcline(quiet=False):
"""Tests for DC line extension in L{{toggle_dcline}.
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
num_tests = 50
t_begin(num_tests, quiet)
tdir = dirname(__file__)
casefile = join(tdir, 't_case9_dcline')
if quiet:
verbose = False
else:
verbose = False
t0 = ''
ppopt = ppoption(OPF_VIOLATION=1e-6, PDIPM_GRADTOL=1e-8,
PDIPM_COMPTOL=1e-8, PDIPM_COSTTOL=1e-9)
ppopt = ppoption(ppopt, OPF_ALG=560, OPF_ALG_DC=200)
ppopt = ppoption(ppopt, OUT_ALL=0, VERBOSE=verbose)
## 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])
## load case
ppc0 = loadcase(casefile)
del ppc0['dclinecost']
ppc = ppc0
ppc = toggle_dcline(ppc, 'on')
ppc = toggle_dcline(ppc, 'off')
ndc = ppc['dcline'].shape[0]
## run AC OPF w/o DC lines
t = ''.join([t0, 'AC OPF (no DC lines) : '])
r0 = runopf(ppc0, ppopt)
success = r0['success']
t_ok(success, [t, 'success'])
r = runopf(ppc, ppopt)
success = r['success']
t_ok(success, [t, 'success'])
t_is(r['f'], r0['f'], 8, [t, 'f'])
t_is( r['bus'][:,ib_data ], r0['bus'][:,ib_data ], 10, [t, 'bus data'])
t_is( r['bus'][:,ib_voltage], r0['bus'][:,ib_voltage], 3, [t, 'bus voltage'])
t_is( r['bus'][:,ib_lam ], r0['bus'][:,ib_lam ], 3, [t, 'bus lambda'])
t_is( r['bus'][:,ib_mu ], r0['bus'][:,ib_mu ], 2, [t, 'bus mu'])
t_is( r['gen'][:,ig_data ], r0['gen'][:,ig_data ], 10, [t, 'gen data'])
t_is( r['gen'][:,ig_disp ], r0['gen'][:,ig_disp ], 3, [t, 'gen dispatch'])
t_is( r['gen'][:,ig_mu ], r0['gen'][:,ig_mu ], 3, [t, 'gen mu'])
t_is(r['branch'][:,ibr_data ], r0['branch'][:,ibr_data ], 10, [t, 'branch data'])
t_is(r['branch'][:,ibr_flow ], r0['branch'][:,ibr_flow ], 3, [t, 'branch flow'])
t_is(r['branch'][:,ibr_mu ], r0['branch'][:,ibr_mu ], 2, [t, 'branch mu'])
t = ''.join([t0, 'AC PF (no DC lines) : '])
ppc1 = {'baseMVA': r['baseMVA'],
'bus': r['bus'][:, :VMIN + 1].copy(),
'gen': r['gen'][:, :APF + 1].copy(),
'branch': r['branch'][:, :ANGMAX + 1].copy(),
'gencost': r['gencost'].copy(),
'dcline': r['dcline'][:, :c.LOSS1 + 1].copy()}
ppc1['bus'][:, VM] = 1
ppc1['bus'][:, VA] = 0
rp = runpf(ppc1, ppopt)
success = rp['success']
t_ok(success, [t, 'success'])
t_is( rp['bus'][:,ib_voltage], r['bus'][:,ib_voltage], 3, [t, 'bus voltage'])
t_is( rp['gen'][:,ig_disp ], r['gen'][:,ig_disp ], 3, [t, 'gen dispatch'])
t_is(rp['branch'][:,ibr_flow ], r['branch'][:,ibr_flow ], 3, [t, 'branch flow'])
## run with DC lines
t = ''.join([t0, 'AC OPF (with DC lines) : '])
ppc = toggle_dcline(ppc, 'on')
r = runopf(ppc, ppopt)
success = r['success']
t_ok(success, [t, 'success'])
expected = array([
[10, 8.9, -10, 10, 1.0674, 1.0935],
[2.2776, 2.2776, 0, 0, 1.0818, 1.0665],
[0, 0, 0, 0, 1.0000, 1.0000],
[10, 9.5, 0.0563, -10, 1.0778, 1.0665]
])
t_is(r['dcline'][:, c.PF:c.VT + 1], expected, 4, [t, 'P Q V'])
expected = array([
[0, 0.8490, 0.6165, 0, 0, 0.2938],
[0, 0, 0, 0.4290, 0.0739, 0],
[0, 0, 0, 0, 0, 0],
[0, 7.2209, 0, 0, 0.0739, 0]
])
t_is(r['dcline'][:, c.MU_PMIN:c.MU_QMAXT + 1], expected, 3, [t, 'mu'])
#.........这里部分代码省略.........
开发者ID:AdrianBajdiuk,项目名称:PowerGridResillience,代码行数:101,代码来源:t_dcline.py
示例6: 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
示例7: 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
示例8: t_scale_load
def t_scale_load(quiet=False):
"""Tests for code in C{scale_load}.
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
n_tests = 275
t_begin(n_tests, quiet)
ppc = loadcase(join(dirname(__file__), 't_auction_case'))
ppc['gen'][7, GEN_BUS] = 2 ## multiple d. loads per area, same bus as gen
ppc['gen'][7, [QG, QMIN, QMAX]] = array([3, 0, 3])
## put it load before gen in matrix
ppc['gen'] = vstack([ppc['gen'][7, :], ppc['gen'][:7, :], ppc['gen'][8, :]])
ld = find(isload(ppc['gen']))
a = [None] * 3
lda = [None] * 3
for k in range(3):
a[k] = find(ppc['bus'][:, BUS_AREA] == k + 1) ## buses in area k
tmp = find( in1d(ppc['gen'][ld, GEN_BUS] - 1, a[k]) )
lda[k] = ld[tmp] ## disp loads in area k
area = [None] * 3
for k in range(3):
area[k] = {'fixed': {}, 'disp': {}, 'both': {}}
area[k]['fixed']['p'] = sum(ppc['bus'][a[k], PD])
area[k]['fixed']['q'] = sum(ppc['bus'][a[k], QD])
area[k]['disp']['p'] = -sum(ppc['gen'][lda[k], PMIN])
area[k]['disp']['qmin'] = -sum(ppc['gen'][lda[k], QMIN])
area[k]['disp']['qmax'] = -sum(ppc['gen'][lda[k], QMAX])
area[k]['disp']['q'] = area[k]['disp']['qmin'] + area[k]['disp']['qmax']
area[k]['both']['p'] = area[k]['fixed']['p'] + area[k]['disp']['p']
area[k]['both']['q'] = area[k]['fixed']['q'] + area[k]['disp']['q']
total = {'fixed': {}, 'disp': {}, 'both': {}}
total['fixed']['p'] = sum(ppc['bus'][:, PD])
total['fixed']['q'] = sum(ppc['bus'][:, QD])
total['disp']['p'] = -sum(ppc['gen'][ld, PMIN])
total['disp']['qmin'] = -sum(ppc['gen'][ld, QMIN])
total['disp']['qmax'] = -sum(ppc['gen'][ld, QMAX])
total['disp']['q'] = total['disp']['qmin'] + total['disp']['qmax']
total['both']['p'] = total['fixed']['p'] + total['disp']['p']
total['both']['q'] = total['fixed']['q'] + total['disp']['q']
##----- single load zone, one scale factor -----
load = array([2])
t = 'all fixed loads (PQ) * 2 : '
bus, _ = scale_load(load, ppc['bus'])
t_is(sum(bus[:, PD]), load * total['fixed']['p'], 8, [t, 'total fixed P'])
t_is(sum(bus[:, QD]), load * total['fixed']['q'], 8, [t, 'total fixed Q'])
opt = {'which': 'FIXED'}
bus, gen = scale_load(load, ppc['bus'], ppc['gen'], None, opt)
t_is(sum(bus[:, PD]), load * total['fixed']['p'], 8, [t, 'total fixed P'])
t_is(sum(bus[:, QD]), load * total['fixed']['q'], 8, [t, 'total fixed Q'])
t_is(-sum(gen[ld, PMIN]), total['disp']['p'], 8, [t, 'total disp P'])
t_is(-sum(gen[ld, QMIN]), total['disp']['qmin'], 8, [t, 'total disp Qmin'])
t_is(-sum(gen[ld, QMAX]), total['disp']['qmax'], 8, [t, 'total disp Qmax'])
t = 'all fixed loads (P) * 2 : '
opt = {'pq': 'P'}
bus, _ = scale_load(load, ppc['bus'], None, None, opt)
t_is(sum(bus[:, PD]), load * total['fixed']['p'], 8, [t, 'total fixed P'])
t_is(sum(bus[:, QD]), total['fixed']['q'], 8, [t, 'total fixed Q'])
opt = {'pq': 'P', 'which': 'FIXED'}
bus, gen = scale_load(load, ppc['bus'], ppc['gen'], None, opt)
t_is(sum(bus[:, PD]), load * total['fixed']['p'], 8, [t, 'total fixed P'])
t_is(sum(bus[:, QD]), total['fixed']['q'], 8, [t, 'total fixed Q'])
t_is(-sum(gen[ld, PMIN]), total['disp']['p'], 8, [t, 'total disp P'])
t_is(-sum(gen[ld, QMIN]), total['disp']['qmin'], 8, [t, 'total disp Qmin'])
t_is(-sum(gen[ld, QMAX]), total['disp']['qmax'], 8, [t, 'total disp Qmax'])
t = 'all loads (PQ) * 2 : '
bus, gen = scale_load(load, ppc['bus'], ppc['gen'])
t_is(sum(bus[:, PD]), load * total['fixed']['p'], 8, [t, 'total fixed P'])
t_is(sum(bus[:, QD]), load * total['fixed']['q'], 8, [t, 'total fixed Q'])
t_is(-sum(gen[ld, PMIN]), load * total['disp']['p'], 8, [t, 'total disp P'])
t_is(-sum(gen[ld, QMIN]), load * total['disp']['qmin'], 8, [t, 'total disp Qmin'])
t_is(-sum(gen[ld, QMAX]), load * total['disp']['qmax'], 8, [t, 'total disp Qmax'])
t = 'all loads (P) * 2 : '
opt = {'pq': 'P'}
bus, gen = scale_load(load, ppc['bus'], ppc['gen'], None, opt)
t_is(sum(bus[:, PD]), load * total['fixed']['p'], 8, [t, 'total fixed P'])
t_is(sum(bus[:, QD]), total['fixed']['q'], 8, [t, 'total fixed Q'])
t_is(-sum(gen[ld, PMIN]), load * total['disp']['p'], 8, [t, 'total disp P'])
t_is(-sum(gen[ld, QMIN]), total['disp']['qmin'], 8, [t, 'total disp Qmin'])
t_is(-sum(gen[ld, QMAX]), total['disp']['qmax'], 8, [t, 'total disp Qmax'])
t = 'all disp loads (PQ) * 2 : '
opt = {'which': 'DISPATCHABLE'}
bus, gen = scale_load(load, ppc['bus'], ppc['gen'], None, opt)
t_is(sum(bus[:, PD]), total['fixed']['p'], 8, [t, 'total fixed P'])
t_is(sum(bus[:, QD]), total['fixed']['q'], 8, [t, 'total fixed Q'])
t_is(-sum(gen[ld, PMIN]), load * total['disp']['p'], 8, [t, 'total disp P'])
t_is(-sum(gen[ld, QMIN]), load * total['disp']['qmin'], 8, [t, 'total disp Qmin'])
t_is(-sum(gen[ld, QMAX]), load * total['disp']['qmax'], 8, [t, 'total disp Qmax'])
#.........这里部分代码省略.........
开发者ID:charlie0389,项目名称:PYPOWER,代码行数:101,代码来源:t_scale_load.py
示例9: 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
示例10: 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
示例11: t_total_load
def t_total_load(quiet=False):
"""Tests for code in C{total_load}.
@author: Ray Zimmerman (PSERC Cornell)
@author: Richard Lincoln
"""
n_tests = 48
t_begin(n_tests, quiet)
ppc = loadcase(join(dirname(__file__), 't_auction_case'))
ppc['gen'][7, GEN_BUS] = 2 ## multiple d. loads per area, same bus as gen
ppc['gen'][7, [QG, QMIN, QMAX]] = array([3, 0, 3])
## put it load before gen in matrix
ppc['gen'] = vstack([ppc['gen'][7, :], ppc['gen'][:7, :], ppc['gen'][8, :]])
ld = find(isload(ppc['gen']))
a = [None] * 3
lda = [None] * 3
for k in range(3):
a[k] = find(ppc['bus'][:, BUS_AREA] == k + 1) ## buses in area k
tmp = find( in1d(ppc['gen'][ld, GEN_BUS] - 1, a[k]) )
lda[k] = ld[tmp] ## disp loads in area k
area = [None] * 3
for k in range(3):
area[k] = {'fixed': {}, 'disp': {}, 'both': {}}
area[k]['fixed']['p'] = sum(ppc['bus'][a[k], PD])
area[k]['fixed']['q'] = sum(ppc['bus'][a[k], QD])
area[k]['disp']['p'] = -sum(ppc['gen'][lda[k], PMIN])
area[k]['disp']['qmin'] = -sum(ppc['gen'][lda[k], QMIN])
area[k]['disp']['qmax'] = -sum(ppc['gen'][lda[k], QMAX])
area[k]['disp']['q'] = area[k]['disp']['qmin'] + area[k]['disp']['qmax']
area[k]['both']['p'] = area[k]['fixed']['p'] + area[k]['disp']['p']
area[k]['both']['q'] = area[k]['fixed']['q'] + area[k]['disp']['q']
total = {'fixed': {}, 'disp': {}, 'both': {}}
total['fixed']['p'] = sum(ppc['bus'][:, PD])
total['fixed']['q'] = sum(ppc['bus'][:, QD])
total['disp']['p'] = -sum(ppc['gen'][ld, PMIN])
total['disp']['qmin'] = -sum(ppc['gen'][ld, QMIN])
total['disp']['qmax'] = -sum(ppc['gen'][ld, QMAX])
total['disp']['q'] = total['disp']['qmin'] + total['disp']['qmax']
total['both']['p'] = total['fixed']['p'] + total['disp']['p']
total['both']['q'] = total['fixed']['q'] + total['disp']['q']
##----- all load -----
t = 'Pd, _ = total_load(bus) : '
Pd, _ = total_load(ppc['bus'])
t_is(Pd, [area[0]['fixed']['p'], area[1]['fixed']['p'], area[2]['fixed']['p']], 12, [t, 'Pd'])
t = 'Pd, Qd = total_load(bus) : '
Pd, Qd = total_load(ppc['bus'])
t_is(Pd, [area[0]['fixed']['p'], area[1]['fixed']['p'], area[2]['fixed']['p']], 12, [t, 'Pd'])
t_is(Qd, [area[0]['fixed']['q'], area[1]['fixed']['q'], area[2]['fixed']['q']], 12, [t, 'Qd'])
t = 'Pd, _ = total_load(bus, gen) : '
Pd, _ = total_load(ppc['bus'], ppc['gen'])
t_is(Pd, [area[0]['both']['p'], area[1]['both']['p'], area[2]['both']['p']], 12, [t, 'Pd'])
t = 'Pd, Qd = total_load(bus, gen) : '
Pd, Qd = total_load(ppc['bus'], ppc['gen'])
t_is(Pd, [area[0]['both']['p'], area[1]['both']['p'], area[2]['both']['p']], 12, [t, 'Pd'])
t_is(Qd, [area[0]['both']['q'], area[1]['both']['q'], area[2]['both']['q']], 12, [t, 'Qd'])
t = 'Pd, _ = total_load(bus, None, \'all\') : '
Pd, _ = total_load(ppc['bus'], None, 'all')
t_is(Pd, total['fixed']['p'], 12, [t, 'Pd'])
t = 'Pd, Qd = total_load(bus, None, \'all\') : '
Pd, Qd = total_load(ppc['bus'], None, 'all')
t_is(Pd, total['fixed']['p'], 12, [t, 'Pd'])
t_is(Qd, total['fixed']['q'], 12, [t, 'Qd'])
t = 'Pd, _ = total_load(bus, gen, \'all\') : '
Pd, _ = total_load(ppc['bus'], ppc['gen'], 'all')
t_is(Pd, total['both']['p'], 12, [t, 'Pd'])
t = 'Pd, Qd = total_load(bus, gen, \'all\') : '
Pd, Qd = total_load(ppc['bus'], ppc['gen'], 'all')
t_is(Pd, total['both']['p'], 12, [t, 'Pd'])
t_is(Qd, total['both']['q'], 12, [t, 'Qd'])
t = 'Pd, _ = total_load(bus, gen, \'all\', \'BOTH\') : '
Pd, _ = total_load(ppc['bus'], ppc['gen'], 'all', 'BOTH')
t_is(Pd, total['both']['p'], 12, [t, 'Pd'])
t = 'Pd, Qd = total_load(bus, gen, \'all\', \'BOTH\') : '
Pd, Qd = total_load(ppc['bus'], ppc['gen'], 'all', 'BOTH')
t_is(Pd, total['both']['p'], 12, [t, 'Pd'])
t_is(Qd, total['both']['q'], 12, [t, 'Qd'])
t = 'Pd, _ = total_load(bus, gen, \'all\', \'FIXED\') : '
Pd, _ = total_load(ppc['bus'], ppc['gen'], 'all', 'FIXED')
t_is(Pd, total['fixed']['p'], 12, [t, 'Pd'])
t = 'Pd, Qd = total_load(bus, gen, \'all\', \'FIXED\') : '
Pd, Qd = total_load(ppc['bus'], ppc['gen'], 'all', 'FIXED')
t_is(Pd, total['fixed']['p'], 12, [t, 'Pd'])
t_is(Qd, total['fixed']['q'], 12, [t, 'Qd'])
#.........这里部分代码省略.........
开发者ID:AdrianBajdiuk,项目名称:PowerGridResillience,代码行数:101,代码来源:t_total_load.py
示例12: 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
示例13: 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
|
请发表评论