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

package lt.ktu.gmj.tasks;

import drm.genetics.simple.SimpleRunner;
import java.util.TreeSet;
import lt.ktu.HostNameRetriever;
import lt.ktu.gmj.*;
import lt.ktu.gmj.propertySheet.*;

// Referenced classes of package lt.ktu.gmj.tasks:
//			KnapGen2Domain, KnapGen2GenTask, KnapGen2Individual

public class KnapGen2 extends AbstractTask
{

	protected KnapGen2Domain domain;
	public String data_url;
	public double total_weight;
	public int iterations;
	public int mutationType;
	public double percentMutating;
	public int mutationLevel;
	public int crossoverType;
	public int crossoverStyle;
	public int crossoverLevel;
	protected SimpleRunner runner;
	protected KnapGen2GenTask task;

	public KnapGen2()
	{
		domain = new KnapGen2Domain();
		data_url = HostNameRetriever.getCodeBase() + "norveda.txt";
		total_weight = 10D;
		iterations = 10;
		mutationType = 0;
		percentMutating = 0.050000000000000003D;
		mutationLevel = 2;
		crossoverType = 0;
		crossoverStyle = 0;
		crossoverLevel = 2;
		task = null;
	}

	public Domain domain()
	{
		return domain;
	}

	protected void init()
	{
		runner = new SimpleRunner();
		task = new KnapGen2GenTask(data_url, total_weight, mutationType, percentMutating, mutationLevel, crossoverType, crossoverStyle, crossoverLevel);
	}

	public IResult f(Point p)
	{
		if(task == null)
			init();
		task.indCount = (int)p.x[0];
		runner.init(task);
		runner.setMutationProbability(p.x[1]);
		runner.setCrossoverProbability(p.x[2]);
		runner.setBestPassPercentage(p.x[3]);
		runner.step(iterations);
		KnapGen2Individual ind = (KnapGen2Individual)((TreeSet)runner.accessIndivids()).first();
		return new SimpleResult(-Math.max(0.0D, ind.getWeight()));
	}

	public void customize(PropertyManager manager)
	{
		manager.add(new DoubleProperty("Total Weight", new FieldProvider(this, "total_weight")));
		manager.add(new UrlProperty("URL of data file", new FieldProvider(this, "data_url")));
		manager.add(new IntProperty("Iterations", new FieldProvider(this, "iterations")));
		manager.add(new ChoiceProperty("Mutation type:", new FieldProvider(this, "mutationType"), new String[] {
			"Single gene mutation", "Simple partial mutation", "Searching best mutation"
		}));
		manager.add(new DoubleProperty("Mutating part", new FieldProvider(this, "percentMutating")));
		manager.add(new IntProperty("Mutation best search level", new FieldProvider(this, "mutationLevel")));
		manager.add(new ChoiceProperty("Crossover type:", new FieldProvider(this, "crossoverType"), new String[] {
			"Simple crossover", "Searching best crossover"
		}));
		manager.add(new ChoiceProperty("Crossover style:", new FieldProvider(this, "crossoverStyle"), new String[] {
			"Single point crossover", "Two points crossover", "Random crossover"
		}));
		manager.add(new IntProperty("Crossover best search level", new FieldProvider(this, "crossoverLevel")));
	}
}
