Changeset 1168
- Timestamp:
- 07/29/08 09:34:36 (4 months ago)
- Files:
-
- trunk/openopt/scikits/openopt/Kernel/Function.py (modified) (3 diffs)
- trunk/openopt/scikits/openopt/Kernel/Point.py (modified) (1 diff)
- trunk/openopt/scikits/openopt/solvers/UkrOpt/ralg_oo.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openopt/scikits/openopt/Kernel/Function.py
r1156 r1168 14 14 assert len(args) == 0 15 15 self.fun = fun 16 17 #TODO: modify for cases where output can be partial 18 self.evals = 0 19 self.same = 0 20 16 21 for key, item in kwargs.iteritems(): 17 22 #assert key in self.__allowedFields__ # TODO: make set comparison … … 48 53 49 54 if not hasattr(self, 'f_key_prev') or any(self.f_key_prev != key_to_compare): 55 self.evals += 1 50 56 # if self.fun.__module__ == 'scikits.openopt.Kernel.Function': 51 57 # setattr(fun, 'x', x) … … 54 60 else: 55 61 self.f_val_prev = self.fun(Input) 62 else: 63 self.same += 1 64 56 65 self.f_key_prev = copy(key_to_compare) 57 66 return deepcopy(self.f_val_prev) trunk/openopt/scikits/openopt/Kernel/Point.py
r1158 r1168 178 178 else: # f(newPoint) is not NaN 179 179 return True 180 181 def isFeas(self): 182 return self.__isFeas__() 183 184 def __isFeas__(self): 185 contol = self.p.contol 186 if hasattr(self, '_mr'): 187 if self._mr > contol: return False 188 else: 189 #TODO: simplify it! 190 #for fn in Residuals: (...) 191 if any(self.lb() > contol): return False 192 if any(self.ub() > contol): return False 193 if any(abs(self.beq()) > contol): return False 194 if any(self.b() > contol): return False 195 if any(abs(self.h()) > contol): return False 196 if any(self.c() > contol): return False 197 return True trunk/openopt/scikits/openopt/solvers/UkrOpt/ralg_oo.py
r1158 r1168 48 48 xPrevIter = x0.copy() 49 49 startPoint = p.point(x) 50 PrevIterPoint = p.point(x)50 prevIterPoint = p.point(x) 51 51 52 52 g = self.__getRalgDirection__(startPoint) 53 54 # p.iterfcn(startPoint) 55 # if p.istop: 56 # p.xf = x 57 # p.ff = f 58 # #r.advanced.ralg.hs = hs; 59 # return 53 if not any(g): 54 p.istop = SMALL_DF 55 p.msg = '|| gradient F(X[k]) || < gradtol' 56 return 60 57 61 58 g2 = copy(g) 62 if p.isFeas(x):63 constrGradPrevIter = zeros(p.n)64 dfPrevIter = g2.copy()65 else:66 constrGradPrevIter = g2.copy()67 dfPrevIter = zeros(p.n)68 59 69 60 # #pass-by-ref! not copy! … … 98 89 #if not self.checkTurnByGradient: 99 90 if newPoint.betterThan(oldPoint): 100 #TODO: handle possible noise here 101 # if ls>1500: 102 # if oldPoint.f() >= newPoint.f() and max(oldPoint.mr(), p.contol) >= newPoint.mr(): 103 # oldPoint, newPoint = newPoint, None 104 # continue 105 # else: 106 # doDilation = False 107 # # and go to label "Line Search Finished" 108 # else: 91 #TODO: 1. handle possible noise here; 2. handle the case 92 # if ls>15: ... 109 93 oldPoint, newPoint = newPoint, None 110 continue 111 112 #Label "Line Search Finished" 113 break 94 else: 95 break 114 96 115 97 if ls >= p.maxLineSearch-1: … … 118 100 119 101 iterPoint = newPoint 120 x = iterPoint.x 102 x = iterPoint.x.copy() 121 103 122 104 doBackwardSearch = 1 … … 150 132 iterPoint = PrevPoint 151 133 152 x = newPoint.x.copy()134 x = iterPoint.x.copy() 153 135 154 136 if ls <= 0: hs *= q1 155 137 156 138 prevIterPointIsFeasible = p.iterValues.r[-1] <= p.contol # p.iterValues.r is max residual defined in ooIter.py 157 currIterPointIsFeasible = p.isFeas(x)139 currIterPointIsFeasible = iterPoint.isFeas() 158 140 159 141 if itn == 0: g2 = self.__getRalgDirection__(newPoint) 142 143 # set dilation direction: 160 144 if prevIterPointIsFeasible == currIterPointIsFeasible == True: 161 145 g1 = g2 - g 162 146 elif prevIterPointIsFeasible == currIterPointIsFeasible == False: 163 if not any(constrGradPrevIter-g2): 164 g1 = zeros(p.n) 165 if all(isfinite(dfPrevIter)): 166 g1 = -p.df(xPrevIter) 167 df = p.df(x) 168 if sum(p.dotmult(p.df(xPrevIter), df))>0: 169 doDilation = False 170 if all(isfinite(df)): 171 g1 += df 172 else: 173 g1 = g2-constrGradPrevIter 174 if sum(p.dotmult(constrGradPrevIter, g2))>0: 175 #TODO: add debugmsg here 176 doDilation = False 147 #doDilation = False 148 g1 = g2-g 149 if sum(p.dotmult(g, g2))>0: 150 p.debugmsg('warning! same gradient for constraints!') 151 doDilation = False 177 152 elif prevIterPointIsFeasible: 178 153 g1 = g2.copy() 179 154 else: 180 #doDilation = False181 155 g1 = -g.copy() 182 156 … … 198 172 p.debugmsg('matrix B restoration in ralg solver') 199 173 b = diag(ones(n)) 200 hs = p.norm(xPrevIter - x)201 #hs = max(p.norm(xPrevIter - x), hsmin) 202 174 hs = p.norm(xPrevIter - iterPoint.x) 175 176 cond_same_point = all(iterPoint.x == p.xk) 203 177 p.iterfcn(iterPoint) 178 if cond_same_point and not p.istop: 179 p.istop = SMALL_DELTA_X 180 p.msg = '|| X[k] - X[k-1] || < xtol' 181 p.stopdict[SMALL_DELTA_X] = True 204 182 205 183 s2 = 0 … … 212 190 p.stopdict.pop(SMALL_DELTA_F) 213 191 if p.stopdict.has_key(SMALL_DELTA_X): 214 #if currIterPointIsFeasible or not prevIterPointIsFeasible: s2 = p.istop 215 if currIterPointIsFeasible or not prevIterPointIsFeasible: s2 = p.istop 192 if currIterPointIsFeasible or not prevIterPointIsFeasible or cond_same_point: s2 = p.istop 216 193 p.stopdict.pop(SMALL_DELTA_X) 217 194 if not s2 and any(p.stopdict.values()): … … 229 206 230 207 g = g2.copy() 231 xPrevIter = x.copy() 232 if currIterPointIsFeasible: 233 constrGradPrevIter = zeros(p.n) 234 dfPrevIter = g2.copy() 235 else: 236 constrGradPrevIter = g2.copy() 237 dfPrevIter =zeros(p.n)# p.df(x) 208 209 xPrevIter = iterPoint.x.copy() 210 211 prevIterPoint, iterPoint = iterPoint, None 212 238 213 239 214 def __getRalgDirection__(self, point):
