Skip to content

Instantly share code, notes, and snippets.

@dhadka
Created March 21, 2016 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhadka/0d008f3d161105c23633 to your computer and use it in GitHub Desktop.
Save dhadka/0d008f3d161105c23633 to your computer and use it in GitHub Desktop.
// FPGAFitnessComparator.java
//
// Author:
// Antonio J. Nebro <antonio@lcc.uma.es>
// Juan J. Durillo <durillo@lcc.uma.es>
//
// Copyright (c) 2011 Antonio J. Nebro, Juan J. Durillo
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package jmetal.util.comparators;
import jmetal.core.Solution;
import java.util.Comparator;
/**
* This class implements a <code>Comparator</code> (a method for comparing
* <code>Solution</code> objects) based on the rank used in FPGA.
*/
public class FPGAFitnessComparator implements Comparator {
/**
* Compares two solutions.
* @param o1 Object representing the first <code>Solution</code>.
* @param o2 Object representing the second <code>Solution</code>.
* @return -1, or 0, or 1 if o1 is less than, equal, or greater than o2,
* respectively.
*/
public int compare(Object o1, Object o2) {
Solution solution1, solution2;
solution1 = (Solution) o1;
solution2 = (Solution) o2;
if (solution1.getRank()==0 && solution2.getRank()> 0) {
return -1;
} else if (solution1.getRank() > 0 && solution2.getRank() == 0) {
return 1;
} else {
if (Double.isInfinite(solution1.getFitness()) && Double.isInfinite(solution2.getFitness())) {
return 0;
} else if (solution1.getFitness() > solution2.getFitness()) {
return -1;
} else if (solution1.getFitness() < solution2.getFitness()) {
return 1;
} else {
return 0;
}
}
} // compare
} // FPGAFitnessComparator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment