All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jeco.core.problem.Problem Maven / Gradle / Ivy

The newest version!
package jeco.core.problem;

public abstract class Problem> {
    //private static final Logger logger = Logger.getLogger(Problem.class.getName());

    public static final double INFINITY = Double.POSITIVE_INFINITY;
    protected int numberOfVariables;
    protected int numberOfObjectives;
    protected double[] lowerBound;
    protected double[] upperBound;

    protected int maxEvaluations;
    protected int numEvaluations;

    public Problem(int numberOfVariables, int numberOfObjectives) {
        this.numberOfVariables = numberOfVariables;
        this.numberOfObjectives = numberOfObjectives;
        this.lowerBound = new double[numberOfVariables];
        this.upperBound = new double[numberOfVariables];
        this.maxEvaluations = Integer.MAX_VALUE;
        resetNumEvaluations();
    }

    public int getNumberOfVariables() {
        return numberOfVariables;
    }

    public int getNumberOfObjectives() {
        return numberOfObjectives;
    }

    public double getLowerBound(int i) {
        return lowerBound[i];
    }

    public double getUpperBound(int i) {
        return upperBound[i];
    }

    public int getMaxEvaluations() {
        return maxEvaluations;
    }

    public void setMaxEvaluations(int maxEvaluations) {
        this.maxEvaluations = maxEvaluations;
    }

    public int getNumEvaluations() {
        return numEvaluations;
    }

    public final void resetNumEvaluations() {
        numEvaluations = 0;
    }
    
    public void setNumEvaluations(int numEvaluations) {
        this.numEvaluations = numEvaluations;
    }

    /**To be implemented by each problem type, returns an initial set of solution of a given size.
     * 
     * @param size size of set of solutions
     * @return A set of solutions
     */
    public abstract Solutions newRandomSetOfSolutions(int size);

    public void evaluate(Solutions solutions) {
        for (Solution solution : solutions) {
            evaluate(solution);
        }
        
    }
    
    /**
     * To be implemented for each problem, for each genotype (solution) returns a String corresponding
     * to the phenotype of a solution
     * @param solution individual to evaluate
     * @return string of phenotype
     */
    public String phenotypeToString(Solution solution) { return "Not implemented"; }

    public abstract void evaluate(Solution solution);

    @Override
    public abstract Problem clone();

    public boolean reachedMaxEvaluations() {
        return (numEvaluations >= maxEvaluations);
    }



    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy