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

package lt.ktu.gmj.methods;

import drm.genetics.AbstractIndividual;
import drm.genetics.Individual;
import drm.genetics.simple.DoubleGene;
import java.util.Random;
import lt.ktu.gmj.*;

public class MethodGAIndividual extends AbstractIndividual
{

	protected Task task;
	protected Point point;
	protected Random random;

	public void setPoint(Point point)
	{
		this.point = new Point(point);
	}

	public Point getPoint()
	{
		return new Point(point);
	}

	public MethodGAIndividual()
	{
		random = new Random();
	}

	public void init(Task task)
	{
		this.task = task;
		Domain domain = task.domain();
		point = new Point(domain);
		genome = new DoubleGene[point.x.length];
		for(int i = 0; i < genome.length; i++)
			genome[i] = new DoubleGene(domain.min[i] + random.nextDouble() * (domain.max[i] - domain.min[i]), domain.min[i], domain.max[i]);

		weight = -task.f(new Point(point)).fx();
	}

	protected void updatePoint()
	{
		for(int i = 0; i < point.x.length; i++)
			point.x[i] = ((DoubleGene)genome[i]).get();

	}

	public double updateWeight()
	{
		updatePoint();
		weight = -task.f(new Point(point)).fx();
		return weight;
	}

	public Individual copy()
	{
		MethodGAIndividual ind = null;
		try
		{
			ind = new MethodGAIndividual();
			ind.task = task;
			ind.point = new Point(point);
			ind.accessGenome(getGenome());
			ind.weight = weight;
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
		}
		return ind;
	}
}
