Changeset 1091

Show
Ignore:
Timestamp:
07/03/08 15:21:41 (2 years ago)
Author:
dmitrey.kroshko
Message:

lots of changes, mostly code cleanup, some minor bugfixes

Files:

Legend:

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

    r1089 r1091  
    1111    __homepage__ = 'Undefined. Use web search' 
    1212    __info__ = 'None' 
    13     __constraintsThatCannotBeHandled__ = ['c', 'h', 'Aeq', 'A', 'lb', 'ub'] 
     13 
     14    # TODO: remove it 
     15    __constraintsThatCannotBeHandled__ = [] 
     16 
     17    __optionalDataThatCanBeHandled__ = [] 
    1418    __isIterPointAlwaysFeasible__ = lambda self, p: p.isUC#TODO: provide possibility of simple True, False 
    1519    __iterfcnConnected__ = False 
  • trunk/openopt/scikits/openopt/Kernel/BaseProblem.py

    r1089 r1091  
    33from oologfcn import * 
    44from ooGraphics import Graphics 
    5 from setDefaultIterFuncs import setDefaultIterFuncs 
     5from setDefaultIterFuncs import setDefaultIterFuncs, IS_MAX_FUN_EVALS_REACHED 
    66from objFunRelated import objFunRelated 
    77from Residuals import Residuals 
     
    1212 
    1313ProbDefaults = {'diffInt': 1e-7,  'xtol': 1e-6,  'noise': 0} 
    14  
    1514from runProbSolver import runProbSolver 
    1615 
    17 class Check: 
    18     def __init__(self): 
    19         self.df = 0# check numerical & 
    20         self.dh = 0# user-supplied gradients 
    21         self.dc = 0 
    22         # lines with difference less than maxViolation will be not shown 
    23         self.maxViolation = 1e-5 
     16 
     17 
    2418 
    2519class user: 
    2620    def __init__(self): 
    2721        pass 
    28  
    29 class Parallel: 
    30     def __init__(self): 
    31         self.f = False# 0 - don't use parallel calclations, 1 - use 
    32         self.c = False 
    33         self.h = False 
    34         #others are under development 
    35         #TODO: add paralell func! 
    36         #self.parallel.fun = dfeval 
    3722 
    3823class oomatrix: 
     
    4631        #return asarray(x) * asarray(y) 
    4732 
    48 class args: 
    49     def __init__(self): pass 
    50     f, c, h = (), (), () 
    51  
    5233class autocreate: 
    5334    def __init__(self): pass 
    5435 
    55 class BaseProblem(oomatrix, objFunRelated, Residuals, ooTextOutput, args): 
     36class BaseProblem(oomatrix, Residuals, ooTextOutput): 
    5637    def __init__(self): 
    5738        self.isObjFunValueASingleNumber = True 
     
    6142        self.name = 'unnamed' 
    6243 
    63         self.check = Check() 
    64         self.parallel = Parallel() 
     44 
    6545        self.graphics = Graphics() 
    6646        self.user = user() 
    67         self.args = args() 
    6847 
    6948        self.plot = False # draw picture or not 
     
    9574        self.data4TextOutput = ['objFunVal', 'log10(maxResidual)'] 
    9675 
    97         #TODO: remove it? 
    98         self.useScaling = 0#if 1, ScaleFactor or TypicalX must be provided, else x0 will be used as  TypicalX. However, OpenOpt automatic scaling isn't tested properly yet. 
    9976 
    10077        self.debug = 0 
     
    10683 
    10784        self.maxIter = 400 
    108         self.maxFunEvals = 10000 
     85        self.maxFunEvals = 10000 # TODO: move it to NinLinProblem class? 
    10986        self.maxCPUTime = inf 
    11087        self.maxTime = inf 
    111         self.maxLineSearch = 500 
    112         self.xtol = ProbDefaults['xtol'] 
    113         self.gradtol = 1e-6 
     88        self.maxLineSearch = 500 # TODO: move it to NinLinProblem class? 
     89        self.xtol = ProbDefaults['xtol'] # TODO: move it to NinLinProblem class? 
     90        self.gradtol = 1e-6 # TODO: move it to NinLinProblem class? 
    11491        self.ftol = 1e-6 
    11592        self.contol = 1e-6 
     
    12198        self.binVars = [] # for problems like MILP 
    12299 
    123         self.noise = ProbDefaults['noise'] 
    124         self.consMode = 'all' 
    125  
    126         #TODO: move it to non-lin funcs classes only 
    127         self.prevVal = {} 
    128         for fn in ['f', 'c', 'h', 'df', 'dc', 'dh', 'd2f', 'd2c', 'd2h']: 
    129             self.prevVal[fn] = {'key':None, 'val':None} 
     100        self.noise = ProbDefaults['noise'] # TODO: move it to NinLinProblem class? 
     101 
    130102 
    131103        # A * x <= b inequalities 
     
    147119        # 0 : <Awhole, x> [j] = bwhole[j] 
    148120 
    149         #finite-difference gradient aproximation step 
    150         self.diffInt = ProbDefaults['diffInt'] 
    151  
    152121        self.scale = None 
    153  
    154         self.isVectoriezed = 0# isn't tested properly yet 
    155  
    156         #f0 = None#TODO: handle me properly 
    157  
    158         #non-linear constraints 
    159         self.c = None # c(x)<=0 
    160         self.h = None # h(x)=0 
    161122 
    162123        self.goal = None# should be redefined by child class 
    163124        # possible values: 'maximum', 'min', 'max', 'minimum', 'minimax' etc 
    164125        self.showGoal = False# can be redefined by child class, used for text & graphic output 
    165  
    166         # TODO: implement in a field self classification: 
    167         # 'minimax', 'multiobjective'(or goalattain?), etc 
    168  
    169         self.fPattern = None 
    170         self.cPattern = None 
    171         self.hPattern = None 
    172  
    173         ##primal.* fields are for OpenOpt developers only, not common users 
    174         #primal.f = None 
    175         #primal.df = None 
    176         #primal.d2f = None 
    177         #primal.c = None 
    178         #primal.h = None 
    179         #primal.dc = None 
    180         #primal.dh = None 
    181         #primal.d2c = None 
    182         #primal.d2h = None 
    183126 
    184127        self.color = 'b' # blue, color for plotting 
     
    199142        # so it may be ignored with some solvers not closely connected to OO Kernel 
    200143 
    201         self.kernelIterFuncs = setDefaultIterFuncs() 
    202  
    203144        self.callback = [] 
    204145 
     
    208149 
    209150        self.special = autocreate() 
     151 
     152        self.optionalData = []#string names of optional data like 'c', 'h', 'Aeq' etc 
     153 
     154    def __finalize__(self): 
     155        pass 
    210156 
    211157    def objFunc(self, x): 
     
    224170        return self.b.size ==0 and self.beq.size==0 and not self.userProvided.c and not self.userProvided.h 
    225171 
    226     def __1stBetterThan2nd__(self,  f1, f2,  r1=None,  r2=None): 
    227         if self.isUC: 
    228             #TODO: check for goal = max/maximum 
    229             return f1 < f2 
    230         else:#then r1, r2 should be defined 
    231             return (r1 < r2 and  self.contol < r2) or (((r1 <= self.contol and r2 <=  self.contol) or r1==r2) and f1 < f2) 
    232  
    233     def __1stCertainlyBetterThan2ndTakingIntoAcoountNoise__(self,   f1, f2,  r1=None,  r2=None): 
    234         if self.isUC: 
    235             #TODO: check for goalType = max 
    236             return f1 + self.noise < f2 - self.noise 
    237         else: 
    238             #return (r1 + self.noise < r2 - self.noise and  self.contol < r2) or \ 
    239             return (r1 < r2  and  self.contol < r2) or \ 
    240             (((r1 <= self.contol and r2 <=  self.contol) or r1==r2) and f1 + self.noise < f2 - self.noise) 
     172#    def __1stBetterThan2nd__(self,  f1, f2,  r1=None,  r2=None): 
     173#        if self.isUC: 
     174#            #TODO: check for goal = max/maximum 
     175#            return f1 < f2 
     176#        else:#then r1, r2 should be defined 
     177#            return (r1 < r2 and  self.contol < r2) or (((r1 <= self.contol and r2 <=  self.contol) or r1==r2) and f1 < f2) 
     178
     179#    def __1stCertainlyBetterThan2ndTakingIntoAcoountNoise__(self,   f1, f2,  r1=None,  r2=None): 
     180#        if self.isUC: 
     181#            #TODO: check for goalType = max 
     182#            return f1 + self.noise < f2 - self.noise 
     183#        else: 
     184#            #return (r1 + self.noise < r2 - self.noise and  self.contol < r2) or \ 
     185#            return (r1 < r2  and  self.contol < r2) or \ 
     186#            (((r1 <= self.contol and r2 <=  self.contol) or r1==r2) and f1 + self.noise < f2 - self.noise) 
    241187 
    242188 
     
    244190        return runProbSolver(self, solvers, *args, **kwargs) 
    245191 
     192 
     193    # TODO: remove it 
    246194    def auxFunc(self, x, *args, **kwargs): 
    247195        r = self.connectedIterFuncField(x, *args, **kwargs) 
     
    253201        return r 
    254202 
     203    # TODO: simplify or remove it 
    255204    def connectIterFcn(self, funcname, calledByUser = True): 
    256205        #this function could be called by user or by RunProbSolver.py 
     
    271220        self.err('OpenOpt error: this function should be overdetermined by child class') 
    272221 
     222    def inspire(self, newProb): 
     223        # fills some fields of new prob with old prob values 
     224 
     225        #TODO: hold it in single place 
     226        for key in ['lb', 'ub', 'A', 'Aeq', 'b', 'beq', 'contol', 'xtol', 'ftol', 'gradtol', 'iprint', 'plot', 'maxIter', 'maxTime', 'maxCPUTime','fEnough', 'goal', 'color', 'debug'] : 
     227            if hasattr(self, key): setattr(newProb, key, getattr(self, key)) 
     228 
     229 
     230class MatrixProblem(BaseProblem): 
     231    __baseClassName__ = 'Matrix' 
     232    def __init__(self): 
     233        BaseProblem.__init__(self) 
     234        self.kernelIterFuncs = setDefaultIterFuncs('Matrix') 
     235 
     236    def __prepare__(self): 
     237        pass 
     238 
     239class Check: 
     240    def __init__(self): 
     241        self.df = 0# check numerical & 
     242        self.dh = 0# user-supplied gradients 
     243        self.dc = 0 
     244        # lines with difference less than maxViolation will be not shown 
     245        self.maxViolation = 1e-5 
     246 
     247class Parallel: 
     248    def __init__(self): 
     249        self.f = False# 0 - don't use parallel calclations, 1 - use 
     250        self.c = False 
     251        self.h = False 
     252        #TODO: add paralell func! 
     253        #self.parallel.fun = dfeval 
     254 
     255class args: 
     256    def __init__(self): pass 
     257    f, c, h = (), (), () 
     258 
     259class NonLinProblem(BaseProblem, objFunRelated, args): 
     260    __baseClassName__ = 'NonLin' 
     261    def __init__(self): 
     262        BaseProblem.__init__(self) 
     263        self.check = Check() 
     264        self.args = args() 
     265        self.consMode = 'all' # TODO: remove it? 
     266        #self.parallel = Parallel() 
     267 
     268        self.prevVal = {} 
     269        for fn in ['f', 'c', 'h', 'df', 'dc', 'dh', 'd2f', 'd2c', 'd2h']: 
     270            self.prevVal[fn] = {'key':None, 'val':None} 
     271 
     272        #finite-difference gradient aproximation step 
     273        self.diffInt = ProbDefaults['diffInt'] 
     274 
     275        #self.isVectoriezed = False 
     276 
     277        #non-linear constraints 
     278        self.c = None # c(x)<=0 
     279        self.h = None # h(x)=0 
     280 
     281#        self.fPattern = None 
     282#        self.cPattern = None 
     283#        self.hPattern = None 
     284        self.kernelIterFuncs = setDefaultIterFuncs('NonLin') 
     285 
    273286    def checkdf(self, *args,  **kwargs): 
    274287        return ooCheckGradient(self, 'df', *args,  **kwargs) 
     
    289302            if type(v) != type(()): setattr(self.args, j, (v,)) 
    290303 
    291     def inspire(self, newProb): 
    292         # fills some fields of new prob with old prob values 
    293  
    294         #TODO: hold it in single place 
    295         for key in ['lb', 'ub', 'A', 'Aeq', 'b', 'beq', 'contol', 'xtol', 'ftol', 'gradtol', 'iprint', 'plot', 'maxIter', 'maxTime', 'maxCPUTime','fEnough', 'goal', 'color', 'debug'] : 
    296             if hasattr(self, key): setattr(newProb, key, getattr(self, key)) 
     304    def __finalize__(self): 
     305        if (self.userProvided.c and any(isnan(self.c(self.xf)))) or (self.userProvided.h and any(isnan(self.h(self.xf)))): 
     306            if self.iprint >= -1: self.warn('some non-linear constraints are equal to NaN') 
     307 
     308    def __prepare__(self): 
     309        self.__makeCorrectArgs__() 
     310        for s in ('f', 'df', 'd2f', 'c', 'dc', 'd2c', 'h', 'dh', 'd2h'): 
     311            if hasattr(self, s) and getattr(self, s) is not None: 
     312                setattr(self.userProvided, s, True) 
     313                self.nEvals[s] = 0 
     314                A = getattr(self,s) 
     315 
     316                if callable(A): #TODO: add or ndarray(A)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
     317                    A = (A,)#make tuple 
     318                setattr(self.user, s, A) 
     319            else: 
     320                setattr(self.userProvided, s, False) 
     321                #setattr(p.user, s, (None,)) 
     322            setattr(self, s, getattr(self, 'user_' + s)) 
     323 
     324        #initialization, getting nf, nc, nh etc: 
     325        for s in ['c', 'h']: 
     326            if getattr(self.userProvided, s): 
     327                getattr(self, s)(self.x0) 
     328            else: 
     329                setattr(self, 'n'+s, 0) 
     330 
     331        if hasattr(self, 'delayedConnectIterFcn'): 
     332            if self.solver.__iterfcnConnected__: self.warn('solver ' + self.solver.__name__ + ' has native iterfcn, user-defined connection via p.connectIterFcn will be ignored') 
     333            else: 
     334                if self.delayedConnectIterFcn == 'df': self.warn('iterfcn now connects to df automatically by default, you can either use other funcs like d2f to suppress the warning or ommit user-defined connecting to df at all') 
     335                self.connectIterFcn('df') 
     336        else: 
     337            if not self.solver.__iterfcnConnected__: 
     338                self.connectIterFcn('df', calledByUser = False) 
  • trunk/openopt/scikits/openopt/Kernel/GLP.py

    r1040 r1091  
    11from ooMisc import assignScript 
    2 from BaseProblem import BaseProblem 
     2from BaseProblem import NonLinProblem 
    33from numpy import asarray, ones, inf, array, iterable 
    44from NLP import nlp_init 
    55 
    6 class GLP(BaseProblem): 
     6class GLP(NonLinProblem): 
     7    __optionalData__ = ['lb', 'ub'] 
    78    def __init__(self, *args, **kwargs): 
    89        if len(args) > 1: self.err('incorrect args number for GLP constructor, must be 0..1 + (optionaly) some kwargs') 
     
    1011        kwargs2 = kwargs.copy() 
    1112        if len(args) > 0: kwargs2['f'] = args[0] 
    12         BaseProblem.__init__(self) 
     13        NonLinProblem.__init__(self) 
    1314 
    1415        glp_init(self, kwargs2) 
  • trunk/openopt/scikits/openopt/Kernel/LLSP.py

    r1040 r1091  
    11from ooMisc import assignScript 
    2 from BaseProblem import BaseProblem 
    3 from numpy import asfarray, ones, inf, dot 
     2from BaseProblem import MatrixProblem 
     3from numpy import asfarray, ones, inf, dot, nan, zeros 
    44from numpy.linalg import norm 
     5import NLP 
    56 
    6 class LLSP(BaseProblem): 
     7class LLSP(MatrixProblem): 
     8    __optionalData__ = ['damp', 'xd', 'c'] 
    79    def __init__(self, *args, **kwargs): 
    810        if len(args) > 2: self.err('incorrect args number for LLSP constructor, must be 0..2 + (optionaly) some kwargs') 
    911        if len(args) > 0: kwargs['C'] = args[0] 
    1012        if len(args) > 1: kwargs['d'] = args[1] 
    11         BaseProblem.__init__(self) 
     13 
     14        MatrixProblem.__init__(self) 
    1215        llsp_init(self, kwargs) 
    1316 
    1417    def objFunc(self, x): 
    15         return norm(dot(self.C, x) - self.d) 
     18        r = norm(dot(self.C, x) - self.d) ** 2  /  2.0 
     19        if self.damp != 0: r += self.damp * norm(x-self.xd)**2 / 2.0 
     20        if any(self.f): r += dot(self.f, x) 
     21        return r 
     22 
     23    def llsp2nlp(self, solver, **kwargs): 
     24        if hasattr(self,'x0'): p = NLP.NLP(ff, self.x0, df=dff) 
     25        else: p = NLP(ff, zeros(self.n), df=dff) 
     26        p.args.f = self # DO NOT USE p.args = self IN PROB ASSIGNMENT! 
     27        self.inspire(p) 
     28        r = p.solve(solver, **kwargs) 
     29        return r 
     30 
     31 
    1632 
    1733def llsp_init(prob, kwargs): 
     
    2642    prob.lb = -inf * ones(prob.n) 
    2743    prob.ub =  inf * ones(prob.n) 
     44    if not kwargs.has_key('damp'): kwargs['damp'] = 0 
     45    if not kwargs.has_key('xd'): kwargs['xd'] = zeros(prob.n) 
     46    if not kwargs.has_key('f'): kwargs['f'] = zeros(prob.n) 
     47 
     48    if prob.x0 is nan: prob.x0 = zeros(prob.n) 
    2849 
    2950    return assignScript(prob, kwargs) 
    3051 
     52#def ff(x, LLSPprob): 
     53#    r = dot(LLSPprob.C, x) - LLSPprob.d 
     54#    return dot(r, r) 
     55ff = lambda x, LLSPprob: LLSPprob.objFunc(x) 
     56dff = lambda x, LLSPprob: 2 * (dot(LLSPprob.C.T, dot(LLSPprob.C,x)  - LLSPprob.d)) 
     57 
  • trunk/openopt/scikits/openopt/Kernel/LP.py

    r1040 r1091  
    11from ooMisc import assignScript 
    2 from BaseProblem import BaseProblem 
    3 from numpy import asarray, ones, inf 
     2from BaseProblem import MatrixProblem 
     3from numpy import asarray, ones, inf, dot, nan, zeros 
    44 
    55 
    6 class LP(BaseProblem): 
     6class LP(MatrixProblem): 
     7    __optionalData__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub'] 
    78    def __init__(self, *args, **kwargs): 
    89        kwargs2 = kwargs.copy() 
     
    1011        if len(args) > 1: self.err('incorrect args number for LP constructor, must be 0..1 + (optionaly) some kwargs') 
    1112        self.probType = 'LP' 
    12         BaseProblem.__init__(self) 
     13        MatrixProblem.__init__(self) 
    1314        lp_init(self, kwargs2) 
    1415 
    1516 
    1617    def objFunc(self, x): 
    17         return self.dotmult(p.f, x) 
     18        return dot(self.f, x) 
    1819 
    1920def lp_init(prob, kwargs): 
     
    2728 
    2829    prob.n = len(f) 
     30    if prob.x0 is nan: prob.x0 = zeros(prob.n) 
    2931    prob.lb = -inf * ones(prob.n) 
    3032    prob.ub =  inf * ones(prob.n) 
  • trunk/openopt/scikits/openopt/Kernel/LSP.py

    r830 r1091  
    1 from BaseProblem import BaseProblem 
     1from BaseProblem import NonLinProblem 
    22from NLP import nlp_init 
    33 
    4 class LSP(BaseProblem): 
     4class LSP(NonLinProblem): 
     5    __optionalData__ = [] 
    56    def __init__(self, *args, **kwargs): 
    67        if len(args) > 2: self.err('incorrect args number for LSP constructor, must be 0..2 + (optionaly) some kwargs') 
    7          
     8 
    89        kwargs2 = kwargs.copy() 
    910        if len(args) > 0: kwargs2['f'] = args[0] 
    1011        if len(args) > 1: kwargs2['x0'] = args[1] 
    11          
    12         BaseProblem.__init__(self) 
     12 
     13        NonLinProblem.__init__(self) 
    1314        self.probType = 'LSP' 
     15        self.allowedGoals = ['minimum', 'min'] 
    1416        self.isObjFunValueASingleNumber = False 
    15          
     17 
    1618        return nlp_init(self, kwargs2) 
    1719 
  • trunk/openopt/scikits/openopt/Kernel/MILP.py

    r1040 r1091  
    11 
    22from ooMisc import assignScript 
    3 from BaseProblem import BaseProblem 
    4 from numpy import asarray, ones, inf 
     3from BaseProblem import MatrixProblem 
     4from numpy import asarray, ones, inf, dot, nan, zeros 
    55 
    66from LP import lp_init 
     
    88 
    99 
    10 class MILP(BaseProblem): 
     10class MILP(MatrixProblem): 
     11    __optionalData__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub'] 
    1112    def __init__(self, *args, **kwargs): 
    1213        if len(args) > 2: self.err('incorrect args number for MILP constructor, must be 0..2 + (optionaly) some kwargs') 
     
    1617        if len(args) > 1: kwargs2['intVars'] = args[1] 
    1718        self.probType = 'MILP' 
    18         BaseProblem.__init__(self) 
     19        MatrixProblem.__init__(self) 
    1920        lp_init(self, kwargs2) 
     21 
     22    def objFunc(self, x): 
     23        return dot(self.f, x) 
    2024 
    2125 
    2226 
    23  
    24  
  • trunk/openopt/scikits/openopt/Kernel/MMP.py

    r1040 r1091  
    1 from BaseProblem import BaseProblem 
     1from BaseProblem import NonLinProblem 
    22from NLP import nlp_init 
    33from numpy import max 
    44 
    5 class MMP(BaseProblem): 
     5class MMP(NonLinProblem): 
    66    """ 
    77    Mini-Max Problem 
    88    """ 
     9    __optionalData__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 
    910    def __init__(self, *args, **kwargs): 
    1011        if len(args) > 2: self.err('incorrect args number for MMP constructor, must be 0..2 + (optionaly) some kwargs') 
     
    1314        if len(args) > 0: kwargs2['f'] = args[0] 
    1415        if len(args) > 1: kwargs2['x0'] = args[1] 
    15         BaseProblem.__init__(self) 
     16        NonLinProblem.__init__(self) 
    1617 
    17         self.allowedGoals = ['minimum', 'min', 'maximum', 'max'] 
     18        self.allowedGoals = ['minimax'] 
    1819 
    1920        nlp_init(self, kwargs2) 
  • trunk/openopt/scikits/openopt/Kernel/NLP.py

    r1040 r1091  
    11from ooMisc import assignScript 
    2 from BaseProblem import BaseProblem 
     2from BaseProblem import NonLinProblem 
    33from numpy import asarray, ones, inf, array, iterable 
    44 
    55 
    6 class NLP(BaseProblem): 
     6class NLP(NonLinProblem): 
     7    __optionalData__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 
    78    def __init__(self, *args, **kwargs): 
    89        if len(args) > 2: self.err('incorrect args number for NLP constructor, must be 0..2 + (optionaly) some kwargs') 
     
    1112        if len(args) > 0: kwargs2['f'] = args[0] 
    1213        if len(args) > 1: kwargs2['x0'] = args[1] 
    13         BaseProblem.__init__(self) 
     14        NonLinProblem.__init__(self) 
    1415 
    1516        self.probType = 'NLP' 
  • trunk/openopt/scikits/openopt/Kernel/NLSP.py

    r1040 r1091  
    1 from BaseProblem import BaseProblem 
     1from BaseProblem import NonLinProblem 
    22from NLP import nlp_init 
    33from numpy.linalg import norm 
     
    55from setDefaultIterFuncs import FVAL_IS_ENOUGH 
    66 
    7 class NLSP(BaseProblem): 
     7class NLSP(NonLinProblem): 
     8    __optionalData__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 
    89    def __init__(self, *args, **kwargs): 
    910        if len(args) > 2: self.err('incorrect args number for NLSP constructor, must be 0..2 + (optionaly) some kwargs') 
     
    1213        if len(args) > 0: kwargs2['f'] = args[0] 
    1314        if len(args) > 1: kwargs2['x0'] = args[1] 
    14         BaseProblem.__init__(self) 
     15        NonLinProblem.__init__(self) 
    1516 
    1617        self.isObjFunValueASingleNumber = False 
  • trunk/openopt/scikits/openopt/Kernel/NSP.py

    r1040 r1091  
    11from ooMisc import assignScript 
    2 from BaseProblem import BaseProblem 
     2from BaseProblem import NonLinProblem 
    33from numpy import asarray, ones, inf 
    44 
     
    77 
    88 
    9 class NSP(BaseProblem): 
     9class NSP(NonLinProblem): 
     10    __optionalData__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 
    1011    def __init__(self, *args, **kwargs): 
    1112        if len(args) > 2: self.err('incorrect args number for NSP constructor, must be 0..2 + (optionaly) some kwargs') 
     
    1415        if len(args) > 0: kwargs2['f'] = args[0] 
    1516        if len(args) > 1: kwargs2['x0'] = args[1] 
    16         BaseProblem.__init__(self) 
     17        NonLinProblem.__init__(self) 
    1718 
    1819 
  • trunk/openopt/scikits/openopt/Kernel/QP.py

    r1089 r1091  
    66 
    77from ooMisc import assignScript 
    8 from BaseProblem import BaseProblem 
     8from BaseProblem import MatrixProblem 
    99from numpy import asfarray, ones, inf, dot, asfarray, nan, zeros 
    1010 
    1111 
    12 class QP(BaseProblem): 
     12class QP(MatrixProblem): 
     13    __optionalData__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub'] 
    1314    def __init__(self, *args, **kwargs): 
    1415        self.probType = 'QP' 
     
    1718        if len(args) > 1: kwargs2['f'] = args[1] 
    1819        if len(args) > 2: self.err('incorrect args number for QP constructor, must be 0..1 + (optionaly) some kwargs') 
    19         BaseProblem.__init__(self) 
     20        MatrixProblem.__init__(self) 
    2021 
    2122        return qp_init(self, kwargs2) 
  • trunk/openopt/scikits/openopt/Kernel/Residuals.py

    r1089 r1091  
    3636        # TODO: add quadratic constraints 
    3737        r = EmptyClass() 
    38         r.c = self.__get_nonLinInEq_Residuals__(x) 
    39         r.h = self.__get_nonLinEq_Residuals__(x) 
     38        # TODO: simplify it! 
     39        if self.__baseClassName__ == 'NonLin': 
     40            r.c = self.__get_nonLinInEq_Residuals__(x) 
     41            r.h = self.__get_nonLinEq_Residuals__(x) 
     42        else: 
     43            r.c = r.h = 0 
    4044        r.A = self.__get_AX_Less_B_Residuals__(x) 
    4145        r.Aeq= self.__get_AeqX_eq_Beq_Residuals__(x) 
  • trunk/openopt/scikits/openopt/Kernel/objFunRelated.py

    r1009 r1091  
    167167    def wrapped_1st_derivatives(p, funcType, x, ind=None, ignorePrev=False): 
    168168        derivativesType = 'd'+funcType 
    169         funcs = getattr(p.user, derivativesType) 
     169        #funcs = getattr(p.user, derivativesType) 
    170170        prevKey = p.prevVal[derivativesType]['key'] 
    171171        if prevKey is not None and p.iter > 0 and all(x == prevKey) and ind is None and not ignorePrev: 
  • trunk/openopt/scikits/openopt/Kernel/ooCheck.py

    r1064 r1091  
    1111        p.err('goal '+ p.goal+' is not available for the '+ p.probType + ' class (at least not implemented yet)') 
    1212 
    13  
     13#    for fn in p.__optionalData__: 
     14#        if not fn in p.solver.__optionalDataThatCanBeHandled__: 
     15#            p.err('the solver ' + p.solverName + ' cannot handle ' + "'" + fn + "' data") 
    1416 
    1517    if p.solver.__constraintsThatCannotBeHandled__ != []: 
     
    2022                    p.err('the solver ' + p.solverName + ' cannot handle ' + "'" + fn + "' constraints") 
    2123 
    22     for fn in ('df', 'dc', 'dh'): 
    23         if getattr(p.check, fn): 
    24             p.info('the option p.check.'+fn+' is obsolete, use p.check'+fn+'() or p.check'+fn+'(x) instead') 
    2524 
    2625    return nErrors 
  • trunk/openopt/scikits/openopt/Kernel/runProbSolver.py

    r1090 r1091  
    8484    if p.graphics.xlabel == 'nf': p.iterValues.nf = [] # iter ObjFunc evaluation number 
    8585 
    86     p.__makeCorrectArgs__() 
     86    p.__prepare__() 
    8787 
    8888    if p.probType in ('LP', 'MILP', 'QP') and p.plot: 
     
    9393    if hasattr(p, 'x0'): p.x0 = atleast_1d(asfarray(p.x0).copy()) 
    9494    for fn in ['lb', 'ub', 'b', 'beq', 'scale', 'diffInt']: 
    95         fv = getattr(p, fn) 
    96         if fv != None:# and fv != []: 
    97             setattr(p, fn, asfarray(fv, dtype='float').flatten()) 
    98         elif fn != 'scale': 
    99             setattr(p, fn, asfarray([])) 
    100  
    101  
    102     if p.scale is not None: 
     95        if hasattr(p, fn): 
     96            fv = getattr(p, fn) 
     97            if fv != None:# and fv != []: 
     98                setattr(p, fn, asfarray(fv, dtype='float').flatten()) 
     99            elif fn != 'scale': 
     100                setattr(p, fn, asfarray([])) 
     101 
     102 
     103    if p.scale is not None and hasattr(p, 'diffInt'): 
    103104        if p.diffInt.size>1 or p.diffInt[0] != ProbDefaults['diffInt']: 
    104105            p.info('using both non-default scale & diffInt is not recommended. diffInt = diffInt/scale will be used') 
     
    125126    p.stopdict = {} 
    126127 
    127     for s in ('f', 'df', 'd2f', 'c', 'dc', 'd2c', 'h', 'dh', 'd2h', 'l', 'dl', 'd2l'): 
    128         if not (s == 'f' and p.probType in ('LP', 'MILP', 'QP')): 
    129             if hasattr(p, s) and getattr(p, s) is not None: 
    130                 setattr(p.userProvided, s, True) 
    131                 p.nEvals[s] = 0 
    132                 A = getattr(p,s) 
    133  
    134                 if callable(A): #TODO: add or ndarray(A)!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
    135                     A = (A,)#make tuple 
    136                 setattr(p.user, s, A) 
    137             else: 
    138                 setattr(p.userProvided, s, False) 
    139                 setattr(p.user, s, (None,)) 
    140             setattr(p, s, getattr(p, 'user_' + s)) 
    141  
    142     #initialization, getting nf, nc, nh etc: 
    143     for s in ['c', 'h']: 
    144         if getattr(p.userProvided, s): 
    145             getattr(p, s)(p.x0) 
    146         else: 
    147             setattr(p, 'n'+s, 0) 
    148128    for s in ['b','beq']: 
    149129        if hasattr(p, s): setattr(p, 'n'+s, len(getattr(p, s))) 
     
    158138    nErr = ooCheck(p) 
    159139    if nErr: p.err("prob check results: " +str(nErr) + "ERRORS!")#however, I guess this line will be never reached. 
    160  
    161     if hasattr(p, 'delayedConnectIterFcn'): 
    162         if p.solver.__iterfcnConnected__: p.warn('solver ' + p.solver.__name__ + ' has native iterfcn, user-defined connection via p.connectIterFcn will be ignored') 
    163         else: 
    164             if p.delayedConnectIterFcn == 'df': p.warn('iterfcn now connects to df automatically by default, you can either use other funcs like d2f to suppress the warning or ommit user-defined connecting to df at all') 
    165             p.connectIterFcn('df') 
    166     else: 
    167         if not p.solver.__iterfcnConnected__: 
    168             p.connectIterFcn('df', calledByUser = False) 
    169140 
    170141    if not p.solver.__iterfcnConnected__: 
     
    226197    else: p.iterfcn(p.xf, p.ff) 
    227198 
    228     if (p.userProvided.c and any(isnan(p.c(p.xf)))) or (p.userProvided.h and any(isnan(p.h(p.xf)))): 
    229         #p. 
    230         if p.iprint >= -1: p.warn('some non-linear constraints are equal to NaN') 
     199    p.__finalize__() 
    231200 
    232201    r = OpenOptResult() 
  • trunk/openopt/scikits/openopt/Kernel/setDefaultIterFuncs.py

    r960 r1091  
    1313IS_NAN_IN_X = -4 
    1414IS_LINE_SEARCH_FAILED = -5 
    15 IS_MAX_ITER_REACHED = -7     
     15IS_MAX_ITER_REACHED = -7 
    1616IS_MAX_CPU_TIME_REACHED = -8 
    1717IS_MAX_TIME_REACHED = -9 
     
    2020 
    2121FAILED_WITH_UNIMPLEMENTED_OR_UNKNOWN_REASON = -1000 
    22          
     22 
    2323def stopcase(arg): 
    2424    if hasattr(arg, 'istop'): istop = arg.istop 
    2525    else: istop = arg 
    26      
     26 
    2727    if istop > 0: return 1 
    2828    elif istop in [IS_MAX_ITER_REACHED, IS_MAX_CPU_TIME_REACHED, IS_MAX_TIME_REACHED, IS_MAX_FUN_EVALS_REACHED]: return 0 
    2929    else: return -1 
    30          
    3130 
    3231 
    33 def setDefaultIterFuncs(): 
     32 
     33def setDefaultIterFuncs(className): 
    3434    d = dict() 
    35      
     35 
    3636    # positive: 
    3737    d[SMALL_DF] = lambda p: small_df(p) 
     
    4646    d[IS_MAX_CPU_TIME_REACHED]  = lambda p: isMaxCPUTimeReached(p) 
    4747    d[IS_MAX_TIME_REACHED]  = lambda p: isMaxTimeReached(p) 
    48     d[IS_MAX_FUN_EVALS_REACHED] = lambda p: isMaxFunEvalsReached(p) 
     48    if className == 'NonLin': d[IS_MAX_FUN_EVALS_REACHED] = lambda p: isMaxFunEvalsReached(p) 
    4949    return d 
    5050 
    5151def small_df(p): 
    52     if not hasattr(p, '_df') or p._df == None or p.norm(p._df) >= p.gradtol: return False  
     52    if not hasattr(p, '_df') or p._df == None or p.norm(p._df) >= p.gradtol: return False 
    5353    return (True, '|| gradient F(X[k]) || < gradtol') 
    5454    #return False if not hasattr(p, 'dF') or p.dF == None or p.norm(p.dF) > p.gradtol else True 
    55          
     55 
    5656def small_deltaX(p): 
    5757    if p.iter == 0: return False 
     
    6161    else: return (True, '|| X[k] - X[k-1] || < xtol') 
    6262    #r = False if p.norm(p.xk - p.x_prev) > p.xtol else True 
    63      
    64          
     63 
     64 
    6565def small_deltaF(p): 
    6666    if p.iter == 0: return False 
    6767    #r = False if p.norm(p.fk - p.f_prev) > p.ftol else True 
    68     if  p.norm(p.iterValues.f[-1] - p.iterValues.f[-2]) >= p.ftol: # or (p.iterValues.r[-1] > p.contol and p.iterValues.r[-1] - p.iterValues.r[-2] < p.contol):  
     68    if  p.norm(p.iterValues.f[-1] - p.iterValues.f[-2]) >= p.ftol: # or (p.iterValues.r[-1] > p.contol and p.iterValues.r[-1] - p.iterValues.r[-2] < p.contol): 
    6969            return False 
    7070    else: return (True, '|| F[k] - F[k-1] || < ftol') 
    71      
     71 
    7272 
    7373def isEnough(p): 
     
    8080       return (True, 'NaN in X[k] coords has been obtained') 
    8181    else: return False 
    82      
     82 
    8383 
    8484def isMaxIterReached(p): 
     
    102102def isMaxFunEvalsReached(p): 
    103103    #if not hasattr(p, 'nFunEvals'): p.warn('no nFunEvals field'); return 0 
    104     if p.nEvals['f'] < p.maxFunEvals: 
     104    if p.nEvals['f'] >= p.maxFunEvals: 
     105        return (True, 'max objfunc evals limit has been reached') 
     106    else: 
    105107        return False 
    106     else:  
    107         return (True, 'max objfunc evals limit has been reached') 
    108108 
    109109 
  • trunk/openopt/scikits/openopt/solvers/BrasilOpt/ALGENCAN_oo.py

    r1090 r1091  
    1212    __homepage__ = 'http://www.ime.usp.br/~egbirgin/tango/' 
    1313    __info__ = "please pay more attention to gradtol param, it's the only one ALGENCAN positive stop criterium, xtol and ftol are unused" 
    14     __constraintsThatCannotBeHandled__ = [] # empty list means the solver can handle all constraints 
     14    __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 
    1515    __isIterPointAlwaysFeasible__ = lambda self, p: p.__isNoMoreThanBoxBounded__() 
    1616 
  • trunk/openopt/scikits/openopt/solvers/BrasilOpt/algencan_oo.py

    r1090 r1091  
    1313    #TODO: edit info! 
    1414    __info__ = "please pay more attention to gradtol param, it's the only one ALGENCAN positive stop criterium, xtol and ftol are unused" 
    15     __constraintsThatCannotBeHandled__ = [] # empty list means the solver can handle all constraints 
     15    __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 
    1616    __isIterPointAlwaysFeasible__ = lambda self, p: p.__isNoMoreThanBoxBounded__() 
    1717 
  • trunk/openopt/scikits/openopt/solvers/CVXOPT/cvxopt_glpk_oo.py

    r934 r1091  
    66    __license__ = "GPL v.2" 
    77    __authors__ = "http://www.gnu.org/software/glpk + Python bindings from http://abel.ee.ucla.edu/cvxopt" 
    8     __alg__ = "see http://www.gnu.org/software/glpk"   
    9     __constraintsThatCannotBeHandled__ = ['c', 'h'] # empty list means the solver can handle all constraints 
     8    __alg__ = "see http://www.gnu.org/software/glpk" 
     9    __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'intVars', 'binVars'] 
    1010    def __init__(self): pass 
    11      
     11 
    1212    def __solver__(self, p): 
    1313        return CVXOPT_LP_Solver(p, 'glpk') 
  • trunk/openopt/scikits/openopt/solvers/CVXOPT/cvxopt_lp_oo.py

    r934 r1091  
    66    __license__ = "LGPL" 
    77    __authors__ = "http://abel.ee.ucla.edu/cvxopt" 
    8     __alg__ = "see http://abel.ee.ucla.edu/cvxopt"  
    9     __constraintsThatCannotBeHandled__ = ['c', 'h'] # empty list means the solver can handle all constraints 
     8    __alg__ = "see http://abel.ee.ucla.edu/cvxopt" 
     9    __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub'] 
    1010    def __init__(self): pass 
    1111    def __solver__(self, p): 
  • trunk/openopt/scikits/openopt/solvers/CVXOPT/cvxopt_qp_oo.py

    r934 r1091  
    66    __license__ = "LGPL" 
    77    __authors__ = "http://abel.ee.ucla.edu/cvxopt" 
    8     __alg__ = "see http://abel.ee.ucla.edu/cvxopt"   
    9     __constraintsThatCannotBeHandled__ = ['c', 'h'] # empty list means the solver can handle all constraints 
     8    __alg__ = "see http://abel.ee.ucla.edu/cvxopt" 
     9    __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub'] 
    1010    def __init__(self): pass 
    1111    def __solver__(self, p): 
  • trunk/openopt/scikits/openopt/solvers/CVXOPT/glpk_oo.py

    r950 r1091  
    77    __authors__ = "http://www.gnu.org/software/glpk + Python bindings from http://abel.ee.ucla.edu/cvxopt" 
    88    __homepage__ = 'http://www.gnu.org/software/glpk' 
    9     #__alg__ = ""   
    10     __constraintsThatCannotBeHandled__ = ['c', 'h'] # empty list means the solver can handle all constraints 
    11      
     9    #__alg__ = "" 
     10    __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'intVars', 'binVars'] 
     11 
    1212    def __init__(self): pass 
    13      
     13 
    1414    def __solver__(self, p): 
    1515        return CVXOPT_LP_Solver(p, 'glpk') 
  • trunk/openopt/scikits/openopt/solvers/CoinOr/ipopt_oo.py

    r1028 r1091  
    1313    __homepage__ = 'http://www.coin-or.org/' 
    1414    __info__ = "requires pyipopt made by Eric Xu You" 
    15     __constraintsThatCannotBeHandled__ = [] # empty list means the solver can handle all constraints 
     15    __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 
    1616 
    1717 
  • trunk/openopt/scikits/openopt/solvers/Standalone/bvls_oo.py

    r933 r1091  
    1313    __license__ = "BSD" 
    1414    __authors__ = 'Robert L. Parker rlparker[at]ucsd.edu, Philip B. Stark stark[at]stat.berkeley.edu' 
    15     __alg__ = '"Bounded Variable Least Squares:  An Algorithm and Applications" by P.B. Stark and R.L. Parker, in the journal "Computational Statistics", vol.10(2), 1995'   
     15    __alg__ = '"Bounded Variable Least Squares:  An Algorithm and Applications" by P.B. Stark and R.L. Parker, in the journal "Computational Statistics", vol.10(2), 1995' 
    1616    __info__ = 'requires manual compilation of bvls.f by f2py, see OO online doc for details' 
    17     __constraintsThatCannotBeHandled__ = ['c', 'h', 'Aeq', 'A'] 
    18      
     17    __optionalDataThatCanBeHandled__ = ['lb', 'ub'] 
     18 
    1919    __bvls_inf__ = 1e300 
    2020    T = float64 
    2121    def __init__(self): pass 
    22      
     22 
    2323    def __solver__(self, p): 
    2424        key = 0 
     
    3232        bl[where(bl==-inf)[0]] = -self.__bvls_inf__ 
    3333        bu[where(bu==inf)[0]] = self.__bvls_inf__ 
    34          
     34 
    3535        xf, w, istop, msg,  iter = BVLS.bvls(key, a, b, bl, bu, p.maxIter, act, zz,  istate) 
    36          
     36 
    3737        p.istop, p.msg, p.iter = istop, msg.rstrip(), iter 
    3838        p.xf = p.xk = xf 
    3939        p.ff = p.fk = w[0] 
    40          
     40 
  • trunk/openopt/scikits/openopt/solvers/Standalone/galileo_oo.py

    r1004 r1091  
    1515    requires finite lb, ub: lb <= x <= ub 
    1616    """ 
    17     __constraintsThatCannotBeHandled__ = ['c', 'h', 'Aeq', 'A'] 
     17    __optionalDataThatCanBeHandled__ = ['lb', 'ub'] 
    1818    __isIterPointAlwaysFeasible__ = lambda self, p: True 
    1919 
  • trunk/openopt/scikits/openopt/solvers/Standalone/toms587_oo.py

    r933 r1091  
    1111    __license__ = "BSD" 
    1212    __authors__ = 'R. J. HANSON AND K. H. HASKELL' 
    13     #__alg__ = ''   
     13    #__alg__ = '' 
    1414    __info__ = 'requires manual compilation of toms_587.f by f2py, see OO online doc for details' 
    15     __constraintsThatCannotBeHandled__ = ['c', 'h'] 
    16      
     15    #__optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub'] 
     16 
    1717    T = float64 
    1818    def __init__(self): pass 
    19      
     19 
    2020    def __solver__(self, p): 
    2121        xBounds2Matrix(p) 
     
    5353        p.ff = p.fk = ff 
    5454        p.istop = 1000 
    55          
    5655 
    5756 
     57 
  • trunk/openopt/scikits/openopt/solvers/UkrOpt/ShorEllipsoid_oo.py

    r1004 r1091  
    1818    __alg__ = "Naum Z. Shor modificated method of ellipsoids" 
    1919    __iterfcnConnected__ = True 
     20    #__optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 
    2021 
    2122    def __init__(self): pass 
     
    2324    def __solver__(self, p): 
    2425 
    25         if p.useScaling: p.err('ShorEllipsoid + scaling isn''t implemented yet') 
     26        #if p.useScaling: p.err('ShorEllipsoid + scaling isn''t implemented yet') 
    2627 
    2728 
  • trunk/openopt/scikits/openopt/solvers/UkrOpt/goldenSection_oo.py

    r1004 r1091  
    55class goldenSection(BaseAlg): 
    66    __name__ = 'goldenSection' 
    7     __constraintsThatCannotBeHandled__ = ['c', 'h', 'Aeq', 'A'] 
     7    __optionalDataThatCanBeHandled__ = ['lb', 'ub'] 
    88    __license__ = "BSD" 
    99    __authors__ = 'Dmitrey' 
  • trunk/openopt/scikits/openopt/solvers/UkrOpt/lincher_oo.py

    r1065 r1091  
    9090    __authors__ = "Dmitrey" 
    9191    __alg__ = "a linearization-based solver written in Cherkassy town, Ukraine" 
    92     __constraintsThatCannotBeHandled__ = [] # empty list means the solver can handle all constraints 
     92    __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 
     93 
    9394    __isIterPointAlwaysFeasible__ = lambda self, p: p.__isNoMoreThanBoxBounded__() 
    9495    __iterfcnConnected__ = True 
  • trunk/openopt/scikits/openopt/solvers/UkrOpt/nsmm_oo.py

    r1004 r1091  
    1111    __alg__ = "based on Naum Z. Shor r-alg" 
    1212    __iterfcnConnected__ = True 
    13     __constraintsThatCannotBeHandled__ = [
     13    __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'
    1414    __info__ = """ 
    1515    Solves mini-max problem 
  • trunk/openopt/scikits/openopt/solvers/UkrOpt/nssolve_oo.py

    r1065 r1091  
    1212    __alg__ = "based on Naum Z. Shor r-alg" 
    1313    __iterfcnConnected__ = True 
    14     __constraintsThatCannotBeHandled__ = [
     14    __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'
    1515    __isIterPointAlwaysFeasible__ = lambda self, p: p.isUC 
    1616    __info__ = """ 
  • trunk/openopt/scikits/openopt/solvers/UkrOpt/ralg_oo.py

    r1089 r1091  
    1111    __authors__ = "Dmitrey" 
    1212    __alg__ = "Naum Z. Shor R-algorithm with adaptive space dilation & some modifications" 
    13     __constraintsThatCannotBeHandled__ = [
     13    __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'
    1414    __iterfcnConnected__ = True 
    1515 
  • trunk/openopt/scikits/openopt/solvers/lp_solve/lpSolve_oo.py

    r1073 r1091  
    1616    __alg__ = "lpsolve" 
    1717    __info__ = 'use p.scale = 1 or True to turn scale mode on' 
    18     __constraintsThatCannotBeHandled__ = ['c', 'h', 'binVars'] # empty list means the solver can handle all constraints 
     18    __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'intVars'] 
    1919    def __init__(self): pass 
    2020    def __solver__(self, p): 
  • trunk/openopt/scikits/openopt/solvers/scipy_optim/scipy_cobyla_oo.py

    r1089 r1091  
    1414    __alg__ = "Constrained Optimization BY Linear Approximation" 
    1515    __info__ = 'constrained NLP solver, no user-defined derivatives are handled'#TODO: add '__info__' field to other solvers 
    16     __constraintsThatCannotBeHandled__ = [] # empty list means the solver can handle all constraints 
     16    __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'] 
    1717 
    1818    def __init__(self): pass 
  • trunk/openopt/scikits/openopt/solvers/scipy_optim/scipy_fminbound_oo.py

    r934 r1091  
    44class scipy_fminbound(BaseAlg): 
    55    __name__ = 'scipy_fminbound' 
    6     __constraintsThatCannotBeHandled__ = ['c', 'h', 'Aeq', 'A'] 
     6    __optionalDataThatCanBeHandled__ = ['lb', 'ub'] 
    77    __license__ = "BSD" 
    88    __authors__ = "Travis E. Oliphant" 
    9     __alg__ = "Brent's method (golden section + parabolic fit)"   
     9    __alg__ = "Brent's method (golden section + parabolic fit)" 
    1010    __info__ = '1-dimensional minimizer for finite box-bound problems' 
    1111    __isIterPointAlwaysFeasible__ = lambda self, p: True 
  • trunk/openopt/scikits/openopt/solvers/scipy_optim/scipy_lbfgsb_oo.py

    r934 r1091  
    88    __name__ = 'scipy_lbfgsb' 
    99    __license__ = "BSD" 
    10     __authors__ = """Ciyou Zhu, Richard Byrd, and Jorge Nocedal <nocedal@ece.nwu.edu>,  
     10    __authors__ = """Ciyou Zhu, Richard Byrd, and Jorge Nocedal <nocedal@ece.nwu.edu>, 
    1111    connected to scipy by David M. Cooke <cookedm@physics.mcmaster.ca> and Travis Oliphant, 
    1212    connected to openopt by Dmitrey""" 
    13     __alg__ = "l-bfgs-b"   
    14     __info__ = 'box-bounded limited-memory NLP solver, can handle lb<=x<=ub constraints, some lb-ub coords can be +/- inf'#TODO: add '__info__' field to other solvers     
    15     __constraintsThatCannotBeHandled__ = ['c', 'h', 'Aeq', 'A'] 
     13    __alg__ = "l-bfgs-b" 
     14    __info__ = 'box-bounded limited-memory NLP solver, can handle lb<=x<=ub constraints, some lb-ub coords can be +/- inf'#TODO: add '__info__' field to other solvers 
     15    __optionalDataThatCanBeHandled__ = ['lb', 'ub'] 
    1616    __isIterPointAlwaysFeasible__ = lambda self, p: True 
    17      
     17 
    1818    def __init__(self):pass 
    19      
     19 
    2020    def __solver__(self, p): 
    2121        WholeRepr2LinConst(p)#TODO: remove me 
    22          
     22 
    2323        bounds = [] 
    24          
     24 
    2525        # don't work in Python ver < 2.5 
    2626        # BOUND = lambda x: x if isfinite(x) else None 
    27          
     27 
    2828        def BOUND(x): 
    2929            if isfinite(x): return x 
    3030            else: return None 
    31          
     31 
    3232        for i in xrange(p.n): bounds.append((BOUND(p.lb[i]), BOUND(p.ub[i]))) 
    33          
    34         xf, ff, d = fmin_l_bfgs_b(p.f, p.x0, fprime=p.df,  
    35                   approx_grad=0,  bounds=bounds,  
     33 
     34        xf, ff, d = fmin_l_bfgs_b(p.f, p.x0, fprime=p.df, 
     35                  approx_grad=0,  bounds=bounds, 
    3636                  iprint=p.iprint, maxfun=p.maxFunEvals) 
    37          
    38         if d['warnflag'] in (0, 2):  
     37 
     38        if d['warnflag'] in (0, 2): 
    3939            # if 2 - some problems can be present, but final check from RunProbSolver will set negative istop if solution is unfeasible 
    4040            istop = SOLVED_WITH_UNIMPLEMENTED_OR_UNKNOWN_REASON 
    4141            if d['warnflag'] == 0: msg = 'converged' 
    4242        elif d['warnflag'] == 1:  istop = IS_MAX_FUN_EVALS_REACHED 
    43          
     43 
    4444        p.xk = p.xf = xf 
    4545        p.fk = p.ff = ff 
    4646        p.istop = istop 
    4747        p.iterfcn() 
    48          
     48 
  • trunk/openopt/scikits/openopt/solvers/scipy_optim/scipy_slsqp_oo.py

    r1000 r1091  
    1414    __alg__ = "Sequential Least SQuares Programming" 
    1515    __info__ = 'constrained NLP solver' 
    16     __constraintsThatCannotBeHandled__ = [
     16    __optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h'
    1717 
    1818    def __init__(self): pass 
  • trunk/openopt/scikits/openopt/solvers/scipy_optim/scipy_tnc_oo.py

    r934 r1091  
    99    __license__ = "BSD" 
    1010    __authors__ = "Stephen G. Nash" 
    11     __alg__ = "undefined"   
     11    __alg__ = "undefined" 
    1212    __info__ = 'box-bounded NLP solver, can handle lb<=x<=ub constraints, some lb-ub coords can be +/- inf' 
    13     __constraintsThatCannotBeHandled__ = ['c', 'h', 'Aeq', 'A'] 
     13    __optionalDataThatCanBeHandled__ = ['lb', 'ub'] 
    1414    __isIterPointAlwaysFeasible__ = lambda self, p: True 
    15      
     15 
    1616    def __init__(self): pass 
    17      
     17 
    1818    def __solver__(self, p): 
    1919        WholeRepr2LinConst(p)#TODO: remove me 
     
    2121        for i in xrange(p.n): bounds.append((p.lb[i], p.ub[i])) 
    2222        messages = 0#TODO: edit me 
    23          
     23 
    2424        p.xk = p.x0.copy() 
    2525        p.fk = p.f(p.x0) 
    26          
     26 
    2727        p.iterfcn() 
    2828        if p.istop: 
    2929            p.xf = p.xk 
    3030            p.ff = p.fk 
    31             return  
    32          
     31            return 
     32 
    3333        xf, nfeval, rc = fmin_tnc(p.f, x0 = p.x0, fprime=p.df, args=(), approx_grad=0, bounds=bounds, messages=messages, maxfun=p.maxFunEvals, ftol=p.ftol, xtol=p.xtol, pgtol=p.gradtol) 
    34          
     34 
    3535        if rc in (INFEASIBLE, NOPROGRESS): istop = FAILED_WITH_UNIMPLEMENTED_OR_UNKNOWN_REASON 
    3636        elif rc == FCONVERGED: istop = SMALL_DELTA_F 
     
    7272        p.xf = xf 
    7373        p.ff = p.fk 
    74          
     74 
    7575if __name__ == '__main__': 
    7676    import sys, os.path as P 
     
    7878    from scikits.openopt import NLP 
    7979    from numpy import * 
    80      
     80 
    8181    N = 750 
    82      
     82 
    8383    ff = lambda x: (((x/32 - 1)**4).sum() + 64*((x/4 -1 )**2).sum()) 
    8484##    ff = lambda x: (arctan((x-arange(x.size))/arange(x.size))**2).sum() 
    8585##    for solver in ('scipy_tnc',  'scipy_lbfgsb', 'ALGENCAN'): 
    8686    for solver in ( 'lincher', 'scipy_lbfgsb', 'ALGENCAN'): 
    87 ##        lb = 0.1*N + arange(N)  
     87##        lb = 0.1*N + arange(N) 
    8888##        ub = 0.8*N + arange(N) 
    8989        #x0 = cos(arange(N)) 
    9090        lb = 50*sin(arange(N))+15 
    9191        ub = lb + 15 
    92         x0 = (lb + ub)/2  
     92        x0 = (lb + ub)/2 
    9393        p = NLP(ff, x0, lb = lb, ub = ub, plot = 0, maxFunEvals = 1e8, maxIter = 1e4, gradtol = 1e-3) 
    9494        #p.c = lambda x: x[0]**2 - (lb[0] + ub[0])**2 / 4.0 
     
    9696        r = p.solve(solver) 
    9797        #assert r.istop > 0 
    98      
    99      
    100      
    101      
    102      
     98 
     99 
     100 
     101 
     102