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

package drm.genetics;

import java.util.Random;
import java.util.Vector;

// Referenced classes of package drm.genetics:
//			Individual, Mutation

public abstract class AbstractMutation
	implements Mutation
{

	protected Random random;
	protected double percentage;
	private Vector randomNumbers;

	public AbstractMutation()
	{
		random = new Random();
		percentage = 0.01D;
		randomNumbers = new Vector();
	}

	public AbstractMutation(double percentage)
	{
		random = new Random();
		this.percentage = 0.01D;
		randomNumbers = new Vector();
		setPercentage(percentage);
	}

	public void setPercentage(double percentage)
	{
		this.percentage = percentage;
	}

	public double getPercentage()
	{
		return percentage;
	}

	public Individual mutate(Individual individ)
	{
		Individual ind = null;
		try
		{
			ind = (Individual)individ.getClass().newInstance();
			ind.accessGenome(individ.getGenome());
			mutateSame(ind);
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
		}
		return ind;
	}

	protected int[] randomNumbers(int max, int count)
	{
		if(randomNumbers.size() != max)
		{
			randomNumbers = new Vector(max);
			for(int i = 0; i < max; i++)
				randomNumbers.add(new Integer(i));

		}
		Vector num = new Vector(randomNumbers);
		int numbers[] = new int[count];
		for(int i = 0; i < count; i++)
			numbers[i] = ((Integer)num.remove(random.nextInt(num.size()))).intValue();

		return numbers;
	}
}
