Home > matpower5.0 > t > t_opf_model.m

t_opf_model

PURPOSE ^

T_OPF_MODEL Tests for OPF_MODEL.

SYNOPSIS ^

function t_opf_model(quiet)

DESCRIPTION ^

T_OPF_MODEL Tests for OPF_MODEL.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function t_opf_model(quiet)
0002 %T_OPF_MODEL Tests for OPF_MODEL.
0003 
0004 %   MATPOWER
0005 %   $Id: t_opf_model.m 2229 2013-12-11 01:28:09Z ray $
0006 %   by Ray Zimmerman, PSERC Cornell
0007 %   Copyright (c) 2012 by Power System Engineering Research Center (PSERC)
0008 %
0009 %   This file is part of MATPOWER.
0010 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0011 %
0012 %   MATPOWER is free software: you can redistribute it and/or modify
0013 %   it under the terms of the GNU General Public License as published
0014 %   by the Free Software Foundation, either version 3 of the License,
0015 %   or (at your option) any later version.
0016 %
0017 %   MATPOWER is distributed in the hope that it will be useful,
0018 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0019 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0020 %   GNU General Public License for more details.
0021 %
0022 %   You should have received a copy of the GNU General Public License
0023 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0024 %
0025 %   Additional permission under GNU GPL version 3 section 7
0026 %
0027 %   If you modify MATPOWER, or any covered work, to interface with
0028 %   other modules (such as MATLAB code and MEX-files) available in a
0029 %   MATLAB(R) or comparable environment containing parts covered
0030 %   under other licensing terms, the licensors of MATPOWER grant
0031 %   you additional permission to convey the resulting work.
0032 
0033 if nargin < 1
0034     quiet = 0;
0035 end
0036 
0037 num_tests = 271;
0038 
0039 t_begin(num_tests, quiet);
0040 
0041 %% define named indices into data matrices
0042 [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
0043     VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
0044 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0045     MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0046     QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0047 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0048     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0049     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0050 
0051 %%-----  opt_model  -----
0052 t = 'constructor';
0053 om = opf_model;
0054 t_ok(isa(om, 'opf_model'), t);
0055 t_ok(isa(om, 'opt_model'), t);
0056 
0057 %%-----  add_vars  -----
0058 t = 'add_vars';
0059 vN = 0;
0060 vNS = 0;
0061 t_ok(getN(om, 'var') == vN, sprintf('%s : var.N  = %d', t, vN));
0062 t_ok(get(om, 'var', 'NS') == vNS, sprintf('%s : var.NS = %d', t, vNS));
0063 
0064 t = 'add_vars(om, ''Va'', 4)';
0065 om = add_vars(om, 'Va', 4);
0066 vNS = vNS + 1; vN = vN + 4;
0067 t_ok(getN(om, 'var') == vN, sprintf('%s : var.N  = %d', t, vN));
0068 t_ok(get(om, 'var', 'NS') == vNS, sprintf('%s : var.NS = %d', t, vNS));
0069 
0070 t = 'add_vars(om, ''Pg'', 3, Pg0, Pgmin, Pgmax)';
0071 om = add_vars(om, 'Pg', 3, [2;4;6], [1;2;3], [10;20;30]);
0072 vNS = vNS + 1; vN = vN + 3;
0073 t_ok(getN(om, 'var') == vN, sprintf('%s : var.N  = %d', t, vN));
0074 t_ok(get(om, 'var', 'NS') == vNS, sprintf('%s : var.NS = %d', t, vNS));
0075 
0076 t = 'add_vars(om, ''x'', dims)';
0077 om = add_vars(om, 'x', {2,2});
0078 t_ok(getN(om, 'var') == vN, sprintf('%s : var.N  = %d', t, vN));
0079 t_ok(get(om, 'var', 'NS') == vNS, sprintf('%s : var.NS = %d', t, vNS));
0080 
0081 t = 'add_vars(om, ''x'', {1,1}, 2)';
0082 om = add_vars(om, 'x', {1,1}, 2);
0083 vNS = vNS + 1; vN = vN + 2;
0084 t_ok(getN(om, 'var') == vN, sprintf('%s : var.N  = %d', t, vN));
0085 t_ok(get(om, 'var', 'NS') == vNS, sprintf('%s : var.NS = %d', t, vNS));
0086 
0087 t = 'add_vars(om, ''x'', {1,2}, 2, x0(1,2))';
0088 om = add_vars(om, 'x', {1,2}, 2, [-1;-2]);
0089 vNS = vNS + 1; vN = vN + 2;
0090 t_ok(getN(om, 'var') == vN, sprintf('%s : var.N  = %d', t, vN));
0091 t_ok(get(om, 'var', 'NS') == vNS, sprintf('%s : var.NS = %d', t, vNS));
0092 
0093 t = 'add_vars(om, ''x'', {2,1}, 3)';
0094 om = add_vars(om, 'x', {2,1}, 3);
0095 vNS = vNS + 1; vN = vN + 3;
0096 t_ok(getN(om, 'var') == vN, sprintf('%s : var.N  = %d', t, vN));
0097 t_ok(get(om, 'var', 'NS') == vNS, sprintf('%s : var.NS = %d', t, vNS));
0098 
0099 t = 'add_vars(om, ''x'', {2,2}, 2, x0(2,2), xmin(2,2), xmax(2,2))';
0100 om = add_vars(om, 'x', {2,2}, 2, [1;0],[0;-1],[2;1]);
0101 vNS = vNS + 1; vN = vN + 2;
0102 t_ok(getN(om, 'var') == vN, sprintf('%s : var.N  = %d', t, vN));
0103 t_ok(get(om, 'var', 'NS') == vNS, sprintf('%s : var.NS = %d', t, vNS));
0104 
0105 t = 'add_vars(om, ''y'', {2,3,4})';
0106 om = add_vars(om, 'y', {2,3,4});
0107 for i = 1:2
0108     for j = 1:3
0109         for k = 1:4
0110             n = i+j+k;
0111             t = sprintf('add_vars(om, ''y'', {%d,%d,%d}, y0, ymin, ymax)', i,j,k);
0112             om = add_vars(om, 'y', {i,j,k}, n, 10*(n:-1:1)', -1*(n:-1:1)', 100+(n:-1:1)');
0113             vNS = vNS + 1; vN = vN + n;
0114             t_ok(getN(om, 'var') == vN, sprintf('%s : var.N  = %d', t, vN));
0115             t_ok(get(om, 'var', 'NS') == vNS, sprintf('%s : var.NS = %d', t, vNS));
0116         end
0117     end
0118 end
0119 
0120 %%-----  getN  -----
0121 t = 'getN(om, ''var'', ''Pg'') == 3';
0122 t_ok(getN(om, 'var', 'Pg') == 3, t);
0123 
0124 t = 'size(getN(om, ''var'', ''x'')) == [2 2]';
0125 t_is(size(getN(om, 'var', 'x')), [2,2], 1e-14, t);
0126 
0127 t = 'getN(om, ''var'', ''x'')(1,2) == 2';
0128 N = getN(om, 'var', 'x');
0129 t_is(N(1,2), 2, 1e-14, t);
0130 
0131 t = 'getN(om, ''var'', ''x'', {2,1}) == 3';
0132 t_is(getN(om, 'var', 'x', {2,1}), 3, 1e-14, t);
0133 
0134 t = 'getN(om, ''var'', ''y'', {2,1,3}) == 6';
0135 t_is(getN(om, 'var', 'y', {2,1,3}), 6, 1e-14, t);
0136 
0137 t = 'getN(om, ''var'')';
0138 t_is(getN(om, 'var'), vN, 1e-14, t);
0139 
0140 %%-----  get_idx  -----
0141 t = 'get_idx : var';
0142 vv = get_idx(om);
0143 t_is([vv.i1.Pg vv.iN.Pg vv.N.Pg], [5 7 3], 1e-14, [t ' : Pg']);
0144 t_is(size(vv.i1.x), [2, 2], 1e-14, [t ' : size(vv.i1.x)']);
0145 t_is([vv.i1.x(2,1) vv.iN.x(2,1) vv.N.x(2,1)], [12 14 3], 1e-14, [t ' : x(2,1)']);
0146 t_is(size(vv.i1.y), [2, 3, 4], 1e-14, [t ' : size(vv.i1.y)']);
0147 t_is([vv.i1.y(2,2,4) vv.iN.y(2,2,4) vv.N.y(2,2,4)], [123 130 8], 1e-14, [t ' : y(2,2,4)']);
0148 
0149 %%-----  getv  -----
0150 t = 'getv(om, ''Va'')';
0151 [v0, vl, vu] = getv(om, 'Va');
0152 t_ok(~any(v0), [t ' : v0']);
0153 t_ok(all(isinf(vl) & vl < 0), [t ' : vl']);
0154 t_ok(all(isinf(vu) & vu > 0), [t ' : vu']);
0155 
0156 t = 'getv(om, ''Pg'')';
0157 [v0, vl, vu] = getv(om, 'Pg');
0158 t_is(v0, [2;4;6], 1e-14, [t ' : v0']);
0159 t_is(vl, [1;2;3], 1e-14, [t ' : vl']);
0160 t_is(vu, [10;20;30], 1e-14, [t ' : vu']);
0161 
0162 t = 'getv(om, ''x'')';
0163 [v0, vl, vu] = getv(om, 'x');
0164 t_is(size(v0), [2,2], 1e-14, [t ' : size(v0)']);
0165 t_is(v0{2,2}, [1;0], 1e-14, [t ' : v0{2,2}']);
0166 t_is(vl{2,2}, [0;-1], 1e-14, [t ' : vl{2,2}']);
0167 t_is(vu{2,2}, [2;1], 1e-14, [t ' : vu{2,2}']);
0168 
0169 for i = 1:2
0170     for j = 1:3
0171         for k = 1:4
0172             n = i+j+k;
0173             t = sprintf('getv(om, ''y'', {%d,%d,%d})', i, j, k);
0174             [v0, vl, vu] = getv(om, 'y', {i,j,k});
0175             t_is(v0, 10*(n:-1:1)', 1e-14, [t ' : v0']);
0176             t_is(vl, -1*(n:-1:1)', 1e-14, [t ' : vl']);
0177             t_is(vu, 100+(n:-1:1)', 1e-14, [t ' : vu']);
0178         end
0179     end
0180 end
0181 
0182 t = 'getv(om)';
0183 [v0, vl, vu] = getv(om);
0184 t_ok(length(v0) == getN(om, 'var'), [t ' : length(v0)']);
0185 t_ok(length(vl) == getN(om, 'var'), [t ' : length(vl)']);
0186 t_ok(length(vu) == getN(om, 'var'), [t ' : length(vu)']);
0187 t_is(v0(vv.i1.x(2,2):vv.iN.x(2,2)), [1;0], 1e-14, [t ' : v0(vv.i1.x(2,2):vv.iN.x(2,2))']);
0188 t_is(vl(vv.i1.x(2,2):vv.iN.x(2,2)), [0;-1], 1e-14, [t ' : vl(vv.i1.x(2,2):vv.iN.x(2,2))']);
0189 t_is(vu(vv.i1.x(2,2):vv.iN.x(2,2)), [2;1], 1e-14, [t ' : vu(vv.i1.x(2,2):vv.iN.x(2,2))']);
0190 n = 8;
0191 t_is(v0(vv.i1.y(2,2,4):vv.iN.y(2,2,4)), 10*(n:-1:1)', 1e-14, [t ' : v0(vv.i1.y(2,2,4):vv.iN.y(2,2,4))']);
0192 t_is(vl(vv.i1.y(2,2,4):vv.iN.y(2,2,4)), -1*(n:-1:1)', 1e-14, [t ' : vl(vv.i1.y(2,2,4):vv.iN.y(2,2,4))']);
0193 t_is(vu(vv.i1.y(2,2,4):vv.iN.y(2,2,4)), 100+(n:-1:1)', 1e-14, [t ' : vu(vv.i1.y(2,2,4):vv.iN.y(2,2,4))']);
0194 
0195 %%-----  add_constraints  -----
0196 t = 'add_constraints';
0197 lN = 0;
0198 lNS = 0;
0199 t_ok(getN(om, 'lin') == lN, sprintf('%s : lin.N  = %d', t, lN));
0200 t_ok(get(om, 'lin', 'NS') == lNS, sprintf('%s : lin.NS = %d', t, lNS));
0201 
0202 t = 'add_constraints(om, ''Pmis'', A, l, u, {''Va'', ''Pg''})';
0203 A = sparse([1:3 1:3 1:3]', [1:3 4:6 7 7 7]', [1 1 1 -1 -1 -1 2 3 4]', 3, 7);
0204 l = -(1:3)'; u = (1:3)';
0205 om = add_constraints(om, 'Pmis', A, l, u, {'Va', 'Pg'});
0206 lNS = lNS + 1; lN = lN + 3;
0207 t_ok(getN(om, 'lin') == lN, sprintf('%s : lin.N  = %d', t, lN));
0208 t_ok(get(om, 'lin', 'NS') == lNS, sprintf('%s : lin.NS = %d', t, lNS));
0209 
0210 t = 'add_constraints(om, ''Qmis'', A, l, u)';
0211 A = sparse([1:3 1:3 1:3]', [1:3 4:6 7 7 7]', [1 1 1 -1 -1 -1 2 3 4]', 3, vN);
0212 om = add_constraints(om, 'Qmis', A, l, u);
0213 lNS = lNS + 1; lN = lN + 3;
0214 t_ok(getN(om, 'lin') == lN, sprintf('%s : lin.N  = %d', t, lN));
0215 t_ok(get(om, 'lin', 'NS') == lNS, sprintf('%s : lin.NS = %d', t, lNS));
0216 
0217 t = 'add_constraints(om, ''mylin'', {2, 2})';
0218 om = add_constraints(om, 'mylin', {2, 2});
0219 t_ok(getN(om, 'lin') == lN, sprintf('%s : lin.N  = %d', t, lN));
0220 t_ok(get(om, 'lin', 'NS') == lNS, sprintf('%s : lin.NS = %d', t, lNS));
0221 
0222 for i = 1:2
0223     for j = 1:2
0224         t = sprintf('add_constraints(om, ''mylin'', {%d,%d}, A, l, u, vs)', i,j);
0225         A = sparse([1:(i+j) 1:(i+j)]', [1:(i+j) 5*ones(1,i+j)]', ...
0226             [ones(i+j,1);-ones(i+j,1)], i+j, 3+2+(i==2 && j==1));
0227         l = -ones(i+j, 1); u = [];
0228         vs = struct('name', {'Pg', 'x'}, 'idx', {{}, {i,j}});
0229         om = add_constraints(om, 'mylin', {i, j}, A, l, u, vs);
0230         lNS = lNS + 1; lN = lN + i+j;
0231         t_ok(getN(om, 'lin') == lN, sprintf('%s : lin.N  = %d', t, lN));
0232         t_ok(get(om, 'lin', 'NS') == lNS, sprintf('%s : lin.NS = %d', t, lNS));
0233     end
0234 end
0235 
0236 %%-----  get_idx  -----
0237 t = 'get_idx : lin';
0238 [vv, ll] = get_idx(om);
0239 t_is([ll.i1.Qmis ll.iN.Qmis ll.N.Qmis], [4 6 3], 1e-14, [t ' : Qmis']);
0240 t_is(size(ll.i1.mylin), [2, 2], 1e-14, [t ' : size(ll.i1.mylin)']);
0241 t_is([ll.i1.mylin(2,1) ll.iN.mylin(2,1) ll.N.mylin(2,1)], [12 14 3], 1e-14, [t ' : mylin(2,1)']);
0242 
0243 %%-----  linear_constraints  -----
0244 t = 'linear_constraints';
0245 [A, l, u] = linear_constraints(om);
0246 t_ok(issparse(A), [t ' : issparse(A)']);
0247 t_is(size(A), [lN, vN], 1e-14, [t ' : size(A)']);
0248 t_is(length(l), lN, 1e-14, [t ' : length(l)']);
0249 t_is(length(u), lN, 1e-14, [t ' : length(u)']);
0250 AA = sparse([1:3 1:3 1:3]', [1:3 4:6 7 7 7]', [1 1 1 -1 -1 -1 2 3 4]', 3, vN);
0251 t_is(full(A(ll.i1.Qmis:ll.iN.Qmis, :)), full(AA), 1e-14, [t ' : A(<Qmis>,:)']);
0252 t_is(full(A(ll.i1.mylin(2,1):ll.iN.mylin(2,1), vv.i1.Pg:vv.iN.Pg)), eye(3,3), 1e-14, [t ' : A(<mylin(2,1)>,<Pg>)']);
0253 t_is(full(A(ll.i1.mylin(2,1):ll.iN.mylin(2,1), vv.i1.x(2,1):vv.iN.x(2,1))), [0 -1 0;0 -1 0;0 -1 0], 1e-14, [t ' : A(<mylin(2,1)>,<x(2,1)>)']);
0254 
0255 %%-----  add_costs  -----
0256 t = 'add_costs';
0257 cN = 0;
0258 cNS = 0;
0259 t_ok(getN(om, 'cost') == cN, sprintf('%s : cost.N  = %d', t, cN));
0260 t_ok(get(om, 'cost', 'NS') == cNS, sprintf('%s : cost.NS = %d', t, cNS));
0261 
0262 t = 'add_costs(om, ''ucost'', cp, {''Va'', ''Pg''})';
0263 cp = struct('N', sparse([1:2 1:2 1:2]', [1:4 5 7]', [1 1 -1 -1 2 2]', 2,7), ...
0264             'Cw', [2;3]);
0265 om = add_costs(om, 'ucost', cp, {'Va', 'Pg'});
0266 cNS = cNS + 1; cN = cN + 2;
0267 t_ok(getN(om, 'cost') == cN, sprintf('%s : cost.N  = %d', t, cN));
0268 t_ok(get(om, 'cost', 'NS') == cNS, sprintf('%s : cost.NS = %d', t, cNS));
0269 
0270 t = 'add_costs(om, ''vcost'', cp)';
0271 cp = struct('N', sparse([1:2 1:2 1:2]', [1:4 5 7]', [1 1 -1 -1 2 2]', 2, vN), ...
0272             'Cw', [2;3]);
0273 om = add_costs(om, 'vcost', cp);
0274 cNS = cNS + 1; cN = cN + 2;
0275 t_ok(getN(om, 'cost') == cN, sprintf('%s : cost.N  = %d', t, cN));
0276 t_ok(get(om, 'cost', 'NS') == cNS, sprintf('%s : cost.NS = %d', t, cNS));
0277 
0278 t = 'add_costs(om, ''wc'', {2,2})';
0279 om = add_costs(om, 'wc', {2,2});
0280 t_ok(getN(om, 'cost') == cN, sprintf('%s : cost.N  = %d', t, cN));
0281 t_ok(get(om, 'cost', 'NS') == cNS, sprintf('%s : cost.NS = %d', t, cNS));
0282 
0283 for i = 1:2
0284     for j = 1:2
0285         t = 'add_costs(om, ''wc'', {i, j}, cp, vs)';
0286         cp.N = sparse([1:(i+j) 1:(i+j)]', [1:(i+j) 5*ones(1,i+j)]', ...
0287             [ones(i+j,1);-ones(i+j,1)], i+j, 3+2+(i==2 && j==1));
0288         cp.Cw = (i+j:-1:1)';
0289         if i == 2
0290             cp.H = sparse((1:i+j)', (1:i+j)', (1:i+j)', i+j, i+j);
0291         end
0292         vs = struct('name', {'Pg', 'x'}, 'idx', {{}, {i,j}});
0293         om = add_costs(om, 'wc', {i, j}, cp, vs);
0294         cNS = cNS + 1; cN = cN + i+j;
0295         t_ok(getN(om, 'cost') == cN, sprintf('%s : cost.N  = %d', t, cN));
0296         t_ok(get(om, 'cost', 'NS') == cNS, sprintf('%s : cost.NS = %d', t, cNS));
0297     end
0298 end
0299 
0300 %%-----  get_cost_params/build_cost_params  -----
0301 t = 'get_cost_params : error';
0302 try
0303     cp = get_cost_params(om);
0304     t_ok(0, t);
0305 catch
0306     t_ok(strfind(lasterr, '@opt_model/get_cost_params: must call build_cost_params first'), t);
0307 end
0308 
0309 t = 'build_cost_params';
0310 om = build_cost_params(om);
0311 cp = get_cost_params(om);
0312 t_ok(isfield(cp, 'N'), t);
0313 
0314 %%-----  get_idx  -----
0315 t = 'get_idx : cost';
0316 [vv, ll, nn, cc] = get_idx(om);
0317 t_is([cc.i1.vcost cc.iN.vcost cc.N.vcost], [3 4 2], 1e-14, [t ' : vcost']);
0318 t_is(size(cc.i1.wc), [2, 2], 1e-14, [t ' : size(cc.i1.wc)']);
0319 t_is([cc.i1.wc(2,1) cc.iN.wc(2,1) cc.N.wc(2,1)], [10 12 3], 1e-14, [t ' : wc(2,1)']);
0320 
0321 %%-----  get_cost_params  -----
0322 t = 'get_cost_params(om, ''ucost'')';
0323 cp = get_cost_params(om, 'ucost');
0324 N = sparse([1:2 1:2 1:2]', [1:4 5 7]', [1 1 -1 -1 2 2]', 2, vN);
0325 t_is(full(cp.N), full(N), 1e-14, [t, ' : N']);
0326 t_is(cp.Cw, [2;3], 1e-14, [t, ' : Cw']);
0327 t_is(full(cp.H), zeros(2,2), 1e-14, [t, ' : H']);
0328 t_is(cp.dd, ones(2,1),  1e-14, [t, ' : dd']);
0329 t_is(cp.rh, zeros(2,1), 1e-14, [t, ' : rh']);
0330 t_is(cp.kk, zeros(2,1), 1e-14, [t, ' : kk']);
0331 t_is(cp.mm, ones(2,1),  1e-14, [t, ' : mm']);
0332 
0333 t = 'get_cost_params(om, ''vcost'')';
0334 cp = get_cost_params(om, 'vcost');
0335 N = sparse([1:2 1:2 1:2]', [1:4 5 7]', [1 1 -1 -1 2 2]', 2, vN);
0336 t_is(full(cp.N), full(N), 1e-14, [t, ' : N']);
0337 t_is(cp.Cw, [2;3], 1e-14, [t, ' : Cw']);
0338 t_is(full(cp.H), zeros(2,2), 1e-14, [t, ' : H']);
0339 t_is(cp.dd, ones(2,1),  1e-14, [t, ' : dd']);
0340 t_is(cp.rh, zeros(2,1), 1e-14, [t, ' : rh']);
0341 t_is(cp.kk, zeros(2,1), 1e-14, [t, ' : kk']);
0342 t_is(cp.mm, ones(2,1),  1e-14, [t, ' : mm']);
0343 
0344 t = 'get_cost_params(om, ''wc'') : error';
0345 try
0346     cp = get_cost_params(om, 'wc')
0347     t_ok(0, t);
0348 catch
0349     t_ok(strfind(lasterr, '@opt_model/get_cost_params: cost set ''wc'' requires an idx arg'), t);
0350 end
0351 
0352 t = 'get_cost_params(om, ''wc'', {1,2})';
0353 cp = get_cost_params(om, 'wc', {1,2});
0354 N = sparse([1:3 1:3]', [vv.i1.Pg-1+(1:3) vv.i1.x(1,2)+ones(1,3)]', [ones(3,1);-ones(3,1)], 3, vN);
0355 t_is(full(cp.N), full(N), 1e-14, [t, ' : N']);
0356 t_is(cp.Cw, [3;2;1], 1e-14, [t, ' : Cw']);
0357 t_is(full(cp.H), zeros(3,3), 1e-14, [t, ' : H']);
0358 t_is(cp.dd, ones(3,1),  1e-14, [t, ' : dd']);
0359 t_is(cp.rh, zeros(3,1), 1e-14, [t, ' : rh']);
0360 t_is(cp.kk, zeros(3,1), 1e-14, [t, ' : kk']);
0361 t_is(cp.mm, ones(3,1),  1e-14, [t, ' : mm']);
0362 
0363 t = 'get_cost_params(om, ''wc'', {2,1})';
0364 cp = get_cost_params(om, 'wc', {2,1});
0365 N = sparse([1:3 1:3]', [vv.i1.Pg-1+(1:3) vv.i1.x(2,1)+ones(1,3)]', [ones(3,1);-ones(3,1)], 3, vN);
0366 t_is(full(cp.N), full(N), 1e-14, [t, ' : N']);
0367 t_is(cp.Cw, [3;2;1], 1e-14, [t, ' : Cw']);
0368 H = sparse(1:3, 1:3, 1:3, 3, 3);
0369 t_is(full(cp.H), full(H), 1e-14, [t, ' : H']);
0370 t_is(cp.dd, ones(3,1),  1e-14, [t, ' : dd']);
0371 t_is(cp.rh, zeros(3,1), 1e-14, [t, ' : rh']);
0372 t_is(cp.kk, zeros(3,1), 1e-14, [t, ' : kk']);
0373 t_is(cp.mm, ones(3,1),  1e-14, [t, ' : mm']);
0374 
0375 t = 'get_cost_params(om)';
0376 cp = get_cost_params(om);
0377 t_ok(issparse(cp.N), [t ' : issparse(cp.N)']);
0378 t_is(size(cp.N), [cN, vN], 1e-14, [t ' : size(cp.N)']);
0379 t_is(size(cp.H), [cN, cN], 1e-14, [t ' : size(cp.H)']);
0380 t_is(length(cp.Cw), cN, 1e-14, [t ' : length(cp.Cw)']);
0381 t_is(length(cp.dd), cN, 1e-14, [t ' : length(cp.dd)']);
0382 t_is(length(cp.rh), cN, 1e-14, [t ' : length(cp.rh)']);
0383 t_is(length(cp.kk), cN, 1e-14, [t ' : length(cp.kk)']);
0384 t_is(length(cp.mm), cN, 1e-14, [t ' : length(cp.mm)']);
0385 N = sparse([1:2 1:2]', [1:4]', [1 1 -1 -1]', 2, 4);
0386 Cw = [2;3];
0387 H = zeros(2,2);
0388 t_is(full(cp.N(cc.i1.vcost:cc.iN.vcost, vv.i1.Va:vv.iN.Va)), full(N), 1e-14, [t ' : N(<vcost>,<Va>)']);
0389 N = sparse([1:2]', [1 3]', [2 2]', 2, 3);
0390 t_is(full(cp.N(cc.i1.vcost:cc.iN.vcost, vv.i1.Pg:vv.iN.Pg)), full(N), 1e-14, [t ' : N(<vcost>,<Pg>)']);
0391 t_is(full(cp.Cw(cc.i1.vcost:cc.iN.vcost)), Cw, 1e-14, [t ' : Cw(<vcost>)']);
0392 t_is(full(cp.H(cc.i1.vcost:cc.iN.vcost, cc.i1.vcost:cc.iN.vcost)), full(H), 1e-14, [t ' : H(<vcost>,<vcost>)']);
0393 N = sparse([1:3]', [1:3]', [1 1 1]', 3, 3);
0394 t_is(full(cp.N(cc.i1.wc(1,2):cc.iN.wc(1,2), vv.i1.Pg:vv.iN.Pg)), full(N), 1e-14, [t ' : N(<wc(1,2)>,<Pg>)']);
0395 N = sparse([1:3]', [2 2 2]', [-1 -1 -1]', 3, 2);
0396 Cw = [3;2;1];
0397 H = zeros(3,3);
0398 t_is(full(cp.N(cc.i1.wc(1,2):cc.iN.wc(1,2), vv.i1.x(1,2):vv.iN.x(1,2))), full(N), 1e-14, [t ' : N(<wc(1,2)>,<x(1,2)>)']);
0399 t_is(full(cp.Cw(cc.i1.wc(1,2):cc.iN.wc(1,2))), Cw, 1e-14, [t ' : Cw(<wc(1,2)>)']);
0400 t_is(full(cp.H(cc.i1.wc(1,2):cc.iN.wc(1,2), cc.i1.wc(1,2):cc.iN.wc(1,2))), full(H), 1e-14, [t ' : H(<wc(1,2)>,<wc(1,2)>)']);
0401 
0402 N = sparse([1:3]', [1:3]', [1 1 1]', 3, 3);
0403 t_is(full(cp.N(cc.i1.wc(2,1):cc.iN.wc(2,1), vv.i1.Pg:vv.iN.Pg)), full(N), 1e-14, [t ' : N(<wc(2,1)>,<Pg>)']);
0404 N = sparse([1:3]', [2 2 2]', [-1 -1 -1]', 3, 3);
0405 Cw = [3;2;1];
0406 H = full(sparse((1:3)', (1:3)', (1:3)', 3, 3));
0407 t_is(full(cp.N(cc.i1.wc(2,1):cc.iN.wc(2,1), vv.i1.x(2,1):vv.iN.x(2,1))), full(N), 1e-14, [t ' : N(<wc(2,1)>,<x(2,1)>)']);
0408 t_is(full(cp.Cw(cc.i1.wc(2,1):cc.iN.wc(2,1))), Cw, 1e-14, [t ' : Cw(<wc(2,1)>)']);
0409 t_is(full(cp.H(cc.i1.wc(2,1):cc.iN.wc(2,1), cc.i1.wc(2,1):cc.iN.wc(2,1))), full(H), 1e-14, [t ' : H(<wc(2,1)>,<wc(2,1)>)']);
0410 
0411 t_is(cp.dd, ones(cN,1),  1e-14, [t, ' : dd']);
0412 t_is(cp.rh, zeros(cN,1), 1e-14, [t, ' : rh']);
0413 t_is(cp.kk, zeros(cN,1), 1e-14, [t, ' : kk']);
0414 t_is(cp.mm, ones(cN,1),  1e-14, [t, ' : mm']);
0415 
0416 %%-----  compute_cost  -----
0417 % f = compute_cost(om, x, name, idx)
0418 t = 'compute_cost(om, x)';
0419 x = (1:vN)';
0420 f = compute_cost(om, x);
0421 t_is(f, 343, 1e-14, t);
0422 
0423 t = 'compute_cost(om, ''ucost'')';
0424 f = compute_cost(om, x, 'ucost');
0425 t_is(f, 52, 1e-14, t);
0426 
0427 t = 'compute_cost(om, ''wc'', {2,1})';
0428 f = compute_cost(om, x, 'wc', {2,1});
0429 t_is(f, 91, 1e-14, t);
0430 
0431 % om
0432 % om = struct(om);
0433 
0434 t_end;

Generated on Mon 26-Jan-2015 15:21:31 by m2html © 2005