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

package drm.genetics.advanced;

import drm.genetics.Individual;
import drm.genetics.simple.SimpleCrossover;

public class BestSelCrossover extends SimpleCrossover
{

	protected int tries;

	public void setTries(int tries)
	{
		this.tries = tries;
	}

	public int getTries()
	{
		return tries;
	}

	public BestSelCrossover()
	{
		tries = 2;
	}

	public BestSelCrossover(int type)
	{
		super(type);
		tries = 2;
	}

	public BestSelCrossover(int type, int tries)
	{
		super(type);
		this.tries = 2;
		setTries(tries);
	}

	public void crossSame(Individual individ1, Individual individ2)
	{
		Individual ind1 = individ1;
		Individual ind2 = individ2;
		Individual rez;
		if(ind1.compareTo(ind2) > 0)
			rez = ind1.copy();
		else
			rez = ind2.copy();
		for(int i = 0; i < tries; i++)
		{
			super.crossSame(ind1, ind2);
			if(ind1.compareTo(ind2) > 0)
			{
				if(rez.compareTo(ind2) > 0)
					ind2 = rez;
				if(ind1.compareTo(rez) > 0)
					rez = ind1.copy();
			} else
			{
				if(rez.compareTo(ind1) > 0)
					ind1 = rez;
				if(ind2.compareTo(rez) > 0)
					rez = ind2.copy();
			}
		}

		individ1.accessGenome(ind1.getGenome());
		individ1.updateWeight();
		individ2.accessGenome(ind1.getGenome());
		individ2.updateWeight();
	}
}
