Changeset 1173
- Timestamp:
- 08/02/08 09:24:27 (4 months ago)
- Files:
-
- trunk/openopt/scikits/openopt/Kernel/BaseProblem.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/Kernel/Point.py (modified) (3 diffs)
- trunk/openopt/scikits/openopt/Kernel/runProbSolver.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/UkrOpt/ralg_oo.py (modified) (8 diffs)
- trunk/openopt/scikits/openopt/tests/chain.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openopt/scikits/openopt/Kernel/BaseProblem.py
r1156 r1173 256 256 #self.check = Check() 257 257 self.args = args() 258 self.isNaNInConstraintsAllowed = False 258 259 self.consMode = 'all' # TODO: remove it? 259 260 #self.parallel = Parallel() trunk/openopt/scikits/openopt/Kernel/Point.py
r1168 r1173 1 1 # created by Dmitrey 2 from numpy import copy, isnan, array, argmax, abs, zeros, any, isfinite 2 from numpy import copy, isnan, array, argmax, abs, zeros, any, isfinite, where 3 3 __docformat__ = "restructuredtext en" 4 4 empty_arr = array(()) … … 163 163 if any(self.c() > criticalResidualValue): return False 164 164 165 if not self.p.isNaNInConstraintsAllowed: 166 if oldPoint.__nnan__() > self.__nnan__(): return True 167 elif oldPoint.__nnan__() < self.__nnan__(): return False 168 # TODO: check me 169 if self.mr() <= self.p.contol and oldPointResidual <= self.p.contol and self.__nnan__() != 0: return self.mr() < oldPointResidual 170 165 171 if self.mr() < oldPointResidual and self.p.contol < oldPointResidual: return True 166 172 … … 196 202 if any(self.c() > contol): return False 197 203 return True 204 205 def __nnan__(self): 206 # returns number of nans in constraints 207 r = 0 208 c = self.c() 209 if any(isnan(c)): 210 r += len(where(isnan(c))[0]) 211 h = self.h() 212 if any(isnan(h)): 213 r += len(where(isnan(h))[0]) 214 return r 215 trunk/openopt/scikits/openopt/Kernel/runProbSolver.py
r1123 r1173 58 58 elif hasattr(p, key): 59 59 setattr(p, key, value) 60 else: p.warn('incorrect parameter for solve(): "' + str(key) + '" - will be ignored ')60 else: p.warn('incorrect parameter for solve(): "' + str(key) + '" - will be ignored (this one has been not found in neither prob nor solver parameters)') 61 61 62 62 p.iterValues = EmptyClass() trunk/openopt/scikits/openopt/solvers/UkrOpt/ralg_oo.py
r1170 r1173 19 19 S = 0 20 20 T = float64 21 22 showLS = False 23 show_nnan = False 21 24 needRej = lambda self, p, b, g_dilated, g: norm(g_dilated) < 1e-10*norm(g) 22 25 #checkTurnByGradient = True … … 47 50 x = x0.copy() 48 51 xPrevIter = x0.copy() 49 startPoint = p.point(x)52 iterPoint = p.point(x) 50 53 prevIterPoint = p.point(x) 51 54 52 g = self.__getRalgDirection__( startPoint)55 g = self.__getRalgDirection__(iterPoint) 53 56 if not any(g): 54 57 p.istop = SMALL_DF … … 74 77 doBackwardSearch = 1 75 78 for ls in xrange(p.maxLineSearch): 76 77 79 ls1 += 1 78 80 x -= hs * g1#dotwise … … 86 88 87 89 newPoint = p.point(x) 90 if self.show_nnan: p.info('ls: %d nnan: %d' % (ls, newPoint.__nnan__())) 88 91 89 92 if ls == 0: … … 144 147 if itn == 0: 145 148 g2 = self.__getRalgDirection__(newPoint) 146 p.debugmsg('hs:' + str(hs)) 147 p.debugmsg('ls:' + str(ls)) 149 p.debugmsg('hs: ' + str(hs)) 150 p.debugmsg('ls: ' + str(ls)) 151 152 if self.showLS: p.info('ls: ' + str(ls)) 153 if self.show_nnan: p.info('nnan: ' + str(iterPoint.__nnan__())) 148 154 149 155 # set dilation direction: 156 if sum(p.dotmult(g, g2))>0: 157 p.debugmsg('ralg warning: slope angle less than pi/2. No dilation for the iter.') 158 doDilation = False 150 159 if prevIterPointIsFeasible == currIterPointIsFeasible == True: 151 160 g1 = g2 - g … … 153 162 #doDilation = False 154 163 g1 = g2-g 155 if sum(p.dotmult(g, g2))>0:156 p.debugmsg('ralg warning: slope angle less than pi/2. No dilation for the iter.')157 doDilation = False158 164 elif prevIterPointIsFeasible: 159 165 g1 = g2.copy() … … 198 204 if currIterPointIsFeasible or not prevIterPointIsFeasible or cond_same_point: s2 = p.istop 199 205 p.stopdict.pop(SMALL_DELTA_X) 206 if s2 and (any(isnan(iterPoint.c())) or any(isnan(iterPoint.h()))) \ 207 and not p.isNaNInConstraintsAllowed\ 208 and not cond_same_point: 209 s2 = 0 200 210 if not s2 and any(p.stopdict.values()): 201 211 for key, val in p.stopdict.iteritems(): … … 222 232 maxRes = point.mr() 223 233 224 if maxRes > point.p.contol or not isfinite(point.f()): 234 if maxRes > point.p.contol \ 235 or (not point.p.isNaNInConstraintsAllowed and any(isnan(point.c())) or any(isnan(point.h())))\ 236 or not isfinite(point.f()): 225 237 dmr = point.dmr() 226 238 if self.S == 0: trunk/openopt/scikits/openopt/tests/chain.py
r1159 r1173 113 113 return r 114 114 115 p = NLP(f, x0, c=c, goal = 'max', plot= 1, maxIter = 1e4, contol = contol, iprint=1, maxFunEvals = 1e10)115 p = NLP(f, x0, c=c, goal = 'max', plot=0, maxIter = 1e4, contol = contol, iprint=1, maxFunEvals = 1e10) 116 116 r = p.solve('ralg') 117 117 … … 124 124 # 122 1.854e+02 -2.10 125 125 #istop: 4 (|| F[k] - F[k-1] || < ftol) 126 #Solver: Time Elapsed = 91.98 CPU Time Elapsed = 91.3126 #Solver: Time Elapsed = 91.98 CPU Time Elapsed = 91.3 127 127 #objFunValue: 185.4275 (feasible, max constraint = 0.008)
