// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) fieldsfirst 
// Source File Name:   Shitk.java

package lt.ktu.gmj.methods;

import java.io.PrintStream;
import lt.ktu.gmj.*;

// Referenced classes of package lt.ktu.gmj.methods:
//			ShitMethodBase, MethodBase

public class Shitk extends ShitMethodBase
{

	private static final int c__1 = 1;
	private static final int c__2 = 2;
	private static final int c__0 = 0;
	private static final int TRUE = 1;
	private static final int FALSE = 0;
	private static final int EXIT_MET = 19;
	private static final int NO_EXIT_MET = 20;
	private static final int LRsWa = 40;
	private int counter;

	public Shitk()
	{
		counter = 0;
		super.iterations = 40;
		super.MParameter = 0;
		super.MEParameter = 0;
	}

	private void func_(int m, int mmax, double g[], Result result, Task task)
	{
		int n = result.point.x.length;
		if(m > 0)
		{
			result.value = task.f(result.point);
			for(int i = 1; i <= m; i++)
				g[i] = task.domain().constraintAt(i - 1, result.point);

		} else
		if(m == 0)
		{
			result.value = task.f(result.point);
		} else
		{
			double t = g[-1 - m];
			g[-m] = task.domain().constraintAt(-m - 1, result.point);
			result.value = new SimpleResult(g[-1 - m]);
			g[-1 - m] = t;
		}
	}

	private int grad_(int m, int mmax, Result result, double g[], double df[], double dg[], short active[], 
			Task task)
	{
		int n = result.point.x.length;
		double on = 1.0D;
		double eps = 9.9999999999999995E-08D;
		int dg_dim1 = mmax;
		int dg_offset = dg_dim1 + 1;
		int i__1 = n;
		for(int i = 1; i <= i__1; i++)
		{
			double d__2 = on;
			double d__1 = result.point.x[i - 1];
			double d__3 = Math.abs(d__1);
			double xeps = eps * Math.max(d__2, d__3);
			double xepsi = on / xeps;
			result.point.x[i - 1] += xeps;
			double temp = result.value.fx();
			func_(0, mmax, g, result, task);
			double feps = result.value.fx();
			result.value = new SimpleResult(temp);
			df[i] = (feps - result.value.fx()) * xepsi;
			if(m != 0)
			{
				int i__2 = m;
				for(int j = 1; j <= i__2; j++)
					if(active[j] != 0)
					{
						int i__3 = -j;
						temp = result.value.fx();
						func_(i__3, mmax, g, result, task);
						double gjeps = result.value.fx();
						result.value = new SimpleResult(temp);
						dg[(j + i * dg_dim1) - dg_offset] = (gjeps - g[j]) * xepsi;
					}

			}
			result.point.x[i - 1] -= xeps;
		}

		return 0;
	}

	private int linsea_(double Chn_a[], double alpham, double phi, double amue, 
			double beta, int maxfun)
	{
		double ha = 0.5D;
		double on = 1.0D;
		short alpha = 0;
		short dphi = 1;
		short iline = 2;
		short ifail = 3;
		short wa_1 = 4;
		short wa_2 = 5;
		if(Chn_a[ifail] == -1D)
		{
			if(Chn_a[iline] >= (double)maxfun)
			{
				Chn_a[ifail] = 1.0D;
				return 0;
			}
		} else
		{
			Chn_a[wa_1] = phi;
			Chn_a[iline] = 0.0D;
			Chn_a[alpha] = alpham;
			Chn_a[wa_2] = Chn_a[alpha];
			Chn_a[iline]++;
			Chn_a[dphi] *= Chn_a[wa_2];
			Chn_a[ifail] = -1D;
			return 0;
		}
		double diff = phi - Chn_a[wa_1];
		if(diff > amue * Chn_a[dphi])
		{
			double d__1 = beta;
			double d__2 = (ha * Chn_a[dphi]) / (Chn_a[dphi] - diff);
			Chn_a[wa_2] = Math.max(d__1, d__2);
			Chn_a[alpha] = Chn_a[wa_2] * Chn_a[alpha];
			Chn_a[iline]++;
			Chn_a[dphi] *= Chn_a[wa_2];
			Chn_a[ifail] = -1D;
			return 0;
		} else
		{
			Chn_a[ifail] = 0.0D;
			return 0;
		}
	}

	private int merit_(int mode, int m, int me, int mmax, int mnn, int nmnn, double acc, double r[], Result result, double df[], double g[], double dg[], double v[], 
			double u[], Task task, double phi[], double dphi[], short active[], double wa[], short index[])
	{
		int n = result.point.x.length;
		double ze = 0.0D;
		double uf = r1mach(1);
		double ha = 0.5D;
		double on = 1.0D;
		int dg_dim1 = mmax;
		int dg_offset = dg_dim1 + 1;
		if(mode == 1)
		{
			if(m == 0 || me == m)
				return 0;
			int me1 = me + 1;
			int i__1 = m;
			for(int j = me1; j <= i__1; j++)
			{
				active[j] = 1;
				if(v[j] == ze && g[j] > acc)
					active[j] = 0;
			}

			return 0;
		}
		if(mode == 2)
		{
			double fact = wa[3];
			if(wa[1] > uf)
				fact = (double)(m << 1) / (wa[1] + (on - wa[2]));
			int i__1 = mnn;
			for(int j = 1; j <= i__1; j++)
			{
				double d__3 = u[j] - v[j];
				double d__1 = wa[3];
				double d__2 = fact * (d__3 * d__3);
				double rnew = Math.min(d__1, d__2);
				d__1 = r[j];
				d__2 = wa[4] * Math.sqrt(r[j]);
				double uad = Math.min(d__1, d__2);
				r[j] = Math.max(rnew, uad);
			}

			return 0;
		}
		if(mode == 3 || mode == 4)
		{
			int i__1;
			if(m != 0)
			{
				i__1 = m;
				for(int j = 1; j <= i__1; j++)
				{
					index[j] = 1;
					if(j > me && g[j] > v[j] / r[j])
						index[j] = 0;
				}

			}
			int mn;
			if(mode != 4)
			{
				phi[0] = result.value.fx();
				if(m != 0)
				{
					i__1 = m;
					for(int j = 1; j <= i__1; j++)
					{
						double phi1;
						if(index[j] != 0)
							phi1 = (v[j] - ha * r[j] * g[j]) * g[j];
						else
							phi1 = (ha * v[j] * v[j]) / r[j];
						phi[0] -= phi1;
					}

				}
				mn = m + n;
				i__1 = n;
				for(int i = 1; i <= i__1; i++)
				{
					double rmj = r[m + i];
					double rmi = on / rmj;
					double rmnj = r[mn + i];
					double rmni = on / rmnj;
					double vmi = v[m + i];
					double vmni = v[mn + i];
					double xmxl = result.point.x[i - 1] - task.domain().min[i - 1];
					double xumx = task.domain().max[i - 1] - result.point.x[i - 1];
					if(xmxl <= vmi * rmi)
						phi[0] -= (vmi - ha * rmj * xmxl) * xmxl;
					if(xmxl > vmi * rmi)
						phi[0] -= ha * rmi * vmi * vmi;
					if(xumx <= vmni * rmni)
						phi[0] -= (vmni - ha * rmnj * xumx) * xumx;
					if(xumx > vmni * rmni)
						phi[0] -= ha * rmni * vmni * vmni;
				}

				return 0;
			}
			i__1 = n;
			for(int i = 1; i <= i__1; i++)
			{
				dphi[i] = df[i];
				double sum = ze;
				if(m != 0)
				{
					int i__2 = m;
					for(int j = 1; j <= i__2; j++)
						if(index[j] != 0)
							sum += dg[(j + i * dg_dim1) - dg_offset] * (v[j] - r[j] * g[j]);

				}
				dphi[i] -= sum;
			}

			if(m != 0)
			{
				i__1 = m;
				for(int j = 1; j <= i__1; j++)
				{
					if(index[j] != 0)
						dphi[n + j] = -g[j];
					if(index[j] == 0)
						dphi[n + j] = -v[j] / r[j];
				}

			}
			mn = m + n;
			i__1 = n;
			for(int i = 1; i <= i__1; i++)
			{
				double vmi = v[m + i];
				double vmni = v[mn + i];
				double xmxl = result.point.x[i - 1] - task.domain().min[i - 1];
				double xumx = task.domain().max[i - 1] - result.point.x[i - 1];
				double rmj = r[m + i];
				double rmi = on / rmj;
				double rmnj = r[mn + i];
				double rmni = on / rmnj;
				if(xmxl <= vmi * rmi)
					dphi[i] = (dphi[i] - vmi) + rmj * xmxl;
				if(xumx <= vmni * rmni)
					dphi[i] = (dphi[i] + vmni) - rmnj * xumx;
				if(xmxl <= vmi * rmi)
					dphi[mn + i] = -xmxl;
				if(xmxl > vmi * rmi)
					dphi[mn + i] = -vmi * rmi;
				if(xumx <= vmni * rmni)
					dphi[mnn + i] = -xumx;
				if(xumx > vmni * rmni)
					dphi[mnn + i] = -vmni * rmni;
			}

			return 0;
		} else
		{
			return 0;
		}
	}

