Changeset 1021
- Timestamp:
- 06/15/08 06:35:08 (4 years ago)
- Location:
- trunk/openopt/scikits/openopt
- Files:
-
- 1 added
- 5 modified
-
Kernel/BaseProblem.py (modified) (2 diffs)
-
Kernel/Point.py (added)
-
Kernel/runProbSolver.py (modified) (8 diffs)
-
__init__.py (modified) (2 diffs)
-
solvers/CoinOr/ipopt_oo.py (modified) (1 diff)
-
solvers/UkrOpt/ralg_oo.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/openopt/scikits/openopt/Kernel/BaseProblem.py
r1008 r1021 7 7 from Residuals import Residuals 8 8 from ooIter import ooIter 9 from Point import Point 9 10 from ooCheckGradient import ooCheckGradient 10 11 from ooIterPrint import ooTextOutput 12 11 13 ProbDefaults = {'diffInt': 1e-7, 'xtol': 1e-6, 'noise': 0} 12 14 … … 77 79 78 80 self.F = lambda x: self.objFuncMultiple2Single(self.objFunc(x)) # TODO: should be changes for LP, MILP, QP classes! 81 82 self.point = lambda *args, **kwargs: Point(self, *args, **kwargs) 79 83 80 84 #you can redirect these ones -
trunk/openopt/scikits/openopt/Kernel/runProbSolver.py
r1020 r1021 10 10 from BaseProblem import ProbDefaults 11 11 from scikits.openopt.Kernel.ooMisc import __solverPaths__ 12 ConTolMultiplier = 0. 999912 ConTolMultiplier = 0.8 13 13 14 14 if __solverPaths__ is None: … … 23 23 __solverPaths__[file[:-6]] = 'scikits.openopt.solvers.' + string.join(rd,'.') + '.'+file[:-3] 24 24 25 26 def my_import(name):27 mod = __import__(name)28 components = name.split('.')29 for comp in components[1:]:30 mod = getattr(mod, comp)31 return mod32 33 class EmptyClass: pass34 class OpenOptResult: pass35 25 36 26 def runProbSolver(p_, solver_str, *args, **kwargs): … … 128 118 129 119 130 p.stopdict = dict()120 p.stopdict = {} 131 121 132 122 for s in ('f', 'df', 'd2f', 'c', 'dc', 'd2c', 'h', 'dh', 'd2h', 'l', 'dl', 'd2l'): … … 136 126 p.nEvals[s] = 0 137 127 A = getattr(p,s) 128 138 129 if callable(A): #TODO: add or ndarray(A)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 139 130 A = (A,)#make tuple … … 205 196 if not hasattr(p, 'fk'): p.fk = p.f(p.xk) 206 197 207 if p.invertObjFunc: p.fk, p.ff = -p.fk, -p.ff 198 if p.invertObjFunc: p.fk, p.ff = -p.fk, -p.ff 199 208 200 p.ff = p.objFuncMultiple2Single(p.ff) 209 201 #if not hasattr(p, 'xf'): p.xf = p.xk … … 215 207 p.stopcase = stopcase(p) 216 208 217 218 219 220 221 ## #for more safety222 ## p.ff = p.f(p.xf)223 224 209 if p.invertObjFunc: p.iterfcn(p.xf, -p.ff) 225 210 else: p.iterfcn(p.xf, p.ff) … … 267 252 r.evals = p.nEvals 268 253 r.evals['iter'] = p.iter 254 255 p.invertObjFunc = False 269 256 270 257 if p.iprint < 0: … … 293 280 294 281 282 ################################################################## 283 def my_import(name): 284 mod = __import__(name) 285 components = name.split('.') 286 for comp in components[1:]: 287 mod = getattr(mod, comp) 288 return mod 289 290 class EmptyClass: pass 291 class OpenOptResult: pass -
trunk/openopt/scikits/openopt/__init__.py
r787 r1021 3 3 4 4 #from info import __doc__, __version__ 5 6 5 7 6 from oo import LP, NLP, NSP, MILP, QP, NLSP, LSP, GLP, LLSP, MMP … … 12 11 test = NumpyTest().test 13 12 14 13 -
trunk/openopt/scikits/openopt/solvers/CoinOr/ipopt_oo.py
r1019 r1021 9 9 __name__ = 'ipopt' 10 10 __license__ = "CPL" 11 #__authors__ = ''12 #__alg__ = ""11 __authors__ = 'Carl Laird (Carnegie Mellon University) and Andreas Wachter' 12 __alg__ = "A. Wachter and L. T. Biegler, On the Implementation of a Primal-Dual Interior Point Filter Line Search Algorithm for Large-Scale Nonlinear Programming, Mathematical Programming 106(1), pp. 25-57, 2006 " 13 13 __homepage__ = 'http://www.coin-or.org/' 14 #__info__ = ""14 __info__ = "requires pyipopt made by Eric Xu You" 15 15 __constraintsThatCannotBeHandled__ = [] # empty list means the solver can handle all constraints 16 16 -
trunk/openopt/scikits/openopt/solvers/UkrOpt/ralg_oo.py
r1004 r1021 2 2 from numpy.linalg import norm 3 3 from scikits.openopt.Kernel.BaseAlg import * 4 from scikits.openopt.Kernel.Point import Point 4 5 from scikits.openopt.Kernel.setDefaultIterFuncs import SMALL_DELTA_X, SMALL_DELTA_F, SMALL_DF, IS_LINE_SEARCH_FAILED 5 6 from UkrOptMisc import getConstrDirection … … 17 18 hmult = 0.5 18 19 T = float64 19 needRej = lambda self, p, b, g : norm(b.flatten(), 1) < min(1e-10, 1e-5*p.gradtol)20 needRej = lambda self, p, b, g_dilated, g: norm(g_dilated) < 1e-10*norm(g) 20 21 #checkTurnByGradient = True 21 22 … … 98 99 ls1 = 0 99 100 100 f = p.f(x)101 mr = p.getMaxResidual(x) 102 103 if ls == 0: fprev, mrprev, xprev = p.fk, p.rk, p.xk.copy()101 newPoint = p.point(x) 102 103 if ls == 0: 104 oldPoint = p.point(p.xk, f = p.fk, mr = p.rk) 104 105 105 106 #if not self.checkTurnByGradient: 106 if p.__1stBetterThan2nd__(fprev, f, mrprev, mr): 107 if p.noise==0 or p.__1stCertainlyBetterThan2ndTakingIntoAcoountNoise__(fprev, f, mrprev, mr): 108 pass# and go to label "Line Search Finished" 109 else: continue 110 else: 111 if fprev == f and mrprev == mr: pass # and go to label "Line Search Finished" 112 elif ls>10: 113 if fprev >= f and max(mrprev, p.contol) >= mr:continue 107 if newPoint.betterThan(oldPoint): 108 #TODO: handle possible noise here 109 if ls>10: 110 if oldPoint.f() >= newPoint.f() and max(oldPoint.mr(), p.contol) >= newPoint.mr(): 111 oldPoint, newPoint = newPoint, None 112 continue 114 113 else: 115 114 doDilation = False 116 115 # and go to label "Line Search Finished" 117 116 else: 118 fprev, mrprev, xprev = f, mr, x.copy()117 oldPoint, newPoint = newPoint, None 119 118 continue 120 119 121 120 #Label "Line Search Finished" 122 g2 = self.__getRalgDirection__(x, p)123 fk, xk, rk = f, x.copy(), mr124 121 break 125 122 123 iterPoint = newPoint 124 x = iterPoint.x 125 126 doBackwardSearch = 1 126 127 if ls == p.maxLineSearch: 127 128 p.istop, p.msg = IS_LINE_SEARCH_FAILED, 'maxLineSearch (' + str(p.maxLineSearch) + ') has been exceeded' 128 129 return 129 130 elif ls == 0 and doBackwardSearch: 130 if p.__1stBetterThan2nd__(p.fk, f, p.rk, rk): 131 x_no_backward = x.copy() 132 f_no_backward = p.f(x_no_backward) 133 mr_no_backward = p.getMaxResidual(x_no_backward) 131 if oldPoint.betterThan(newPoint): 132 PrevPoint = iterPoint 134 133 while 1: 135 134 hs *= self.hmult 136 137 x_prev, hs_prev, g2_prev = x.copy(), hs, g2.copy() 138 f_prev = p.f(x_prev) 139 mr_prev = max(p.getMaxResidual(x), p.contol) 135 hs_prev = hs 140 136 141 137 if itn == 0: … … 145 141 hs /= self.hmult 146 142 147 mr_new = p.getMaxResidual(x) 148 f_new = p.f(x) 149 150 # if p.__1stBetterThan2nd__(f_new, f_prev, mr_new, mr_prev): 151 # bestIterPoint, bestIterPointF, bestIterPointDirection, bestIterPointResidual = x.copy(), f_new, g2.copy(), mr_new 152 153 g2 = self.__getRalgDirection__(x, p) 154 155 if sum(p.dotmult(g1,g2))>0 or mr_new > mr_prev or f_new > f_prev or \ 156 abs(f_new - f_no_backward) < 15 * p.ftol or p.norm(x - x_no_backward) < 15 * p.xtol: 157 x, hs, g2 = x_prev, hs_prev, g2_prev 143 newPoint = p.point(x) 144 145 if newPoint.mr() > PrevPoint.mr() or newPoint.f() > PrevPoint.f() or abs(newPoint.f() - iterPoint.f()) < 15 * p.ftol or p.norm(newPoint.x - iterPoint.x) < 15 * p.xtol: 146 iterPoint, hs = PrevPoint, hs_prev 158 147 break 148 149 PrevPoint = newPoint 150 159 151 ls -= 1 160 if itn != 0: break 161 162 xk, fk = x.copy(), p.f(x) 152 if itn != 0: 153 break 154 iterPoint = PrevPoint 155 156 x = iterPoint.x.copy() 157 fk, xk, rk = iterPoint.f(), x.copy(), iterPoint.mr() 163 158 164 159 if ls <= 0: hs *= q1 165 160 166 161 prevIterPointIsFeasible = p.iterValues.r[-1] <= p.contol # p.iterValues.r is max residual defined in ooIter.py 167 currIterPointIsFeasible = p.getMaxResidual(x) <= p.contol 168 162 currIterPointIsFeasible = p.isFeas(x) 163 164 g2 = self.__getRalgDirection__(x, p) 169 165 if prevIterPointIsFeasible == currIterPointIsFeasible == True: 170 166 g1 = g2 - g … … 197 193 p._df = g2.copy() 198 194 199 if not self.needRej(p, b, g ):195 if not self.needRej(p, b, g1, g): 200 196 if all(isfinite(g)) and ng > 1e-50 and doDilation: 201 197 g = (g / ng).reshape((-1,1)) … … 209 205 #hs = max(p.norm(xPrevIter - x), hsmin) 210 206 207 #xk, fk, rk = iterPoint.x, iterPoint.f(), iterPoint.mr() 211 208 p.iterfcn(xk, fk) 212 209 … … 233 230 234 231 if p.istop: 235 # p.xf = bestIterPoint236 # p.ff = bestIterPointF237 #p.advanced.ralg.hs = max(norm(xPrevIter - x), hsmin)238 #p._df = _df239 232 return 240 # x = bestIterPoint.copy() 241 # g = bestIterPointDirection.copy() 242 # if p.norm(x-bestIterPoint) < p.norm(bestIterPoint-xPrevIter): 243 # x = bestIterPoint.copy() 244 # ####g = bestIterPointDirection.copy() 245 # #g, fname, ind = self.__getRalgDirection__(x, p) 246 # else: 247 # x = (x+xPrevIter) / 2.0 248 #g, fname, ind = self.__getRalgDirection__(x, p) 249 # if dot(g2, bestIterPointDirection) > 0: 250 # g = bestIterPointDirection.copy() 251 # else: 252 # g = g2.copy() 233 253 234 g = g2.copy() 254 235 xPrevIter = x.copy()
