Package pypower :: Package t :: Module t_runmarket
[hide private]
[frames] | no frames]

Source Code for Module pypower.t.t_runmarket

  1  # Copyright (C) 2005-2011 Power System Engineering Research Center (PSERC) 
  2  # Copyright (C) 2011 Richard Lincoln 
  3  # 
  4  # PYPOWER is free software: you can redistribute it and/or modify 
  5  # it under the terms of the GNU General Public License as published 
  6  # by the Free Software Foundation, either version 3 of the License, 
  7  # or (at your option) any later version. 
  8  # 
  9  # PYPOWER is distributed in the hope that it will be useful, 
 10  # but WITHOUT ANY WARRANTY], without even the implied warranty of 
 11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 12  # GNU General Public License for more details. 
 13  # 
 14  # You should have received a copy of the GNU General Public License 
 15  # along with PYPOWER. If not, see <http://www.gnu.org/licenses/>. 
 16   
 17  """Tests for code in C{runmkt}, C{smartmkt} and C{auction}. 
 18  """ 
 19   
 20  from numpy import array, ones, flatnonzero as find 
 21   
 22  from scipy.sparse import csr_matrix as sparse 
 23   
 24  from pypower.ppoption import ppoption 
 25  from pypower.loadcase import loadcase 
 26  from pypower.isload import isload 
 27   
 28  from pypower.idx_bus import BUS_I, LAM_P, LAM_Q 
 29  from pypower.idx_gen import GEN_BUS 
 30   
 31  from pypower.t.t_begin import t_begin 
 32  from pypower.t.t_is import t_is 
 33  from pypower.t.t_skip import t_skip 
 34  from pypower.t.t_end import t_end 
 35   
 36   
