/* * See org.jgap.FitnessFunction#evaluate(org.jgap.IChromosome) */ @Override protected double evaluate(IChromosome chromosome) { // NB all fitness measures for individual genes are normalised to be between 0 and 1 (inclusive) Integer polyphony = EvolveImprovisers.getPolyphonyOf(chromosome); Integer maxNotesToGenerate = EvolveImprovisers.getMaxNotesOf(chromosome); Integer key = EvolveImprovisers.getKeyOf(chromosome); Integer noteRange = EvolveImprovisers.getNoteRangeOf(chromosome); Integer lowestNote = EvolveImprovisers.getLowestNoteOf(chromosome); Integer rhythmMultiplier = EvolveImprovisers.getRhythmMultiplierOf(chromosome); Integer noteRestRatio = EvolveImprovisers.getNoteRestRatioOf(chromosome); Integer medianTempo = EvolveImprovisers.getMedianTempoOf(chromosome); Integer tempoVariance = EvolveImprovisers.getTempoVarianceOf(chromosome); int[] improParameters = new int[9]; improParameters[0] = polyphony; improParameters[1] = maxNotesToGenerate; improParameters[2] = key; improParameters[3] = noteRange; improParameters[4] = lowestNote; improParameters[5] = rhythmMultiplier; improParameters[6] = noteRestRatio; improParameters[7] = medianTempo; improParameters[8] = tempoVariance; // Score score = RandomSounds.generate(polyphony, maxNotesToGenerate, key, noteRange, // lowestNote); Integer noOfImprovisations = EvolveImprovisers.getNumImprovisationsOf(chromosome); Improvisations improviserOutput = new Improvisations(noOfImprovisations, improParameters, true); String filename = EvolveImprovisers.toString(chromosome); System.err.println("Evaluating " + filename); // TODO What I want to do next here: // 1. Access a permanent but evolving population of compositions from the composer (i.e. // Composer not Improviser) // Improvisations improviserOutput = chromosome.getApplicationData(); // 2. rate all and evolve population accordingly (on the assumption it gets picked later) improviserOutput.ratePopulation(); // 3. use fitness ratings to calculate Ritchie's criteria on that improviser/composer's output double criteriaFitness = RitchieCriteria.calculateRitchieCriteria(improviserOutput); presentCriteriaAndWaitTillUserReady(); // 4. return some weighted sum of the criteria as the fitness function score for that // improviser/composer return criteriaFitness; }
private void presentCriteriaAndWaitTillUserReady() { System.out.print( "Press ENTER to continue when you have finished looking at the output of Ritchie's criteria for this Improviser"); BufferedReader in = Improvisations.getBufferedReaderIn(); try { in.readLine(); // dont worry about doing anything with this, just pause till some input // received to continue } catch (Exception e) { } }