Changeset 1509

Show
Ignore:
Timestamp:
09/28/08 16:09:16 (2 months ago)
Author:
dmitrey.kroshko
Message:

some changes for converters

Files:

Legend:

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

    r1456 r1509  
    1010from ooCheckGradient import ooCheckGradient 
    1111from ooIterPrint import ooTextOutput 
     12from ooMisc import setNonLinFincsNumber 
    1213 
    1314ProbDefaults = {'diffInt': 1e-7,  'xtol': 1e-6,  'noise': 0} 
     
    4950 
    5051        self.graphics = Graphics() 
     52        self.xlabel = 'time' 
    5153        self.user = user() 
    5254 
     
    226228        self.err('OpenOpt error: this function should be overdetermined by child class') 
    227229 
    228     def inspire(self, newProb): 
     230    def inspire(self, newProb, sameConstraints=True): 
    229231        # fills some fields of new prob with old prob values 
    230232        newProb.castFrom = self.probType 
     233 
    231234        #TODO: hold it in single place 
    232         for key in ['lb', 'ub', 'A', 'Aeq', 'b', 'beq', 'contol', 'xtol', 'ftol', 'gtol', 'iprint', 'plot', 'maxIter', 'maxTime', 'maxCPUTime','fEnough', 'goal', 'color', 'debug', 'maxFunEvals'] : 
     235 
     236        fieldsToAssert = ['userProvided', 'contol', 'xtol', 'ftol', 'gtol', 'iprint', 'plot', 'maxIter', 'maxTime', 'maxCPUTime','fEnough', 'goal', 'color', 'debug', 'maxFunEvals', 'xlabel'] 
     237        if sameConstraints: fieldsToAssert+= ['lb', 'ub', 'A', 'Aeq', 'b', 'beq'] 
     238 
     239        for key in ['userProvided', 'lb', 'ub', 'A', 'Aeq', 'b', 'beq', 'contol', 'xtol', 'ftol', 'gtol', 'iprint', 'plot', 'maxIter', 'maxTime', 'maxCPUTime','fEnough', 'goal', 'color', 'debug', 'maxFunEvals', 'xlabel'] : 
    233240            if hasattr(self, key): setattr(newProb, key, getattr(self, key)) 
     241 
     242        # note: because of 'userProvided' from prev line 
     243        #self self.userProvided is same to newProb.userProvided 
     244        if sameConstraints: 
     245            for key in ['c','dc','h','dh','d2c','d2h']: 
     246                if hasattr(self.userProvided, key): 
     247                    if getattr(self.userProvided, key): 
     248                        setattr(newProb, key, getattr(self, key)) 
     249                    else: 
     250                        setattr(newProb, key, None) 
     251 
    234252 
    235253 
     
    319337        self.x0 = ravel(self.x0) 
    320338        self.__makeCorrectArgs__() 
     339        #self.nEvals = {'f':0} 
    321340        for s in ('f', 'df', 'd2f', 'c', 'dc', 'd2c', 'h', 'dh', 'd2h'): 
    322341            derivativeOrder = len(s)-1 
     
    342361 
    343362        #initialization, getting nf, nc, nh etc: 
    344         for s in ['c', 'h']: 
    345             if getattr(self.userProvided, s): 
    346                 tmp = getattr(self, s)(self.x0) # I add ymp for debug 
     363        for s in ['c', 'h', 'f']: 
     364            if not getattr(self.userProvided, s): 
     365                setattr(self, 'n'+s, 0) 
    347366            else: 
    348                 setattr(self, 'n'+s, 0
     367                setNonLinFincsNumber(self,  s
    349368 
    350369        if hasattr(self, 'delayedConnectIterFcn'): 
  • trunk/openopt/scikits/openopt/Kernel/LLAVP.py

    r1147 r1509  
    2222        return r 
    2323 
    24     def llavp2nsp(self, solver, **kwargs): 
     24    def llavp2nsp(self, solver): 
    2525        if hasattr(self,'x0'): p = NSP.NSP(ff, self.x0, df=dff) 
    2626        else: p = NSP.NSP(ff, zeros(self.n), df=dff) 
    2727        p.args.f = self # DO NOT USE p.args = self IN PROB ASSIGNMENT! 
    2828        self.inspire(p) 
     29        self.iprint = -1 
    2930        #p.checkdf() 
    30         r = p.solve(solver, **kwargs) 
     31        #p.solver.__optionalDataThatCanBeHandled__ += ['damp', 'X', 'c'] 
     32        r = p.solve(solver) 
     33        self.xf, self.ff, self.rf = r.xf, r.ff, r.rf 
    3134        return r 
    3235 
  • trunk/openopt/scikits/openopt/Kernel/LLSP.py

    r1408 r1509  
    2727        p.args.f = self # DO NOT USE p.args = self IN PROB ASSIGNMENT! 
    2828        self.inspire(p) 
     29        self.iprint = -1 
    2930        #p.checkdf() 
    30         r = p.solve(solver, **kwargs) 
     31        r = p.solve(solver, show = False) 
     32        self.xf, self.ff, self.rf = r.xf, r.ff, r.rf 
    3133        return r 
    3234 
  • trunk/openopt/scikits/openopt/Kernel/LP.py

    r1417 r1509  
    2424        else: p = NLP.NLP(ff, zeros(self.n), df=dff) 
    2525        self.inspire(p) 
    26         r = p.solve(solver, **kwargs) 
     26        self.iprint = -1 
     27        r = p.solve(solver, show=False) 
     28        self.xf, self.ff, self.rf = r.xf, r.ff, r.rf 
    2729        return r 
     30 
    2831 
    2932def lp_init(prob, kwargs): 
  • trunk/openopt/scikits/openopt/Kernel/LSP.py

    r1421 r1509  
    2525        return (fv ** 2).sum() 
    2626 
    27     def lsp2nlp(self, solver, **kwargs): 
     27#    def lsp2nlp(self, solver, **kwargs): 
     28#        ff = lambda x: sum(asfarray(self.f(x))**2) 
     29#        if hasattr(self, 'df'): 
     30#            dff = lambda x: dot(2*asfarray(self.f(x)), asfarray(self.df(x))) 
     31#            p = NLP.NLP(ff, self.x0, df=dff) 
     32#        else: 
     33#            p = NLP.NLP(ff, self.x0) 
     34#        self.inspire(p) 
     35#        r = p.solve(solver, **kwargs) 
     36#        return r 
     37    def lsp2nlp(self, solver): 
     38        #self.solver = getSolverFromStringName(self, solver) 
     39        #self.__prepare__() 
     40#        FF = oofun(self.f) 
     41#        if hasattr(self, 'df') and self.df is not None: #TODO: replace by userSupplied 
     42#            FF.d = self.df 
    2843        ff = lambda x: sum(asfarray(self.f(x))**2) 
    2944        if hasattr(self, 'df'): 
     
    3247        else: 
    3348            p = NLP.NLP(ff, self.x0) 
    34         self.inspire(p) 
    35         r = p.solve(solver, **kwargs) 
     49        #p = NLP.NLP(FF, self.x0) 
     50        self.inspire(p, sameConstraints=True) 
     51 
     52 
     53        def lsp_iterfcn(*args,  **kwargs): 
     54            p.primalIterFcn(*args,  **kwargs) 
     55#            if len(args) != 0 and type(args[0]) != ndarray: # hence Point 
     56#                p.primalIterFcn(args[0].x, max(abs(self.f(args[0].x))), args[0].mr(),  **kwargs) 
     57#                # TODO: add nNaNs 
     58#            elif len(args) > 1: 
     59#                p.primalIterFcn(args[0], max(abs(self.f(args[0]))), *args[2:],  **kwargs) 
     60#            elif kwargs.has_key('fk'): 
     61#                kwargs['fk'] = max(abs(self.f(args[0]))) 
     62#                p.primalIterFcn(*args, **kwargs) 
     63#            else: 
     64#                p.primalIterFcn(*args,  **kwargs) 
     65            p.xk = self.xk 
     66            p.fk = p.f(p.xk) 
     67            p.rk = self.rk 
     68            # TODO: add nNaNs 
     69 
     70#            self.xk = p.xk.copy() 
     71#            self.fk = max(abs(asfarray(self.f(self.xk)))) 
     72#            self.rk = p.rk 
     73 
     74#            self.istop = p.istop 
     75 
     76#            cond1 = self.iprint>0 and self.iter>0 and self.iter % self.iprint == 0 
     77
     78#            cond2 = (self.iter == 0 or (self.istop and (p.rk <= p.contol ))) \ 
     79#            and self.iprint>=0 and not self.lastIterTextOutputWasInvolved 
     80            p.istop = self.istop 
     81 
     82
     83
     84#        def nlsp_callback(nlsp): 
     85#            # nlsp = self 
     86#            if all(abs(asfarray(self.f(nlsp.xk))) < self.ftol)  and self.getMaxResidual(nlsp.xk) < self.contol: 
     87#                if nlsp.isUC: msg_contol = '' #TODO: make available self.isUC instead of p.isUC 
     88#                else: msg_contol = 'and contol ' 
     89#                self.msg = 'solution with required ftol ' + msg_contol+ 'has been reached' 
     90#                return (15, self.msg) 
     91#            else: 
     92#                return False 
     93 
     94        #self.callback = [nlsp_callback] 
     95        #self.kernelIterFuncs.pop(SMALL_DELTA_F) 
     96        p.primalIterFcn,  p.iterfcn = self.iterfcn, lsp_iterfcn 
     97        p.goal = 'min' 
     98 
     99        p.iprint = -1 
     100 
     101        r = p.solve(solver, show=False) 
     102        #r.ff = ff(r.xf) 
     103 
    36104        return r 
  • trunk/openopt/scikits/openopt/Kernel/NLSP.py

    r1504 r1509  
    22from NLP import nlp_init 
    33from numpy.linalg import norm 
    4 from numpy import inf, asfarray, atleast_1d, dot 
    5 from setDefaultIterFuncs import FVAL_IS_ENOUGH 
     4from numpy import inf, asfarray, atleast_1d, dot, abs, ndarray 
     5from setDefaultIterFuncs import FVAL_IS_ENOUGH, SMALL_DELTA_F 
     6from nonOptMisc import getSolverFromStringName 
    67import NLP 
    78#from Function import oofun 
     
    2526        self.showGoal = False 
    2627 
    27         self.kernelIterFuncs.pop(FVAL_IS_ENOUGH) #= lambda *args: False#TODO: remove it at all 
     28        #self.kernelIterFuncs.pop(FVAL_IS_ENOUGH) #= lambda *args: False#TODO: remove it at all 
    2829        #return 
    2930 
     
    3233        return norm(atleast_1d(asfarray(fv)), inf) 
    3334 
    34     def nlsp2nlp(self, solver, **kwargs): 
     35    def nlsp2nlp(self, solver): 
     36        #self.solver = getSolverFromStringName(self, solver) 
     37        #self.__prepare__() 
    3538#        FF = oofun(self.f) 
    3639#        if hasattr(self, 'df') and self.df is not None: #TODO: replace by userSupplied 
     
    4346            p = NLP.NLP(ff, self.x0) 
    4447        #p = NLP.NLP(FF, self.x0) 
    45         self.inspire(p
     48        self.inspire(p, sameConstraints=True
    4649 
    47         def nlsp_iterfcn(p): 
    48             if all(abs(asfarray(self.f(p.xk)))) < p.ftol and self.getMaxResidual(p.xk) < p.contol: 
    49                 if self.isUC: msg_contol = '' 
     50 
     51        def nlsp_iterfcn(*args,  **kwargs): 
     52            if len(args) != 0 and type(args[0]) != ndarray: # hence Point 
     53                p.primalIterFcn(args[0].x, max(abs(self.f(args[0].x))), args[0].mr(),  **kwargs) 
     54                # TODO: add nNaNs 
     55            elif len(args) > 1: 
     56                p.primalIterFcn(args[0], max(abs(self.f(args[0]))), *args[2:],  **kwargs) 
     57            elif kwargs.has_key('fk'): 
     58                kwargs['fk'] = max(abs(self.f(args[0]))) 
     59                p.primalIterFcn(*args, **kwargs) 
     60            else: 
     61                p.primalIterFcn(*args,  **kwargs) 
     62            p.xk = self.xk 
     63            p.fk = p.f(p.xk) 
     64            p.rk = self.rk 
     65            # TODO: add nNaNs 
     66 
     67#            self.xk = p.xk.copy() 
     68#            self.fk = max(abs(asfarray(self.f(self.xk)))) 
     69#            self.rk = p.rk 
     70 
     71#            self.istop = p.istop 
     72 
     73#            cond1 = self.iprint>0 and self.iter>0 and self.iter % self.iprint == 0 
     74
     75#            cond2 = (self.iter == 0 or (self.istop and (p.rk <= p.contol ))) \ 
     76#            and self.iprint>=0 and not self.lastIterTextOutputWasInvolved 
     77            p.istop = self.istop 
     78 
     79        ftol_init = self.ftol 
     80        contol_init = self.contol 
     81
     82
     83        def nlsp_callback(nlsp): 
     84            # nlsp = self 
     85            if all(abs(asfarray(self.f(nlsp.xk))) < ftol_init)  and self.getMaxResidual(nlsp.xk) < contol_init: 
     86                if nlsp.isUC: msg_contol = '' #TODO: make available self.isUC instead of p.isUC 
    5087                else: msg_contol = 'and contol ' 
    5188                self.msg = 'solution with required ftol ' + msg_contol+ 'has been reached' 
     
    5491                return False 
    5592 
    56         p.callback = nlsp_iterfcn 
     93        self.callback = [nlsp_callback] 
     94        self.kernelIterFuncs.pop(SMALL_DELTA_F) 
     95        p.primalIterFcn,  p.iterfcn = self.iterfcn, nlsp_iterfcn 
    5796        p.goal = 'min' 
    58         r = p.solve(solver, **kwargs) 
     97        #self.fEnough = self.ftol 
     98 
     99        p.iprint=-5 
     100 
     101        Multiplier = 1e16 
     102 
     103        #self.ftol /= Multiplier 
     104        self.xtol /= Multiplier 
     105        self.gtol /= Multiplier 
     106 
     107        r = p.solve(solver, show=False) 
     108 
     109        #self.ftol *= Multiplier 
     110        self.xtol *= Multiplier 
     111        self.gtol *= Multiplier 
     112 
     113        if self.istop == FVAL_IS_ENOUGH: 
     114            self.msg = 'solution with required ftol ' + msg_contol+ 'has been reached' 
     115            self.istop = 15 
     116 
     117        #self.iterfcn(xk = r.xk, fk = r.fk, rk = r.rk) 
     118        #self.show = show 
     119 
     120        # TODO: fix it! 
     121        #r.iterValues.f = self.iterValues.f 
     122 
     123        #r.ff = max(abs(asfarray(self.f(r.xf)))) 
    59124        return r 
  • trunk/openopt/scikits/openopt/Kernel/QP.py

    r1408 r1509  
    2525        return asfarray(0.5*dot(x, dot(self.H, x)) + dot(self.f, x).sum()).flatten() 
    2626 
    27     def qp2nlp(self, solver, **kwargs): 
     27    def qp2nlp(self, solver): 
    2828        if hasattr(self,'x0'): p = NLP.NLP(ff, self.x0, df=dff, d2f=d2ff) 
    2929        else: p = NLP.NLP(ff, zeros(self.n), df=dff, d2f=d2ff) 
    3030        p.args.f = self # DO NOT USE p.args = self IN PROB ASSIGNMENT! 
    3131        self.inspire(p) 
     32        self.iprint = -1 
    3233        #p.checkdf() 
    33         r = p.solve(solver, **kwargs) 
     34        r = p.solve(solver, show=False) 
     35        self.xf, self.ff, self.rf = r.xf, r.ff, r.rf 
    3436        return r 
    3537 
  • trunk/openopt/scikits/openopt/Kernel/objFunRelated.py

    r1482 r1509  
    22from numpy import * 
    33from setDefaultIterFuncs import USER_DEMAND_EXIT 
    4 from ooMisc import killThread 
     4from ooMisc import killThread, setNonLinFincsNumber 
    55 
    66none_type = type(None) 
     
    5959 
    6060        #if p.iter == 0: 
    61         if not hasattr(p, 'n'+userFunctionType): 
    62             fv = funcs#getattr(p, userFunctionType) 
    63             if len(fv) == 1: p.functype[userFunctionType] = 'single func' 
    64             if fv is None or (type(fv) in [list, tuple] and fv[0] is None): 
    65                 setattr(p, 'n'+userFunctionType, 0) 
    66             elif type(fv) in [list, tuple] and len(fv)>1: 
    67                 # TODO: handle problems w/o x0, like GLP 
    68                 number = 0 
    69                 arr = [] 
    70                 for func in fv: 
    71 #                    if func.__module__ == 'scikits.openopt.Kernel.Function': 
    72 #                        func.x = p.x0 
    73                     number += asarray(func(*(p.x0,) + args)).size 
    74                     arr.append(number) 
    75                 if len(arr) < number: p.functype[userFunctionType] = 'block' 
    76                 elif len(arr) > 1: p.functype[userFunctionType] = 'some funcs' 
    77                 else: assert p.functype[userFunctionType] == 'single func' 
    78                 setattr(p, 'n' + userFunctionType, number) 
    79                 if p.functype[userFunctionType] == 'block': 
    80                     setattr(p, 'arr_of_indexes_' + userFunctionType, array(arr)-1) 
    81             elif p.x0 is not None: 
    82                 FV = fv 
    83                 if not (type(FV) in [list, tuple]): 
    84                     FV = [FV] 
    85                 setattr(p, 'n'+userFunctionType, asfarray(FV[0](*(p.x0, ) + args)).size) 
    86             else: 
    87                 FV = fv 
    88                 if not (type(FV) in [list, tuple]): 
    89                     FV = [FV] 
    90                 setattr(p, 'n'+userFunctionType, asfarray(FV[0](*(0.5*(p.lb+p.ub),  ) + args)).size) 
    91             p.prevVal[userFunctionType]['val'] = zeros(getattr(p, 'n'+userFunctionType)) 
     61        if not hasattr(p, 'n'+userFunctionType): setNonLinFincsNumber(p,  userFunctionType) 
     62        p.prevVal[userFunctionType]['val'] = zeros(getattr(p, 'n'+userFunctionType)) 
    9263 
    9364        if ind is None: 
  • trunk/openopt/scikits/openopt/Kernel/ooGraphics.py

    r1437 r1509  
    3636        self.drawingInOneWindow = True#some solvers for the same problem 
    3737        #what do you want on label x? 
    38         self.xlabel = 'time'#case-unsensitive 
     38        #self.xlabel = 'time'#case-unsensitive 
    3939        #other values: CPUTime, iter 
    4040        #ignores time, spent on figure updatings 
     
    116116 
    117117        #setting xlabel, ylabel, title etc 
    118         tx = lower(self.xlabel) 
     118        tx = lower(p.xlabel) 
    119119        if isNewTrajectory: 
    120120 
  • trunk/openopt/scikits/openopt/Kernel/ooIter.py

    r1482 r1509  
    3535        p.lastDrawIter = 0 
    3636 
    37     if not p.isFinished or p.objFuncMultiple2Single(p.fk) != p.iterValues.f[-1]: p.solver.__decodeIterFcnArgs__(p,  *args,  **kwargs) 
     37    if not p.isFinished or len(p.iterValues.f) == 0 or p.objFuncMultiple2Single(p.fk) != p.iterValues.f[-1]: p.solver.__decodeIterFcnArgs__(p,  *args,  **kwargs) 
    3838    if p.graphics.xlabel == 'nf': p.iterValues.nf.append(p.nEvals['f']) 
    3939 
  • trunk/openopt/scikits/openopt/Kernel/ooMisc.py

    r1437 r1509  
    1 from numpy import zeros, ones, copy, isfinite, where, asarray, inf, array 
     1from numpy import zeros, ones, copy, isfinite, where, asarray, inf, array, asfarray 
    22__docformat__ = "restructuredtext en" 
    33 
     
    133133        p.err("Error in assignment or this feature isn't implemented yet") 
    134134 
     135def setNonLinFincsNumber(p,  userFunctionType): 
     136    # userFunctionType  should be 'f', 'c' or 'h' 
     137    args = getattr(p.args, userFunctionType) 
     138    fv = getattr(p.user, userFunctionType) 
     139 
     140    if len(fv) == 1: p.functype[userFunctionType] = 'single func' 
     141    if fv is None or (type(fv) in [list, tuple] and fv[0] is None): 
     142        setattr(p, 'n'+userFunctionType, 0) 
     143    elif type(fv) in [list, tuple] and len(fv)>1: 
     144        # TODO: handle problems w/o x0, like GLP 
     145        number = 0 
     146        arr = [] 
     147        for func in fv: 
     148#                    if func.__module__ == 'scikits.openopt.Kernel.Function': 
     149#                        func.x = p.x0 
     150            number += asarray(func(*(p.x0,) + args)).size 
     151            arr.append(number) 
     152        if len(arr) < number: p.functype[userFunctionType] = 'block' 
     153        elif len(arr) > 1: p.functype[userFunctionType] = 'some funcs' 
     154        else: assert p.functype[userFunctionType] == 'single func' 
     155        setattr(p, 'n' + userFunctionType, number) 
     156        if p.functype[userFunctionType] == 'block': 
     157            setattr(p, 'arr_of_indexes_' + userFunctionType, array(arr)-1) 
     158    elif p.x0 is not None: 
     159        FV = fv 
     160        if not (type(FV) in [list, tuple]): 
     161            FV = [FV] 
     162        setattr(p, 'n'+userFunctionType, asfarray(FV[0](*(p.x0, ) + args)).size) 
     163    else: 
     164        FV = fv 
     165        if not (type(FV) in [list, tuple]): 
     166            FV = [FV] 
     167        setattr(p, 'n'+userFunctionType, asfarray(FV[0](*(0.5*(p.lb+p.ub),  ) + args)).size) 
     168 
     169 
     170 
    135171class isSolved: 
    136172    def __init__(self): pass 
    137173class killThread: 
    138174    def __init__(self): pass 
     175 
     176 
  • trunk/openopt/scikits/openopt/Kernel/runProbSolver.py

    r1456 r1509  
    99from string import capitalize, lower 
    1010from BaseProblem import ProbDefaults 
     11from nonOptMisc import getSolverFromStringName 
    1112#from scikits.openopt.Kernel.ooMisc import __solverPaths__ 
    1213ConTolMultiplier = 0.8 
     
    4243 
    4344    if ':' in solver_str: 
     45        isConverter = True 
    4446        probTypeToConvert,  solverName = solver_str.split(':', 1) 
    4547        converterName = lower(p.probType)+'2'+probTypeToConvert 
    4648        converter = getattr(p, converterName) 
    47         return converter(solverName, *args, **kwargs) 
     49        p.solver = getSolverFromStringName(p, solverName) 
     50        #return converter(solverName, *args, **kwargs) 
     51    else: 
     52        isConverter = False 
     53        p.solver = getSolverFromStringName(p, solver_str) 
    4854 
    4955    if kwargs.has_key('debug'): 
    5056       p.debug =  kwargs['debug'] 
    5157 
    52     if p.debug: 
    53         solverClass =  getattr(my_import(solverPaths[solver_str]), solver_str) 
    54     else: 
    55         try: 
    56             solverClass = getattr(my_import(solverPaths[solver_str]), solver_str) 
    57         except: 
    58             p.err('incorrect solver is called, maybe the solver "' + solver_str +'" is not installed. Maybe setting p.debug=1 could specify the matter more precisely') 
    59  
    60     p.solver = solverClass() 
     58 
     59    #p.solver = solverClass() 
    6160#    p.solverName = p.solver.__name__ 
    6261#    setattr(p, p.solverName, EmptyClass()) 
     
    143142        if hasattr(p, s): setattr(p, 'n'+s, len(getattr(p, s))) 
    144143 
    145     if p.probType not in ['LP', 'QP', 'MILP', 'LLSP']: p.objFunc(p.x0) 
     144    #if p.probType not in ['LP', 'QP', 'MILP', 'LLSP']: p.objFunc(p.x0) 
    146145 
    147146    p.isUC = p.__isUnconstrained__() 
     
    149148        assert p.data4TextOutput[-1] == 'log10(maxResidual)' 
    150149        p.data4TextOutput = p.data4TextOutput[:-1] 
    151  
    152     nErr = ooCheck(p) 
    153     if nErr: p.err("prob check results: " +str(nErr) + "ERRORS!")#however, I guess this line will be never reached. 
    154150 
    155151    if not p.solver.__iterfcnConnected__: 
     
    176172        print s 
    177173 
    178     p.iterfcn(p.x0) 
     174 
    179175 
    180176    try: 
    181         solver(p) 
     177        if isConverter: 
     178            # TODO: will R be somewhere used? 
     179            R = converter(solverName) 
     180        else: 
     181            nErr = ooCheck(p) 
     182            if nErr: p.err("prob check results: " +str(nErr) + "ERRORS!")#however, I guess this line will be never reached. 
     183 
     184            p.iterfcn(p.x0) 
     185            solver(p) 
    182186#    except killThread: 
    183187#        if p.plot: 
     
    194198#        return None 
    195199    except isSolved: 
    196         p.fk = p.f(p.xk) 
    197         p.xf = p.xk 
    198         p.ff = p.objFuncMultiple2Single(p.fk) 
     200#        p.fk = p.f(p.xk) 
     201#        p.xf = p.xk 
     202#        p.ff = p.objFuncMultiple2Single(p.fk) 
    199203 
    200204        if p.istop == 0: p.istop = 1000 
     
    205209    p.isFinished = True 
    206210    if hasattr(p, 'xf') and (not hasattr(p, 'xk') or array_equiv(p.xk, p.x0)): p.xk = p.xf 
    207     if hasattr(p, 'xk'): p.fk = p.objFunc(p.xk) 
    208211    if not hasattr(p,  'xf') or all(p.xf==nan): p.xf = p.xk 
     212 
     213    p.fk = p.objFunc(p.xk) 
    209214    if not hasattr(p,  'ff') or any(p.ff==nan): p.ff = p.objFunc(p.xf) 
    210  
    211215 
    212216    if not hasattr(p, 'fk'): p.fk = p.ff 
    213217    if p.invertObjFunc:  p.fk, p.ff = -p.fk, -p.ff 
     218 
     219    if asfarray(p.ff).size > 1: p.ff = p.objFuncMultiple2Single(p.fk) 
    214220 
    215221    #p.ff = p.objFuncMultiple2Single(p.ff) 
     
    300306        pylab.show() 
    301307 
    302 ################################################################## 
    303 def my_import(name): 
    304     mod = __import__(name) 
    305     components = name.split('.') 
    306     for comp in components[1:]: 
    307         mod = getattr(mod, comp) 
    308     return mod 
    309  
    310308class EmptyClass: pass 
    311309class OpenOptResult: pass