/* GPNodeComparator.java * J Scott Cameron * * implements Comparator in order to * sort the Genetic Program nodes. */ import java.util.*; import java.io.*; import GPNodeContainer; public class GPNodeComparator implements Comparator { public GPNodeComparator() {} /* returns a 1 if Node 1 is less fit * a -1 if Node 1 is more fit * and 0 if they are equal * this will reverse sort the nodes */ public int compare(Object o1, Object o2) { GPNodeContainer g1 = (GPNodeContainer)o1; GPNodeContainer g2 = (GPNodeContainer)o2; if(g1.getRating() < g2.getRating()) { return 1; } else if(g1.getRating() > g2.getRating()) { return -1; } return 0; } }