Changeset 1173

Show
Ignore:
Timestamp:
08/02/08 09:24:27 (4 months ago)
Author:
dmitrey.kroshko
Message:

some ralg changes (handling out of dom cases) + "isNaNInConstraintsAllowed" parameter (for NLP/NSP problems) + update in tests/chain.py + some other changes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openopt/scikits/openopt/Kernel/BaseProblem.py

    r1156 r1173  
    256256        #self.check = Check() 
    257257        self.args = args() 
     258        self.isNaNInConstraintsAllowed = False 
    258259        self.consMode = 'all' # TODO: remove it? 
    259260        #self.parallel = Parallel() 
  • trunk/openopt/scikits/openopt/Kernel/Point.py

    r1168 r1173  
    11# created by Dmitrey 
    2 from numpy import copy, isnan, array, argmax, abs, zeros, any, isfinite 
     2from numpy import copy, isnan, array, argmax, abs, zeros, any, isfinite, where 
    33__docformat__ = "restructuredtext en" 
    44empty_arr = array(()) 
     
    163163                if any(self.c() > criticalResidualValue): return False 
    164164 
     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 
    165171            if self.mr() < oldPointResidual and self.p.contol < oldPointResidual: return True 
    166172 
     
    196202            if any(self.c() > contol): return False 
    197203        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  
    5858        elif hasattr(p, key): 
    5959            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)') 
    6161 
    6262    p.iterValues = EmptyClass() 
  • trunk/openopt/scikits/openopt/solvers/UkrOpt/ralg_oo.py

    r1170 r1173  
    1919    S = 0 
    2020    T = float64 
     21 
     22    showLS = False 
     23    show_nnan = False 
    2124    needRej = lambda self, p, b, g_dilated, g: norm(g_dilated)  < 1e-10*norm(g) 
    2225    #checkTurnByGradient = True 
     
    4750        x = x0.copy() 
    4851        xPrevIter = x0.copy() 
    49         startPoint = p.point(x) 
     52        iterPoint = p.point(x) 
    5053        prevIterPoint = p.point(x) 
    5154 
    52         g = self.__getRalgDirection__(startPoint) 
     55        g = self.__getRalgDirection__(iterPoint) 
    5356        if not any(g): 
    5457            p.istop = SMALL_DF 
     
    7477            doBackwardSearch = 1 
    7578            for ls in xrange(p.maxLineSearch): 
    76  
    7779                ls1 += 1 
    7880                x -= hs * g1#dotwise 
     
    8688 
    8789                newPoint = p.point(x) 
     90                if self.show_nnan: p.info('ls: %d nnan: %d' % (ls, newPoint.__nnan__())) 
    8891 
    8992                if ls == 0: 
     
    144147            if itn == 0: 
    145148                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__())) 
    148154 
    149155            # 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 
    150159            if prevIterPointIsFeasible == currIterPointIsFeasible == True: 
    151160                g1 = g2 - g 
     
    153162                #doDilation = False 
    154163                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 = False 
    158164            elif prevIterPointIsFeasible: 
    159165                g1 = g2.copy() 
     
    198204                    if currIterPointIsFeasible or not prevIterPointIsFeasible or cond_same_point: s2 = p.istop 
    199205                    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 
    200210                if not s2 and any(p.stopdict.values()): 
    201211                    for key,  val in p.stopdict.iteritems(): 
     
    222232        maxRes = point.mr() 
    223233 
    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()): 
    225237            dmr = point.dmr() 
    226238            if self.S == 0: 
  • trunk/openopt/scikits/openopt/tests/chain.py

    r1159 r1173  
    113113   return r 
    114114 
    115 p = NLP(f, x0, c=c, goal = 'max', plot=1, maxIter = 1e4, contol = contol, iprint=1, maxFunEvals = 1e10) 
     115p = NLP(f, x0, c=c, goal = 'max', plot=0, maxIter = 1e4, contol = contol, iprint=1, maxFunEvals = 1e10) 
    116116r = p.solve('ralg') 
    117117 
     
    124124# 122  1.854e+02              -2.10 
    125125#istop:  4 (|| F[k] - F[k-1] || < ftol) 
    126 #Solver:   Time Elapsed = 91.98        CPU Time Elapsed = 91.3 
     126#Solver:   Time Elapsed = 91.98     CPU Time Elapsed = 91.3 
    127127#objFunValue: 185.4275 (feasible, max constraint =  0.008)