	private Result nlpql1_(int m, int me, int mmax, int nmax, int mnn2, Result result, double g[], 
			double df[], double dg[], double u[], Task task, double c[], double d[], double acc, double scbou, int maxfun, int maxit, int ifail, int lwa, 
			int lkwa, short active[], int lactiv, short index[], ResultLogger logger)
	{
		int n = result.point.x.length;
		int n1 = n + 1;
		int lact = mmax + 5;
		int mm1 = lact + 1;
		int mm2 = lact + 2;
		int mm3 = lact + 3;
		int mm4 = lact + 4;
		int mm5 = lact + 5;
		int mm7 = lact + 6;
		int mnn = m + n + n;
		int nmnn = n + mnn;
		int iscg = 1;
		int iscf = iscg + mmax;
		int i1 = iscf + 1;
		int i2 = i1 + 1;
		int i3 = i2 + 1;
		int i4 = i3 + 1;
		int i5 = i4 + 1;
		int i6 = i5 + 1;
		int ivmu = i6 + 1;
		int idel = ivmu + mnn;
		int idla = idel + n1;
		int iclf = idla + n;
		int ibdel = iclf + n1;
		int ieta = ibdel + n;
		int ixold = ieta + n;
		int idlaol = ixold + n;
		int iv = idlaol + n;
		int iw = iv + n1;
		int ivmuol = iw + n1;
		int idphi = ivmuol + mnn;
		int ipen = idphi + mnn + n;
		int ifb = ipen + mnn;
		int igb = ifb + 1;
		int iwaql = igb + mmax;
		int itest = iwaql;
		int lwaql = lwa - itest;
		int lkwa0 = lkwa - 7;
		double vmu[] = new double[mnn + 1];
		double del[] = new double[n1 + 1];
		double dla[] = new double[n + 1];
		double dclf[] = new double[n1 + 1];
		double bdel[] = new double[n + 1];
		double eta[] = new double[n + 1];
		double xold[] = new double[n + 1];
		double dlaold[] = new double[n + 1];
		double v[] = new double[n1 + 1];
		double w[] = new double[n1 + 1];
		double vmuold[] = new double[mnn + 1];
		double dphi[] = new double[mnn + n + 1];
		double rpen[] = new double[mnn + 1];
		double scg[] = new double[mmax + 1];
		double fbest[] = new double[2];
		double gbest[] = new double[mmax + 1];
		double wa[] = new double[40];
		int iaw[] = new int[lkwa0];
		int nfunc = 0;
		int ngrad = 0;
		int iter = 0;
		int nql = 0;
		int iline = 0;
		int iflise = 0;
		int nopt = 0;
		double phi = 0.0D;
		double dfdel = 0.0D;
		double dbd = 0.0D;
		double alpham = 0.0D;
		double alphao = 0.0D;
		double scf = 0.0D;
		double prod = 0.0D;
		short lscf = 0;
		short lscg = 0;
		short lline = 0;
		short lrest = 0;
		short lalsd = 0;
		short lbest = 0;
		double dbdfac = 0.20000000000000001D;
		double zefac = 1.0D;
		double rpeno = 10D;
		double rpens = 0.01D;
		double zefacu = 1000000D;
		double rpenu = 1000000000D;
		double delta = 0.90000000000000002D;
		double beta = 0.10000000000000001D;
		double amue = 0.0001D;
		double alm = 1.0D;
		int maxit1 = maxit;
		int maxit2 = maxit / 2;
		ifail = 0;
		fbest[0] = 0.0D;
		for(int i = 0; i < n; i++)
		{
			if(result.point.x[i] < task.domain().min[i])
				result.point.x[i] = task.domain().min[i];
			if(result.point.x[i] > task.domain().max[i])
				result.point.x[i] = task.domain().max[i];
		}

		return nlpql2_(m, me, mmax, nmax, result, g, df, dg, u, task, c, d, acc, scbou, maxfun, maxit1, ifail, dbdfac, zefac, rpeno, rpens, rpenu, zefacu, delta, beta, amue, alm, vmu, del, dla, dclf, bdel, eta, xold, dlaold, v, w, vmuold, dphi, rpen, scg, fbest[0], gbest, wa, lwaql, n1, mnn, mnn2, nmnn, nfunc, ngrad, iter, nql, iline, iflise, nopt, iaw, lkwa0, phi, dfdel, dbd, alpham, alphao, scf, prod, active, lact, lscf, lscg, lline, lrest, lalsd, lbest, index, logger);
	}

