Package pypower :: Module ppoption
[hide private]
[frames] | no frames]

Source Code for Module pypower.ppoption

  1  # Copyright (C) 1996-2011 Power System Engineering Research Center (PSERC) 
  2  # Copyright (C) 2009-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  """Used to set and retrieve a PYPOWER options vector. 
 18  """ 
 19   
 20  PF_OPTIONS = [ 
 21      ('pf_alg', 1, '''power flow algorithm: 
 22  1 - Newton's method, 
 23  2 - Fast-Decoupled (XB version), 
 24  3 - Fast-Decoupled (BX version), 
 25  4 - Gauss Seidel'''), 
 26   
 27      ('pf_tol', 1e-8, 'termination tolerance on per unit P & Q mismatch'), 
 28   
 29      ('pf_max_it', 10, 'maximum number of iterations for Newton\'s method'), 
 30   
 31      ('pf_max_it_fd', 30, 'maximum number of iterations for fast ' 
 32       'decoupled method'), 
 33   
 34      ('pf_max_it_gs', 1000, 'maximum number of iterations for ' 
 35       'Gauss-Seidel method'), 
 36   
 37      ('enforce_q_lims', False, 'enforce gen reactive power limits, at ' 
 38       'expense of |V|'), 
 39   
 40      ('pf_dc', False, '''use DC power flow formulation, for power flow and OPF: 
 41  False - use AC formulation & corresponding algorithm opts, 
 42  True  - use DC formulation, ignore AC algorithm options''') 
 43  ] 
 44   
 45  OPF_OPTIONS = [ 
 46      ('opf_alg', 0, '''algorithm to use for OPF: 
 47  0 - choose best default solver available in the 
 48  following order, 500, 540, 520 then 100/200 
 49  Otherwise the first digit specifies the problem 
 50  formulation and the second specifies the solver, 
 51  as follows, (see the User's Manual for more details) 
 52  500 - generalized formulation, MINOS, 
 53  540 - generalized formulation, MIPS 
 54  primal/dual interior point method, 
 55  545 - generalized formulation (except CCV), SC-MIPS 
 56  step-controlled primal/dual interior point method'''), 
 57   
 58      ('opf_poly2pwl_pts', 10, 'number of evaluation points to use when ' 
 59       'converting from polynomial to piece-wise linear costs)'), 
 60   
 61      ('opf_violation', 5e-6, 'constraint violation tolerance'), 
 62   
 63      ('opf_flow_lim', 0, '''qty to limit for branch flow constraints: 
 64  0 - apparent power flow (limit in MVA), 
 65  1 - active power flow (limit in MW), 
 66  2 - current magnitude (limit in MVA at 1 p.u. voltage'''), 
 67   
 68      ('opf_ignore_ang_lim', False, 'ignore angle difference limits for ' 
 69       'branches even if specified'), 
 70   
 71      ('opf_alg_dc', 0, '''solver to use for DC OPF: 
 72  0 - choose default solver based on availability in the 
 73  following order, 600, 500, 200. 
 74  200 - PIPS, Python Interior Point Solver 
 75  primal/dual interior point method, 
 76  250 - PIPS-sc, step-controlled variant of PIPS 
 77  400 - IPOPT, requires pyipopt interface to IPOPT solver 
 78  available from: https://projects.coin-or.org/Ipopt/ 
 79  500 - CPLEX, requires Python interface to CPLEX solver 
 80  600 - MOSEK, requires Python interface to MOSEK solver 
 81  available from: http://www.mosek.com/''') 
 82  ] 
 83   
 84  OUTPUT_OPTIONS = [ 
 85      ('verbose', 1, '''amount of progress info printed: 
 86  0 - print no progress info, 
 87  1 - print a little progress info, 
 88  2 - print a lot of progress info, 
 89  3 - print all progress info'''), 
 90   
 91      ('out_all', -1, '''controls printing of results: 
 92  -1 - individual flags control what prints, 
 93  0 - don't print anything 
 94      (overrides individual flags, except OUT_RAW), 
 95  1 - print everything 
 96      (overrides individual flags, except OUT_RAW)'''), 
 97   
 98      ('out_sys_sum', True, 'print system summary'), 
 99   
100      ('out_area_sum', False, 'print area summaries'), 
101   
102      ('out_bus', True, 'print bus detail'), 
103   
104      ('out_branch', True, 'print branch detail'), 
105   
106      ('out_gen', False, '''print generator detail 
107  (OUT_BUS also includes gen info)'''), 
108   
109      ('out_all_lim', -1, '''control constraint info output: 
110  -1 - individual flags control what constraint info prints, 
111  0 - no constraint info (overrides individual flags), 
112  1 - binding constraint info (overrides individual flags), 
113  2 - all constraint info (overrides individual flags)'''), 
114   
115      ('out_v_lim', 1, '''control output of voltage limit info: 
116  0 - don't print, 
117  1 - print binding constraints only, 
118  2 - print all constraints 
119  (same options for OUT_LINE_LIM, OUT_PG_LIM, OUT_QG_LIM)'''), 
120   
121      ('out_line_lim', 1, 'control output of line limit info'), 
122   
123      ('out_pg_lim', 1, 'control output of gen P limit info'), 
124   
125      ('out_qg_lim', 1, 'control output of gen Q limit info'), 
126   
127      ('out_raw', False, 'print raw data'), 
128   
129      ('return_raw_der', 0, '''return constraint and derivative info 
130  in results['raw'] (in keys g, dg, df, d2f))''') 
131  ] 
132   
133  PDIPM_OPTIONS = [ 
134      ('pdipm_feastol', 0, '''feasibility (equality) tolerance 
135  for Primal-Dual Interior Points Methods, set 
136  to value of OPF_VIOLATION by default'''), 
137      ('pdipm_gradtol', 1e-6, '''gradient tolerance for 
138  Primal-Dual Interior Points Methods'''), 
139      ('pdipm_comptol', 1e-6, '''complementary condition (inequality) 
140  tolerance for Primal-Dual Interior Points Methods'''), 
141      ('pdipm_costtol', 1e-6, '''optimality tolerance for 
142  Primal-Dual Interior Points Methods'''), 
143      ('pdipm_max_it',  150, '''maximum number of iterations for 
144  Primal-Dual Interior Points Methods'''), 
145      ('scpdipm_red_it', 20, '''maximum number of reductions per iteration 
146  for Step-Control Primal-Dual Interior Points Methods''') 
147  ] 
148   
149   
150 -def ppoption(ppopt=None, **kw_args):
151 """Used to set and retrieve a PYPOWER options vector. 152 153 C{opt = ppoption()} returns the default options vector 154 155 C{opt = ppoption(NAME1=VALUE1, NAME2=VALUE2, ...)} returns the default 156 options vector with new values for the specified options, NAME# is the 157 name of an option, and VALUE# is the new value. 158 159 C{opt = ppoption(OPT, NAME1=VALUE1, NAME2=VALUE2, ...)} same as above 160 except it uses the options vector OPT as a base instead of the default 161 options vector. 162 163 Examples:: 164 opt = ppoption(PF_ALG=2, PF_TOL=1e-4); 165 opt = ppoption(opt, OPF_ALG=565, VERBOSE=2) 166 167 @author: Ray Zimmerman (PSERC Cornell) 168 @author: Richard Lincoln 169 """ 170 171 default_ppopt = {} 172 173 options = PF_OPTIONS + OPF_OPTIONS + OUTPUT_OPTIONS + PDIPM_OPTIONS 174 175 for name, default, _ in options: 176 default_ppopt[name.upper()] = default 177 178 ppopt = default_ppopt if ppopt == None else ppopt.copy() 179 180 ppopt.update(kw_args) 181 182 return ppopt
183