37 -def t_runmarket(quiet=False):
38 """Tests for code in C{runmkt}, C{smartmkt} and C{auction}. 39 40 @author: Ray Zimmerman (PSERC Cornell) 41 @author: Richard Lincoln 42 """ 43 n_tests = 20 44 45 t_begin(n_tests, quiet) 46 47 try: 48 from pypower.extras.smartmarket import runmarket 49 except ImportError: 50 t_skip(n_tests, 'smartmarket code not available') 51 t_end; 52 return 53 54 ppc = loadcase('t_auction_case') 55 56 ppopt = ppoption(OPF_ALG=560, OUT_ALL_LIM=1, 57 OUT_BRANCH=0, OUT_SYS_SUM=0) 58 ppopt = ppoption(ppopt, OUT_ALL=0, VERBOSE=1) 59 #ppopt = ppoption(ppopt, OUT_GEN=1, OUT_BRANCH=0, OUT_SYS_SUM=0) 60 61 offers = {'P': {}, 'Q': {}} 62 bids = {'P': {}, 'Q': {}} 63 64 offers['P']['qty'] = array([ 65 [12, 24, 24], 66 [12, 24, 24], 67 [12, 24, 24], 68 [12, 24, 24], 69 [12, 24, 24], 70 [12, 24, 24] 71 ]) 72 offers['P']['prc'] = array([ 73 [20, 50, 60], 74 [20, 40, 70], 75 [20, 42, 80], 76 [20, 44, 90], 77 [20, 46, 75], 78 [20, 48, 60] 79 ]) 80 bids['P']['qty'] = array([ 81 [10, 10, 10], 82 [10, 10, 10], 83 [10, 10, 10] 84 ]) 85 bids['P']['prc'] = array([ 86 [100, 70, 60], 87 # [100, 64.3, 20], 88 # [100, 30.64545, 0], 89 [100, 50, 20], 90 [100, 60, 50] 91 ]) 92 93 offers['Q']['qty'] = [ 60, 60, 60, 60, 60, 60, 0, 0, 0 ] 94 offers['Q']['prc'] = [ 0, 0, 0, 0, 0, 3, 0, 0, 0 ] 95 bids.Q['qty'] = [ 15, 15, 15, 15, 15, 15, 15, 12, 7.5 ] 96 # bids.Q['prc'] = [ 0, 0, 0, 0, 0, 0, 0, 83.9056, 0 ] 97 bids.Q['prc'] = [ 0, 0, 0, 0, 0, 0, 0, 20, 0 ] 98 99 t = 'marginal Q offer, marginal PQ bid, auction_type = 5' 100 mkt = {'auction_type': 5, 101 't': [], 102 'u0': [], 103 'lim': []} 104 r, co, cb, _, _, _, _ = runmarket(ppc, offers, bids, mkt, ppopt) 105 co5 = co.copy() 106 cb5 = cb.copy() 107 108 # [ co['P']['qty'] co['P']['prc'] ] 109 # [ cb['P']['qty'] cb['P']['prc'] ] 110 # [ co['Q']['qty'] co['Q']['prc'] ] 111 # [ cb['Q']['qty'] cb['Q']['prc'] ] 112 113 i2e = r['bus'][:, BUS_I] 114 e2i = sparse((max(i2e), 1)) 115 e2i[i2e] = range(r['bus'].size) 116 G = find( isload(r['gen']) == 0 ) ## real generators 117 L = find( isload(r['gen']) ) ## dispatchable loads 118 Gbus = e2i[r['gen'][G, GEN_BUS]] 119 Lbus = e2i[r['gen'][L, GEN_BUS]] 120 121 t_is( co['P']['qty'], ones((6, 1)) * [12, 24, 0], 2, [t, ' : gen P quantities'] ) 122 t_is( co['P']['prc'][0, :], 50.1578, 3, [t, ' : gen 1 P prices'] ) 123 t_is( cb['P']['qty'], [[10, 10, 10], [10, 0.196, 0], [10, 10, 0]], 2, [t, ' : load P quantities'] ) 124 t_is( cb['P']['prc'][1, :], 56.9853, 4, [t, ' : load 2 P price'] ) 125 t_is( co['P']['prc'][:, 0], r['bus'][Gbus, LAM_P], 8, [t, ' : gen P prices'] ) 126 t_is( cb['P']['prc'][:, 0], r['bus'][Lbus, LAM_P], 8, [t, ' : load P prices'] ) 127 128 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'] ) 129 t_is( co['Q']['prc'], [0, 0, 0, 0, 0, 3, 0.4861, 2.5367, 1.3763], 4, [t, ' : Q offer prices'] ) 130 t_is( cb['Q']['qty'], [0, 0, 0, 0, 0, 0, 15, 4.0785, 5], 2, [t, ' : Q bid quantities'] ) 131 t_is( cb['Q']['prc'], [0, 0, 0, 0, 0, 3, 0.4861, 2.5367, 1.3763], 4, [t, ' : Q bid prices'] ) 132 t_is( co['Q']['prc'], r['bus'][[Gbus, Lbus], LAM_Q], 8, [t, ' : Q offer prices'] ) 133 t_is( cb['Q']['prc'], co['Q']['prc'], 8, [t, ' : Q bid prices'] ) 134 135 t = 'marginal Q offer, marginal PQ bid, auction_type = 0' 136 mkt['auction_type'] = 0 137 r, co, cb, _, _, _, _ = runmarket(ppc, offers, bids, mkt, ppopt) 138 t_is( co['P']['qty'], co5['P']['qty'], 8, [t, ' : gen P quantities'] ) 139 t_is( cb['P']['qty'], cb5['P']['qty'], 8, [t, ' : load P quantities'] ) 140 t_is( co['P']['prc'], offers['P']['prc'], 8, [t, ' : gen P prices'] ) 141 t_is( cb['P']['prc'], bids['P']['prc'], 8, [t, ' : load P prices'] ) 142 143 t_is( co['Q']['qty'], co5['Q']['qty'], 8, [t, ' : gen Q quantities'] ) 144 t_is( cb['Q']['qty'], cb5['Q']['qty'], 8, [t, ' : load Q quantities'] ) 145 t_is( co['Q']['prc'], offers['Q']['prc'], 8, [t, ' : gen Q prices'] ) 146 t_is( cb['Q']['prc'], bids['Q']['prc'], 8, [t, ' : load Q prices'] ) 147 148 149 t_end
150