	private Result nlpql2_(int m, int me, int mmax, int nmax, Result result, double g[], double df[], 
			double dg[], double u[], Task task, double dcl[], double cd[], double acc, 
			double scbou, int maxfun, int maxit, int ifail, double dbdfac, 
			double zefac, double rpeno, double rpens, double rpenu, double zefacu, double delta, double beta, 
			double amue, double alm, double vmu[], double del[], double dla[], 
			double dclf[], double bdel[], double eta[], double xold[], double dlaold[], double v[], double w[], 
			double vmuold[], double dphi[], double rpen[], double scg[], double fbest, double gbest[], 
			double wa[], int lwa, int n1, int mnn, int mnn2, int nmnn, int nfunc, 
			int ngrad, int iter, int nql, int iline, int iflise, int nopt, int iw[], 
			int liw, double phi, double dfdel, double dbd, 
			double alpham, double alphao, double scf, double prod, short active[], int lactiv, short lscf, short lscg, short lline, short lrest, 
			short lalsd, short lbest, short index[], ResultLogger logger)
	{
		int n = result.point.x.length;
		double ze = 0.0D;
		double on = 1.0D;
		double tw = 2D;
		double uf = r1mach(1);
		double of = r1mach(2);
		int mn = m + n;
		int me1 = me + 1;
		int n2 = n + n;
		int lwaql = lwa - 40;
		int liwql = liw - 10;
		int ilwls = mmax + 1;
		int ior = 1;
		double sqacc = Math.sqrt(acc);
		double dcl11 = zefac;
		double phi_a[] = new double[10];
		double delnm = ze;
		double xnm = ze;
		int iflis = 0;
		int ifail1 = iter;
		int mn1 = m + n1 + 1;
		int max_ = mmax;
		int mnn1 = m + n1 + n;
		int dcl_dim1 = nmax;
		int dcl_offset = dcl_dim1 + 1;
		int dg_dim1 = mmax;
		int dg_offset = dg_dim1 + 1;
		lrest = 0;
		lalsd = 0;
		nfunc = 0;
		ngrad = 0;
		iter = 0;
		nql = 0;
		nopt = 0;
		int i__1;
		if(m != 0)
		{
			i__1 = m;
			for(int j = 1; j <= i__1; j++)
				active[j] = 1;

		}
		func_(m, max_, g, result, task);
		grad_(m, mmax, result, g, df, dg, active, task);
		lscf = 0;
		lscg = 0;
		if(Math.abs(result.value.fx()) >= scbou)
		{
			lscf = 1;
			if(scbou > ze)
				scf = on / Math.sqrt(Math.abs(result.value.fx()));
			result.value = new SimpleResult(scf * result.value.fx());
			i__1 = n;
			for(int i = 1; i <= i__1; i++)
				df[i] = scf * df[i];

		}
		if(m != 0)
		{
			i__1 = m;
			for(int j = 1; j <= i__1; j++)
			{
				double d__1 = g[j];
				if(Math.abs(d__1) >= scbou)
					lscg = 1;
			}

			if(lscg != 0)
			{
				i__1 = m;
				for(int j = 1; j <= i__1; j++)
				{
					if(scbou > ze)
					{
						double d__2 = on;
						double d__1 = g[j];
						double d__3 = Math.sqrt(Math.abs(d__1));
						scg[j] = on / Math.max(d__2, d__3);
					}
					g[j] = scg[j] * g[j];
					int i__2 = n;
					for(int i = 1; i <= i__2; i++)
						dg[(j + i * dg_dim1) - dg_offset] = scg[j] * dg[(j + i * dg_dim1) - dg_offset];

				}

			}
		}
		nfunc++;
		ngrad++;
		dclf[n1] = ze;
		df[n1] = ze;
		i__1 = n;
		for(int i = 1; i <= i__1; i++)
		{
			del[i] = -df[i];
			dcl[(n1 + i * dcl_dim1) - dcl_offset] = ze;
			dcl[(i + n1 * dcl_dim1) - dcl_offset] = ze;
		}

		dcl[(n1 + n1 * dcl_dim1) - dcl_offset] = zefac;
		i__1 = n;
		for(int i = 1; i <= i__1; i++)
		{
			dclf[i] = df[i];
			cd[i] = on;
			int i__2 = n;
			for(int j = 1; j <= i__2; j++)
				dcl[(i + j * dcl_dim1) - dcl_offset] = ze;

			dcl[(i + i * dcl_dim1) - dcl_offset] = on;
		}

		i__1 = mnn;
		for(int j = 1; j <= i__1; j++)
		{
			rpen[j] = rpens;
			vmu[j] = ze;
		}

		int mer1m = 3;
		phi_a[0] = phi;
		merit_(mer1m, m, me, mmax, mnn, nmnn, acc, rpen, result, df, g, dg, vmu, u, task, phi_a, dphi, active, wa, index);
		phi = phi_a[0];
		do
		{
			lline = 0;
			if(lscf != 0)
				result.value = new SimpleResult(result.value.fx() / scf);
			if(lscf != 0)
				result.value  = new SimpleResult(result.value.fx() * scf);;
			if(m != 0 && (lscf != 0 || lscg != 0))
			{
				i__1 = m;
				for(int j = 1; j <= i__1; j++)
				{
					if(lscf != 0)
						vmu[j] /= scf;
					if(lscg != 0)
					{
						vmu[j] *= scg[j];
						g[j] /= scg[j];
					}
				}

			}
			ior = shop_(task, result, u, mnn, g, m, v, w, iter, nfunc, ngrad, nql, ifail, ifail1, iflis, logger);
			int L126 = 1;
			if(ior != 19)
			{
				if(m != 0 && (lscf != 0 || lscg != 0))
				{
					i__1 = m;
					for(int j = 1; j <= i__1; j++)
					{
						if(lscf != 0)
							vmu[j] *= scf;
						if(lscg != 0)
						{
							vmu[j] /= scg[j];
							g[j] *= scg[j];
						}
					}

				}
				if(++iter >= maxit)
				{
					ifail = 1;
				} else
				{
					i__1 = n;
					for(int i = 1; i <= i__1; i++)
					{
						dclf[i] = df[i];
						v[i] = task.domain().min[i - 1] - result.point.x[i - 1];
						w[i] = task.domain().max[i - 1] - result.point.x[i - 1];
					}

					ifail1 = iter;
					if(lrest != 0 || lalsd != 0)
						ifail1 = 1;
					ifail1 = ql_(m, me, mmax, n, nmax, mnn, dcl, dclf, dg, g, v, w, del, u, ifail1, lwaql, iw, liwql);
					del[n1] = ze;
					nql++;
					lrest = 0;
					if(ifail1 == 0)
						L126 = 0;
					else
					if(iter != 1)
					{
						double d__1 = dbd * dfdel;
						double fact = (tw * Math.abs(d__1)) / (Math.sqrt(dbd) * (on - del[n1]));
						fact *= fact;
						dcl11 = Math.max(zefac, fact);
						dcl[(n1 + n1 * dcl_dim1) - dcl_offset] = Math.min(zefacu, dcl11);
					}
				}
			}
			int L14 = 2;
			int L18 = 2;
			while(L14 != 0) 
			{
				int L90 = 1;
				int L19 = 1;
				int L197 = 1;
label0:
				while(L90 != 0) 
				{
					int L154 = 1;
					int L28;
label1:
					for(L28 = 1; L154 != 0 && L14 != 1;)
					{
						int L127 = 1;
						if(L126 != 0 && L18 != 1)
						{
							i__1 = n;
							for(int i = 1; i <= i__1; i++)
								del[i] = ze;

							del[n1] = on;
							if(m != 0)
							{
								i__1 = m;
								for(int j = 1; j <= i__1; j++)
								{
									dg[(j + n1 * dg_dim1) - dg_offset] = -g[j];
									if(active[j] == 0)
										dg[(j + n1 * dg_dim1) - dg_offset] = ze;
								}

							}
							v[n1] = ze;
							w[n1] = on;
							ifail1 = -iter;
							if(lrest == 0 || lalsd != 0)
								ifail1 = -1;
							ifail1 = ql_(m, me, mmax, n1, nmax, mnn2, dcl, dclf, dg, g, v, w, del, u, ifail1, lwaql, iw, liwql);
							nql++;
							mn1 = m + n1 + 1;
							mnn1 = m + n1 + n;
							lrest = 1;
							if(ifail1 != 0)
							{
								ifail = ifail1 + 10;
								L90 = 0;
							}
						}
						int L151 = 2;
label2:
						while(L151 != 0) 
						{
							if(L90 != 0 || L151 != 1 || L18 == 1)
							{
								if(L126 != 0 || L151 == 1 && L18 != 1)
								{
									if(L151 != 1)
									{
										i__1 = mnn1;
										for(int i = mn1; i <= i__1; i++)
											u[i - 1] = u[i];

										double sdcl11 = dcl[(n1 + n1 * dcl_dim1) - dcl_offset];
										dcl11 = dcl[(n1 + n1 * dcl_dim1) - dcl_offset];
									}
									if(L151 != 1 || del[n1] < delta)
									{
										L126 = 0;
									} else
									{
										if(L151 != 1)
										{
											dcl[(n1 + n1 * dcl_dim1) - dcl_offset] = dcl11 * rpeno;
											dcl[(n1 + n1 * dcl_dim1) - dcl_offset] *= rpeno;
											if(dcl11 < zefacu)
												continue;
										}
										lalsd = 1;
										mer1m = 4;
										phi_a[0] = phi;
										merit_(mer1m, m, me, mmax, mnn, nmnn, acc, rpen, result, df, g, dg, vmu, u, task, phi_a, dphi, active, wa, index);
										phi = phi_a[0];
										i__1 = n;
										for(int i = 1; i <= i__1; i++)
											dclf[i] = dphi[i];

										ifail1 = 1;
										int ipql1 = 0;
										ifail1 = ql_(ipql1, ipql1, mmax, n, nmax, n2, dcl, dclf, dg, g, v, w, del, u, ifail1, lwaql, iw, liwql);
									}
								}
								if(L126 != 0 && L18 != 1 && ifail1 > 0)
								{
									ifail = ifail1 + 10;
								} else
								{
									if(L18 != 1)
									{
										if(L126 != 0)
										{
											if(m != 0)
											{
												i__1 = n2;
												for(int i = 1; i <= i__1; i++)
												{
													int i1 = i - 1;
													u[mnn - i1] = u[n2 - i1];
												}

												i__1 = m;
												for(int j = 1; j <= i__1; j++)
													u[j] = vmu[j] - dphi[n + j];

											}
										} else
										{
											lalsd = 0;
										}
										alpham = of;
										xnm = ze;
										delnm = ze;
										i__1 = n;
										for(int i = 1; i <= i__1; i++)
										{
											if(w[i] < del[i])
												del[i] = w[i];
											if(v[i] > del[i])
												del[i] = v[i];
											double d__1 = del[i];
											double uad = Math.abs(d__1);
											if(del[i] > uf)
												alpham = Math.min(alpham, w[i] / del[i]);
											if(del[i] < -uf)
												alpham = Math.min(alpham, v[i] / del[i]);
											d__1 = result.point.x[i - 1];
											double d__2 = Math.abs(d__1);
											xnm = Math.max(d__2, xnm);
											delnm = Math.max(uad, delnm);
										}

										alpham = Math.max(on, alpham);
										alpham = Math.min(alpham, alm);
									}
									L18 = 2;
									i__1 = n;
									for(int i = 1; i <= i__1; i++)
									{
										double uad = df[i];
										if(lalsd != 0)
											uad = dphi[i];
										dla[i] = uad - u[m + i] - u[mn + i];
									}

									if(m != 0 && lalsd == 0)
									{
										i__1 = m;
										for(int j = 1; j <= i__1; j++)
											if(u[j] != ze)
											{
												int i__2 = n;
												for(int i = 1; i <= i__2; i++)
													dla[i] -= dg[(j + i * dg_dim1) - dg_offset] * u[j];

											}

									}
									if(lline != 0)
									{
										L90 = 0;
										L19 = 0;
										continue label0;
									}
									dfdel = ze;
									double dlan = ze;
									i__1 = n;
									for(int i = 1; i <= i__1; i++)
									{
										dfdel += df[i] * del[i];
										dlaold[i] = dla[i];
										double d__2 = dlan;
										double d__1 = dla[i];
										double d__3 = Math.abs(d__1);
										dlan = Math.max(d__2, d__3);
										xold[i] = result.point.x[i - 1];
									}

									i__1 = mnn;
									for(int j = 1; j <= i__1; j++)
										vmuold[j] = vmu[j];

									dbd = ze;
									i__1 = n;
									double sum;
									for(int i = 1; i <= i__1; i++)
									{
										sum = ze;
										int i__2 = n;
										for(int j = 1; j <= i__2; j++)
											sum += dcl[(i + j * dcl_dim1) - dcl_offset] * del[j];

										dbd += sum * del[i];
										bdel[i] = sum;
									}

									double sres = ze;
									sum = Math.abs(dfdel);
									if(lscf != 0)
										sum /= scf;
									if(m != 0)
									{
										i__1 = m;
										for(int j = 1; j <= i__1; j++)
										{
											double d__1 = g[j];
											double uad = Math.abs(d__1);
											if(lscg != 0)
												uad /= scg[j];
											if(j <= me || g[j] < ze)
												sres += uad;
											sum += Math.abs(u[j] * g[j]);
										}

									}
									i__1 = n;
									int L59 = 0;
									for(int i = 1; i <= i__1; i++)
										sum = sum + Math.abs(u[m + i] * v[i]) + Math.abs(u[mn + i] * w[i]);

									while(dbd < uf) 
									{
										if(sres < sqacc)
										{
											L59 = 1;
											break;
										}
										if(dbd > ze)
										{
											L127 = 0;
											break;
										}
										if(lalsd == 0)
										{
											L151 = 1;
										} else
										{
											ifail = 7;
											L90 = 0;
											break;
										}
										continue label2;
									}
									if(L90 != 0 && L127 != 0)
									{
										if(L59 == 0 && (sum >= acc || sres > sqacc))
											L127 = 0;
										else
										if(L59 == 0 && dlan > Math.sqrt(sqacc) && dbd > acc && ++nopt < 3)
											L127 = 0;
										if(L127 != 0)
											ifail = 0;
									}
								}
							}
							if(L127 != 0)
							{
								if(lscf != 0)
									result.value = new SimpleResult(result.value.fx() / scf);
								if(m == 0 || lscf == 0 && lscg == 0)
									return result;
								i__1 = m;
								for(int j = 1; j <= i__1; j++)
								{
									if(lscf != 0)
										u[j] /= scf;
									if(lscg != 0)
									{
										u[j] *= scg[j];
										g[j] /= scg[j];
									}
								}

								return result;
							}
							for(int L99 = 0; L99 == 0;)
							{
								if(lalsd == 0)
								{
									wa[1] = dbd;
									wa[2] = del[n1];
									wa[3] = rpenu;
									wa[4] = iter;
									mer1m = 2;
									phi_a[0] = phi;
									merit_(mer1m, m, me, mmax, mnn, nmnn, acc, rpen, result, df, g, dg, vmu, u, task, phi_a, dphi, active, wa, index);
									phi = phi_a[0];
								} else
								{
									double sum = ze;
									i__1 = n;
									for(int i = 1; i <= i__1; i++)
										sum = sum + dphi[i] * del[i] + Math.abs(u[m + i] * v[i]) + Math.abs(u[mn + i] * w[i]);

									if(sum <= Math.sqrt(sqacc))
									{
										i__1 = mnn;
										for(int j = 1; j <= i__1; j++)
										{
											double d__1 = zefacu;
											double d__2 = rpen[j] * rpeno;
											rpen[j] = Math.min(d__1, d__2);
										}

										mer1m = 4;
										phi_a[0] = phi;
										merit_(mer1m, m, me, mmax, mnn, nmnn, acc, rpen, result, df, g, dg, vmu, u, task, phi_a, dphi, active, wa, index);
										phi = phi_a[0];
									}
									L99 = 1;
								}
								break;
							}

							for(int L95 = 1; L95 != 0;)
							{
								mer1m = 3;
								int mer2m = 4;
								phi_a[0] = phi;
								merit_(mer1m, m, me, mmax, mnn, nmnn, acc, rpen, result, df, g, dg, vmu, u, task, phi_a, dphi, active, wa, index);
								phi = phi_a[0];
								if(lalsd == 0)
								{
									phi_a[0] = phi;
									merit_(mer2m, m, me, mmax, mnn, nmnn, acc, rpen, result, df, g, dg, vmu, u, task, phi_a, dphi, active, wa, index);
									phi = phi_a[0];
								}
								prod = ze;
								i__1 = n;
								for(int i = 1; i <= i__1; i++)
									prod += dphi[i] * del[i];

								i__1 = mnn;
								for(int j = 1; j <= i__1; j++)
									prod += dphi[j + n] * (u[j] - vmu[j]);

								double phiold = phi;
								if(prod < ze)
								{
									L28 = 0;
									L154 = 0;
									break label1;
								}
								double rpmax = ze;
								i__1 = mnn;
								for(int j = 1; j <= i__1; j++)
								{
									rpen[j] *= rpeno;
									double d__1 = rpmax;
									double d__2 = rpen[j];
									rpmax = Math.max(d__1, d__2);
								}

								if(rpmax >= rpenu)
								{
									L95 = 0;
									break;
								}
							}

							if(lalsd == 0)
							{
								if(lrest == 0 || dbd < acc)
								{
									L151 = 1;
								} else
								{
									dcl11 = dcl[(n1 + n1 * dcl_dim1) - dcl_offset];
									if(dcl11 >= zefacu)
									{
										L151 = 1;
									} else
									{
										dcl11 *= rpeno;
										dcl11 *= rpeno;
										dcl[(n1 + n1 * dcl_dim1) - dcl_offset] = dcl11;
										L154 = 1;
									}
								}
								continue;
							}
							L151 = 0;
							break;
						}
						L154 = 0;
						break;
					}

					if(L14 != 1)
					{
						if(L28 != 0)
						{
							ifail = 2;
							L90 = 1;
							continue;
						}
						wa[6] = xnm;
						wa[7] = delnm;
						lbest = 0;
						iflise = 0;
					}
					L14 = 2;
					phi_a[0] = alphao;
					phi_a[1] = prod;
					phi_a[2] = iline;
					phi_a[3] = iflise;
					phi_a[4] = wa[6];
					phi_a[5] = wa[7];
					linsea_(phi_a, alpham, phi, amue, beta, maxfun);
					alphao = phi_a[0];
					prod = phi_a[1];
					iline = (int)phi_a[2];
					iflise = (int)phi_a[3];
					wa[6] = phi_a[4];
					wa[7] = phi_a[5];
					if(iflise <= -2)
					{
						lbest = 1;
						fbest = result.value.fx();
						if(m == 0)
						{
							L14 = 1;
							L90 = 1;
							continue;
						}
						i__1 = m;
						for(int j = 1; j <= i__1; j++)
							gbest[j] = g[j];

					}
					i__1 = n;
					for(int i = 1; i <= i__1; i++)
						result.point.x[i - 1] = xold[i] + alphao * del[i];

					i__1 = mnn;
					for(int j = 1; j <= i__1; j++)
						vmu[j] = vmuold[j] + alphao * (u[j] - vmuold[j]);

					if(iflise == 0)
					{
						L19 = 1;
						L90 = 0;
						break;
					}
					if(iflise != 1)
					{
						if(iflise <= 1)
						{
							L197 = 0;
							L19 = 1;
							L90 = 0;
							break;
						}
						ifail = iflise + 1000;
						L90 = 1;
					} else
					{
						ifail = 4;
						L90 = 1;
					}
				}
				if(L19 != 0)
				{
					int L17 = 1;
					if(L197 != 0)
					{
						lline = 1;
						if(lbest == 0)
						{
							L17 = 0;
						} else
						{
							result.value = new SimpleResult(fbest);
							if(m == 0)
							{
								L17 = 0;
							} else
							{
								i__1 = m;
								for(int j = 1; j <= i__1; j++)
									g[j] = gbest[j];

							}
						}
					}
					if(L17 != 0)
					{
						L197 = 1;
						func_(m, mmax, g, result, task);
						if(lscf != 0)
							result.value = new SimpleResult(result.value.fx() * scf);
						if(m != 0 && lscg != 0)
						{
							i__1 = m;
							for(int j = 1; j <= i__1; j++)
								g[j] = scg[j] * g[j];

						}
						nfunc++;
						mer1m = 3;
						phi_a[0] = phi;
						merit_(mer1m, m, me, mmax, mnn, nmnn, acc, rpen, result, df, g, dg, vmu, u, task, phi_a, dphi, active, wa, index);
						phi = phi_a[0];
						if(lline == 0)
						{
							L14 = 1;
							continue;
						}
					}
					L17 = 1;
					mer1m = 1;
					phi_a[0] = phi;
					merit_(mer1m, m, me, mmax, mnn, nmnn, acc, rpen, result, df, g, dg, vmu, u, task, phi_a, dphi, active, wa, index);
					phi = phi_a[0];
					if(lscf != 0)
						result.value = new SimpleResult(result.value.fx() / scf);
					if(m != 0 && lscg != 0)
					{
						i__1 = m;
						for(int j = 1; j <= i__1; j++)
							g[j] /= scg[j];

					}
					grad_(m, mmax, result, g, df, dg, active, task);
					ngrad++;
					if(lscf != 0)
					{
						result.value = new SimpleResult(result.value.fx() * scf);
						i__1 = n;
						for(int i = 1; i <= i__1; i++)
							df[i] = scf * df[i];

					}
					if(m != 0 && lscg != 0)
					{
						i__1 = m;
						for(int j = 1; j <= i__1; j++)
						{
							g[j] *= scg[j];
							if(active[j] != 0)
							{
								int i__2 = n;
								for(int i = 1; i <= i__2; i++)
									dg[(j + i * dg_dim1) - dg_offset] *= scg[j];

							}
						}

					}
					if(lline != 0)
					{
						L18 = 1;
						L14 = 2;
					} else
					{
						mer1m = 4;
						phi_a[0] = phi;
						merit_(mer1m, m, me, mmax, mnn, nmnn, acc, rpen, result, df, g, dg, vmu, u, task, phi_a, dphi, active, wa, index);
						phi = phi_a[0];
						prod = ze;
						i__1 = n;
						for(int i = 1; i <= i__1; i++)
							prod += dphi[i] * del[i];

						i__1 = mnn;
						for(int j = 1; j <= i__1; j++)
							prod += dphi[n + j] * (u[j] - vmuold[j]);

						L14 = 1;
					}
					continue;
				}
				L14 = 0;
				break;
			}
			double edel = ze;
			dbd = dbd * alphao * alphao;
			i__1 = n;
			for(int i = 1; i <= i__1; i++)
			{
				bdel[i] *= alphao;
				eta[i] = dla[i] - dlaold[i];
				edel += alphao * del[i] * eta[i];
			}

			double dbd1 = dbdfac * dbd;
			if(edel < dbd1)
			{
				double theta = (dbd - dbd1) / (dbd - edel);
				double theta1 = on - theta;
				i__1 = n;
				for(int i = 1; i <= i__1; i++)
					eta[i] = theta * eta[i] + theta1 * bdel[i];

				edel = dbd1;
			}
			double dbdi = Math.sqrt(on / dbd);
			double edeli = Math.sqrt(on / edel);
			i__1 = n;
			for(int i = 1; i <= i__1; i++)
			{
				bdel[i] = dbdi * bdel[i];
				eta[i] = edeli * eta[i];
			}

			i__1 = n;
			for(int i = 1; i <= i__1; i++)
			{
				int i__2 = n;
				for(int j = 1; j <= i__2; j++)
					dcl[(i + j * dcl_dim1) - dcl_offset] = (dcl[(i + j * dcl_dim1) - dcl_offset] + eta[i] * eta[j]) - bdel[i] * bdel[j];

			}

		} while(true);
	}

