Changeset 1091
- Timestamp:
- 07/03/08 15:21:41 (2 years ago)
- Files:
-
- trunk/openopt/scikits/openopt/Kernel/BaseAlg.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/Kernel/BaseProblem.py (modified) (15 diffs)
- trunk/openopt/scikits/openopt/Kernel/GLP.py (modified) (2 diffs)
- trunk/openopt/scikits/openopt/Kernel/LLSP.py (modified) (2 diffs)
- trunk/openopt/scikits/openopt/Kernel/LP.py (modified) (3 diffs)
- trunk/openopt/scikits/openopt/Kernel/LSP.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/Kernel/MILP.py (modified) (3 diffs)
- trunk/openopt/scikits/openopt/Kernel/MMP.py (modified) (2 diffs)
- trunk/openopt/scikits/openopt/Kernel/NLP.py (modified) (2 diffs)
- trunk/openopt/scikits/openopt/Kernel/NLSP.py (modified) (3 diffs)
- trunk/openopt/scikits/openopt/Kernel/NSP.py (modified) (3 diffs)
- trunk/openopt/scikits/openopt/Kernel/QP.py (modified) (2 diffs)
- trunk/openopt/scikits/openopt/Kernel/Residuals.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/Kernel/objFunRelated.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/Kernel/ooCheck.py (modified) (2 diffs)
- trunk/openopt/scikits/openopt/Kernel/runProbSolver.py (modified) (5 diffs)
- trunk/openopt/scikits/openopt/Kernel/setDefaultIterFuncs.py (modified) (6 diffs)
- trunk/openopt/scikits/openopt/solvers/BrasilOpt/ALGENCAN_oo.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/BrasilOpt/algencan_oo.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/CVXOPT/cvxopt_glpk_oo.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/CVXOPT/cvxopt_lp_oo.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/CVXOPT/cvxopt_qp_oo.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/CVXOPT/glpk_oo.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/CoinOr/ipopt_oo.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/Standalone/bvls_oo.py (modified) (2 diffs)
- trunk/openopt/scikits/openopt/solvers/Standalone/galileo_oo.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/Standalone/toms587_oo.py (modified) (2 diffs)
- trunk/openopt/scikits/openopt/solvers/UkrOpt/ShorEllipsoid_oo.py (modified) (2 diffs)
- trunk/openopt/scikits/openopt/solvers/UkrOpt/goldenSection_oo.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/UkrOpt/lincher_oo.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/UkrOpt/nsmm_oo.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/UkrOpt/nssolve_oo.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/UkrOpt/ralg_oo.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/lp_solve/lpSolve_oo.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/scipy_optim/scipy_cobyla_oo.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/scipy_optim/scipy_fminbound_oo.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/scipy_optim/scipy_lbfgsb_oo.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/scipy_optim/scipy_slsqp_oo.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/scipy_optim/scipy_tnc_oo.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openopt/scikits/openopt/Kernel/BaseAlg.py
r1089 r1091 11 11 __homepage__ = 'Undefined. Use web search' 12 12 __info__ = 'None' 13 __constraintsThatCannotBeHandled__ = ['c', 'h', 'Aeq', 'A', 'lb', 'ub'] 13 14 # TODO: remove it 15 __constraintsThatCannotBeHandled__ = [] 16 17 __optionalDataThatCanBeHandled__ = [] 14 18 __isIterPointAlwaysFeasible__ = lambda self, p: p.isUC#TODO: provide possibility of simple True, False 15 19 __iterfcnConnected__ = False trunk/openopt/scikits/openopt/Kernel/BaseProblem.py
r1089 r1091 3 3 from oologfcn import * 4 4 from ooGraphics import Graphics 5 from setDefaultIterFuncs import setDefaultIterFuncs 5 from setDefaultIterFuncs import setDefaultIterFuncs, IS_MAX_FUN_EVALS_REACHED 6 6 from objFunRelated import objFunRelated 7 7 from Residuals import Residuals … … 12 12 13 13 ProbDefaults = {'diffInt': 1e-7, 'xtol': 1e-6, 'noise': 0} 14 15 14 from runProbSolver import runProbSolver 16 15 17 class Check: 18 def __init__(self): 19 self.df = 0# check numerical & 20 self.dh = 0# user-supplied gradients 21 self.dc = 0 22 # lines with difference less than maxViolation will be not shown 23 self.maxViolation = 1e-5 16 17 24 18 25 19 class user: 26 20 def __init__(self): 27 21 pass 28 29 class Parallel:30 def __init__(self):31 self.f = False# 0 - don't use parallel calclations, 1 - use32 self.c = False33 self.h = False34 #others are under development35 #TODO: add paralell func!36 #self.parallel.fun = dfeval37 22 38 23 class oomatrix: … … 46 31 #return asarray(x) * asarray(y) 47 32 48 class args:49 def __init__(self): pass50 f, c, h = (), (), ()51 52 33 class autocreate: 53 34 def __init__(self): pass 54 35 55 class BaseProblem(oomatrix, objFunRelated, Residuals, ooTextOutput, args):36 class BaseProblem(oomatrix, Residuals, ooTextOutput): 56 37 def __init__(self): 57 38 self.isObjFunValueASingleNumber = True … … 61 42 self.name = 'unnamed' 62 43 63 self.check = Check() 64 self.parallel = Parallel() 44 65 45 self.graphics = Graphics() 66 46 self.user = user() 67 self.args = args()68 47 69 48 self.plot = False # draw picture or not … … 95 74 self.data4TextOutput = ['objFunVal', 'log10(maxResidual)'] 96 75 97 #TODO: remove it?98 self.useScaling = 0#if 1, ScaleFactor or TypicalX must be provided, else x0 will be used as TypicalX. However, OpenOpt automatic scaling isn't tested properly yet.99 76 100 77 self.debug = 0 … … 106 83 107 84 self.maxIter = 400 108 self.maxFunEvals = 10000 85 self.maxFunEvals = 10000 # TODO: move it to NinLinProblem class? 109 86 self.maxCPUTime = inf 110 87 self.maxTime = inf 111 self.maxLineSearch = 500 112 self.xtol = ProbDefaults['xtol'] 113 self.gradtol = 1e-6 88 self.maxLineSearch = 500 # TODO: move it to NinLinProblem class? 89 self.xtol = ProbDefaults['xtol'] # TODO: move it to NinLinProblem class? 90 self.gradtol = 1e-6 # TODO: move it to NinLinProblem class? 114 91 self.ftol = 1e-6 115 92 self.contol = 1e-6 … … 121 98 self.binVars = [] # for problems like MILP 122 99 123 self.noise = ProbDefaults['noise'] 124 self.consMode = 'all' 125 126 #TODO: move it to non-lin funcs classes only 127 self.prevVal = {} 128 for fn in ['f', 'c', 'h', 'df', 'dc', 'dh', 'd2f', 'd2c', 'd2h']: 129 self.prevVal[fn] = {'key':None, 'val':None} 100 self.noise = ProbDefaults['noise'] # TODO: move it to NinLinProblem class? 101 130 102 131 103 # A * x <= b inequalities … … 147 119 # 0 : <Awhole, x> [j] = bwhole[j] 148 120 149 #finite-difference gradient aproximation step150 self.diffInt = ProbDefaults['diffInt']151 152 121 self.scale = None 153 154 self.isVectoriezed = 0# isn't tested properly yet155 156 #f0 = None#TODO: handle me properly157 158 #non-linear constraints159 self.c = None # c(x)<=0160 self.h = None # h(x)=0161 122 162 123 self.goal = None# should be redefined by child class 163 124 # possible values: 'maximum', 'min', 'max', 'minimum', 'minimax' etc 164 125 self.showGoal = False# can be redefined by child class, used for text & graphic output 165 166 # TODO: implement in a field self classification:167 # 'minimax', 'multiobjective'(or goalattain?), etc168 169 self.fPattern = None170 self.cPattern = None171 self.hPattern = None172 173 ##primal.* fields are for OpenOpt developers only, not common users174 #primal.f = None175 #primal.df = None176 #primal.d2f = None177 #primal.c = None178 #primal.h = None179 #primal.dc = None180 #primal.dh = None181 #primal.d2c = None182 #primal.d2h = None183 126 184 127 self.color = 'b' # blue, color for plotting … … 199 142 # so it may be ignored with some solvers not closely connected to OO Kernel 200 143 201 self.kernelIterFuncs = setDefaultIterFuncs()202 203 144 self.callback = [] 204 145 … … 208 149 209 150 self.special = autocreate() 151 152 self.optionalData = []#string names of optional data like 'c', 'h', 'Aeq' etc 153 154 def __finalize__(self): 155 pass 210 156 211 157 def objFunc(self, x): … … 224 170 return self.b.size ==0 and self.beq.size==0 and not self.userProvided.c and not self.userProvided.h 225 171 226 def __1stBetterThan2nd__(self, f1, f2, r1=None, r2=None):227 if self.isUC:228 #TODO: check for goal = max/maximum229 return f1 < f2230 else:#then r1, r2 should be defined231 return (r1 < r2 and self.contol < r2) or (((r1 <= self.contol and r2 <= self.contol) or r1==r2) and f1 < f2)232 233 def __1stCertainlyBetterThan2ndTakingIntoAcoountNoise__(self, f1, f2, r1=None, r2=None):234 if self.isUC:235 #TODO: check for goalType = max236 return f1 + self.noise < f2 - self.noise237 else:238 #return (r1 + self.noise < r2 - self.noise and self.contol < r2) or \239 return (r1 < r2 and self.contol < r2) or \240 (((r1 <= self.contol and r2 <= self.contol) or r1==r2) and f1 + self.noise < f2 - self.noise)172 # def __1stBetterThan2nd__(self, f1, f2, r1=None, r2=None): 173 # if self.isUC: 174 # #TODO: check for goal = max/maximum 175 # return f1 < f2 176 # else:#then r1, r2 should be defined 177 # return (r1 < r2 and self.contol < r2) or (((r1 <= self.contol and r2 <= self.contol) or r1==r2) and f1 < f2) 178 # 179 # def __1stCertainlyBetterThan2ndTakingIntoAcoountNoise__(self, f1, f2, r1=None, r2=None): 180 # if self.isUC: 181 # #TODO: check for goalType = max 182 # return f1 + self.noise < f2 - self.noise 183 # else: 184 # #return (r1 + self.noise < r2 - self.noise and self.contol < r2) or \ 185 # return (r1 < r2 and self.contol < r2) or \ 186 # (((r1 <= self.contol and r2 <= self.contol) or r1==r2) and f1 + self.noise < f2 - self.noise) 241 187 242 188 … … 244 190 return runProbSolver(self, solvers, *args, **kwargs) 245 191 192 193 # TODO: remove it 246 194 def auxFunc(self, x, *args, **kwargs): 247 195 r = self.connectedIterFuncField(x, *args, **kwargs) … … 253 201 return r 254 202 203 # TODO: simplify or remove it 255 204 def connectIterFcn(self, funcname, calledByUser = True): 256 205 #this function could be called by user or by RunProbSolver.py … … 271 220 self.err('OpenOpt error: this function should be overdetermined by child class') 272 221 222 def inspire(self, newProb): 223 # fills some fields of new prob with old prob values 224 225 #TODO: hold it in single place 226 for key in ['lb', 'ub', 'A', 'Aeq', 'b', 'beq', 'contol', 'xtol', 'ftol', 'gradtol', 'iprint', 'plot', 'maxIter', 'maxTime', 'maxCPUTime','fEnough', 'goal', 'color', 'debug'] : 227 if hasattr(self, key): setattr(newProb, key, getattr(self, key)) 228 229 230 class MatrixProblem(BaseProblem): 231 __baseClassName__ = 'Matrix' 232 def __init__(self): 233 BaseProblem.__init__(self) 234 self.kernelIterFuncs = setDefaultIterFuncs('Matrix') 235 236 def __prepare__(self): 237 pass 238 239 class Check: 240 def __init__(self): 241 self.df = 0# check numerical & 242 self.dh = 0# user-supplied gradients 243 self.dc = 0 244 # lines with difference less than maxViolation will be not shown 245 self.maxViolation = 1e-5 246 247 class Parallel: 248 def __init__(self): 249 self.f = False# 0 - don't use parallel calclations, 1 - use 250 self.c = False 251 self.h = False 252 #TODO: add paralell func! 253 #self.parallel.fun = dfeval 254 255 class args: 256 def __init__(self): pass 257 f, c, h = (), (), () 258 259 class NonLinProblem(BaseProblem, objFunRelated, args): 260 __baseClassName__ = 'NonLin' 261 def __init__(self): 262 BaseProblem.__init__(self) 263 self.check = Check() 264 self.args = args() 265 self.consMode = 'all' # TODO: remove it? 266 #self.parallel = Parallel() 267 268 self.prevVal = {} 269 for fn in ['f', 'c', 'h', 'df', 'dc', 'dh', 'd2f', 'd2c', 'd2h']: 270 self.prevVal[fn] = {'key':None, 'val':None} 271 272 #finite-difference gradient aproximation step 273 self.diffInt = ProbDefaults['diffInt'] 274 275 #self.isVectoriezed = False 276 277 #non-linear constraints 278 self.c = None # c(x)<=0 279 self.h = None # h(x)=0 280 281 # self.fPattern = None 282 # self.cPattern = None 283 # self.hPattern = None 284 self.kernelIterFuncs = setDefaultIterFuncs('NonLin') 285 273 286 def checkdf(self, *args, **kwargs): 274 287 return ooCheckGradient(self, 'df', *args, **kwargs) … … 289 302 if type(v) != type(()): setattr(self.args, j, (v,)) 290 303 291 def inspire(self, newProb): 292 # fills some fields of new prob with old prob values 293 294 #TODO: hold it in single place 295 for key in ['lb', 'ub', 'A', 'Aeq', 'b', 'beq', 'contol', 'xtol', 'ftol', 'gradtol', 'iprint', 'plot', 'maxIter', 'maxTime', 'maxCPUTime','fEnough', 'goal', 'color', 'debug'] : 296 if hasattr(self, key): setattr(newProb, key, getattr(self, key)) 304 def __finalize__(self): 305 if (self.userProvided.c and any(isnan(self.c(self.xf)))) or (self.userProvided.h and any(isnan(self.h(self.xf)))): 306 if self.iprint >= -1: self.warn('some non-linear constraints are equal to NaN') 307 308 def __prepare__(self): 309 self.__makeCorrectArgs__() 310 for s in ('f', 'df', 'd2f', 'c', 'dc', 'd2c', 'h', 'dh', 'd2h'): 311 if hasattr(self, s) and getattr(self, s) is not None: 312 setattr(self.userProvided, s, True) 313 self.nEvals[s] = 0 314 A = getattr(self,s) 315 316 if callable(A): #TODO: add or ndarray(A)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 317 A = (A,)#make tuple 318 setattr(self.user, s, A) 319 else: 320 setattr(self.userProvided, s, False) 321 #setattr(p.user, s, (None,)) 322 setattr(self, s, getattr(self, 'user_' + s)) 323 324 #initialization, getting nf, nc, nh etc: 325 for s in ['c', 'h']: 326 if getattr(self.userProvided, s): 327 getattr(self, s)(self.x0) 328 else: 329 setattr(self, 'n'+s, 0) 330 331 if hasattr(self, 'delayedConnectIterFcn'): 332 if self.solver.__iterfcnConnected__: self.warn('solver ' + self.solver.__name__ + ' has native iterfcn, user-defined connection via p.connectIterFcn will be ignored') 333 else: 334 if self.delayedConnectIterFcn == 'df': self.warn('iterfcn now connects to df automatically by default, you can either use other funcs like d2f to suppress the warning or ommit user-defined connecting to df at all') 335 self.connectIterFcn('df') 336 else: 337 if not self.solver.__iterfcnConnected__: 338 self.connectIterFcn('df', calledByUser = False) trunk/openopt/scikits/openopt/Kernel/GLP.py
r1040 r1091 1 1 from ooMisc import assignScript 2 from BaseProblem import BaseProblem2 from BaseProblem import NonLinProblem 3 3 from numpy import asarray, ones, inf, array, iterable 4 4 from NLP import nlp_init 5 5 6 class GLP(BaseProblem): 6 class GLP(NonLinProblem): 7 __optionalData__ = ['lb', 'ub'] 7 8 def __init__(self, *args, **kwargs): 8 9 if len(args) > 1: self.err('incorrect args number for GLP constructor, must be 0..1 + (optionaly) some kwargs') … … 10 11 kwargs2 = kwargs.copy() 11 12 if len(args) > 0: kwargs2['f'] = args[0] 12 BaseProblem.__init__(self)13 NonLinProblem.__init__(self) 13 14 14 15 glp_init(self, kwargs2) trunk/openopt/scikits/openopt/Kernel/LLSP.py
r1040 r1091 1 1 from ooMisc import assignScript 2 from BaseProblem import BaseProblem3 from numpy import asfarray, ones, inf, dot 2 from BaseProblem import MatrixProblem 3 from numpy import asfarray, ones, inf, dot, nan, zeros 4 4 from numpy.linalg import norm 5 import NLP 5 6 6 class LLSP(BaseProblem): 7 class LLSP(MatrixProblem): 8 __optionalData__ = ['damp', 'xd', 'c'] 7 9 def __init__(self, *args, **kwargs): 8 10 if len(args) > 2: self.err('incorrect args number for LLSP constructor, must be 0..2 + (optionaly) some kwargs') 9 11 if len(args) > 0: kwargs['C'] = args[0] 10 12 if len(args) > 1: kwargs['d'] = args[1] 11 BaseProblem.__init__(self) 13 14 MatrixProblem.__init__(self) 12 15 llsp_init(self, kwargs) 13 16 14 17 def objFunc(self, x): 15 return norm(dot(self.C, x) - self.d) 18 r = norm(dot(self.C, x) - self.d) ** 2 / 2.0 19 if self.damp != 0: r += self.damp * norm(x-self.xd)**2 / 2.0 20 if any(self.f): r += dot(self.f, x) 21 return r 22 23 def llsp2nlp(self, solver, **kwargs): 24 if hasattr(self,'x0'): p = NLP.NLP(ff, self.x0, df=dff) 25 else: p = NLP(ff, zeros(self.n), df=dff) 26 p.args.f = self # DO NOT USE p.args = self IN PROB ASSIGNMENT! 27 self.inspire(p) 28 r = p.solve(solver, **kwargs) 29 return r 30 31 16 32 17 33 def llsp_init(prob, kwargs): … … 26 42 prob.lb = -inf * ones(prob.n) 27 43 prob.ub = inf * ones(prob.n) 44 if not kwargs.has_key('damp'): kwargs['damp'] = 0 45 if not kwargs.has_key('xd'): kwargs['xd'] = zeros(prob.n) 46 if not kwargs.has_key('f'): kwargs['f'] = zeros(prob.n) 47 48 if prob.x0 is nan: prob.x0 = zeros(prob.n) 28 49 29 50 return assignScript(prob, kwargs) 30 51 52 #def ff(x, LLSPprob): 53 # r = dot(LLSPprob.C, x) - LLSPprob.d 54 # return dot(r, r) 55 ff = lambda x, LLSPprob: LLSPprob.objFunc(x) 56 dff = lambda x, LLSPprob: 2 * (dot(LLSPprob.C.T, dot(LLSPprob.C,x) - LLSPprob.d)) 57 trunk/openopt/scikits/openopt/Kernel/LP.py
r1040 r1091 1 1 from ooMisc import assignScript 2 from BaseProblem import BaseProblem3 from numpy import asarray, ones, inf 2 from BaseProblem import MatrixProblem 3 from numpy import asarray, ones, inf, dot, nan, zeros 4 4 5 5 6 class LP(BaseProblem): 6 class LP(MatrixProblem): 7 __optionalData__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub'] 7 8 def __init__(self, *args, **kwargs): 8 9 kwargs2 = kwargs.copy() … … 10 11 if len(args) > 1: self.err('incorrect args number for LP constructor, must be 0..1 + (optionaly) some kwargs') 11 12 self.probType = 'LP' 12 BaseProblem.__init__(self)13 MatrixProblem.__init__(self) 13 14 lp_init(self, kwargs2) 14 15 15 16 16 17 def objFunc(self, x): 17 return self.dotmult(p.f, x)18 return dot(self.f, x) 18 19 19 20 def lp_init(prob, kwargs): … … 27 28 28 29 prob.n = len(f) 30 if prob.x0 is nan: prob.x0 = zeros(prob.n) 29 31 prob.lb = -inf * ones(prob.n) 30 32 prob.ub = inf * ones(prob.n) trunk/openopt/scikits/openopt/Kernel/LSP.py
r830 r1091 1 from BaseProblem import BaseProblem1 from BaseProblem import NonLinProblem 2 2 from NLP import nlp_init 3 3 4 class LSP(BaseProblem): 4 class LSP(NonLinProblem): 5 __optionalData__ = [] 5 6 def __init__(self, *args, **kwargs): 6 7 if len(args) > 2: self.err('incorrect args number for LSP constructor, must be 0..2 + (optionaly) some kwargs') 7 8 8 9 kwargs2 = kwargs.copy() 9 10 if len(args) > 0: kwargs2['f'] = args[0] 10 11 if len(args) > 1: kwargs2['x0'] = args[1] 11 12 BaseProblem.__init__(self)12 13 NonLinProblem.__init__(self) 13 14 self.probType = 'LSP' 15 self.allowedGoals = ['minimum', 'min'] 14 16 self.isObjFunValueASingleNumber = False 15 17 16 18 return nlp_init(self, kwargs2) 17 19 trunk/openopt/scikits/openopt/Kernel/MILP.py
r1040 r1091 1 1 2 2 from ooMisc import assignScript 3 from BaseProblem import BaseProblem4 from numpy import asarray, ones, inf 3 from BaseProblem import MatrixProblem 4 from numpy import asarray, ones, inf, dot, nan, zeros 5 5 6 6 from LP import lp_init … … 8 8 9 9 10 class MILP(BaseProblem): 10 class MILP(MatrixProblem): 11 __optionalData__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub'] 11 12 def __init__(self, *args, **kwargs): 12 13 if len(args) > 2: self.err('incorrect args number for MILP constructor, must be 0..2 + (optionaly) some kwargs') … … 16 17 if len(args) > 1: kwargs2['intVars'] = args[1] 17 18 self.probType = 'MILP' 18 BaseProblem.__init__(self)19 MatrixProblem.__init__(self) 19 20 lp_init(self, kwargs2) 21 22 def objFunc(self, x): 23 return dot(self.f, x) 20 24 21 25 22 26 23 24 trunk/openopt/scikits/openopt/Kernel/MMP.py
r1040 r1091 1 from BaseProblem import BaseProblem1 from BaseProblem import NonLinProblem 2 2 from NLP import nlp_init 3 3 from numpy import max 4 4 5 class MMP( BaseProblem):5 class MMP(NonLinProblem): 6 6 """ 7 7 Mini-Max Problem 8 8 """ 9 __optionalData__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 9 10 def __init__(self, *args, **kwargs): 10 11 if len(args) > 2: self.err('incorrect args number for MMP constructor, must be 0..2 + (optionaly) some kwargs') … … 13 14 if len(args) > 0: kwargs2['f'] = args[0] 14 15 if len(args) > 1: kwargs2['x0'] = args[1] 15 BaseProblem.__init__(self)16 NonLinProblem.__init__(self) 16 17 17 self.allowedGoals = ['minim um', 'min', 'maximum', 'max']18 self.allowedGoals = ['minimax'] 18 19 19 20 nlp_init(self, kwargs2) trunk/openopt/scikits/openopt/Kernel/NLP.py
r1040 r1091 1 1 from ooMisc import assignScript 2 from BaseProblem import BaseProblem2 from BaseProblem import NonLinProblem 3 3 from numpy import asarray, ones, inf, array, iterable 4 4 5 5 6 class NLP(BaseProblem): 6 class NLP(NonLinProblem): 7 __optionalData__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 7 8 def __init__(self, *args, **kwargs): 8 9 if len(args) > 2: self.err('incorrect args number for NLP constructor, must be 0..2 + (optionaly) some kwargs') … … 11 12 if len(args) > 0: kwargs2['f'] = args[0] 12 13 if len(args) > 1: kwargs2['x0'] = args[1] 13 BaseProblem.__init__(self)14 NonLinProblem.__init__(self) 14 15 15 16 self.probType = 'NLP' trunk/openopt/scikits/openopt/Kernel/NLSP.py
r1040 r1091 1 from BaseProblem import BaseProblem1 from BaseProblem import NonLinProblem 2 2 from NLP import nlp_init 3 3 from numpy.linalg import norm … … 5 5 from setDefaultIterFuncs import FVAL_IS_ENOUGH 6 6 7 class NLSP(BaseProblem): 7 class NLSP(NonLinProblem): 8 __optionalData__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 8 9 def __init__(self, *args, **kwargs): 9 10 if len(args) > 2: self.err('incorrect args number for NLSP constructor, must be 0..2 + (optionaly) some kwargs') … … 12 13 if len(args) > 0: kwargs2['f'] = args[0] 13 14 if len(args) > 1: kwargs2['x0'] = args[1] 14 BaseProblem.__init__(self)15 NonLinProblem.__init__(self) 15 16 16 17 self.isObjFunValueASingleNumber = False trunk/openopt/scikits/openopt/Kernel/NSP.py
r1040 r1091 1 1 from ooMisc import assignScript 2 from BaseProblem import BaseProblem2 from BaseProblem import NonLinProblem 3 3 from numpy import asarray, ones, inf 4 4 … … 7 7 8 8 9 class NSP(BaseProblem): 9 class NSP(NonLinProblem): 10 __optionalData__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 10 11 def __init__(self, *args, **kwargs): 11 12 if len(args) > 2: self.err('incorrect args number for NSP constructor, must be 0..2 + (optionaly) some kwargs') … … 14 15 if len(args) > 0: kwargs2['f'] = args[0] 15 16 if len(args) > 1: kwargs2['x0'] = args[1] 16 BaseProblem.__init__(self)17 NonLinProblem.__init__(self) 17 18 18 19 trunk/openopt/scikits/openopt/Kernel/QP.py
r1089 r1091 6 6 7 7 from ooMisc import assignScript 8 from BaseProblem import BaseProblem8 from BaseProblem import MatrixProblem 9 9 from numpy import asfarray, ones, inf, dot, asfarray, nan, zeros 10 10 11 11 12 class QP(BaseProblem): 12 class QP(MatrixProblem): 13 __optionalData__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub'] 13 14 def __init__(self, *args, **kwargs): 14 15 self.probType = 'QP' … … 17 18 if len(args) > 1: kwargs2['f'] = args[1] 18 19 if len(args) > 2: self.err('incorrect args number for QP constructor, must be 0..1 + (optionaly) some kwargs') 19 BaseProblem.__init__(self)20 MatrixProblem.__init__(self) 20 21 21 22 return qp_init(self, kwargs2) trunk/openopt/scikits/openopt/Kernel/Residuals.py
r1089 r1091 36 36 # TODO: add quadratic constraints 37 37 r = EmptyClass() 38 r.c = self.__get_nonLinInEq_Residuals__(x) 39 r.h = self.__get_nonLinEq_Residuals__(x) 38 # TODO: simplify it! 39 if self.__baseClassName__ == 'NonLin': 40 r.c = self.__get_nonLinInEq_Residuals__(x) 41 r.h = self.__get_nonLinEq_Residuals__(x) 42 else: 43 r.c = r.h = 0 40 44 r.A = self.__get_AX_Less_B_Residuals__(x) 41 45 r.Aeq= self.__get_AeqX_eq_Beq_Residuals__(x) trunk/openopt/scikits/openopt/Kernel/objFunRelated.py
r1009 r1091 167 167 def wrapped_1st_derivatives(p, funcType, x, ind=None, ignorePrev=False): 168 168 derivativesType = 'd'+funcType 169 funcs = getattr(p.user, derivativesType)169 #funcs = getattr(p.user, derivativesType) 170 170 prevKey = p.prevVal[derivativesType]['key'] 171 171 if prevKey is not None and p.iter > 0 and all(x == prevKey) and ind is None and not ignorePrev: trunk/openopt/scikits/openopt/Kernel/ooCheck.py
r1064 r1091 11 11 p.err('goal '+ p.goal+' is not available for the '+ p.probType + ' class (at least not implemented yet)') 12 12 13 13 # for fn in p.__optionalData__: 14 # if not fn in p.solver.__optionalDataThatCanBeHandled__: 15 # p.err('the solver ' + p.solverName + ' cannot handle ' + "'" + fn + "' data") 14 16 15 17 if p.solver.__constraintsThatCannotBeHandled__ != []: … … 20 22 p.err('the solver ' + p.solverName + ' cannot handle ' + "'" + fn + "' constraints") 21 23 22 for fn in ('df', 'dc', 'dh'):23 if getattr(p.check, fn):24 p.info('the option p.check.'+fn+' is obsolete, use p.check'+fn+'() or p.check'+fn+'(x) instead')25 24 26 25 return nErrors trunk/openopt/scikits/openopt/Kernel/runProbSolver.py
r1090 r1091 84 84 if p.graphics.xlabel == 'nf': p.iterValues.nf = [] # iter ObjFunc evaluation number 85 85 86 p.__ makeCorrectArgs__()86 p.__prepare__() 87 87 88 88 if p.probType in ('LP', 'MILP', 'QP') and p.plot: … … 93 93 if hasattr(p, 'x0'): p.x0 = atleast_1d(asfarray(p.x0).copy()) 94 94 for fn in ['lb', 'ub', 'b', 'beq', 'scale', 'diffInt']: 95 fv = getattr(p, fn) 96 if fv != None:# and fv != []: 97 setattr(p, fn, asfarray(fv, dtype='float').flatten()) 98 elif fn != 'scale': 99 setattr(p, fn, asfarray([])) 100 101 102 if p.scale is not None: 95 if hasattr(p, fn): 96 fv = getattr(p, fn) 97 if fv != None:# and fv != []: 98 setattr(p, fn, asfarray(fv, dtype='float').flatten()) 99 elif fn != 'scale': 100 setattr(p, fn, asfarray([])) 101 102 103 if p.scale is not None and hasattr(p, 'diffInt'): 103 104 if p.diffInt.size>1 or p.diffInt[0] != ProbDefaults['diffInt']: 104 105 p.info('using both non-default scale & diffInt is not recommended. diffInt = diffInt/scale will be used') … … 125 126 p.stopdict = {} 126 127 127 for s in ('f', 'df', 'd2f', 'c', 'dc', 'd2c', 'h', 'dh', 'd2h', 'l', 'dl', 'd2l'):128 if not (s == 'f' and p.probType in ('LP', 'MILP', 'QP')):129 if hasattr(p, s) and getattr(p, s) is not None:130 setattr(p.userProvided, s, True)131 p.nEvals[s] = 0132 A = getattr(p,s)133 134 if callable(A): #TODO: add or ndarray(A)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!135 A = (A,)#make tuple136 setattr(p.user, s, A)137 else:138 setattr(p.userProvided, s, False)139 setattr(p.user, s, (None,))140 setattr(p, s, getattr(p, 'user_' + s))141 142 #initialization, getting nf, nc, nh etc:143 for s in ['c', 'h']:144 if getattr(p.userProvided, s):145 getattr(p, s)(p.x0)146 else:147 setattr(p, 'n'+s, 0)148 128 for s in ['b','beq']: 149 129 if hasattr(p, s): setattr(p, 'n'+s, len(getattr(p, s))) … … 158 138 nErr = ooCheck(p) 159 139 if nErr: p.err("prob check results: " +str(nErr) + "ERRORS!")#however, I guess this line will be never reached. 160 161 if hasattr(p, 'delayedConnectIterFcn'):162 if p.solver.__iterfcnConnected__: p.warn('solver ' + p.solver.__name__ + ' has native iterfcn, user-defined connection via p.connectIterFcn will be ignored')163 else:164 if p.delayedConnectIterFcn == 'df': p.warn('iterfcn now connects to df automatically by default, you can either use other funcs like d2f to suppress the warning or ommit user-defined connecting to df at all')165 p.connectIterFcn('df')166 else:167 if not p.solver.__iterfcnConnected__:168 p.connectIterFcn('df', calledByUser = False)169 140 170 141 if not p.solver.__iterfcnConnected__: … … 226 197 else: p.iterfcn(p.xf, p.ff) 227 198 228 if (p.userProvided.c and any(isnan(p.c(p.xf)))) or (p.userProvided.h and any(isnan(p.h(p.xf)))): 229 #p. 230 if p.iprint >= -1: p.warn('some non-linear constraints are equal to NaN') 199 p.__finalize__() 231 200 232 201 r = OpenOptResult() trunk/openopt/scikits/openopt/Kernel/setDefaultIterFuncs.py
r960 r1091 13 13 IS_NAN_IN_X = -4 14 14 IS_LINE_SEARCH_FAILED = -5 15 IS_MAX_ITER_REACHED = -7 15 IS_MAX_ITER_REACHED = -7 16 16 IS_MAX_CPU_TIME_REACHED = -8 17 17 IS_MAX_TIME_REACHED = -9 … … 20 20 21 21 FAILED_WITH_UNIMPLEMENTED_OR_UNKNOWN_REASON = -1000 22 22 23 23 def stopcase(arg): 24 24 if hasattr(arg, 'istop'): istop = arg.istop 25 25 else: istop = arg 26 26 27 27 if istop > 0: return 1 28 28 elif istop in [IS_MAX_ITER_REACHED, IS_MAX_CPU_TIME_REACHED, IS_MAX_TIME_REACHED, IS_MAX_FUN_EVALS_REACHED]: return 0 29 29 else: return -1 30 31 30 32 31 33 def setDefaultIterFuncs(): 32 33 def setDefaultIterFuncs(className): 34 34 d = dict() 35 35 36 36 # positive: 37 37 d[SMALL_DF] = lambda p: small_df(p) … … 46 46 d[IS_MAX_CPU_TIME_REACHED] = lambda p: isMaxCPUTimeReached(p) 47 47 d[IS_MAX_TIME_REACHED] = lambda p: isMaxTimeReached(p) 48 d[IS_MAX_FUN_EVALS_REACHED] = lambda p: isMaxFunEvalsReached(p)48 if className == 'NonLin': d[IS_MAX_FUN_EVALS_REACHED] = lambda p: isMaxFunEvalsReached(p) 49 49 return d 50 50 51 51 def small_df(p): 52 if not hasattr(p, '_df') or p._df == None or p.norm(p._df) >= p.gradtol: return False 52 if not hasattr(p, '_df') or p._df == None or p.norm(p._df) >= p.gradtol: return False 53 53 return (True, '|| gradient F(X[k]) || < gradtol') 54 54 #return False if not hasattr(p, 'dF') or p.dF == None or p.norm(p.dF) > p.gradtol else True 55 55 56 56 def small_deltaX(p): 57 57 if p.iter == 0: return False … … 61 61 else: return (True, '|| X[k] - X[k-1] || < xtol') 62 62 #r = False if p.norm(p.xk - p.x_prev) > p.xtol else True 63 64 63 64 65 65 def small_deltaF(p): 66 66 if p.iter == 0: return False 67 67 #r = False if p.norm(p.fk - p.f_prev) > p.ftol else True 68 if p.norm(p.iterValues.f[-1] - p.iterValues.f[-2]) >= p.ftol: # or (p.iterValues.r[-1] > p.contol and p.iterValues.r[-1] - p.iterValues.r[-2] < p.contol): 68 if p.norm(p.iterValues.f[-1] - p.iterValues.f[-2]) >= p.ftol: # or (p.iterValues.r[-1] > p.contol and p.iterValues.r[-1] - p.iterValues.r[-2] < p.contol): 69 69 return False 70 70 else: return (True, '|| F[k] - F[k-1] || < ftol') 71 71 72 72 73 73 def isEnough(p): … … 80 80 return (True, 'NaN in X[k] coords has been obtained') 81 81 else: return False 82 82 83 83 84 84 def isMaxIterReached(p): … … 102 102 def isMaxFunEvalsReached(p): 103 103 #if not hasattr(p, 'nFunEvals'): p.warn('no nFunEvals field'); return 0 104 if p.nEvals['f'] < p.maxFunEvals: 104 if p.nEvals['f'] >= p.maxFunEvals: 105 return (True, 'max objfunc evals limit has been reached') 106 else: 105 107 return False 106 else:107 return (True, 'max objfunc evals limit has been reached')108 108 109 109 trunk/openopt/scikits/openopt/solvers/BrasilOpt/ALGENCAN_oo.py
r1090 r1091 12 12 __homepage__ = 'http://www.ime.usp.br/~egbirgin/tango/' 13 13 __info__ = "please pay more attention to gradtol param, it's the only one ALGENCAN positive stop criterium, xtol and ftol are unused" 14 __ constraintsThatCannotBeHandled__ = [] # empty list means the solver can handle all constraints14 __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 15 15 __isIterPointAlwaysFeasible__ = lambda self, p: p.__isNoMoreThanBoxBounded__() 16 16 trunk/openopt/scikits/openopt/solvers/BrasilOpt/algencan_oo.py
r1090 r1091 13 13 #TODO: edit info! 14 14 __info__ = "please pay more attention to gradtol param, it's the only one ALGENCAN positive stop criterium, xtol and ftol are unused" 15 __ constraintsThatCannotBeHandled__ = [] # empty list means the solver can handle all constraints15 __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 16 16 __isIterPointAlwaysFeasible__ = lambda self, p: p.__isNoMoreThanBoxBounded__() 17 17 trunk/openopt/scikits/openopt/solvers/CVXOPT/cvxopt_glpk_oo.py
r934 r1091 6 6 __license__ = "GPL v.2" 7 7 __authors__ = "http://www.gnu.org/software/glpk + Python bindings from http://abel.ee.ucla.edu/cvxopt" 8 __alg__ = "see http://www.gnu.org/software/glpk" 9 __ constraintsThatCannotBeHandled__ = ['c', 'h'] # empty list means the solver can handle all constraints8 __alg__ = "see http://www.gnu.org/software/glpk" 9 __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'intVars', 'binVars'] 10 10 def __init__(self): pass 11 11 12 12 def __solver__(self, p): 13 13 return CVXOPT_LP_Solver(p, 'glpk') trunk/openopt/scikits/openopt/solvers/CVXOPT/cvxopt_lp_oo.py
r934 r1091 6 6 __license__ = "LGPL" 7 7 __authors__ = "http://abel.ee.ucla.edu/cvxopt" 8 __alg__ = "see http://abel.ee.ucla.edu/cvxopt" 9 __ constraintsThatCannotBeHandled__ = ['c', 'h'] # empty list means the solver can handle all constraints8 __alg__ = "see http://abel.ee.ucla.edu/cvxopt" 9 __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub'] 10 10 def __init__(self): pass 11 11 def __solver__(self, p): trunk/openopt/scikits/openopt/solvers/CVXOPT/cvxopt_qp_oo.py
r934 r1091 6 6 __license__ = "LGPL" 7 7 __authors__ = "http://abel.ee.ucla.edu/cvxopt" 8 __alg__ = "see http://abel.ee.ucla.edu/cvxopt" 9 __ constraintsThatCannotBeHandled__ = ['c', 'h'] # empty list means the solver can handle all constraints8 __alg__ = "see http://abel.ee.ucla.edu/cvxopt" 9 __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub'] 10 10 def __init__(self): pass 11 11 def __solver__(self, p): trunk/openopt/scikits/openopt/solvers/CVXOPT/glpk_oo.py
r950 r1091 7 7 __authors__ = "http://www.gnu.org/software/glpk + Python bindings from http://abel.ee.ucla.edu/cvxopt" 8 8 __homepage__ = 'http://www.gnu.org/software/glpk' 9 #__alg__ = "" 10 __ constraintsThatCannotBeHandled__ = ['c', 'h'] # empty list means the solver can handle all constraints11 9 #__alg__ = "" 10 __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'intVars', 'binVars'] 11 12 12 def __init__(self): pass 13 13 14 14 def __solver__(self, p): 15 15 return CVXOPT_LP_Solver(p, 'glpk') trunk/openopt/scikits/openopt/solvers/CoinOr/ipopt_oo.py
r1028 r1091 13 13 __homepage__ = 'http://www.coin-or.org/' 14 14 __info__ = "requires pyipopt made by Eric Xu You" 15 __ constraintsThatCannotBeHandled__ = [] # empty list means the solver can handle all constraints15 __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 16 16 17 17 trunk/openopt/scikits/openopt/solvers/Standalone/bvls_oo.py
r933 r1091 13 13 __license__ = "BSD" 14 14 __authors__ = 'Robert L. Parker rlparker[at]ucsd.edu, Philip B. Stark stark[at]stat.berkeley.edu' 15 __alg__ = '"Bounded Variable Least Squares: An Algorithm and Applications" by P.B. Stark and R.L. Parker, in the journal "Computational Statistics", vol.10(2), 1995' 15 __alg__ = '"Bounded Variable Least Squares: An Algorithm and Applications" by P.B. Stark and R.L. Parker, in the journal "Computational Statistics", vol.10(2), 1995' 16 16 __info__ = 'requires manual compilation of bvls.f by f2py, see OO online doc for details' 17 __ constraintsThatCannotBeHandled__ = ['c', 'h', 'Aeq', 'A']18 17 __optionalDataThatCanBeHandled__ = ['lb', 'ub'] 18 19 19 __bvls_inf__ = 1e300 20 20 T = float64 21 21 def __init__(self): pass 22 22 23 23 def __solver__(self, p): 24 24 key = 0 … … 32 32 bl[where(bl==-inf)[0]] = -self.__bvls_inf__ 33 33 bu[where(bu==inf)[0]] = self.__bvls_inf__ 34 34 35 35 xf, w, istop, msg, iter = BVLS.bvls(key, a, b, bl, bu, p.maxIter, act, zz, istate) 36 36 37 37 p.istop, p.msg, p.iter = istop, msg.rstrip(), iter 38 38 p.xf = p.xk = xf 39 39 p.ff = p.fk = w[0] 40 40 trunk/openopt/scikits/openopt/solvers/Standalone/galileo_oo.py
r1004 r1091 15 15 requires finite lb, ub: lb <= x <= ub 16 16 """ 17 __ constraintsThatCannotBeHandled__ = ['c', 'h', 'Aeq', 'A']17 __optionalDataThatCanBeHandled__ = ['lb', 'ub'] 18 18 __isIterPointAlwaysFeasible__ = lambda self, p: True 19 19 trunk/openopt/scikits/openopt/solvers/Standalone/toms587_oo.py
r933 r1091 11 11 __license__ = "BSD" 12 12 __authors__ = 'R. J. HANSON AND K. H. HASKELL' 13 #__alg__ = '' 13 #__alg__ = '' 14 14 __info__ = 'requires manual compilation of toms_587.f by f2py, see OO online doc for details' 15 __constraintsThatCannotBeHandled__ = ['c', 'h']16 15 #__optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub'] 16 17 17 T = float64 18 18 def __init__(self): pass 19 19 20 20 def __solver__(self, p): 21 21 xBounds2Matrix(p) … … 53 53 p.ff = p.fk = ff 54 54 p.istop = 1000 55 56 55 57 56 57 trunk/openopt/scikits/openopt/solvers/UkrOpt/ShorEllipsoid_oo.py
r1004 r1091 18 18 __alg__ = "Naum Z. Shor modificated method of ellipsoids" 19 19 __iterfcnConnected__ = True 20 #__optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 20 21 21 22 def __init__(self): pass … … 23 24 def __solver__(self, p): 24 25 25 if p.useScaling: p.err('ShorEllipsoid + scaling isn''t implemented yet')26 #if p.useScaling: p.err('ShorEllipsoid + scaling isn''t implemented yet') 26 27 27 28 trunk/openopt/scikits/openopt/solvers/UkrOpt/goldenSection_oo.py
r1004 r1091 5 5 class goldenSection(BaseAlg): 6 6 __name__ = 'goldenSection' 7 __ constraintsThatCannotBeHandled__ = ['c', 'h', 'Aeq', 'A']7 __optionalDataThatCanBeHandled__ = ['lb', 'ub'] 8 8 __license__ = "BSD" 9 9 __authors__ = 'Dmitrey' trunk/openopt/scikits/openopt/solvers/UkrOpt/lincher_oo.py
r1065 r1091 90 90 __authors__ = "Dmitrey" 91 91 __alg__ = "a linearization-based solver written in Cherkassy town, Ukraine" 92 __constraintsThatCannotBeHandled__ = [] # empty list means the solver can handle all constraints 92 __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 93 93 94 __isIterPointAlwaysFeasible__ = lambda self, p: p.__isNoMoreThanBoxBounded__() 94 95 __iterfcnConnected__ = True trunk/openopt/scikits/openopt/solvers/UkrOpt/nsmm_oo.py
r1004 r1091 11 11 __alg__ = "based on Naum Z. Shor r-alg" 12 12 __iterfcnConnected__ = True 13 __ constraintsThatCannotBeHandled__ = []13 __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 14 14 __info__ = """ 15 15 Solves mini-max problem trunk/openopt/scikits/openopt/solvers/UkrOpt/nssolve_oo.py
r1065 r1091 12 12 __alg__ = "based on Naum Z. Shor r-alg" 13 13 __iterfcnConnected__ = True 14 __ constraintsThatCannotBeHandled__ = []14 __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 15 15 __isIterPointAlwaysFeasible__ = lambda self, p: p.isUC 16 16 __info__ = """ trunk/openopt/scikits/openopt/solvers/UkrOpt/ralg_oo.py
r1089 r1091 11 11 __authors__ = "Dmitrey" 12 12 __alg__ = "Naum Z. Shor R-algorithm with adaptive space dilation & some modifications" 13 __ constraintsThatCannotBeHandled__ = []13 __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 14 14 __iterfcnConnected__ = True 15 15 trunk/openopt/scikits/openopt/solvers/lp_solve/lpSolve_oo.py
r1073 r1091 16 16 __alg__ = "lpsolve" 17 17 __info__ = 'use p.scale = 1 or True to turn scale mode on' 18 __ constraintsThatCannotBeHandled__ = ['c', 'h', 'binVars'] # empty list means the solver can handle all constraints18 __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'intVars'] 19 19 def __init__(self): pass 20 20 def __solver__(self, p): trunk/openopt/scikits/openopt/solvers/scipy_optim/scipy_cobyla_oo.py
r1089 r1091 14 14 __alg__ = "Constrained Optimization BY Linear Approximation" 15 15 __info__ = 'constrained NLP solver, no user-defined derivatives are handled'#TODO: add '__info__' field to other solvers 16 __ constraintsThatCannotBeHandled__ = [] # empty list means the solver can handle all constraints16 __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 17 17 18 18 def __init__(self): pass trunk/openopt/scikits/openopt/solvers/scipy_optim/scipy_fminbound_oo.py
r934 r1091 4 4 class scipy_fminbound(BaseAlg): 5 5 __name__ = 'scipy_fminbound' 6 __ constraintsThatCannotBeHandled__ = ['c', 'h', 'Aeq', 'A']6 __optionalDataThatCanBeHandled__ = ['lb', 'ub'] 7 7 __license__ = "BSD" 8 8 __authors__ = "Travis E. Oliphant" 9 __alg__ = "Brent's method (golden section + parabolic fit)" 9 __alg__ = "Brent's method (golden section + parabolic fit)" 10 10 __info__ = '1-dimensional minimizer for finite box-bound problems' 11 11 __isIterPointAlwaysFeasible__ = lambda self, p: True trunk/openopt/scikits/openopt/solvers/scipy_optim/scipy_lbfgsb_oo.py
r934 r1091 8 8 __name__ = 'scipy_lbfgsb' 9 9 __license__ = "BSD" 10 __authors__ = """Ciyou Zhu, Richard Byrd, and Jorge Nocedal <nocedal@ece.nwu.edu>, 10 __authors__ = """Ciyou Zhu, Richard Byrd, and Jorge Nocedal <nocedal@ece.nwu.edu>, 11 11 connected to scipy by David M. Cooke <cookedm@physics.mcmaster.ca> and Travis Oliphant, 12 12 connected to openopt by Dmitrey""" 13 __alg__ = "l-bfgs-b" 14 __info__ = 'box-bounded limited-memory NLP solver, can handle lb<=x<=ub constraints, some lb-ub coords can be +/- inf'#TODO: add '__info__' field to other solvers 15 __ constraintsThatCannotBeHandled__ = ['c', 'h', 'Aeq', 'A']13 __alg__ = "l-bfgs-b" 14 __info__ = 'box-bounded limited-memory NLP solver, can handle lb<=x<=ub constraints, some lb-ub coords can be +/- inf'#TODO: add '__info__' field to other solvers 15 __optionalDataThatCanBeHandled__ = ['lb', 'ub'] 16 16 __isIterPointAlwaysFeasible__ = lambda self, p: True 17 17 18 18 def __init__(self):pass 19 19 20 20 def __solver__(self, p): 21 21 WholeRepr2LinConst(p)#TODO: remove me 22 22 23 23 bounds = [] 24 24 25 25 # don't work in Python ver < 2.5 26 26 # BOUND = lambda x: x if isfinite(x) else None 27 27 28 28 def BOUND(x): 29 29 if isfinite(x): return x 30 30 else: return None 31 31 32 32 for i in xrange(p.n): bounds.append((BOUND(p.lb[i]), BOUND(p.ub[i]))) 33 34 xf, ff, d = fmin_l_bfgs_b(p.f, p.x0, fprime=p.df, 35 approx_grad=0, bounds=bounds, 33 34 xf, ff, d = fmin_l_bfgs_b(p.f, p.x0, fprime=p.df, 35 approx_grad=0, bounds=bounds, 36 36 iprint=p.iprint, maxfun=p.maxFunEvals) 37 38 if d['warnflag'] in (0, 2): 37 38 if d['warnflag'] in (0, 2): 39 39 # if 2 - some problems can be present, but final check from RunProbSolver will set negative istop if solution is unfeasible 40 40 istop = SOLVED_WITH_UNIMPLEMENTED_OR_UNKNOWN_REASON 41 41 if d['warnflag'] == 0: msg = 'converged' 42 42 elif d['warnflag'] == 1: istop = IS_MAX_FUN_EVALS_REACHED 43 43 44 44 p.xk = p.xf = xf 45 45 p.fk = p.ff = ff 46 46 p.istop = istop 47 47 p.iterfcn() 48 48 trunk/openopt/scikits/openopt/solvers/scipy_optim/scipy_slsqp_oo.py
r1000 r1091 14 14 __alg__ = "Sequential Least SQuares Programming" 15 15 __info__ = 'constrained NLP solver' 16 __ constraintsThatCannotBeHandled__ = []16 __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 17 17 18 18 def __init__(self): pass trunk/openopt/scikits/openopt/solvers/scipy_optim/scipy_tnc_oo.py
r934 r1091 9 9 __license__ = "BSD" 10 10 __authors__ = "Stephen G. Nash" 11 __alg__ = "undefined" 11 __alg__ = "undefined" 12 12 __info__ = 'box-bounded NLP solver, can handle lb<=x<=ub constraints, some lb-ub coords can be +/- inf' 13 __ constraintsThatCannotBeHandled__ = ['c', 'h', 'Aeq', 'A']13 __optionalDataThatCanBeHandled__ = ['lb', 'ub'] 14 14 __isIterPointAlwaysFeasible__ = lambda self, p: True 15 15 16 16 def __init__(self): pass 17 17 18 18 def __solver__(self, p): 19 19 WholeRepr2LinConst(p)#TODO: remove me … … 21 21 for i in xrange(p.n): bounds.append((p.lb[i], p.ub[i])) 22 22 messages = 0#TODO: edit me 23 23 24 24 p.xk = p.x0.copy() 25 25 p.fk = p.f(p.x0) 26 26 27 27 p.iterfcn() 28 28 if p.istop: 29 29 p.xf = p.xk 30 30 p.ff = p.fk 31 return 32 31 return 32 33 33 xf, nfeval, rc = fmin_tnc(p.f, x0 = p.x0, fprime=p.df, args=(), approx_grad=0, bounds=bounds, messages=messages, maxfun=p.maxFunEvals, ftol=p.ftol, xtol=p.xtol, pgtol=p.gradtol) 34 34 35 35 if rc in (INFEASIBLE, NOPROGRESS): istop = FAILED_WITH_UNIMPLEMENTED_OR_UNKNOWN_REASON 36 36 elif rc == FCONVERGED: istop = SMALL_DELTA_F … … 72 72 p.xf = xf 73 73 p.ff = p.fk 74 74 75 75 if __name__ == '__main__': 76 76 import sys, os.path as P … … 78 78 from scikits.openopt import NLP 79 79 from numpy import * 80 80 81 81 N = 750 82 82 83 83 ff = lambda x: (((x/32 - 1)**4).sum() + 64*((x/4 -1 )**2).sum()) 84 84 ## ff = lambda x: (arctan((x-arange(x.size))/arange(x.size))**2).sum() 85 85 ## for solver in ('scipy_tnc', 'scipy_lbfgsb', 'ALGENCAN'): 86 86 for solver in ( 'lincher', 'scipy_lbfgsb', 'ALGENCAN'): 87 ## lb = 0.1*N + arange(N) 87 ## lb = 0.1*N + arange(N) 88 88 ## ub = 0.8*N + arange(N) 89 89 #x0 = cos(arange(N)) 90 90 lb = 50*sin(arange(N))+15 91 91 ub = lb + 15 92 x0 = (lb + ub)/2 92 x0 = (lb + ub)/2 93 93 p = NLP(ff, x0, lb = lb, ub = ub, plot = 0, maxFunEvals = 1e8, maxIter = 1e4, gradtol = 1e-3) 94 94 #p.c = lambda x: x[0]**2 - (lb[0] + ub[0])**2 / 4.0 … … 96 96 r = p.solve(solver) 97 97 #assert r.istop > 0 98 99 100 101 102 98 99 100 101 102
