/usr/lib/python2.7/dist-packages/openopt/solvers/UkrOpt/ii_engine.py is in python-openopt 0.38+svn1589-1.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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | from interalgLLR import *
from interalgT import r42
from numpy import inf, prod, searchsorted, all, sum
def r14IP(p, nlhc, residual, definiteRange, y, e, vv, asdf1, C, CBKPMV, itn, g, nNodes, \
frc, fTol, Solutions, varTols, _in, dataType, \
maxNodes, _s, indTC, xRecord):
required_sigma = p.ftol * 0.99 # to suppress roundoff effects
m, n = y.shape
if 1:
ip = func10(y, e, vv)
ip.dictOfFixedFuncs = p.dictOfFixedFuncs
o, a, definiteRange = func8(ip, asdf1, dataType)
else:
vv = p._freeVarsList
o, a, definiteRange = func82(y, e, vv, asdf1, dataType, p)
if not all(definiteRange):
p.err('''
numerical integration with interalg is implemented
for definite (real) range only, no NaN values in integrand are allowed''')
o, a = o.reshape(2*n, m).T, a.reshape(2*n, m).T
r42(o, a)
if itn == 0:
# TODO: fix it
#_s = atleast_1d(nanmax(a-o))
_s = atleast_1d(inf)
nodes = func11(y, e, None, indTC, None, o, a, _s, p)
#OLD
# nodes.sort(key = lambda obj: obj.key)
# #nodes.sort(key = lambda obj: obj.volumeResidual, reverse=True)
#
# if len(_in) == 0:
# an = nodes
# else:
# arr1 = [node.key for node in _in]
# arr2 = [node.key for node in nodes]
## arr1 = -array([node.volumeResidual for node in _in])
## arr2 = -array([node.volumeResidual for node in nodes])
#
# r10 = searchsorted(arr1, arr2)
# an = insert(_in, r10, nodes)
#NEW
#nodes.sort(key = lambda obj: obj.key)
#nodes.sort(key = lambda obj: obj.volumeResidual, reverse=True)
if len(_in) == 0:
an = nodes
else:
an = hstack((_in, nodes)).tolist()
if 1:
an.sort(key = lambda obj: obj.key, reverse=False)
#an.sort(key = lambda obj: obj.minres, reverse=False)
else:
an.sort(key=lambda obj: obj.volumeResidual, reverse=False)
ao_diff = array([node.key for node in an])
volumes = array([node.volume for node in an])
if 1:
r10 = ao_diff <= 0.5*(required_sigma-p._residual) / (prod(p.ub-p.lb) - p._volume)
#r10 = nanmax(a-o, 1) <= required_sigma / prod(p.ub-p.lb)
ind = where(r10)[0]
# TODO: use true_sum
#print sum(array([an[i].F for i in ind]) * array([an[i].volume for i in ind]))
#print 'p._F:', p._F, 'delta:', sum(array([an[i].F for i in ind]) * array([an[i].volume for i in ind]))
v = volumes[ind]
p._F += sum(array([an[i].F for i in ind]) * v)
residuals = ao_diff[ind] * v
p._residual += residuals.sum()
p._volume += v.sum()
# print '1: %e' % v.sum()
volume_0 = p._volume
#print 'iter:', p.iter, 'nNodes:', len(an), 'F:', p._F, 'div:', ao_diff / (required_sigma / prod(p.ub-p.lb))
an = asarray(an, object)
an = an[where(logical_not(r10))[0]]
# changes
if 0:
minres = array([node.minres for node in an])
r10 = minres <= 0.5*(required_sigma-p._residual) / (prod(p.ub-p.lb) - p._volume)
ind = where(r10)[0]
for i in ind:
node = an[i]
minres_ind = node.minres_ind
minres = node.minres
node_volume = prod(node.e-node.y) # TODO: get rid of cycle here
minres_residual = node.a[minres_ind] - node.o[minres_ind]
minres_F = 0.5*(node.a[minres_ind] + node.o[minres_ind])
p._residual += 0.5 * minres_residual * node_volume
p._F += 0.5 * minres_F * node_volume
p._volume += 0.5 * node_volume
node.volume *= 0.5
node.minres = inf
if minres_ind < n:
node.y[minres_ind] += 0.5 * (node.e[minres_ind] - node.y[minres_ind])
#node.key = min((node.key, node.a[minres_ind-n] - node.o[minres_ind-n]))
else:
node.e[minres_ind-n] -= 0.5 * (node.e[minres_ind-n] - node.y[minres_ind-n])
#node.key = min((node.key, node.a[minres_ind] - node.o[minres_ind]))
node.minres = node.complementary_minres
# if ind.size != 0 : print '2: %e' % (p._volume - volume_0)
# changes end
else:
residuals = ao_diff * volumes
p._residual = 0.5*sum(residuals)
#print 'sum(residuals): ', sum(residuals)
if p._residual < required_sigma:
p._F = sum(array([node.F for node in an]) * v)
an = []
#p._Residual = p._residual + sum(asarray([node.volume for node in an]) * asarray([node.key for node in an]))
nNodes.append(len(an))
p.iterfcn(xk=array(nan), fk=p._F, rk = 0)#TODO: change rk to something like p._r0 - p._residual
if p.istop != 0:
ao_diff = array([node.key for node in an])
volumes = array([node.volume for node in an])
p._residual += sum(ao_diff * volumes)
_s = None
#an, g = func9(an, fo, g, 'IP')
#nn = 1 if asdf1.isUncycled and all(isfinite(a)) and all(isfinite(o)) and p._isOnlyBoxBounded else maxNodes
#an, g = func5(an, nn, g)
return an, g, inf, _s, Solutions, xRecord, frc, CBKPMV
|