/usr/share/pyshared/openopt/kernel/GLP.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 | from ooMisc import assignScript
from baseProblem import NonLinProblem
from numpy import asarray, ones, inf, array
from setDefaultIterFuncs import MAX_NON_SUCCESS
class GLP(NonLinProblem):
probType = 'GLP'
_optionalData = ['lb', 'ub', 'c', 'A', 'b']
expectedArgs = ['f', 'x0']
allowedGoals = ['minimum', 'min', 'maximum', 'max']
goal = 'minimum'
showGoal = False
isObjFunValueASingleNumber = True
plotOnlyCurrentMinimum= True
_currentBestPoint = None
_nonSuccessCounter = 0
maxNonSuccess = 15
def __init__(self, *args, **kwargs):
#if len(args) > 1: self.err('incorrect args number for GLP constructor, must be 0..1 + (optionaly) some kwargs')
NonLinProblem.__init__(self, *args, **kwargs)
def maxNonSuccess(p):
newPoint = p.point(p.xk)
if self._currentBestPoint is None:
self._currentBestPoint = newPoint
return False
elif newPoint.betterThan(self._currentBestPoint):
self._currentBestPoint = newPoint
self._nonSuccessCounter = 0
return False
self._nonSuccessCounter += 1
if self._nonSuccessCounter > self.maxNonSuccess:
return (True, 'Non-Success Number > maxNonSuccess = ' + str(self.maxNonSuccess))
else:
return False
self.kernelIterFuncs[MAX_NON_SUCCESS] = maxNonSuccess
if 'lb' in kwargs.keys():
self.n = len(kwargs['lb'])
elif 'ub' in kwargs.keys():
self.n = len(kwargs['ub'])
elif 'b' in kwargs.keys():
self.n = asarray(b).size
if hasattr(self, 'n'):
if not hasattr(self, 'lb'):
self.lb = -inf * ones(self.n)
if not hasattr(self, 'ub'):
self.ub = inf * ones(self.n)
if 'x0' not in kwargs.keys(): self.x0 = (asarray(self.lb) + asarray(self.ub)) / 2.0
|