	private Result nlpql_(int maxit, int m, int me, Result result, Task task, int ifail, int lwa, 
			int lkwa, short index[], int lactiv, short active[], ResultLogger logger)
	{
		double acc = 9.9999999999999995E-08D;
		double scbou = 1000D;
		int m1 = Math.max(1, m);
		int n1 = result.point.x.length + 1;
		int maxfun = 10;
		int mnn1 = m1 + n1 + n1;
		int mnn2 = m + n1 + n1;
		int ig = 1;
		int idf = ig + m1;
		int idg = idf + n1;
		int iu = idg + m1 * n1;
		int idcl = iu + mnn2;
		int icd = idcl + n1 * n1;
		int iwa = icd + n1;
		int lwa1 = (lwa - iwa) + 1;
		double g[] = new double[m1 + 1];
		double df[] = new double[n1 + 1];
		double dg[] = new double[m1 * n1 + 1];
		double u[] = new double[mnn2 + 1];
		double c[] = new double[n1 * n1 + 1];
		double d[] = new double[n1 + 1];
		return nlpql1_(m, me, m1, n1, mnn2, result, g, df, dg, u, task, c, d, acc, scbou, maxfun, maxit, ifail, lwa1, lkwa, active, lactiv, index, logger);
	}

	private int ql_(int m, int me, int mmax, int n, int nmax, int mnn, double c[], 
			double d[], double a[], double b[], double xl[], double xu[], double x[], double u[], 
			int ifail, int lwar, int iwar[], int liwar)
	{
		double diag = 0.0D;
		double zero = 0.0D;
		int nact[] = new int[1];
		int info[] = new int[1];
		int mn = m + n;
		int inw1 = nmax + 1;
		int inw2 = inw1 + mmax;
		double war_1[] = new double[nmax + 1];
		double war_inw1[] = new double[mmax + 1];
		double war_inw2[] = new double[(lwar - nmax - mmax) + 1];
		int i__1;
		int in;
		if(m > 0)
		{
			in = inw1;
			i__1 = m;
			for(int j = 1; j <= i__1; j++)
				war_inw1[j] = -b[j];

		}
		int lw = (nmax << 1) * nmax + (nmax << 3) + m;
		i__1 = n;
		for(int i = 1; i <= i__1; i++)
			war_1[i] = d[i];

		zqpcvx_(n, m, me, mmax, mn, nmax, a, war_inw1, war_1, c, xl, xu, x, nact, iwar, info, diag, war_inw2, lw);
		ifail = 0;
		if(info[0] < 0)
		{
			ifail = Math.abs(info[0]) + 10;
			i__1 = nact[0];
			for(int i = 1; i <= i__1; i++)
			{
				int i77 = (inw2 - 1) + i;
			}

			return ifail;
		}
		i__1 = mnn;
		for(int j = 1; j <= i__1; j++)
			u[j] = zero;

		in = inw2 - 1;
		i__1 = nact[0];
		for(int i = 1; i <= i__1; i++)
		{
			int j = iwar[i];
			u[j] = war_inw2[i];
		}

		return ifail;
	}

