import java.lang.*; import java.awt.*; import java.applet.*; public class Population { private int Size; private int ChromosomeLength; private int GeneMinValue; private int GeneMaxValue; private int TopFitness; private Position Start; public Chromosome[] Chromosomes; public Population(int _Size, int _ChromosomeLength, int _GeneMinValue, int _GeneMaxValue, Position _Start) { Size = _Size; ChromosomeLength= _ChromosomeLength; GeneMinValue = _GeneMinValue; GeneMaxValue = _GeneMaxValue; TopFitness = 0; Start = _Start; // the full-population to hold solutions Chromosomes = new Chromosome[Size]; for(int i=0; i lo0) { // Arbitrarily establishing partition element as the midpoint of the array. midval = a[ ( lo0 + hi0 ) / 2 ].Fitness(); // loop through the array until indices cross while( lo <= hi ) { // starting from the left index. // find the first element that is less than or equal to the partition element while( ( lo < hi0 ) && ( a[lo].Fitness() > midval )) { ++lo; } // starting from the right index. // find an element that is graeter than or equal to the partition element while( ( hi > lo0 ) && ( a[hi].Fitness() < midval )) { --hi; } // if the indexes have not crossed, swap if( lo <= hi ) { Chromosome temp; temp = a[lo]; a[lo] = a[hi]; a[hi] = temp; ++lo; --hi; } } // If the right index has not reached the left side of array // then sort the left partition. if( lo0 < hi ) { QuickSort( a, lo0, hi ); } // If the left index has not reached the right side of array // then sort the right partition. if( lo < hi0 ) { QuickSort( a, lo, hi0 ); } } } }