package geneticAlgorithm;

import java.io.*;
import java.lang.Math;

/**
 * Functionable interface defines what parameters and what algorithms 
 * each GA problem should supply.
 */
public interface Functionable {
  // user functions
  /**
   * Each problem specific initialization steps.
   */
  public void start();
  /**
   * Each problem specific finilizing steps.
   */
  public void done();
  // system parameters
  /**
   * returns individuals size
   */
  public int indSize();
  /**
   * The alpha-bet size. Each element value would be in the range 0 - (abcSize - 1).
   */
  public int abcSize();
  /**
   * Total population size. Number of individuals.
   */
  public int popSize();
  /**
   * Number of generations counted by the main loop. Sending subpopulation to a remote machine for several subgenerations would be counted as one generation in the main loop.
    */
  public int generations();
  /**
   * Number of subpopulations. Each subpopulation will have popSize/subPopulation individuals.
   */
  public int subPopulations();
  /**
   * Number of fitness improvment steps each remote machine should perform.
   */
  public int subGenerations();
  /**
   * Maximum number of non-fitness-improving trials that a remote machine should do before stop trying.
   */
  public int maxTrials();
  /**
   * 1/mutationRatio of a population would be mutated.
   */
  public int mutationRatio();
  /**
   * Returns true if achieved fitness is good enough.
   */
  public boolean finished(double fitness);
  /**
    Compares two fitnesses and returns true if the first one is better.
    */
  public boolean better(double fitness1, double fitness2);
  /**
    Receives one individual and returns its fitness.
    */
  public double calc(Ind ind);
  /**
    Receives two individuals and returns a child.
    */
  public Ind crossOver(Ind oldInd, Ind ind2);
  /**
   * Mutates a given individuals.
   */
  public void mutate(Ind ind);
}