	private double r1mach(int i)
	{
		switch(i)
		{
		case 1: // '\001'
			return Double.MIN_VALUE;

		case 2: // '\002'
			return 1.7976931348623157E+308D;

		case 3: // '\003'
		case 4: // '\004'
			return 1E-08D;
		}
		System.out.println("error: r1mach failed...");
		return 0.0D;
	}

	public Result run(ResultLogger logger, Task task)
	{
		Domain domain = task.domain();
		counter = 0;
		Result result = new Result(counter, task.domain().defaultPoint, task.f(task.domain().defaultPoint));
		if(result.value.fx() <= 0.0D)
		{
			result.value = new SimpleResult(0.5D);
			logger.log(result);
		}
		int ifail = 0;
		int mmax = Math.max(1, super.MParameter);
		int lwa = 1000;
		int lkwa = 100;
		int lactiv = 100;
		short active[] = new short[lactiv];
		short index[] = new short[mmax + 1];
		boolean _tmp = super.MParameter != 0 && super.MParameter != super.MEParameter;
		Result res = nlpql_(super.iterations, super.MParameter, super.MEParameter, result, task, ifail, lwa, lkwa, index, lactiv, active, logger);
		task.domain().defaultPoint = res.point;
		return res;
	}

	private int shop_(Task task, Result result, double u[], int mnn, double g[], int m, double v[], 
			double w[], int iter, int nfunc, int ngrad, int nql, int ifail, int ifail1, 
			int iflis, ResultLogger logger)
	{
		Point point = new Point(result.point);
		Result rest = new Result(counter++, point, task.f(point));
		logger.log(rest);
		return 20;
	}

