// 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:   Subregion.java

package lt.ktu.gmj.methods;

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

// Referenced classes of package lt.ktu.gmj.methods:
//			Random

class Subregion
{

	Vector allPoints;
	double min[];
	double max[];
	double ray1;
	Point center;
	Task task;
	//double resultReg;
	IResult resultReg;
	Result r;
	Result result;

	public Subregion(Vector vector, Task task1, double d, int i, ResultLogger resultlogger, Domain domain, 
			Result result1)
	{
		result = result1;
		task = task1;
		resultReg = new SimpleResult(10000D);
		min = new double[((Point)vector.elementAt(0)).x.length];
		max = new double[((Point)vector.elementAt(0)).x.length];
		int j = 0;
		for(int k = 0; k < vector.size(); k++)
		{
			if(resultReg.fx() > task1.f((Point)vector.elementAt(k)).fx() )
				resultReg = task1.f((Point)vector.elementAt(k));
			j = k;
		}

		center = (Point)vector.elementAt(j);
		ray1 = d - ((Point)vector.elementAt(0)).distance(center);
		ray1 = d / 2D;
		System.out.println("Spindulys lygus" + ray1);
		setMinMax(center, ray1, domain);
		vector = new Vector();
		for(int l = 0; l < i; l++)
		{
			Random random = new Random(center, max, min);
			if(verify(random, domain))
			{
				vector.addElement(random);
				r = new Result(l, random, task1.f(random));
				resultlogger.log(r);
				if(r.value.fx() < result1.value.fx())
					result1 = r;
			}
		}

	}

	public Result getResult()
	{
		return result;
	}

	void setMinMax(Point point, double d, Domain domain)
	{
		for(int i = 0; i < point.x.length; i++)
		{
			System.out.println("domain.max[" + i + "]=" + domain.max[i] + " domain.min[" + i + "]=" + domain.min[i]);
			max[i] = point.x[i] + d;
			if(max[i] > domain.max[i])
				max[i] = domain.max[i];
			min[i] = point.x[i] - d;
			if(min[i] < domain.min[i])
				min[i] = domain.min[i];
			System.out.println("max[" + i + "]=" + max[i] + " min[" + i + "]=" + min[i]);
		}

		System.out.println("=================================");
	}

	boolean verify(Point point, Domain domain)
	{
		boolean flag = true;
		for(int i = 0; i < point.x.length; i++)
			if(domain.max[i] < point.x[i] || point.x[i] < domain.min[i])
				flag = false;

		return flag;
	}
}
