/*
 * BaseFunctionFitness.java
 *
 * Created on March 25, 2006, 3:00 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package cz.pcland.ga.fitness;
import cz.pcland.ga.BaseIndividual;
import java.util.*;
import cz.pcland.functions.*;
/**
 *
 * @author petr
 */
public abstract class BaseFunctionFitness {
    FunctionInstance instance;
    
    /** Creates a new instance of BaseFunctionFitness */
    public BaseFunctionFitness() {
    }

    
    /**
     * Decodes value represented by Individual to some decimal number.
     * For example: binary to decimal or hamming to decimal order.
     */
    public abstract double decode(BaseIndividual str);
    
    /**
     * Converts some decinal value to the given interval stored in current instance of function.
     */
     public double convertValueToInterval(double decodedValue){
        double maxd = Math.pow(2,(instance.precision))-1;
        double computed = (decodedValue/maxd)*Math.abs(instance.from - instance.to)+instance.from;
        return computed;
    }
    
    /**
     * Returns function value in xValue point.
     */
    public abstract double getFunctionValue(double xValue);
 
    /**
     * Stores current instance to be solved.
     */
    public void setDataObject(Object instance){
        if(instance instanceof FunctionInstance) {
            this.instance = (FunctionInstance)instance;
        }
    }
    
}
