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

Source Code for Module pypower.cplex_options

  1  # Copyright (C) 2010-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  """Sets options for CPLEX. 
 18  """ 
 19   
 20  try: 
 21      from cplex import cplexoptimset 
 22  except ImportError: 
 23  #    print "CPLEX not available" 
 24      pass 
 25   
 26  from pypower.util import feval 
 27   
 28   
29 -def cplex_options(overrides=None, ppopt=None):
30 """Sets options for CPLEX. 31 32 Sets the values for the options dict normally passed to 33 C{cplexoptimset}. 34 35 Inputs are all optional, second argument must be either a string 36 (C{fname}) or a dict (C{ppopt}): 37 38 Output is an options dict to pass to C{cplexoptimset}. 39 40 Example: 41 42 If C{ppopt['CPLEX_OPT'] = 3}, then after setting the default CPLEX options, 43 CPLEX_OPTIONS will execute the following user-defined function 44 to allow option overrides:: 45 46 opt = cplex_user_options_3(opt, ppopt) 47 48 The contents of cplex_user_options_3.py, could be something like:: 49 50 def cplex_user_options_3(opt, ppopt): 51 opt = {} 52 opt['threads'] = 2 53 opt['simplex']['refactor'] = 1 54 opt['timelimit'] = 10000 55 return opt 56 57 For details on the available options, see the I{"Parameters Reference 58 Manual"} section of the CPLEX documentation at: 59 U{http://publib.boulder.ibm.com/infocenter/cosinfoc/v12r2/} 60 61 @param overrides: 62 - dict containing values to override the defaults 63 - fname: name of user-supplied function called after default 64 options are set to modify them. Calling syntax is:: 65 66 modified_opt = fname(default_opt) 67 68 @param ppopt: PYPOWER options vector, uses the following entries: 69 - OPF_VIOLATION - used to set opt.simplex.tolerances.feasibility 70 - VERBOSE - used to set opt.barrier.display, 71 opt.conflict.display, opt.mip.display, opt.sifting.display, 72 opt.simplex.display, opt.tune.display 73 - CPLEX_LPMETHOD - used to set opt.lpmethod 74 - CPLEX_QPMETHOD - used to set opt.qpmethod 75 - CPLEX_OPT - user option file, if ppopt['CPLEX_OPT'] is non-zero 76 non-zero it is appended to 'cplex_user_options_' to form 77 the name of a user-supplied function used as C{fname} 78 described above, except with calling syntax:: 79 80 modified_opt = fname(default_opt, ppopt) 81 82 @see: C{cplexlp}, C{cplexqp}, L{ppoption}. 83 84 @author: Ray Zimmerman (PSERC Cornell) 85 @author: Richard Lincoln 86 """ 87 ##----- initialization and arg handling ----- 88 ## defaults 89 verbose = 1 90 feastol = 1e-6 91 fname = '' 92 93 ## second argument 94 if ppopt != None: 95 if isinstance(ppopt, basestring): ## 2nd arg is FNAME (string) 96 fname = ppopt 97 have_ppopt = False 98 else: ## 2nd arg is ppopt (MATPOWER options vector) 99 have_ppopt = True 100 ## (make default OPF_VIOLATION correspond to default CPLEX feastol) 101 feastol = ppopt['OPF_VIOLATION'] / 5 102 verbose = ppopt['VERBOSE'] 103 lpmethod = ppopt['CPLEX_LPMETHOD'] 104 qpmethod = ppopt['CPLEX_QPMETHOD'] 105 if ppopt['CPLEX_OPT']: 106 fname = 'cplex_user_options_#d' % ppopt['CPLEX_OPT'] 107 else: 108 have_ppopt = False 109 110 ##----- set default options for CPLEX ----- 111 opt = cplexoptimset('cplex') 112 opt['simplex']['tolerances']['feasibility'] = feastol 113 114 ## printing 115 vrb = max([0, verbose - 1]) 116 opt['barrier']['display'] = vrb 117 opt['conflict']['display'] = vrb 118 opt['mip']['display'] = vrb 119 opt['sifting']['display'] = vrb 120 opt['simplex']['display'] = vrb 121 opt['tune']['display'] = vrb 122 123 ## solution algorithm 124 if have_ppopt: 125 opt['lpmethod'] = ppopt['CPLEX_LPMETHOD'] 126 opt['qpmethod'] = ppopt['CPLEX_QPMETHOD'] 127 #else: 128 # opt['lpmethod'] = 2 129 # opt['qpmethod'] = 2 130 131 ##----- call user function to modify defaults ----- 132 if len(fname) > 0: 133 if have_ppopt: 134 opt = feval(fname, opt, ppopt) 135 else: 136 opt = feval(fname, opt) 137 138 139 ##----- apply overrides ----- 140 if overrides is not None: 141 names = overrides.keys() 142 for k in range(len(names)): 143 if isinstance(overrides[names[k]], dict): 144 names2 = overrides[names[k]].keys() 145 for k2 in range(len(names2)): 146 if isinstance(overrides[names[k]][names2[k2]], dict): 147 names3 = overrides[names[k]][names2[k2]].keys() 148 for k3 in range(len(names3)): 149 opt[names[k]][names2[k2]][names3[k3]] = overrides[names[k]][names2[k2]][names3[k3]] 150 else: 151 opt[names[k]][names2[k2]] = overrides[names[k]][names2[k2]] 152 else: 153 opt[names[k]] = overrides[names[k]] 154 155 return opt
156 157 158 #-------------------------- Default Options Struct -------------------------- 159 # as returned by ... 160 # >> opt = cplexoptimset('cplex') 161 # 162 # opt = 163 # advance: 1 164 # barrier: [1x1 struct] 165 # algorithm: 0 166 # colnonzeros: 0 167 # convergetol: 1.0000e-08 168 # crossover: 0 169 # display: 1 170 # limits: [1x1 struct] 171 # corrections: -1 172 # growth: 1.0000e+12 173 # iteration: 2.1000e+09 174 # objrange: 1.0000e+20 175 # ordering: 0 176 # qcpconvergetol: 1.0000e-07 177 # startalg: 1 178 # clocktype: 2 179 # conflict: [1x1 struct] 180 # display: 1 181 # emphasis: [1x1 struct] 182 # memory: 0 183 # mip: 0 184 # numerical: 0 185 # feasopt: [1x1 struct] 186 # mode: 0 187 # tolerance: 1.0000e-06 188 # lpmethod: 0 189 # mip: [1x1 struct] 190 # cuts: [1x1 struct] 191 # cliques: 0 192 # covers: 0 193 # disjunctive: 0 194 # flowcovers: 0 195 # gomory: 0 196 # gubcovers: 0 197 # implied: 0 198 # mcfcut: 0 199 # mircut: 0 200 # pathcut: 0 201 # zerohalfcut: 0 202 # display: 2 203 # interval: 0 204 # limits: [1x1 struct] 205 # aggforcut: 3 206 # auxrootthreads: 0 207 # cutpasses: 0 208 # cutsfactor: 4 209 # eachcutlimit: 2.1000e+09 210 # gomorycand: 200 211 # gomorypass: 0 212 # nodes: 2.1000e+09 213 # polishtime: 0 214 # populate: 20 215 # probetime: 1.0000e+75 216 # repairtries: 0 217 # solutions: 2.1000e+09 218 # strongcand: 10 219 # strongit: 0 220 # submipnodelim: 500 221 # treememory: 1.0000e+75 222 # ordertype: 0 223 # polishafter: [1x1 struct] 224 # absmipgap: 0 225 # mipgap: 0 226 # nodes: 2.1000e+09 227 # solutions: 2.1000e+09 228 # time: 1.0000e+75 229 # pool: [1x1 struct] 230 # absgap: 1.0000e+75 231 # capacity: 2.1000e+09 232 # intensity: 0 233 # relgap: 1.0000e+75 234 # replace: 0 235 # strategy: [1x1 struct] 236 # backtrack: 0.9999 237 # bbinterval: 7 238 # branch: 0 239 # dive: 0 240 # file: 1 241 # fpheur: 0 242 # heuristicfreq: 0 243 # kappastats: 0 244 # lbheur: 0 245 # miqcpstrat: 0 246 # nodeselect: 1 247 # order: 1 248 # presolvenode: 0 249 # probe: 0 250 # rinsheur: 0 251 # search: 0 252 # startalgorithm: 0 253 # subalgorithm: 0 254 # variableselect: 0 255 # tolerances: [1x1 struct] 256 # absmipgap: 1.0000e-06 257 # integrality: 1.0000e-05 258 # lowercutoff: -1.0000e+75 259 # mipgap: 1.0000e-04 260 # objdifference: 0 261 # relobjdifference: 0 262 # uppercutoff: 1.0000e+75 263 # parallel: 0 264 # preprocessing: [1x1 struct] 265 # aggregator: -1 266 # boundstrength: -1 267 # coeffreduce: 2 268 # depency: -1 269 # dual: 0 270 # fill: 10 271 # linear: 1 272 # numpass: -1 273 # presolve: 1 274 # qpmakepsd: 1 275 # reduce: 3 276 # relax: -1 277 # repeatpresolve: -1 278 # symmetry: -1 279 # qpmethod: 0 280 # read: [1x1 struct] 281 # constraints: 30000 282 # datacheck: 0 283 # nonzeros: 250000 284 # qpnonzeros: 5000 285 # scale: 0 286 # variables: 60000 287 # sifting: [1x1 struct] 288 # algorithm: 0 289 # display: 1 290 # iterations: 2.1000e+09 291 # simplex: [1x1 struct] 292 # crash: 1 293 # dgradient: 0 294 # display: 1 295 # limits: [1x1 struct] 296 # iterations: 2.1000e+09 297 # lowerobj: -1.0000e+75 298 # perturbation: 0 299 # singularity: 10 300 # upperobj: 1.0000e+75 301 # perturbation: [1x1 struct] 302 # indicator: 0 303 # constant: 1.0000e-06 304 # pgradient: 0 305 # pricing: 0 306 # refactor: 0 307 # tolerances: [1x1 struct] 308 # feasibility: 1.0000e-06 309 # markowitz: 0.0100 310 # optimality: 1.0000e-06 311 # threads: 0 312 # timelimit: 1.0000e+75 313 # tune: [1x1 struct] 314 # display: 1 315 # measure: 1 316 # repeat: 1 317 # timelimit: 10000 318 # workdir: '.' 319 # workmem: 128 320