Changeset 1049
- Timestamp:
- 06/21/08 15:17:50 (2 months ago)
- Files:
-
- trunk/openopt/scikits/openopt/Kernel/BaseAlg.py (modified) (2 diffs)
- trunk/openopt/scikits/openopt/Kernel/Point.py (modified) (2 diffs)
- trunk/openopt/scikits/openopt/solvers/UkrOpt/ralg_oo.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openopt/scikits/openopt/Kernel/BaseAlg.py
r1004 r1049 1 1 __docformat__ = "restructuredtext en" 2 from numpy import atleast_1d, all, asarray 2 from numpy import atleast_1d, all, asarray, ndarray 3 3 4 4 class BaseAlg: … … 27 27 xArg, fArg, rArg = True, True, True 28 28 29 if len(args)>0: p.xk = args[0] 30 elif kwargs.has_key('xk'): p.xk = kwargs['xk'] 31 else: xArg = False 29 if len(args) == 1 and type(args[0]) != ndarray: # hence Point 30 point = args[0] 31 p.xk, p.fk, p.rk = point.x, point.f(), point.mr() 32 else: 33 if len(args)>0: p.xk = args[0] 34 elif kwargs.has_key('xk'): p.xk = kwargs['xk'] 35 else: xArg = False 32 36 33 if len(args)>1: p.fk = args[1]34 elif kwargs.has_key('fk'): p.fk = kwargs['fk']35 else: fArg = False37 if len(args)>1: p.fk = args[1] 38 elif kwargs.has_key('fk'): p.fk = kwargs['fk'] 39 else: fArg = False 36 40 37 if len(args)>2: p.rk = args[2]38 elif kwargs.has_key('rk'): p.rk = kwargs['rk']39 else: rArg = False41 if len(args)>2: p.rk = args[2] 42 elif kwargs.has_key('rk'): p.rk = kwargs['rk'] 43 else: rArg = False 40 44 41 45 #TODO: handle kwargs correctly! (decodeIterFcnArgs) trunk/openopt/scikits/openopt/Kernel/Point.py
r1022 r1049 1 1 # created by Dmitrey 2 from numpy import copy, isnan, array, argmax, abs 2 from numpy import copy, isnan, array, argmax, abs, zeros 3 3 __docformat__ = "restructuredtext en" 4 4 empty_arr = array(()) … … 102 102 103 103 def __dmr(self, retAll = False): 104 g = zeros(self.p.n) 105 maxResidual, resType, ind = self.mr(retAll=True) 106 if resType == 'lb': 107 g[ind] -= 1 # N * (-1), -1 = dConstr/dx = d(lb-x)/dx 108 elif resType == 'ub': 109 g[ind] += 1 # N * (+1), +1 = dConstr/dx = d(x-ub)/dx 110 elif resType == 'A': 111 g += self.A[ind] 112 elif resType == 'Aeq': 113 rr = self.p.matmult(self.p.Aeq[ind], self.x)-self.p.beq[ind] 114 if rr < 0: g -= self.p.Aeq[ind] 115 else: g += self.p.Aeq[ind] 116 elif resType == 'c': 117 dc = self.p.dc(self.x, ind=ind).flatten() 118 g += dc 119 elif resType == 'h': 120 dh = self.p.dh(self.x, ind=ind).flatten() 121 if self.p.h(self.x, ind=ind) < 0: g -= dh#CHECKME!! 122 else: g += dh#CHECKME!! 104 if not hasattr(self, '_dmr'): 105 g = zeros(self.p.n) 106 maxResidual, resType, ind = self.mr(retAll=True) 107 if resType == 'lb': 108 g[ind] -= 1 # N * (-1), -1 = dConstr/dx = d(lb-x)/dx 109 elif resType == 'ub': 110 g[ind] += 1 # N * (+1), +1 = dConstr/dx = d(x-ub)/dx 111 elif resType == 'A': 112 g += self.A[ind] 113 elif resType == 'Aeq': 114 rr = self.p.matmult(self.p.Aeq[ind], self.x)-self.p.beq[ind] 115 if rr < 0: g -= self.p.Aeq[ind] 116 else: g += self.p.Aeq[ind] 117 elif resType == 'c': 118 dc = self.p.dc(self.x, ind=ind).flatten() 119 g += dc 120 elif resType == 'h': 121 dh = self.p.dh(self.x, ind=ind).flatten() 122 if self.p.h(self.x, ind=ind) < 0: g -= dh#CHECKME!! 123 else: g += dh#CHECKME!! 124 self._dmr, self._dmrName, self._dmrInd = g, resType, ind 123 125 if retAll: 124 return g, resType, ind126 return copy(self._dmr), resType, ind 125 127 else: 126 return g128 return copy(self._dmr) 127 129 128 130 def betterThan(self, *args, **kwargs): trunk/openopt/scikits/openopt/solvers/UkrOpt/ralg_oo.py
r1041 r1049 46 46 ############################################# 47 47 48 startPoint = p.point(p.x0) 48 49 x = x0.copy() 49 50 xPrevIter = x0.copy() 50 xf = x0.copy() 51 xk = x0.copy() 52 p.xk = x0.copy() 53 54 f = p.f(x) 55 56 fk = f 57 ff = f 58 p.fk = fk 59 60 g = self.__getRalgDirection__(x, p) 51 #p.xk = x0.copy() 52 #f = startPoint.f() 53 #p.fk = f 54 55 g = self.__getRalgDirection__(startPoint) 61 56 p._df = copy(g) 62 57 63 p.iterfcn( )58 p.iterfcn(startPoint) 64 59 if p.istop: 65 60 p.xf = x … … 68 63 return 69 64 70 g2 = self.__getRalgDirection__(x, p)65 g2 = copy(g) 71 66 if p.rk <= p.contol: 72 67 constrGradPrevIter = zeros(p.n) … … 163 158 currIterPointIsFeasible = p.isFeas(x) 164 159 165 g2 = self.__getRalgDirection__( x, p)160 g2 = self.__getRalgDirection__(iterPoint) 166 161 if prevIterPointIsFeasible == currIterPointIsFeasible == True: 167 162 g1 = g2 - g … … 240 235 dfPrevIter =zeros(p.n)# p.df(x) 241 236 242 def __getRalgDirection55__(self, x, p): 243 maxRes = p.getMaxResidual(x) 244 if maxRes > p.contol: 245 d = -getConstrDirection(p, x, 1e-7) 246 else: 247 d = p.df(x) 248 return d 249 250 def __getRalgDirection__(self, x, p): 251 maxRes = p.getMaxResidual(x) 252 if maxRes > p.contol: 237 def __getRalgDirection__(self, point): 238 maxRes = point.mr() 239 if maxRes > point.p.contol: 240 dmr = point.dmr() 253 241 if self.S == 0: 254 d = p.getMaxConstrGradient(x)255 else: 256 d = p .df(x) + self.S*p.getMaxConstrGradient(x)257 else: 258 d = p .df(x)242 d = dmr 243 else: 244 d = point.df() + self.S*dmr 245 else: 246 d = point.df() 259 247 return d 260 248