	private int zqpcvx_(int n, int m, int meq, int mmax, int mn, int nmax, double a[], 
			double b[], double grad[], double g[], double xl[], double xu[], double x[], int nact[], 
			int iact[], int info[], double diag, double w[], int lw)
	{
		double onha = 1.5D;
		double xmag = 0.0D;
		double temp = 0.0D;
		double zero = 0.0D;
		double vfact = 1.0D;
		double xmagr = 0.01D;
		double ratio = zero;
		double vsmall = 1E-10D;
		double one = 1.0D;
		double res = zero;
		double two = 2D;
		double diagr = two;
		int iflag = 1;
		int ifinc = 3;
		int kfinc = Math.max(10, n);
		int kdrop = 0;
		int knext = m;
		int iwz = nmax;
		int iwr = iwz + nmax * nmax;
		int iww = iwr + (nmax * (nmax + 3)) / 2;
		int iwd = iww + nmax;
		int iwx = iwd + nmax;
		int iwa = iwx + nmax;
		int iws = iww - n;
		int is = iws;
		int g_dim1 = nmax;
		int g_offset = g_dim1 + 1;
		int a_dim1 = mmax;
		int a_offset = a_dim1 + 1;
		nact[0] = 0;
		int i__1;
		int i__2;
		if(m > 0)
		{
			i__1 = m;
			for(int k = 1; k <= i__1; k++)
			{
				double sum = zero;
				i__2 = n;
				for(int i = 1; i <= i__2; i++)
				{
					double d__1 = a[(k + i * a_dim1) - a_offset];
					sum += d__1 * d__1;
				}

				if(sum <= zero)
				{
					sum = one / Math.sqrt(sum);
					int ia = iwa + k;
					w[ia] = sum;
				} else
				if(b[k] == zero)
				{
					int ia = iwa + k;
					w[ia] = sum;
				} else
				{
					info[0] = -k;
					if(k <= meq)
						return 0;
					if(b[k] <= 0.0D)
					{
						int ia = iwa + k;
						w[ia] = sum;
					} else
					{
						return 0;
					}
				}
			}

		}
		i__1 = n;
		for(int k = 1; k <= i__1; k++)
		{
			int ia = iwa + m + k;
			w[ia] = one;
		}

		diag = zero;
		i__1 = n;
		for(int i = 1; i <= i__1; i++)
		{
			int id = iwd + i;
			w[id] = g[(i + i * g_dim1) - g_offset];
			double d__1 = diag;
			double d__2 = vsmall - w[id];
			diag = Math.max(d__1, d__2);
			if(i != n)
			{
				int ii = i + 1;
				i__2 = n;
				for(int j = ii; j <= i__2; j++)
				{
					d__1 = w[id];
					d__2 = g[(j + j * g_dim1) - g_offset];
					double ga = -Math.min(d__1, d__2);
					d__1 = w[id] - g[(j + j * g_dim1) - g_offset];
					d__2 = g[(i + j * g_dim1) - g_offset];
					double gb = Math.abs(d__1) + Math.abs(d__2);
					if(gb > zero)
					{
						d__1 = g[(i + j * g_dim1) - g_offset];
						ga += (d__1 * d__1) / gb;
					}
					diag = Math.max(diag, ga);
				}

			}
		}

		int L70 = 2;
label0:
		while(L70 != 0) 
		{
			if(diag > zero || L70 == 1)
			{
				L70 = 2;
				diag = diagr * diag;
				i__1 = n;
				for(int i = 1; i <= i__1; i++)
				{
					int id = iwd + i;
					g[(i + i * g_dim1) - g_offset] = diag + w[id];
				}

			}
			int ir = iwr;
			i__1 = n;
			int L140 = 1;
			int j;
			for(j = 1; j <= i__1; j++)
			{
				int ira = iwr;
				int irb = ir + 1;
				i__2 = j;
				for(int i = 1; i <= i__2; i++)
				{
					temp = g[(i + j * g_dim1) - g_offset];
					if(i != 1)
					{
						int i__3 = ir;
						for(int k = irb; k <= i__3; k++)
							temp -= w[k] * w[++ira];

					}
					ir++;
					ira++;
					if(i < j)
						w[ir] = temp / w[ira];
				}

				if(temp < vsmall)
				{
					L140 = 0;
					break;
				}
				w[ir] = Math.sqrt(temp);
			}

			if(L140 == 0)
			{
				w[j] = one;
				double sumx = one;
				int k = j;
				for(int L150 = 1; L150 != 0;)
				{
					double sum = zero;
					int ira = ir - 1;
					i__1 = j;
					for(int i = k; i <= i__1; i++)
					{
						sum -= w[ira] * w[i];
						ira += i;
					}

					ir -= k;
					k--;
					w[k] = sum / w[ir];
					double d__1 = w[k];
					sumx += d__1 * d__1;
					if(k < 2)
					{
						diag = (diag + vsmall) - temp / sumx;
						L70 = 1;
						continue label0;
					}
				}

			}
			L70 = 0;
			break;
		}
		int nm = n - 1;
		i__2 = n;
		for(int i = 1; i <= i__2; i++)
		{
			int iz = iwz + i;
			if(i != 1)
			{
				i__1 = i;
				for(int j = 2; j <= i__1; j++)
				{
					w[iz] = zero;
					iz += n;
				}

			}
			int ir = iwr + (i + i * i) / 2;
			w[iz] = one / w[ir];
			if(i != n)
			{
				int iza = iz;
				i__1 = nm;
				for(int j = i; j <= i__1; j++)
				{
					ir += i;
					double sum = zero;
					int i__3 = iz;
					int i__4 = n;
					int k = iza;
					while(i__4 >= 0 ? k <= i__3 || false : k >= i__3 || false) 
					{
						sum += w[k] * w[ir];
						ir++;
						k += i__4;
					}
					iz += n;
					w[iz] = -sum / w[ir];
				}

			}
		}

		int iterc = 1;
		int itref = 0;
		int jfinc = -kfinc;
		int L340 = 1;
		int L280 = 1;
		int L250 = 1;
		int L230 = 1;
		int L450 = 1;
label1:
		while(L250 != 0) 
		{
			if(L230 != 0)
			{
				iflag = 1;
				iws = iww - n;
				i__2 = n;
				for(int i = 1; i <= i__2; i++)
				{
					x[i] = zero;
					int iw = iww + i;
					w[iw] = grad[i];
					if(i <= nact[0])
					{
						w[i] = zero;
						is = iws + i;
						int k = iact[i];
						if(k <= m)
							w[is] = b[k];
						else
						if(k > mn)
						{
							int k1 = k - mn;
							w[is] = -xu[k1];
						} else
						{
							int k1 = k - m;
							w[is] = xl[k1];
						}
					}
				}

				xmag = zero;
				vfact = 1.0D;
				if(nact[0] <= 0)
					L340 = 0;
				else
					L280 = 0;
			}
			L230 = 0;
			if(L340 != 0 && L280 != 0 && L450 != 0)
			{
				iflag = 2;
				iws = iww - n;
				i__2 = n;
				for(int i = 1; i <= i__2; i++)
				{
					int iw = iww + i;
					w[iw] = grad[i];
					i__1 = n;
					for(int j = 1; j <= i__1; j++)
						w[iw] += g[(i + j * g_dim1) - g_offset] * x[j];

				}

			}
			double sum;
			if(nact[0] != 0 && L340 != 0 && L450 != 0)
			{
				if(L280 != 0)
				{
					i__2 = nact[0];
					for(int k = 1; k <= i__2; k++)
					{
						int kk = iact[k];
						is = iws + k;
						if(kk <= m)
						{
							w[is] = b[kk];
							i__1 = n;
							for(int i = 1; i <= i__1; i++)
							{
								int iw = iww + i;
								w[iw] -= w[k] * a[(kk + i * a_dim1) - a_offset];
								w[is] -= x[i] * a[(kk + i * a_dim1) - a_offset];
							}

						} else
						if(kk > mn)
						{
							int k1 = kk - mn;
							int iw = iww + k1;
							w[iw] += w[k];
							w[is] = -xu[k1] + x[k1];
						} else
						{
							int k1 = kk - m;
							int iw = iww + k1;
							w[iw] -= w[k];
							w[is] = xl[k1] - x[k1];
						}
					}

				}
				L280 = 1;
				int ir = iwr;
				int ip = iww + 1;
				int ipp = iww + n;
				int il = iws + 1;
				int iu = iws + nact[0];
				i__2 = iu;
				for(int i = il; i <= i__2; i++)
				{
					sum = zero;
					if(i != il)
					{
						int ju = i - 1;
						i__1 = ju;
						for(int j = il; j <= i__1; j++)
							sum += w[++ir] * w[j];

					}
					w[i] = (w[i] - sum) / w[++ir];
				}

				i__2 = n;
				for(int i = 1; i <= i__2; i++)
				{
					int iz = iwz + i;
					sum = zero;
					i__1 = iu;
					for(int j = il; j <= i__1; j++)
					{
						sum += w[j] * w[iz];
						iz += n;
					}

					x[i] += sum;
					i__1 = n;
					for(int j = 1; j <= i__1; j++)
					{
						int iw = iww + j;
						w[iw] += sum * g[(i + j * g_dim1) - g_offset];
					}

				}

			}
			L340 = 1;
			int jflag;
			if(L450 != 0)
			{
				int kflag = 1;
				int jl = iww + 1;
				int iz = iwz;
				i__2 = n;
				for(int i = 1; i <= i__2; i++)
				{
					is = iws + i;
					w[is] = zero;
					int iwwn = iww + n;
					i__1 = iwwn;
					for(int j = jl; j <= i__1; j++)
						w[is] += w[++iz] * w[j];

				}

				int L410 = 1;
				if(nact[0] != n)
				{
					int il = iws + nact[0] + 1;
					int iza = iwz + nact[0] * n;
					i__2 = n;
					for(int i = 1; i <= i__2; i++)
					{
						sum = zero;
						iz = iza + i;
						i__1 = iww;
						for(int j = il; j <= i__1; j++)
						{
							sum += w[iz] * w[j];
							iz += n;
						}

						x[i] -= sum;
					}

					info[0] = iterc;
					if(nact[0] == 0)
						L410 = 0;
				}
				if(L410 != 0)
				{
					int lflag = 3;
					int ir = iwr + (nact[0] + nact[0] * nact[0]) / 2;
					int i = nact[0];
					sum = zero;
					int L770_1 = 2;
					while(L770_1 != 0) 
					{
						int iw;
						if(L770_1 == 1)
						{
							int ira = ir - 1;
							sum = zero;
							i__2 = nact[0];
							for(int j = i; j <= i__2; j++)
							{
								iw = iww + j;
								sum += w[ira] * w[iw];
								ira += j;
							}

							ir -= i;
							i--;
						}
						iw = iww + i;
						is = iws + i;
						w[iw] = (w[is] - sum) / w[ir];
						if(i > 1)
						{
							L770_1 = 1;
							continue;
						}
						L770_1 = 0;
						break;
					}
					i__2 = nact[0];
					for(int k = 1; k <= i__2; k++)
					{
						int iw = iww + k;
						w[k] += w[iw];
					}

				}
				L410 = 1;
				jflag = 1;
				sum = zero;
				i__2 = n;
				for(int i = 1; i <= i__2; i++)
				{
					double d__3 = g[(i + i * g_dim1) - g_offset] * x[i];
					sum += Math.abs(x[i]) * vfact * Math.abs(grad[i]) + Math.abs(d__3);
				}

				xmag = Math.max(xmag, sum);
				if(iflag == itref)
					continue;
				kdrop = 0;
			}
			int ia;
			while(kdrop < nact[0] && L450 != 0) 
				if(w[++kdrop] < zero && iact[kdrop] > meq)
				{
					int nu = nact[0];
					int mflag = 1;
					ia = iwa + iact[kdrop];
					if(iact[kdrop] > mn)
						ia -= n;
					w[ia] = -w[ia];
					if(kdrop == nact[0])
					{
						nact[0]--;
					} else
					{
						int iz = iwz + kdrop * n;
						int ir = iwr + (kdrop + kdrop * kdrop) / 2;
						do
						{
							int ira = ir;
							ir = ir + kdrop + 1;
							double d__1 = w[ir - 1];
							double d__2 = w[ir];
							double d__3 = Math.abs(d__1);
							double d__4 = Math.abs(d__2);
							temp = Math.max(d__3, d__4);
							d__1 = w[ir - 1] / temp;
							d__2 = w[ir] / temp;
							sum = temp * Math.sqrt(d__1 * d__1 + d__2 * d__2);
							double ga = w[ir - 1] / sum;
							double gb = w[ir] / sum;
							i__2 = kdrop;
							int j = (ir + 1) - kdrop;
							for(int i = 1; i <= i__2; i++)
							{
								j = ++ira - kdrop;
								temp = w[ira];
								w[ira] = w[j];
								w[j] = temp;
							}

							w[ir] = zero;
							w[j] = sum;
							kdrop++;
							i__2 = nu;
							for(int i = kdrop; i <= i__2; i++)
							{
								temp = ga * w[ira] + gb * w[ira + 1];
								w[ira + 1] = ga * w[ira + 1] - gb * w[ira];
								w[ira] = temp;
								ira += i;
							}

							i__2 = n;
							for(int i = 1; i <= i__2; i++)
							{
								j = ++iz - n;
								temp = ga * w[j] + gb * w[iz];
								w[iz] = ga * w[iz] - gb * w[j];
								w[j] = temp;
							}

							iact[kdrop - 1] = iact[kdrop];
							w[kdrop - 1] = w[kdrop];
						} while(kdrop < nact[0]);
						nact[0]--;
					}
					continue label1;
				}
			L450 = 1;
			double cvmax = zero;
			if(m > 0)
			{
				i__2 = m;
				for(int k = 1; k <= i__2; k++)
				{
					ia = iwa + k;
					if(w[ia] > zero)
					{
						sum = -b[k];
						i__1 = n;
						for(int i = 1; i <= i__1; i++)
							sum += x[i] * a[(k + i * a_dim1) - a_offset];

						double sumx = -sum * w[ia];
						if(k <= meq)
							sumx = Math.abs(sumx);
						if(sumx > cvmax)
						{
							double d__1 = b[k];
							temp = Math.abs(d__1);
							i__1 = n;
							for(int i = 1; i <= i__1; i++)
							{
								d__1 = x[i] * a[(k + i * a_dim1) - a_offset];
								temp += Math.abs(d__1);
							}

							double tempa = temp + Math.abs(sum);
							if(tempa > temp)
							{
								temp += onha * Math.abs(sum);
								if(temp > tempa)
								{
									cvmax = sumx;
									res = sum;
									knext = k;
								}
							}
						}
					}
				}

			}
			i__2 = n;
			for(int k = 1; k <= i__2; k++)
			{
				short lower = 1;
				ia = iwa + m + k;
				if(w[ia] <= zero)
					continue;
				sum = xl[k] - x[k];
				if(sum < 0.0D)
				{
					sum = x[k] - xu[k];
					lower = 0;
				} else
				if(sum == 0.0D)
					continue;
				if(sum > cvmax)
				{
					cvmax = sum;
					res = -sum;
					knext = k + m;
					if(lower == 0)
						knext = k + mn;
				}
			}

			info[0] = iterc;
			if(cvmax <= vsmall)
			{
				if(iterc == 0)
				{
					L250 = 0;
					break;
				}
				jfinc = -1;
				if(++itref == 1)
					continue;
				L250 = 0;
				break;
			}
			int L530 = 1;
			if(++jfinc != 0)
				if(jfinc != ifinc)
				{
					L530 = 0;
				} else
				{
					double fdiff = zero;
					double fdiffa = zero;
					i__2 = n;
					for(int i = 1; i <= i__2; i++)
					{
						sum = two * grad[i];
						double sumx = Math.abs(sum);
						i__1 = n;
						int ix;
						for(int j = 1; j <= i__1; j++)
						{
							ix = iwx + j;
							temp = g[(i + j * g_dim1) - g_offset] * (w[ix] + x[j]);
							sum += temp;
							sumx += Math.abs(temp);
						}

						ix = iwx + i;
						double d__1 = x[i] - w[ix];
						fdiff += sum * (x[i] - w[ix]);
						fdiffa += sumx * Math.abs(d__1);
					}

					info[0] = 0;
					sum = fdiffa + fdiff;
					if(sum <= fdiffa)
					{
						if(iterc == 0)
						{
							L250 = 0;
							break;
						}
						jfinc = -1;
						if(++itref == 1)
							continue;
						L250 = 0;
						break;
					}
					temp = fdiffa + onha * fdiff;
					if(temp <= sum)
					{
						if(iterc == 0)
						{
							L250 = 0;
							break;
						}
						jfinc = -1;
						if(++itref == 1)
							continue;
						L250 = 0;
						break;
					}
					jfinc = 0;
				}
			if(L530 != 0)
			{
				i__2 = n;
				for(int i = 1; i <= i__2; i++)
				{
					int ix = iwx + i;
					w[ix] = x[i];
				}

			}
			iterc++;
			iws = iwr + (nact[0] + nact[0] * nact[0]) / 2;
			int L549 = 1;
			if(knext <= m)
			{
				i__2 = n;
				for(int i = 1; i <= i__2; i++)
				{
					int iw = iww + i;
					w[iw] = a[(knext + i * a_dim1) - a_offset];
				}

				L549 = 0;
			}
			int L550;
			for(L550 = 1; L549 != 0;)
			{
				i__2 = n;
				for(int i = 1; i <= i__2; i++)
				{
					int iw = iww + i;
					w[iw] = zero;
				}

				int k1 = knext - m;
				if(k1 <= n)
				{
					int iw = iww + k1;
					w[iw] = one;
					int iz = iwz + k1;
					i__2 = n;
					for(int i = 1; i <= i__2; i++)
					{
						is = iws + i;
						w[is] = w[iz];
						iz += n;
					}

					L550 = 0;
				} else
				{
					k1 = knext - mn;
					int iw = iww + k1;
					w[iw] = -one;
					int iz = iwz + k1;
					i__2 = n;
					for(int i = 1; i <= i__2; i++)
					{
						is = iws + i;
						w[is] = -w[iz];
						iz += n;
					}

					L550 = 0;
					L549 = 0;
				}
				break;
			}

			L549 = 1;
			if(L550 != 0)
			{
				int kflag = 2;
				int jl = iww + 1;
				int iz = iwz;
				i__2 = n;
				for(int i = 1; i <= i__2; i++)
				{
					is = iws + i;
					w[is] = zero;
					int iwwn = iww + n;
					i__1 = iwwn;
					for(int j = jl; j <= i__1; j++)
						w[is] += w[++iz] * w[j];

				}

			}
			double parnew = zero;
			int L580 = 1;
			int L570 = 0;
			int L640 = 1;
label2:
			while(L580 != 0) 
			{
				if(nact[0] == n || L570 != 0)
				{
					L570 = 0;
					int lflag = 1;
					int ir = iwr + (nact[0] + nact[0] * nact[0]) / 2;
					int i = nact[0];
					sum = zero;
					int L770_2 = 2;
					while(L770_2 != 0) 
					{
						int iw;
						if(L770_2 == 1)
						{
							int ira = ir - 1;
							sum = zero;
							i__2 = nact[0];
							for(int j = i; j <= i__2; j++)
							{
								iw = iww + j;
								sum += w[ira] * w[iw];
								ira += j;
							}

							ir -= i;
							i--;
						}
						iw = iww + i;
						is = iws + i;
						w[iw] = (w[is] - sum) / w[ir];
						if(i > 1)
						{
							L770_2 = 1;
							continue;
						}
						L770_2 = 0;
						break;
					}
					int ip = iww + 1;
					int ipp = iww + nact[0];
					kdrop = 0;
					i__2 = nact[0];
					for(int k = 1; k <= i__2; k++)
						if(iact[k] > meq)
						{
							int iw = iww + k;
							if(res * w[iw] < zero)
							{
								temp = w[k] / w[iw];
								if(kdrop == 0)
								{
									kdrop = k;
									ratio = temp;
								} else
								if(Math.abs(temp) < Math.abs(ratio))
								{
									kdrop = k;
									ratio = temp;
								}
							}
						}

				} else
				{
					int nu = n;
					int nflag = 1;
					int iz = iwz + nu * n;
					iz -= n;
					do
					{
						is = iws + nu;
						if(--nu == nact[0])
							break;
						if(w[is] == zero)
						{
							iz -= n;
						} else
						{
							double d__1 = w[is - 1];
							double d__2 = w[is];
							double d__3 = Math.abs(d__1);
							double d__4 = Math.abs(d__2);
							temp = Math.max(d__3, d__4);
							d__1 = w[is - 1] / temp;
							d__2 = w[is] / temp;
							sum = temp * Math.sqrt(d__1 * d__1 + d__2 * d__2);
							double ga = w[is - 1] / sum;
							double gb = w[is] / sum;
							w[is - 1] = sum;
							i__2 = n;
							for(int i = 1; i <= i__2; i++)
							{
								int k = iz + n;
								temp = ga * w[iz] + gb * w[k];
								w[k] = ga * w[k] - gb * w[iz];
								w[iz] = temp;
								iz--;
							}

						}
					} while(true);
					is = iws + nact[0];
					if(nact[0] == 0)
					{
						L580 = 0;
						L640 = 0;
						break;
					}
					double suma = zero;
					double sumb = zero;
					double sumc = zero;
					iz = iwz + nact[0] * n;
					i__2 = n;
					for(int i = 1; i <= i__2; i++)
					{
						int iw = iww + i;
						double d__1 = w[iw] * w[iz];
						suma += w[iw] * w[++iz];
						sumb += Math.abs(d__1);
						d__1 = w[iz];
						sumc += d__1 * d__1;
					}

					temp = sumb + Math.abs(suma) * 0.10000000000000001D;
					double tempa = sumb + Math.abs(suma) * 0.20000000000000001D;
					int lflag;
					if(temp <= sumb || tempa <= temp || sumb <= vsmall)
					{
						lflag = 1;
						L570 = 1;
						continue;
					}
					sumc = Math.sqrt(sumc);
					ia = iwa + knext;
					if(knext <= m)
						sumc /= w[ia];
					temp = sumc + Math.abs(suma) * 0.10000000000000001D;
					tempa = sumc + Math.abs(suma) * 0.20000000000000001D;
					if(temp <= sumc || tempa <= temp)
					{
						lflag = 4;
						int ir = iwr + (nact[0] + nact[0] * nact[0]) / 2;
						int i = nact[0];
						sum = zero;
						int L770_3 = 2;
						while(L770_3 != 0) 
						{
							int iw;
							if(L770_3 == 1)
							{
								int ira = ir - 1;
								sum = zero;
								i__2 = nact[0];
								for(int j = i; j <= i__2; j++)
								{
									iw = iww + j;
									sum += w[ira] * w[iw];
									ira += j;
								}

								ir -= i;
								i--;
							}
							iw = iww + i;
							is = iws + i;
							w[iw] = (w[is] - sum) / w[ir];
							if(i > 1)
							{
								L770_3 = 1;
								continue;
							}
							L770_3 = 0;
							break;
						}
					} else
					{
						L580 = 0;
						L640 = 0;
						break;
					}
					int ip;
					int ipp;
					if(knext <= m)
					{
						i__2 = n;
						for(int i = 1; i <= i__2; i++)
						{
							suma = a[(knext + i * a_dim1) - a_offset];
							sumb = Math.abs(suma);
							i__1 = nact[0];
							for(int k = 1; k <= i__1; k++)
							{
								int kk = iact[k];
								int iw = iww + k;
								temp = w[iw] * a[(kk + i * a_dim1) - a_offset];
								suma -= temp;
								sumb += Math.abs(temp);
							}

							if(suma <= vsmall)
								continue;
							temp = sumb + Math.abs(suma) * 0.10000000000000001D;
							tempa = sumb + Math.abs(suma) * 0.20000000000000001D;
							if(temp <= sumb || tempa <= temp)
								continue;
							is = iws + nact[0];
							L580 = 0;
							L640 = 0;
							break label2;
						}

						lflag = 1;
						ip = iww + 1;
						ipp = iww + nact[0];
						kdrop = 0;
						i__2 = nact[0];
						for(int k = 1; k <= i__2; k++)
							if(iact[k] > meq)
							{
								int iw = iww + k;
								if(res * w[iw] < zero)
								{
									temp = w[k] / w[iw];
									if(kdrop == 0)
									{
										kdrop = k;
										ratio = temp;
									} else
									if(Math.abs(temp) < Math.abs(ratio))
									{
										kdrop = k;
										ratio = temp;
									}
								}
							}

						L580 = 0;
						break;
					}
					int k1 = knext - m;
					if(k1 > n)
						k1 -= n;
					i__2 = n;
					for(int i = 1; i <= i__2; i++)
					{
						suma = zero;
						if(i == k1)
						{
							suma = one;
							if(knext > mn)
								suma = -one;
						}
						sumb = Math.abs(suma);
						i__1 = nact[0];
						for(int k = 1; k <= i__1; k++)
						{
							int kk = iact[k];
							if(kk > m)
							{
								kk -= m;
								temp = zero;
								if(kk == i)
									temp = w[iww + kk];
								kk -= n;
								if(kk == i)
									temp = -w[iww + kk];
							} else
							{
								int iw = iww + k;
								temp = w[iw] * a[(kk + i * a_dim1) - a_offset];
							}
							suma -= temp;
							sumb += Math.abs(temp);
						}

						temp = sumb + Math.abs(suma) * 0.10000000000000001D;
						tempa = sumb + Math.abs(suma) * 0.20000000000000001D;
						if(temp <= sumb || tempa <= temp)
							continue;
						is = iws + nact[0];
						L580 = 0;
						L640 = 0;
						break label2;
					}

					lflag = 1;
					ip = iww + 1;
					ipp = iww + nact[0];
					kdrop = 0;
					i__2 = nact[0];
					for(int k = 1; k <= i__2; k++)
						if(iact[k] > meq)
						{
							int iw = iww + k;
							if(res * w[iw] < zero)
							{
								temp = w[k] / w[iw];
								if(kdrop == 0)
								{
									kdrop = k;
									ratio = temp;
								} else
								if(Math.abs(temp) < Math.abs(ratio))
								{
									kdrop = k;
									ratio = temp;
								}
							}
						}

				}
				L580 = 0;
				break;
			}
			if(L640 != 0)
			{
				info[0] = -knext;
				if(kdrop == 0)
				{
					if(iterc == 0)
					{
						L250 = 0;
						break;
					}
					jfinc = -1;
					if(++itref == 1)
						continue;
					L250 = 0;
					break;
				}
				double parinc = ratio;
				parnew = parinc;
				i__2 = nact[0];
				for(int k = 1; k <= i__2; k++)
				{
					int iw = iww + k;
					w[k] -= parinc * w[iw];
					if(iact[k] > meq)
					{
						double d__1 = zero;
						double d__2 = w[k];
						w[k] = Math.max(d__1, d__2);
					}
				}

			}
			while(kdrop != 0 || L640 == 0) 
			{
				if(L640 != 0)
				{
					int nu = nact[0] + 1;
					int mflag = 2;
					ia = iwa + iact[kdrop];
					if(iact[kdrop] > mn)
						ia -= n;
					w[ia] = -w[ia];
					int iz;
					if(kdrop == nact[0])
					{
						nact[0]--;
					} else
					{
						iz = iwz + kdrop * n;
						int ir = iwr + (kdrop + kdrop * kdrop) / 2;
						for(int L810 = 1; L810 != 0;)
						{
							int ira = ir;
							ir = ir + kdrop + 1;
							double d__1 = w[ir - 1];
							double d__2 = w[ir];
							double d__3 = Math.abs(d__1);
							double d__4 = Math.abs(d__2);
							temp = Math.max(d__3, d__4);
							d__1 = w[ir - 1] / temp;
							d__2 = w[ir] / temp;
							sum = temp * Math.sqrt(d__1 * d__1 + d__2 * d__2);
							double ga = w[ir - 1] / sum;
							double gb = w[ir] / sum;
							i__2 = kdrop;
							int j = (ir + 1) - kdrop;
							for(int i = 1; i <= i__2; i++)
							{
								j = ++ira - kdrop;
								temp = w[ira];
								w[ira] = w[j];
								w[j] = temp;
							}

							w[ir] = zero;
							w[j] = sum;
							kdrop++;
							i__2 = nu;
							for(int i = kdrop; i <= i__2; i++)
							{
								temp = ga * w[ira] + gb * w[ira + 1];
								w[ira + 1] = ga * w[ira + 1] - gb * w[ira];
								w[ira] = temp;
								ira += i;
							}

							i__2 = n;
							for(int i = 1; i <= i__2; i++)
							{
								j = ++iz - n;
								temp = ga * w[j] + gb * w[iz];
								w[iz] = ga * w[iz] - gb * w[j];
								w[j] = temp;
							}

							iact[kdrop - 1] = iact[kdrop];
							w[kdrop - 1] = w[kdrop];
							if(kdrop >= nact[0])
							{
								nact[0]--;
								L810 = 0;
								break;
							}
						}

					}
					iws = iws - nact[0] - 1;
					nu = Math.min(n, nu);
					i__2 = nu;
					for(int i = 1; i <= i__2; i++)
					{
						is = iws + i;
						int j = is + nact[0];
						w[is] = w[j + 1];
					}

					int nflag = 2;
					iz = iwz + nu * n;
					iz -= n;
					do
					{
						is = iws + nu;
						if(--nu == nact[0])
							break;
						if(w[is] == zero)
						{
							iz -= n;
						} else
						{
							double d__1 = w[is - 1];
							double d__2 = w[is];
							double d__3 = Math.abs(d__1);
							double d__4 = Math.abs(d__2);
							temp = Math.max(d__3, d__4);
							d__1 = w[is - 1] / temp;
							d__2 = w[is] / temp;
							sum = temp * Math.sqrt(d__1 * d__1 + d__2 * d__2);
							double ga = w[is - 1] / sum;
							double gb = w[is] / sum;
							w[is - 1] = sum;
							i__2 = n;
							for(int i = 1; i <= i__2; i++)
							{
								int k = iz + n;
								temp = ga * w[iz] + gb * w[k];
								w[k] = ga * w[k] - gb * w[iz];
								w[iz] = temp;
								iz--;
							}

						}
					} while(true);
					is = iws + nact[0];
				}
				L640 = 1;
				double sumy = w[is + 1];
				double step = -res / sumy;
				double parinc = step / sumy;
				if(nact[0] != 0)
				{
					int lflag = 2;
					int ir = iwr + (nact[0] + nact[0] * nact[0]) / 2;
					int i = nact[0];
					sum = zero;
					int L770_4 = 2;
					while(L770_4 != 0) 
					{
						int iw;
						if(L770_4 == 1)
						{
							int ira = ir - 1;
							sum = zero;
							i__2 = nact[0];
							for(int j = i; j <= i__2; j++)
							{
								iw = iww + j;
								sum += w[ira] * w[iw];
								ira += j;
							}

							ir -= i;
							i--;
						}
						iw = iww + i;
						is = iws + i;
						w[iw] = (w[is] - sum) / w[ir];
						if(i > 1)
						{
							L770_4 = 1;
							continue;
						}
						L770_4 = 0;
						break;
					}
					int ip = iww + 1;
					int ipp = iww + nact[0];
					kdrop = 0;
					i__2 = nact[0];
					for(int k = 1; k <= i__2; k++)
						if(iact[k] > meq)
						{
							int iw = iww + k;
							if(res * w[iw] < zero)
							{
								temp = w[k] / w[iw];
								if(kdrop == 0)
								{
									kdrop = k;
									ratio = temp;
								} else
								if(Math.abs(temp) < Math.abs(ratio))
								{
									kdrop = k;
									ratio = temp;
								}
							}
						}

					if(kdrop != 0)
					{
						temp = one - ratio / parinc;
						if(temp <= zero)
							kdrop = 0;
						if(kdrop != 0)
						{
							step = ratio * sumy;
							parinc = ratio;
							res = temp * res;
						}
					}
				}
				int iwy = iwz + nact[0] * n;
				i__2 = n;
				for(int i = 1; i <= i__2; i++)
				{
					int iy = iwy + i;
					x[i] += step * w[iy];
				}

				parnew += parinc;
				if(nact[0] < 1)
					break;
				i__2 = nact[0];
				for(int k = 1; k <= i__2; k++)
				{
					int iw = iww + k;
					w[k] -= parinc * w[iw];
					if(iact[k] > meq)
					{
						double d__1 = zero;
						double d__2 = w[k];
						w[k] = Math.max(d__1, d__2);
					}
				}

			}
			nact[0]++;
			w[nact[0]] = parnew;
			iact[nact[0]] = knext;
			ia = iwa + knext;
			if(knext > mn)
				ia -= n;
			w[ia] = -w[ia];
			jflag = 2;
			sum = zero;
			i__2 = n;
			for(int i = 1; i <= i__2; i++)
			{
				double d__3 = g[(i + i * g_dim1) - g_offset] * x[i];
				sum += Math.abs(x[i]) * vfact * Math.abs(grad[i]) + Math.abs(d__3);
			}

			xmag = Math.max(xmag, sum);
			if(sum < xmagr * xmag)
				L230 = 1;
			else
			if(itref <= 0)
				L450 = 0;
		}
		i__2 = n;
		for(int i = 1; i <= i__2; i++)
		{
			int id = iwd + i;
			g[(i + i * g_dim1) - g_offset] = w[id];
		}

		return 0;
	}
}
