当前位置: 首页>>代码示例>>Java>>正文


Java ObjectiveComparator类代码示例

本文整理汇总了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        
}
 
开发者ID:organicsmarthome,项目名称:OSHv2,代码行数:53,代码来源:Distance.java


注:本文中的jmetal.util.comparators.ObjectiveComparator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。