COMPUTE_COST Computes a user-defined cost. ----- DEPRECATED - use EVAL_LEGACY_COST instead ----- F_U = OM.COMPUTE_COST(X) F_U = OM.COMPUTE_COST(X, NAME) F_U = OM.COMPUTE_COST(X, NAME, IDX) Computes the value of a user defined cost, either for all user defined costs or for a named set of costs. When specifying a named set, if NAME refers to an indexed name but IDX is not provided, then COMPUTE_COST will be called recursively for all corresponding values of IDX and the costs summed. Let X be the full set of optimization variables and F_U(X, CP) be the user-defined cost at X, corresponding to the set of cost parameters in the CP struct returned by GET_COST_PARAMS, where CP is a struct with the following fields: N - nw x nx sparse matrix Cw - nw x 1 vector H - nw x nw sparse matrix (optional, all zeros by default) dd, mm - nw x 1 vectors (optional, all ones by default) rh, kk - nw x 1 vectors (optional, all zeros by default) These parameters are used as follows to compute F_U(X, CP) R = N*x - rh / kk(i), R(i) < -kk(i) K(i) = < 0, -kk(i) <= R(i) <= kk(i) \ -kk(i), R(i) > kk(i) RR = R + K U(i) = / 0, -kk(i) <= R(i) <= kk(i) \ 1, otherwise DDL(i) = / 1, dd(i) = 1 \ 0, otherwise DDQ(i) = / 1, dd(i) = 2 \ 0, otherwise Dl = diag(mm) * diag(U) * diag(DDL) Dq = diag(mm) * diag(U) * diag(DDQ) w = (Dl + Dq * diag(RR)) * RR F_U(X, CP) = 1/2 * w'*H*w + Cw'*w See also OPT_MODEL, ADD_COSTS, PARAMS_LEGACY_COST.
0001 function f = compute_cost(om, x, varargin) 0002 %COMPUTE_COST Computes a user-defined cost. 0003 % 0004 % ----- DEPRECATED - use EVAL_LEGACY_COST instead ----- 0005 % 0006 % F_U = OM.COMPUTE_COST(X) 0007 % F_U = OM.COMPUTE_COST(X, NAME) 0008 % F_U = OM.COMPUTE_COST(X, NAME, IDX) 0009 % 0010 % Computes the value of a user defined cost, either for all user 0011 % defined costs or for a named set of costs. When specifying a named set, 0012 % if NAME refers to an indexed name but IDX is not provided, then 0013 % COMPUTE_COST will be called recursively for all corresponding values 0014 % of IDX and the costs summed. 0015 % 0016 % Let X be the full set of optimization variables and F_U(X, CP) be the 0017 % user-defined cost at X, corresponding to the set of cost parameters in 0018 % the CP struct returned by GET_COST_PARAMS, where CP is a struct with the 0019 % following fields: 0020 % N - nw x nx sparse matrix 0021 % Cw - nw x 1 vector 0022 % H - nw x nw sparse matrix (optional, all zeros by default) 0023 % dd, mm - nw x 1 vectors (optional, all ones by default) 0024 % rh, kk - nw x 1 vectors (optional, all zeros by default) 0025 % 0026 % These parameters are used as follows to compute F_U(X, CP) 0027 % 0028 % R = N*x - rh 0029 % 0030 % / kk(i), R(i) < -kk(i) 0031 % K(i) = < 0, -kk(i) <= R(i) <= kk(i) 0032 % \ -kk(i), R(i) > kk(i) 0033 % 0034 % RR = R + K 0035 % 0036 % U(i) = / 0, -kk(i) <= R(i) <= kk(i) 0037 % \ 1, otherwise 0038 % 0039 % DDL(i) = / 1, dd(i) = 1 0040 % \ 0, otherwise 0041 % 0042 % DDQ(i) = / 1, dd(i) = 2 0043 % \ 0, otherwise 0044 % 0045 % Dl = diag(mm) * diag(U) * diag(DDL) 0046 % Dq = diag(mm) * diag(U) * diag(DDQ) 0047 % 0048 % w = (Dl + Dq * diag(RR)) * RR 0049 % 0050 % F_U(X, CP) = 1/2 * w'*H*w + Cw'*w 0051 % 0052 % See also OPT_MODEL, ADD_COSTS, PARAMS_LEGACY_COST. 0053 0054 % MATPOWER 0055 % Copyright (c) 2008-2017, Power Systems Engineering Research Center (PSERC) 0056 % by Ray Zimmerman, PSERC Cornell 0057 % 0058 % This file is part of MATPOWER. 0059 % Covered by the 3-clause BSD License (see LICENSE file for details). 0060 % See https://matpower.org for more info. 0061 0062 f = om.eval_legacy_cost(x, varargin{:});