import java.util.Random; import java.util.Vector; import java.io.*; public class GA { static final int hypothesisLength = 10; static float fitness_threshold, r, m; static int p; static String examplesFile; static String[] population; static int[] fitnesses; Vector examples = new Vector(); int[] probabilitiesContainer; public static void main(String[] args) { //args: fitness_threshold + p + r + m + exampleFiles fitness_threshold = Float.parseFloat(args[0]); //Temporarily p = Integer.parseInt(args[1]); r = Float.parseFloat(args[2]); m = Float.parseFloat(args[3]); examplesFile = args[4]; population = new String[p]; fitnesses = new int[p]; new GA().start(); } //********************************************************************* void start(){ readExamples(); fitness_threshold = fitness_threshold * examples.size(); initializePopulation(); int max = 0; int iteration = 1; while( (max = findMaxFitnessOfPopulation()) < fitness_threshold ){ //just for display iteration++; System.out.println("\n\n***Next Iteration***\n"); for(int i=0; i
max) max = fitnesses[i]; } return max; } //********************************************************************* /*we put only hypothesis with targetValue==Yes in polulation; * so:1-if precondition of an example is consistent with hypo * and its targetValue==Yes ==> increment the correctness for hypo * 2-if precondition of an example is not consistent with hypo * and its targetValue==No ==> increment the correctness for hypo */ void assignFitnessToPopulation(){ //System.out.println("\n***Fitnesses***"); int correctness; for(int i=0; i