------------------------------ deprecated ------------------------------ OPF solvers based on LPCONSTR to be removed in a future version. -------------------------------------------------------------------------- LPSETUP Solves a LP problem using a callable LP routine. [X, DUALS, IDX_WORKC, IDX_BINDC] = ... LPSETUP(A, F, B, NEQUS, VLB, VUB, IDX_WORKC, MPOPT) The LP problem is defined as follows: min f' * x S.T. a * x =< b vlb =< x =< vub All of the equality constraints must appear before inequality constraints. NEQUS specifies how many of the constraints are equality constraints. The algorithm (set in MPOPT) can be set to the following options: 320 - solve LP using ICS (equality constraints are eliminated) 340 - solve LP using Iterative Constraint Search (ICS) (equality constraints are preserved, typically superior to 320 & 360) 360 - solve LP with full set of constraints See also LPOPF_SOLVER.
0001 function [x, duals, idx_workc, idx_bindc] = LPsetup(a, f, b, nequs, vlb, vub, idx_workc, mpopt) 0002 %------------------------------ deprecated ------------------------------ 0003 % OPF solvers based on LPCONSTR to be removed in a future version. 0004 %-------------------------------------------------------------------------- 0005 %LPSETUP Solves a LP problem using a callable LP routine. 0006 % [X, DUALS, IDX_WORKC, IDX_BINDC] = ... 0007 % LPSETUP(A, F, B, NEQUS, VLB, VUB, IDX_WORKC, MPOPT) 0008 % 0009 % The LP problem is defined as follows: 0010 % 0011 % min f' * x 0012 % S.T. a * x =< b 0013 % vlb =< x =< vub 0014 % 0015 % All of the equality constraints must appear before inequality constraints. 0016 % NEQUS specifies how many of the constraints are equality constraints. 0017 % 0018 % The algorithm (set in MPOPT) can be set to the following options: 0019 % 0020 % 320 - solve LP using ICS (equality constraints are eliminated) 0021 % 340 - solve LP using Iterative Constraint Search (ICS) 0022 % (equality constraints are preserved, typically superior to 320 & 360) 0023 % 360 - solve LP with full set of constraints 0024 % 0025 % See also LPOPF_SOLVER. 0026 0027 % MATPOWER 0028 % $Id: LPsetup.m,v 1.16 2011/11/11 16:09:00 cvs Exp $ 0029 % by Deqiang (David) Gan, PSERC Cornell & Zhejiang University 0030 % Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC) 0031 % 0032 % This file is part of MATPOWER. 0033 % See http://www.pserc.cornell.edu/matpower/ for more info. 0034 % 0035 % MATPOWER is free software: you can redistribute it and/or modify 0036 % it under the terms of the GNU General Public License as published 0037 % by the Free Software Foundation, either version 3 of the License, 0038 % or (at your option) any later version. 0039 % 0040 % MATPOWER is distributed in the hope that it will be useful, 0041 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0042 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0043 % GNU General Public License for more details. 0044 % 0045 % You should have received a copy of the GNU General Public License 0046 % along with MATPOWER. If not, see <http://www.gnu.org/licenses/>. 0047 % 0048 % Additional permission under GNU GPL version 3 section 7 0049 % 0050 % If you modify MATPOWER, or any covered work, to interface with 0051 % other modules (such as MATLAB code and MEX-files) available in a 0052 % MATLAB(R) or comparable environment containing parts covered 0053 % under other licensing terms, the licensors of MATPOWER grant 0054 % you additional permission to convey the resulting work. 0055 0056 %% options 0057 alg = mpopt(11); 0058 0059 % ----- solve LP directly ----- 0060 0061 if alg == 360 %% sparse LP with full constraints 0062 [x, duals] = mp_lp(f, a, b, vlb, vub, [], nequs, -1, 100); 0063 duals = duals(1:length(b)); % MATLAB built-in LP solver has more elements in duals than we want 0064 idx_workc = []; idx_bindc = []; 0065 return; 0066 end 0067 0068 % ----- solve LP using constraint relaxation (equality constraints are preserved) ------ 0069 0070 if alg == 340 %% sparse LP with relaxed constraints 0071 if isempty(idx_workc) == 1 0072 idx_workc = find(b < 1.0e-5); 0073 end 0074 [x, duals, idx_workc, idx_bindc] = LPrelax(a, f, b, nequs, vlb, vub, idx_workc, mpopt); 0075 return; 0076 end 0077 0078 % ----- solve LP using constraint relaxation (equality constraints are eliminated) ------ 0079 0080 % so alg == 320 %% dense LP 0081 0082 % set up the indicies of variables and constraints 0083 0084 idx_x1 = 2:nequs; idx_x2 = [1 nequs:length(f)]; 0085 idx_c1 = 1:nequs-1; idx_c2 = nequs:length(b); 0086 0087 % eliminate equality constraints 0088 0089 b1 = b(idx_c1); 0090 b2 = b(idx_c2); 0091 0092 a11 = a(idx_c1, idx_x1); a12 = a(idx_c1, idx_x2); 0093 a21 = a(idx_c2, idx_x1); a22 = a(idx_c2, idx_x2); 0094 0095 a11b1 = a11 \ b1; 0096 a11a12 = a11 \ a12; 0097 0098 % set up the reduced LP 0099 0100 fred = -((f(idx_x1))' * a11a12)' + f(idx_x2); 0101 ared = [-a21 * a11a12 + a22 0102 -a11a12 0103 a11a12]; 0104 bred = [ b2 - a21 * a11b1 0105 vub(idx_x1) - a11b1 0106 a11b1 - vlb(idx_x1)]; 0107 vubred = vub(idx_x2); 0108 vlbred = vlb(idx_x2); 0109 nequsred = nequs - length(idx_x1); 0110 0111 % solve the reduced LP problem using constraint relaxation 0112 0113 if isempty(idx_workc) == 1 0114 idx_workc = find(b2< 1.0e-5); 0115 end 0116 [x2, dualsred, idx_workc, idx_bindc] = LPrelax(ared, fred, bred, nequsred, vlbred, vubred, idx_workc, mpopt); 0117 0118 % parse the solution of the reduced LP to get the solution of the original LP 0119 0120 x(idx_x1) = a11b1 - a11a12 * x2; x(idx_x2) = x2; x = x'; 0121 0122 dualsc2 = dualsred(1:length(idx_c2)); 0123 0124 temp = find(dualsc2); 0125 dualsc1 = a11' \ ( -f(idx_x1) - (a21(temp, :))' * dualsc2(temp) ); 0126 0127 duals(idx_c1) = dualsc1; 0128 duals(idx_c2) = dualsc2; 0129 duals = duals';