private static void lnsrlb(int n, double[] l, int _l_offset, double[] u, int _u_offset,
int[] nbd, int _nbd_offset, double[] x, int _x_offset, double f, ref double fold, ref double gd,
ref double gdold, double[] g, int _g_offset, double[] d, int _d_offset, double[] r, int _r_offset,
double[] t, int _t_offset, double[] z, int _z_offset, ref double stp,
ref double dnorm, ref double dtd, ref double xstep, ref double stpmx, int iter,
ref int ifun, ref int iback, ref int nfgv, ref int info, ref string task,
bool boxed, bool cnstnd, ref string csave, int[] isave, int _isave_offset,
double[] dsave, int _dsave_offset)
{
int i = 0;
double a1 = 0.0d;
double a2 = 0.0d;
if ((task.Substring((1) - 1, 5).StartsWith("FG_LN", StringComparison.OrdinalIgnoreCase)))
{
goto L556;
}
//
dtd = ddot(n, d, _d_offset, 1, d, _d_offset, 1);
dnorm = System.Math.Sqrt(dtd);
//
// c Determine the maximum step length.
//
stpmx = 10000000000.0;
if (cnstnd)
{
if ((iter == 0))
{
stpmx = 1.0;
}
else
{
{
for (i = 1; i <= n; i++)
{
a1 = d[(i - (1)) + _d_offset];
if ((nbd[(i - (1)) + _nbd_offset] != 0))
{
if (((a1 < 0.0) && (nbd[(i - (1)) + _nbd_offset] <= 2)))
{
a2 = (l[(i - (1)) + _l_offset] - x[(i - (1)) + _x_offset]);
if ((a2 >= 0.0))
{
stpmx = 0.0;
}
else if (((a1 * stpmx) < a2))
{
stpmx = (a2 / a1);
}
}
else if (((a1 > 0.0) && (nbd[(i - (1)) + _nbd_offset] >= 2)))
{
a2 = (u[(i - (1)) + _u_offset] - x[(i - (1)) + _x_offset]);
if ((a2 <= 0.0))
{
stpmx = 0.0;
}
else if (((a1 * stpmx) > a2))
{
stpmx = (a2 / a1);
}
}
}
}
}
}
}
//
if (((iter == 0) && (!boxed)))
{
if (double.IsNaN(dnorm))
stp = stpmx;
else
stp = System.Math.Min((1.0 / dnorm), stpmx);
}
else
{
stp = 1.0;
}
//
dcopy(n, x, _x_offset, 1, t, _t_offset, 1);
dcopy(n, g, _g_offset, 1, r, _r_offset, 1);
fold = f;
ifun = 0;
iback = 0;
csave = "START";
L556:
gd = BoundedBroydenFletcherGoldfarbShanno.ddot(n, g, _g_offset, 1, d, _d_offset, 1);
if ((ifun == 0))
{
gdold = gd;
if ((gd >= 0.0))
{
// the directional derivative >=0.
// Line search is impossible.
// DISPLAY: " ascent direction in projection gd = " + gd
info = -4;
return;
}
}
dcsrch(f, gd, ref stp,
0.001000000000000000020816681711721685132943,
0.9000000000000000222044604925031308084726,
0.1000000000000000055511151231257827021182, 0.0,
stpmx, ref csave, isave, _isave_offset, dsave, _dsave_offset);
//
xstep = (stp * dnorm);
if (((!csave.StartsWith("CONV", StringComparison.OrdinalIgnoreCase))
&& (!csave.StartsWith("WARN", StringComparison.OrdinalIgnoreCase))))
{
task = "FG_LNSRCH";
ifun = (ifun + 1);
nfgv = (nfgv + 1);
iback = (ifun - 1);
if ((stp == 1.0))
{
dcopy(n, z, _z_offset, 1, x, _x_offset, 1);
}
else
{
{
for (i = 1; i <= n; i++)
{
x[(i - (1)) + _x_offset] = ((stp * d[(i - (1)) + _d_offset]) + t[(i - (1)) + _t_offset]);
}
}
}
}
else
{
task = "NEW_X";
}
}