本文整理汇总了Java中jmetal.util.comparators.ObjectiveComparator类的典型用法代码示例。如果您正苦于以下问题:Java ObjectiveComparator类的具体用法?Java ObjectiveComparator怎么用?Java ObjectiveComparator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectiveComparator类属于jmetal.util.comparators包,在下文中一共展示了ObjectiveComparator类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: crowdingDistanceAssignment
import jmetal.util.comparators.ObjectiveComparator; //导入依赖的package包/类
/** Assigns crowding distances to all solutions in a <code>SolutionSet</code>.
* @param solutionSet The <code>SolutionSet</code>.
* @param nObjs Number of objectives.
*/
public void crowdingDistanceAssignment(SolutionSet solutionSet, int nObjs) {
int size = solutionSet.size();
if (size == 0)
return;
if (size == 1) {
solutionSet.get(0).setCrowdingDistance(Double.POSITIVE_INFINITY);
return;
} // if
if (size == 2) {
solutionSet.get(0).setCrowdingDistance(Double.POSITIVE_INFINITY);
solutionSet.get(1).setCrowdingDistance(Double.POSITIVE_INFINITY);
return;
} // if
//Use a new SolutionSet to evite alter original solutionSet
SolutionSet front = new SolutionSet(size);
for (int i = 0; i < size; i++){
front.add(solutionSet.get(i));
}
for (int i = 0; i < size; i++)
front.get(i).setCrowdingDistance(0.0);
double objetiveMaxn;
double objetiveMinn;
double distance;
for (int i = 0; i<nObjs; i++) {
// Sort the population by Obj n
front.sort(new ObjectiveComparator(i));
objetiveMinn = front.get(0).getObjective(i);
objetiveMaxn = front.get(front.size()-1).getObjective(i);
//Set de crowding distance
front.get(0).setCrowdingDistance(Double.POSITIVE_INFINITY);
front.get(size-1).setCrowdingDistance(Double.POSITIVE_INFINITY);
for (int j = 1; j < size-1; j++) {
distance = front.get(j+1).getObjective(i) - front.get(j-1).getObjective(i);
distance = distance / (objetiveMaxn - objetiveMinn);
distance += front.get(j).getCrowdingDistance();
front.get(j).setCrowdingDistance(distance);
} // for
} // for
}