/usr/share/pyshared/openopt/kernel/baseSolver.py is in python-openopt 0.38+svn1589-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | __docformat__ = "restructuredtext en"
from numpy import atleast_1d, all, asarray, ndarray, copy, ravel, isnan, where, isscalar, asscalar
from openopt.kernel.Point import Point
class baseSolver:
def __init__(self):pass
__name__ = 'Undefined. If you are a user and got the message, inform developers please.'
__license__ = "Undefined. If you are a user and got the message, inform developers please."
__authors__ = "Undefined. If you are a user and got the message, inform developers please."
__alg__ = "Undefined"
__solver__ = "Undefined. If you are a user and got the message, inform developers please."
__homepage__ = 'Undefined. Use web search'
__info__ = 'None'
_requiresBestPointDetection = False
_requiresFiniteBoxBounds = False
"""__cannotHandleExceptions__ is
True for ipopt and mb some others,
somehow exceptions raised in OO and
passed through ipopt
cannot be catched by OO
"""
__cannotHandleExceptions__ = False
__optionalDataThatCanBeHandled__ = []
__isIterPointAlwaysFeasible__ = lambda self, p: p.isUC#TODO: provide possibility of simple True, False
iterfcnConnected = False
funcForIterFcnConnection = 'df' # the field is used for non-linear solvers with not-connected iter function
_canHandleScipySparse = False # True if can handle linear constraints Ax<=b, Aeq x = beq and nonlin cons derivs
properTextOutput = False
# these ones below are used in iterfcn (ooIter.py)
# to decode input args
# and can be overdetermined by child class (LP, QP, network etc)
__expectedArgs__ = ['xk', 'fk', 'rk'] #point, objFunVal, max residual
def __decodeIterFcnArgs__(self, p, *args, **kwargs):
"""
decode and assign x, f, maxConstr
(and/or other fields) to p.iterValues
"""
fArg = True
if len(args)>0 and isinstance(args[0], Point):
if len(args) != 1: p.err('incorrect iterfcn args, if you see this contact OO developers')
point = args[0]
p.xk, p.fk = point.x, point.f()
p.rk, p.rtk, p.rik = point.mr(True)
p.nNaNs = point.nNaNs()
if p.solver._requiresBestPointDetection and (p.iter == 0 or point.betterThan(p._bestPoint)): p._bestPoint = point
else:
if len(args)>0: p.xk = args[0]
elif 'xk' in kwargs.keys(): p.xk = kwargs['xk']
elif not hasattr(p, 'xk'): p.err('iterfcn must get x value, if you see it inform oo developers')
if p._baseClassName == 'NonLin':
p.nNaNs = len(where(isnan(p.c(p.xk)))[0]) + len(where(isnan(p.h(p.xk)))[0])
if p.solver._requiresBestPointDetection:
currPoint = p.point(p.xk)
if p.iter == 0 or currPoint.betterThan(p._bestPoint): p._bestPoint = currPoint
if len(args)>1: p.fk = args[1]
elif 'fk' in kwargs.keys(): p.fk = kwargs['fk']
else: fArg = False
if len(args)>2:
#p.pWarn('executing deprecated code, inform developers')
p.rk = args[2]
elif 'rk' in kwargs.keys():
#p.pWarn('executing deprecated code, inform developers')
p.rk = kwargs['rk']
else:
p.rk, p.rtk, p.rik = p.getMaxResidual(p.xk, True)
p.iterValues.r.append(ravel(p.rk)[0])
if p.probType != 'IP':
# recalculations are not performed
p.rk, p.rtk, p.rik = p.getMaxResidual(p.xk, True)
p.iterValues.rt.append(p.rtk)
p.iterValues.ri.append(p.rik)
if p._baseClassName == 'NonLin': p.iterValues.nNaNs.append(p.nNaNs)
#TODO: handle kwargs correctly! (decodeIterFcnArgs)
# for key in kwargs.keys():
# if p.debug: print 'decodeIterFcnArgs>>', key, kwargs[key]
# setattr(p, key, kwargs[key])
p.iterValues.x.append(copy(p.xk))
if not p.storeIterPoints and len(p.iterValues.x) > 2:
p.iterValues.x.pop(0)
if not fArg:
p.Fk = p.F(p.xk)
p.fk = copy(p.Fk)
else:
if asarray(p.fk).size >1:
if p.debug and p.iter <= 1: p.warn('please fix solver iter output func, objFuncVal should be single number (use p.F)')
p.Fk = p.objFuncMultiple2Single(asarray(p.fk))
else:
p.Fk = p.fk
#if p.isObjFunValueASingleNumber: p.Fk = p.fk
#else: p.Fk = p.objFuncMultiple2Single(fv)
v = ravel(p.Fk)[0]
if p.invertObjFunc: v = -v
p.iterValues.f.append(v)
if not isscalar(p.fk) and p.fk.size == 1:
p.fk = asscalar(p.fk)
|