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

Source Code for Module pypower.t.t_auction_pips

  1  # Copyright (C) 2004-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 auction.py, using PIPS solver. 
 18  """ 
 19   
 20  from numpy import array, copy, ones, diag, flatnonzero as find 
 21  from scipy.sparse import csr_matrix as sparse 
 22   
 23  from pypower.ppoption import ppoption 
 24   
 25  from pypower.t.t_begin import t_begin 
 26  from pypower.t.t_is import t_is 
 27   
 28   
29 -def t_auction_pips(quiet=False):
30 """Tests for code in auction.py, using PIPS solver. 31 32 @author: Ray Zimmerman (PSERC Cornell) 33 @author: Richard Lincoln 34 """ 35 n_tests = 183 36 37 t_begin(n_tests, quiet) 38 39 try: 40 from pypower.extras.smartmarket import runmkt 41 except ImportError: 42 t_skip(n_tests, 'smartmarket code not available') 43 return 44 45 ppopt = ppoption 46 ppopt['OPF_VIOLATION'] = 1e-7 47 ppopt['PDIPM_GRADTOL'] = 1e-6 48 ppopt['PDIPM_COMPTOL'] = 1e-7 49 ppopt['PDIPM_COSTTOL'] = 5e-9 50 ppopt['OPF_ALG'] = 560 51 ppopt['OUT_ALL_LIM'] = 1 52 ppopt['OUT_BRANCH'] = 0 53 ppopt['OUT_SYS_SUM'] = 0 54 ppopt['OUT_ALL'] = 0 55 ppopt['VERBOSE'] = 0 56 q = array([ 57 [12, 24, 24], 58 [12, 24, 24], 59 [12, 24, 24], 60 [12, 24, 24], 61 [12, 24, 24], 62 [12, 24, 24], 63 [10, 10, 10], 64 [10, 10, 10], 65 [10, 10, 10], 66 ]) 67 68 ##----- one offer block marginal @ $50 ----- 69 p = array([ 70 [20, 50, 60], 71 [20, 40, 70], 72 [20, 42, 80], 73 [20, 44, 90], 74 [20, 46, 75], 75 [20, 48, 60], 76 [100, 70, 60], 77 [100, 50, 20], 78 [100, 60, 50] 79 ]) 80 81 t = 'one marginal offer @ $50, auction_type = 5' 82 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 83 runmkt('t_auction_case', q, p, 1150, 100, [], [], mpopt) 84 cq5 = cq.copy() 85 cp5 = cp.copy() 86 i2e = bus.bus_i 87 e2i = sparse((max(i2e), 1)) 88 e2i[i2e] = range(bus.size()) 89 G = find( isload(gen) == False ) ## real generators 90 L = find( isload(gen) ) ## dispatchable loads 91 Gbus = e2i[gen.gen_bus[G]] 92 Lbus = e2i[gen.gen_bus[L]] 93 Qfudge = zeros(p.shape) 94 Qfudge[L, :] = \ 95 diag(gen.Qg[L] / gen.Pg[L] * bus.lam_Q[Lbus]) * ones(p[L :].shape) 96 97 t_is( cq[G[0], 1:3], [23.32, 0], 2, t ) 98 t_is( cp[G[0], :], 50, 4, t ) 99 t_is( cq[L[1], 0:2], [10, 0], 2, t ) 100 t_is( cp[L[1], :], 54.0312, 4, t ) 101 t_is( cp[G, 0], bus.lam_P[Gbus], 8, [t, ' : gen prices'] ) 102 t_is( cp[L, 0], bus.lam_P[Lbus] + Qfudge[L, 0], 8, [t, ' : load prices'] ) 103 104 lao_X = p(G[0], 1) / bus.lam_P[Gbus[0], LAM_P] 105 fro_X = p(G(5), 2) / bus.lam_P[Gbus[5], LAM_P] 106 lab_X = p(L(2), 1) / (bus.lam_P[Lbus[2]] + Qfudge[L[2], 0]) 107 frb_X = p(L(1), 1) / (bus.lam_P[Lbus[1]] + Qfudge[L[1], 0]) 108 109 t_is( lao_X, 1, 4, 'lao_X') 110 t_is( fro_X, 1.1324, 4, 'fro_X') 111 t_is( lab_X, 1.0787, 4, 'lab_X') 112 t_is( frb_X, 0.9254, 4, 'frb_X') 113 114 t = 'one marginal offer @ $50, auction_type = 1' 115 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 116 runmkt('t_auction_case', q, p, 1110, 100, [], [], mpopt) 117 cp1 = cp.copy() 118 t_is( cq, cq5, 8, [t, ' : quantities'] ) 119 t_is( cp, cp5, 6, [t, ' : prices'] ) 120 121 t = 'one marginal offer @ $50, auction_type = 2' 122 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 123 runmkt('t_auction_case', q, p, 1120, 100, [], [], mpopt) 124 cp2 = cp.copy() 125 t_is( cq, cq5, 8, [t, ' : quantities'] ) 126 t_is( cp[G, :], cp5[G, :] * fro_X, 8, [t, ' : gen prices'] ) 127 t_is( cp[L[0:1], :], cp5[L[0:1], :] * fro_X, 8, [t, ' : load 1,2 prices'] ) 128 t_is( cp[L[2], :], 60, 5, [t, ' : load 3 price'] ) ## clipped by accepted bid 129 130 t = 'one marginal offer @ $50, auction_type = 3' 131 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 132 runmkt('t_auction_case', q, p, 1130, 100, [], [], mpopt) 133 cp3 = cp.copy() 134 t_is( cq, cq5, 8, [t, ' : quantities'] ) 135 t_is( cp, cp5 * lab_X, 8, [t, ' : prices'] ) 136 137 t = 'one marginal offer @ $50, auction_type = 4' 138 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 139 runmkt('t_auction_case', q, p, 1140, 100, [], [], mpopt) 140 t_is( cq, cq5, 8, [t, ' : quantities'] ) 141 t_is( cp[G[0], :], p[G[0], 1], 8, [t, ' : gen 1 price'] ) 142 t_is( cp[G[1:6], :], cp5[G[1:6], :] * frb_X, 8, [t, ' : gen 2-6 prices'] ) 143 t_is( cp[L, :], cp5[L, :] * frb_X, 8, [t, ' : load prices'] ) 144 145 t = 'one marginal offer @ $50, auction_type = 6' 146 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 147 runmkt('t_auction_case', q, p, 1160, 100, [], [], mpopt) 148 t_is( cq, cq5, 8, [t, ' : quantities'] ) 149 t_is( cp, cp3, 8, [t, ' : prices'] ) 150 p2 = p.copy() 151 p2[L, :] = array([ 152 [100, 100, 100], 153 [100, 0, 0], 154 [100, 100, 0] 155 ]) 156 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 157 runmkt('t_auction_case', q, p2, 1160, 100, [], [], mpopt) 158 t_is( cq, cq5, 5, [t, ' : quantities'] ) 159 t_is( cp[G, :], cp5[G, :] * fro_X, 4, [t, ' : gen prices'] ) 160 t_is( cp[L, :], cp5[L, :] * fro_X, 4, [t, ' : load prices'] ) ## load 3 not clipped as in FRO 161 162 t = 'one marginal offer @ $50, auction_type = 7' 163 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 164 runmkt('t_auction_case', q, p, 1170, 100, [], [], mpopt) 165 t_is( cq, cq5, 8, [t, ' : quantities'] ) 166 t_is( cp, cp5 * (lao_X + lab_X) / 2, 8, [t, ' : prices'] ) 167 t_is( cp, (cp1 + cp3) / 2, 8, [t, ' : prices'] ) 168 169 t = 'one marginal offer @ $50, auction_type = 8' 170 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 171 runmkt('t_auction_case', q, p, 1180, 100, [], [], mpopt) 172 t_is( cq, cq5, 8, [t, ' : quantities'] ) 173 t_is( cp[G, :], cp1[G, :], 8, [t, ' : gen prices'] ) 174 t_is( cp[L, :], cp3[L, :], 8, [t, ' : load prices'] ) 175 176 t = 'one marginal offer @ $50, auction_type = 0' 177 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 178 runmkt('t_auction_case', q, p, 1100, 100, [], [], mpopt) 179 t_is( cq, cq5, 8, [t, ' : quantities'] ) 180 t_is( cp, p, 8, [t, ' : prices'] ) 181 182 183 ##----- one bid block marginal @ $55 ----- 184 p[L[1], 1] = 55 185 t = 'one marginal bid @ $55, auction_type = 5' 186 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 187 runmkt('t_auction_case', q, p, 1150, 100, [], [], mpopt) 188 cq5 = cq.copy() 189 cp5 = cp.copy() 190 Qfudge = zeros(p.shape) 191 Qfudge[L, :] = diag(gen.Qg[L] / gen.Pg[L] * bus.lam_Q[Lbus]) * ones(p[L, :].shape) 192 193 t_is( cq[G[0], 1:3], [24, 0], 2, t ) 194 t_is( cp[G[0], :], 50.016, 3, t ) 195 t_is( cq[L[1], 0:2], [10, 0.63], 2, t ) 196 t_is( cp[L[1], :], 55, 4, t ) 197 t_is( cp[G, 0], bus.lam_P[Gbus], 8, [t, ' : gen prices'] ) 198 t_is( cp[L, 0], bus.lam_P[Lbus] + Qfudge[L, 0], 8, [t, ' : load prices'] ) 199 200 lao_X = p[G[0], 1] / bus.lam_P[Gbus[0]] 201 fro_X = p[G[5], 2] / bus.lam_P[Gbus[5]] 202 lab_X = p[L[1], 1] / (bus.lam_P[Lbus[1]] + Qfudge[L[1], 0]) 203 frb_X = p[L[2], 2] / (bus.lam_P[Lbus[2]] + Qfudge[L[2], 0]) 204 205 t_is( lao_X, 0.9997, 4, 'lao_X') 206 t_is( fro_X, 1.1111, 4, 'fro_X') 207 t_is( lab_X, 1, 4, 'lab_X') 208 t_is( frb_X, 0.8960, 4, 'frb_X') 209 210 t = 'one marginal bid @ $55, auction_type = 1' 211 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 212 runmkt('t_auction_case', q, p, 1110, 100, [], [], mpopt) 213 cp1 = cp.copy() 214 t_is( cq, cq5, 8, [t, ' : quantities'] ) 215 t_is( cp, cp5 * lao_X, 8, [t, ' : prices'] ) 216 217 t = 'one marginal bid @ $55, auction_type = 2' 218 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 219 runmkt('t_auction_case', q, p, 1120, 100, [], [], mpopt) 220 cp2 = cp.copy() 221 t_is( cq, cq5, 8, [t, ' : quantities'] ) 222 t_is( cp[G, :], cp5[G, :] * fro_X, 8, [t, ' : gen prices'] ) 223 t_is( cp[L[0], :], cp5[L[0], :] * fro_X, 8, [t, ' : load 1 price'] ) 224 t_is( cp[L[1], :], 55, 5, [t, ' : load 2 price'] ) 225 t_is( cp[L[2], :], 60, 5, [t, ' : load 3 price'] ) 226 227 t = 'one marginal bid @ $55, auction_type = 3' 228 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 229 runmkt('t_auction_case', q, p, 1130, 100, [], [], mpopt) 230 cp3 = cp.copy() 231 t_is( cq, cq5, 8, [t, ' : quantities'] ) 232 t_is( cp, cp5, 7, [t, ' : prices'] ) 233 234 t = 'one marginal bid @ $55, auction_type = 4' 235 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 236 runmkt('t_auction_case', q, p, 1140, 100, [], [], mpopt) 237 cp4 = cp.copy() 238 t_is( cq, cq5, 8, [t, ' : quantities'] ) 239 t_is( cp[G[0], :], 50, 5, [t, ' : gen 1 price'] ) 240 t_is( cp[G[1:6], :], cp5[G[1:6], :] * frb_X, 8, [t, ' : gen 2-6 prices'] ) 241 t_is( cp[L, :], cp5[L, :] * frb_X, 8, [t, ' : load prices'] ) 242 243 t = 'one marginal bid @ $55, auction_type = 6' 244 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 245 runmkt('t_auction_case', q, p, 1160, 100, [], [], mpopt) 246 t_is( cq, cq5, 8, [t, ' : quantities'] ) 247 t_is( cp, cp1, 8, [t, ' : prices'] ) 248 249 p2 = p.copy() 250 p2[G, :] = array([ 251 [0, 0, 100], 252 [0, 0, 100], 253 [0, 0, 100], 254 [0, 0, 100], 255 [0, 0, 100], 256 [0, 0, 100] 257 ]) 258 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 259 runmkt('t_auction_case', q, p2, 1160, 100, [], [], mpopt) 260 t_is( cq, cq5, 3, [t, ' : quantities'] ) 261 t_is( cp[G, :], cp5[G, :] * frb_X, 3, [t, ' : gen prices'] ) ## gen 1, not clipped this time 262 t_is( cp[L, :], cp4[L, :], 3, [t, ' : load prices'] ) 263 264 t = 'one marginal bid @ $55, auction_type = 7' 265 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 266 runmkt('t_auction_case', q, p, 1170, 100, [], [], mpopt) 267 t_is( cq, cq5, 8, [t, ' : quantities'] ) 268 t_is( cp, cp5 * (lao_X + lab_X) / 2, 8, [t, ' : prices'] ) 269 t_is( cp, (cp1 + cp3) / 2, 8, [t, ' : prices'] ) 270 271 t = 'one marginal bid @ $55, auction_type = 8' 272 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 273 runmkt('t_auction_case', q, p, 1180, 100, [], [], mpopt) 274 t_is( cq, cq5, 8, [t, ' : quantities'] ) 275 t_is( cp[G, :], cp1[G, :], 8, [t, ' : gen prices'] ) 276 t_is( cp[L, :], cp3[L, :], 8, [t, ' : load prices'] ) 277 278 t = 'one marginal bid @ $55, auction_type = 0' 279 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 280 runmkt('t_auction_case', q, p, 1100, 100, [], [], mpopt) 281 t_is( cq, cq5, 8, [t, ' : quantities'] ) 282 t_is( cp, p, 8, [t, ' : prices'] ) 283 284 285 ##----- one bid block marginal @ $54.50 and one offer block marginal @ $50 ----- 286 p[L[1], 1] = 54.5 287 t = 'marginal offer @ $50, bid @ $54.50, auction_type = 5' 288 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 289 runmkt('t_auction_case', q, p, 1150, 100, [], [], mpopt) 290 cq5 = cq.copy() 291 cp5 = cp.copy() 292 Qfudge = zeros(p.shape) 293 Qfudge[L, :] = diag(gen.Qg[L] / gen.Pg[L] * bus.lam_Q[Lbus]) * ones(p[L, :].shape) 294 295 t_is( cq[G[0], 1:3], [23.74, 0], 2, t ) 296 t_is( cp[G[0], :], 50, 4, t ) 297 t_is( cq[L[1], 0:2], [10, 0.39], 2, t ) 298 t_is( cp[L[1], :], 54.5, 4, t ) 299 t_is( cp[G, 0], bus.lam_P[Gbus], 8, [t, ' : gen prices'] ) 300 t_is( cp[L, 0], bus.lam_P[Lbus] + Qfudge[L, 0], 8, [t, ' : load prices'] ) 301 302 lao_X = p[G[0], 1] / bus.lam_P[Gbus[0]] 303 fro_X = p[G[5], 2] / bus.lam_P[Gbus[5]] 304 lab_X = p[L[1], 1] / (bus.lam_P[Lbus[1]] + Qfudge[L[1], 0]) 305 frb_X = p[L[2], 2] / (bus.lam_P[Lbus[2]] + Qfudge[L[2], 0]) 306 307 t_is( lao_X, 1, 4, 'lao_X') 308 t_is( fro_X, 1.1221, 4, 'fro_X') 309 t_is( lab_X, 1, 4, 'lab_X') 310 t_is( frb_X, 0.8976, 4, 'frb_X') 311 312 t = 'marginal offer @ $50, bid @ $54.50, auction_type = 1' 313 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 314 runmkt('t_auction_case', q, p, 1110, 100, [], [], mpopt) 315 cp1 = cp.copy() 316 t_is( cq, cq5, 8, [t, ' : quantities'] ) 317 t_is( cp, cp5, 4, [t, ' : prices'] ) 318 319 t = 'marginal offer @ $50, bid @ $54.50, auction_type = 2' 320 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 321 runmkt('t_auction_case', q, p, 1120, 100, [], [], mpopt) 322 cp2 = cp.copy() 323 t_is( cq, cq5, 8, [t, ' : quantities'] ) 324 t_is( cp[G, :], cp5[G, :] * fro_X, 5, [t, ' : gen prices'] ) 325 t_is( cp[L[0], :], cp5[L[0], :] * fro_X, 5, [t, ' : load 1 price'] ) 326 t_is( cp[L[1], :], 54.5, 5, [t, ' : load 2 price'] ) 327 t_is( cp[L[2], :], 60, 5, [t, ' : load 3 price'] ) 328 329 t = 'marginal offer @ $50, bid @ $54.50, auction_type = 3' 330 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 331 runmkt('t_auction_case', q, p, 1130, 100, [], [], mpopt) 332 cp3 = cp.copy() 333 t_is( cq, cq5, 8, [t, ' : quantities'] ) 334 t_is( cp, cp5, 6, [t, ' : prices'] ) 335 336 t = 'marginal offer @ $50, bid @ $54.50, auction_type = 4' 337 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 338 runmkt('t_auction_case', q, p, 1140, 100, [], [], mpopt) 339 cp4 = cp.copy() 340 t_is( cq, cq5, 8, [t, ' : quantities'] ) 341 t_is( cp[G[0], :], 50, 5, [t, ' : gen 1 price'] ) 342 t_is( cp[G[1:5], :], cp5[G[1:5], :] * frb_X, 8, [t, ' : gen 2-5 prices'] ) 343 t_is( cp[G[5], :], 48, 5, [t, ' : gen 6 price'] ) 344 t_is( cp[L, :], cp5[L, :] * frb_X, 8, [t, ' : load prices'] ) 345 346 t = 'marginal offer @ $50, bid @ $54.50, auction_type = 6' 347 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 348 runmkt('t_auction_case', q, p, 1160, 100, [], [], mpopt) 349 t_is( cq, cq5, 8, [t, ' : quantities'] ) 350 t_is( cp, cp5, 4, [t, ' : prices'] ) 351 352 t = 'marginal offer @ $50, bid @ $54.50, auction_type = 7' 353 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 354 runmkt('t_auction_case', q, p, 1170, 100, [], [], mpopt) 355 t_is( cq, cq5, 8, [t, ' : quantities'] ) 356 t_is( cp, cp5, 4, [t, ' : prices'] ) 357 358 t = 'marginal offer @ $50, bid @ $54.50, auction_type = 8' 359 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 360 runmkt('t_auction_case', q, p, 1180, 100, [], [], mpopt) 361 t_is( cq, cq5, 8, [t, ' : quantities'] ) 362 t_is( cp, cp5, 4, [t, ' : prices'] ) 363 364 t = 'marginal offer @ $50, bid @ $54.50, auction_type = 0' 365 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 366 runmkt('t_auction_case', q, p, 1100, 100, [], [], mpopt) 367 t_is( cq, cq5, 8, [t, ' : quantities'] ) 368 t_is( cp, p, 8, [t, ' : prices'] ) 369 370 371 ##----- gen 1 at Pmin, load 3 block 2 marginal @ $60 ----- 372 t = 'gen 1 @ Pmin, marginal bid @ $60, auction_type = 5' 373 p[L[1], 1] = 50 ## undo previous change 374 p2 = p.copy() 375 p2[G[0], 1:3] = [65, 65] 376 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 377 runmkt('t_auction_case', q, p2, 1150, 100, [], [], mpopt) 378 Qfudge = zeros(p.shape) 379 Qfudge[L, :] = diag(gen.Qg[L] / gen.Pg[L] * bus.lam_Q[Lbus]) * ones(p[L, :].shape) 380 381 t_is( cp[G[0], :], 65, 4, [t, ' : gen 1 price'] ) 382 t_is( cp[G[1], :], 54.2974, 4, [t, ' : gen 2 price'] ) 383 cq5 = cq.copy() 384 cp5 = cp.copy() 385 cp_lam = cp5.copt() 386 cp_lam[0, :] = bus.lam_P[Gbus[0]] ## unclipped 387 388 lao_X = p2[G[5], 1] / bus.lam_P[Gbus[5]] 389 fro_X = p2[G[5], 2] / bus.lam_P[Gbus[5]] 390 lab_X = p2[L[2], 1] / (bus.lam_P[Lbus[2]] + Qfudge[L[2], 0]) 391 frb_X = p2[L[1], 1] / (bus.lam_P[Lbus[1]] + Qfudge[L[1], 0]) 392 393 t_is( lao_X, 0.8389, 4, 'lao_X') 394 t_is( fro_X, 1.0487, 4, 'fro_X') 395 t_is( lab_X, 1, 4, 'lab_X') 396 t_is( frb_X, 0.8569, 4, 'frb_X') 397 398 t = 'gen 1 @ Pmin, marginal bid @ $60, auction_type = 1' 399 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 400 runmkt('t_auction_case', q, p2, 1110, 100, [], [], mpopt) 401 cp1 = cp.copy() 402 t_is( cq, cq5, 8, [t, ' : quantities'] ) 403 t_is( cp[G[0], :], 65, 8, [t, ' : gen 1 price'] ) 404 t_is( cp[G[1:6], :], cp_lam[G[1:6], :] * lao_X, 8, [t, ' : gen 2-6 prices'] ) 405 t_is( cp[L, :], cp_lam[L, :] * lao_X, 8, [t, ' : load prices'] ) 406 407 t = 'gen 1 @ Pmin, marginal bid @ $60, auction_type = 2' 408 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 409 runmkt('t_auction_case', q, p2, 1120, 100, [], [], mpopt) 410 t_is( cq, cq5, 8, [t, ' : quantities'] ) 411 t_is( cp[G[0], :], 65, 8, [t, ' : gen 1 price'] ) 412 t_is( cp[G[1:6], :], cp_lam[G[1:6], :] * fro_X, 8, [t, ' : gen 2-6 prices'] ) 413 t_is( cp[L[0:2], :], cp_lam[L[0:2], :] * fro_X, 8, [t, ' : load 1-2 prices'] ) 414 t_is( cp[L[2], :], 60, 8, [t, ' : load 3 price'] ) 415 416 t = 'gen 1 @ Pmin, marginal bid @ $60, auction_type = 3' 417 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 418 runmkt('t_auction_case', q, p2, 1130, 100, [], [], mpopt) 419 cp3 = cp.copy() 420 t_is( cq, cq5, 8, [t, ' : quantities'] ) 421 t_is( cp[G[0], :], 65, 8, [t, ' : gen 1 price'] ) 422 t_is( cp[G[1:6], :], cp_lam[G[1:6], :], 6, [t, ' : gen 2-6 prices'] ) 423 t_is( cp[L, :], cp_lam[L, :], 6, [t, ' : load prices'] ) 424 425 t = 'gen 1 @ Pmin, marginal bid @ $60, auction_type = 4' 426 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 427 runmkt('t_auction_case', q, p2, 1140, 100, [], [], mpopt) 428 cp4 = cp.copy() 429 t_is( cq, cq5, 8, [t, ' : quantities'] ) 430 t_is( cp[G[0], :], 65, 5, [t, ' : gen 1 price'] ) 431 t_is( cp[G[1:6], :], cp5[G[1:6], :] * frb_X, 8, [t, ' : gen 2-6 prices'] ) 432 t_is( cp[L, :], cp5[L, :] * frb_X, 8, [t, ' : load prices'] ) 433 434 t = 'gen 1 @ Pmin, marginal bid @ $60, auction_type = 6' 435 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 436 runmkt('t_auction_case', q, p2, 1160, 100, [], [], mpopt) 437 t_is( cq, cq5, 8, [t, ' : quantities'] ) 438 t_is( cp, cp4, 8, [t, ' : prices'] ) 439 440 t = 'gen 1 @ Pmin, marginal bid @ $60, auction_type = 7' 441 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 442 runmkt('t_auction_case', q, p2, 1170, 100, [], [], mpopt) 443 t_is( cq, cq5, 8, [t, ' : quantities'] ) 444 t_is( cp[G[0], :], 65, 4, [t, ' : gen 1 price'] ) 445 t_is( cp[G[1:6], :], cp_lam[G[1:6], :] * (lao_X + lab_X) / 2, 8, [t, ' : gen 2-6 prices'] ) 446 t_is( cp[L, :], cp_lam[L, :] * (lao_X + lab_X) / 2, 8, [t, ' : load prices'] ) 447 t_is( cp, (cp1 + cp3) / 2, 8, [t, ' : prices'] ) 448 449 t = 'gen 1 @ Pmin, marginal bid @ $60, auction_type = 8' 450 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 451 runmkt('t_auction_case', q, p2, 1180, 100, [], [], mpopt) 452 t_is( cq, cq5, 8, [t, ' : quantities'] ) 453 t_is( cp[G, :], cp1[G, :], 8, [t, ' : prices'] ) 454 t_is( cp[L, :], cp3[L, :], 8, [t, ' : prices'] ) 455 456 t = 'gen 1 @ Pmin, marginal bid @ $60, auction_type = 0' 457 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 458 runmkt('t_auction_case', q, p2, 1100, 100, [], [], mpopt) 459 t_is( cq, cq5, 8, [t, ' : quantities'] ) 460 t_is( cp, p2, 8, [t, ' : prices'] ) 461 462 463 ##----- gen 1 at Pmin, gen 6 block 3 marginal @ $60 ----- 464 t = 'gen 1 @ Pmin, marginal offer @ $60, auction_type = 5' 465 p2[L, :] = array([ 466 [100, 100, 100], 467 [100, 0, 0], 468 [100, 100, 0] 469 ]) 470 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 471 runmkt('t_auction_case', q, p2, 1150, 100, [], [], mpopt) 472 Qfudge = zeros(p.shape) 473 Qfudge[L, :] = diag(gen.Qg[L] / gen.Pg[L] * bus.lam_Q[Lbus]) * ones(p[L, :].shape) 474 475 t_is( cp[G[0], :], 65, 4, [t, ' : gen 1 price'] ) 476 t_is( cp[G[1], :], 57.1612, 4, [t, ' : gen 2 price'] ) 477 cq5 = cq.copy() 478 cp5 = cp.copy() 479 cp_lam = cp5.copy() 480 cp_lam[0, :] = bus.lamP[Gbus[0]] ## unclipped 481 482 lao_X = p2[G[5], 2] / bus.lam_P[Gbus[5]] 483 fro_X = p2[G[0], 2] / bus.lam_P[Gbus[0]] 484 lab_X = p2[L[2], 1] / (bus.lam_P[Lbus[2]] + Qfudge[L[2], 0]) 485 frb_X = p2[L[1], 1] / (bus.lam_P[Lbus[1]] + Qfudge[L[1], 0]) 486 487 t_is( lao_X, 1, 4, 'lao_X') 488 t_is( fro_X, 1.1425, 4, 'fro_X') 489 t_is( lab_X, 1.5813, 4, 'lab_X') 490 t_is( frb_X, 0, 4, 'frb_X') 491 492 t = 'gen 1 @ Pmin, marginal offer @ $60, auction_type = 1' 493 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 494 runmkt('t_auction_case', q, p2, 1110, 100, [], [], mpopt) 495 cp1 = cp.copy() 496 t_is( cq, cq5, 8, [t, ' : quantities'] ) 497 t_is( cp, cp5, 6, [t, ' : prices'] ) 498 499 t = 'gen 1 @ Pmin, marginal offer @ $60, auction_type = 2' 500 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 501 runmkt('t_auction_case', q, p2, 1120, 100, [], [], mpopt) 502 t_is( cq, cq5, 8, [t, ' : quantities'] ) 503 t_is( cp, cp_lam * fro_X, 8, [t, ' : prices'] ) 504 505 t = 'gen 1 @ Pmin, marginal offer @ $60, auction_type = 3' 506 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 507 runmkt('t_auction_case', q, p2, 1130, 100, [], [], mpopt) 508 cp3 = cp.copy() 509 t_is( cq, cq5, 8, [t, ' : quantities'] ) 510 t_is( cp, cp_lam * lab_X, 8, [t, ' : prices'] ) 511 512 t = 'gen 1 @ Pmin, marginal offer @ $60, auction_type = 4' 513 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 514 runmkt('t_auction_case', q, p2, 1140, 100, [], [], mpopt) 515 t_is( cq, cq5, 8, [t, ' : quantities'] ) 516 t_is( cp[G, 0], [654042444660], 4, [t, ' : gen prices'] ) 517 t_is( cp[L, :], cp_lam[L, :] * frb_X, 8, [t, ' : prices'] ) 518 519 t = 'gen 1 @ Pmin, marginal offer @ $60, auction_type = 6' 520 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 521 runmkt('t_auction_case', q, p2, 1160, 100, [], [], mpopt) 522 t_is( cq, cq5, 8, [t, ' : quantities'] ) 523 t_is( cp, cp_lam * fro_X, 8, [t, ' : prices'] ) 524 525 t = 'gen 1 @ Pmin, marginal offer @ $60, auction_type = 7' 526 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 527 runmkt('t_auction_case', q, p2, 1170, 100, [], [], mpopt) 528 t_is( cq, cq5, 8, [t, ' : quantities'] ) 529 t_is( cp, cp_lam * (lao_X + lab_X) / 2, 8, [t, ' : prices'] ) 530 t_is( cp, (cp_lam + cp3) / 2, 7, [t, ' : prices'] ) 531 532 t = 'gen 1 @ Pmin, marginal offer @ $60, auction_type = 8' 533 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 534 runmkt('t_auction_case', q, p2, 1180, 100, [], [], mpopt) 535 t_is( cq, cq5, 8, [t, ' : quantities'] ) 536 t_is( cp[G, :], cp5[G, :], 7, [t, ' : prices'] ) 537 t_is( cp[L, :], cp3[L, :], 8, [t, ' : prices'] ) 538 539 t = 'gen 1 @ Pmin, marginal offer @ $60, auction_type = 0' 540 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 541 runmkt('t_auction_case', q, p2, 1100, 100, [], [], mpopt) 542 t_is( cq, cq5, 8, [t, ' : quantities'] ) 543 t_is( cp, p2, 8, [t, ' : prices'] ) 544 545 546 ##----- gen 2 decommitted, one offer block marginal @ $60 ----- 547 p[G[1], :] = p[G[1], :] + 100 548 549 t = 'price of decommited gen, auction_type = 5' 550 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 551 runmkt('t_auction_case', q, p, 1150, 200, [], [], mpopt) 552 cp5 = cp.copy() 553 Qfudge = zeros(p.shape) 554 Qfudge[L, :] = diag(gen.Qg[L] / gen.Pg[L] * bus.lam_Q[Lbus]) * ones(p[L, :].shape) 555 t_is(sum(cq[1, :]), 0, 8, t) 556 t_is(cp[1, 0], 59.194, 3, t) 557 558 # Xo = p[0:6, :] / (diag(bus.lam_P[Gbus]) * ones(p[G, :].shape)) 559 # ao = (cq[0:6, :] != 0) 560 # ro = (cq[0:6, :] == 0) 561 # Xb = p[6:9, :] / (diag(bus.lam_P[Lbus] + gen.Qg[L] / gen.Pg[L] * bus.lam_Q[Lbus]) * ones(p[L, :].shape)) 562 # ab = (cq[6:9, :] != 0) 563 # rb = (cq[6:9, :] == 0) 564 # aXo = ao * Xo 565 # rXo = ro * Xo 566 # aXb = ab * Xb 567 # rXb = rb * Xb 568 569 lao_X = p[G[5], 2] / bus.lam_P[Gbus[5]] 570 fro_X = p[G[0], 2] / bus.lam_P[Gbus[0]] 571 lab_X = p[L[0], 1] / (bus.lam_P[Lbus[0]] + Qfudge[L[0], 0]) 572 frb_X = p[L[0], 2] / (bus.lam_P[Lbus[0]] + Qfudge[L[0], 0]) 573 574 t_is( lao_X, 1, 4, 'lao_X') 575 t_is( fro_X, 1.0212, 4, 'fro_X') 576 t_is( lab_X, 1.1649, 4, 'lab_X') 577 t_is( frb_X, 0.9985, 4, 'frb_X') 578 579 t = 'price of decommited gen, auction_type = 1' 580 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 581 runmkt('t_auction_case', q, p, 1110, 200, [], [], mpopt) 582 t_is(cp[1, 0], 59.194, 3, t) 583 584 t = 'price of decommited gen, auction_type = 2' 585 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 586 runmkt('t_auction_case', q, p, 1120, 200, [], [], mpopt) 587 t_is(cp[1, 0], cp5[1, 0] * fro_X, 3, t) 588 589 t = 'price of decommited gen, auction_type = 3' 590 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 591 runmkt('t_auction_case', q, p, 1130, 200, [], [], mpopt) 592 t_is(cp[1, 0], cp5[1, 0] * lab_X, 3, t) 593 594 t = 'price of decommited gen, auction_type = 4' 595 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 596 runmkt('t_auction_case', q, p, 1140, 200, [], [], mpopt) 597 t_is(cp[1, 0], cp5[1, 0] * frb_X, 3, t) 598 599 t = 'price of decommited gen, auction_type = 6' 600 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 601 runmkt('t_auction_case', q, p, 1160, 200, [], [], mpopt) 602 t_is(cp[1, 0], cp5[1, 0] * fro_X, 3, t) 603 604 t = 'price of decommited gen, auction_type = 7' 605 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 606 runmkt('t_auction_case', q, p, 1170, 200, [], [], mpopt) 607 t_is(cp[1, 0], cp5[1, 0] * (lao_X + lab_X) / 2, 3, t) 608 609 t = 'price of decommited gen, auction_type = 0' 610 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 611 runmkt('t_auction_case', q, p, 1100, 200, [], [], mpopt) 612 t_is(cp[1, 0], 120, 3, t) 613 614 t = 'single block, marginal offer @ $50, auction_type = 5' 615 q = array([ 616 [60], 617 [36], 618 [36], 619 [36], 620 [36], 621 [36], 622 [30], 623 [10], 624 [20] 625 ]) 626 627 p = array([ 628 [50], 629 [40], 630 [42], 631 [44], 632 [46], 633 [48], 634 [100], 635 [100], 636 [100] 637 ]) 638 639 MVAbase, cq, cp, bus, gen, gencost, branch, f, dispatch, success, et = \ 640 runmkt('t_auction_case', q, p, 1150, 100, [], [], mpopt) 641 t_is( cq[G[0]], 35.32, 2, t ) 642 t_is( cq[G[1:6]], q[G[1:6]], 8, [t, ' : gen qtys'] ) 643 t_is( cp[G[0]], 50, 4, t ) 644 t_is( cq[L], q[L], 8, [t, ' : load qtys'] ) 645 t_is( cp[L[1], :], 54.03, 2, t ) 646 t_is( cp[G], bus.lam_P[Gbus], 8, [t, ' : gen prices'] ) 647 Qfudge = zeros(p.shape) 648 Qfudge[L, :] = diag(gen.Qg[L] / gen.Pg[L] * bus.lam_Q[Lbus]) * ones(p[L, :].shape) 649 t_is( cp[L], bus.lam_P[Lbus] + Qfudge[L, 0], 8, [t, ' : load prices'] ) 650 651 t_end()
652