zoukankan      html  css  js  c++  java
  • 多目标优化非支配关系实现

    多目标优化非支配关系实现

    觉得有用的话,欢迎一起讨论相互学习~

    我的微博我的github我的B站

    规则

    • 如果个体A在所有目标上都小于等于个体B且在有至少一个目标上小于个体B则称个体A支配B。
    • 如果不存在个体A支配个体B的情况并且A在至少一个目标上比B小并且B在至少一个目标上比A小,则称A和B是非支配关系
    • 详细思路可以参见NSGA-II入门

    matlab

    % 遍历所有M个目标值
    for obj_index=1:Global.M
        if NewPop.obj(obj_index)<=Population(i).obj(obj_index)
          % 如果目标值小于等于则计数值加1
           offspringless_or_equal= offspringless_or_equal+1;
           if NewPop.obj(obj_index)<Population(i).obj(obj_index)
             % 如果目标值完全小于则计数值加1
              offspringless=offspringless+1;
           end
        else parentless=parentless+1;
        end                 
    end
    % 如果新解可以支配旧解
    if((offspringless_or_equal==Global.M)&&(offspringless>0))
        Population(i)=NewPop;
    %如果两者非支配
    elseif((offspringless>0)&&(parentless>0))
    

    java

    /**
      * Compares two solutions.
      *
      * @param object1
      *            Object representing the first <code>Solution</code>.
      * @param object2
      *            Object representing the second <code>Solution</code>.
      * @return -1, or 0, or 1 if solution1 dominates solution2, both are
      *         non-dominated, or solution1 is dominated by solution22,
      *         respectively.
      */
     public int compare(Object object1, Object object2) {
       if (object1 == null)
         return 1;
       else if (object2 == null)
         return -1;
    
       Solution solution1 = (Solution) object1;
       Solution solution2 = (Solution) object2;
    
    
       int dominate1; // dominate1 indicates if some objective of solution1
               // dominates the same objective in solution2. dominate2
       int dominate2; // is the complementary of dominate1.
    
       dominate1 = 0;
       dominate2 = 0;
    
       int flag; // stores the result of the comparison
    
       // Test to determine whether at least a solution violates some
       // constraint
       if (violationConstraintComparator_.needToCompare(solution1, solution2))
         return violationConstraintComparator_.compare(solution1, solution2);
       /*
        * if (solution1.getOverallConstraintViolation()!=
        * solution2.getOverallConstraintViolation() &&
        * (solution1.getOverallConstraintViolation() < 0) ||
        * (solution2.getOverallConstraintViolation() < 0)){ return
        * (overallConstraintViolationComparator_.compare(solution1,solution2));
        * }
        */
    
       // Equal number of violated constraints. Applying a dominance Test then
       double value1, value2;
       for (int i = 0; i < solution1.getNumberOfObjectives(); i++) {
         // solution1.getNumberofbjectives中存储的是所有Task的目标函数数,而此处仅仅评价的是isChosen出来的目标函数
         if (!isChosen_[i])
           continue;
    
         value1 = solution1.getObjective(i);
         value2 = solution2.getObjective(i);
         if (value1 < value2) {
           flag = -1;
         } else if (value1 > value2) {
           flag = 1;
         } else {
           flag = 0;
         }
    
         if (flag == -1) {
           dominate1 = 1;
         }
    
         if (flag == 1) {
           dominate2 = 1;
         }
       }
    
       if (dominate1 == dominate2) {
         return 0; // No one dominate the other 两个解都至少有一个目标比另一个目标好
       }
       if (dominate1 == 1) {
         return -1; // solution1 dominate 这几个函数的位置十分关键,如果两者非支配,return语句直接返回0值,此处还能进行到,必定是不满足以上条件。
       }
       return 1; // solution2 dominate
     } // compare
    } // DominanceComparator
    
    

    better or worst

    count=0;
    frontnumbers=[];
    for i=1:pop
        for j=i:pop
            if i==j
                continue;
            end
            better=0;
            worse=0;
            if population(i).convio < population(j).convio
                % convio是ZDT4-RC才会使用的属性
                population(i).dominatedset=[population(i).dominatedset j];% 但是j是索引,不是个体还是需要注意!
                population(i).dominatedsetlength=population(i).dominatedsetlength+1;% 支配解的数量
                population(j).dominationcount=population(j).dominationcount+1;% 被支配解的数量
                % 相对而言,如果j支配了i的话
            elseif population(i).convio > population(j).convio
                population(j).dominatedset=[population(j).dominatedset i];
                population(j).dominatedsetlength=population(j).dominatedsetlength+1;
                population(i).dominationcount=population(i).dominationcount+1;                        
            else
                % 最后是为非ZDT-RC问题设计的,因为非ZDT4-RC中没有convio参数
                for k = 1:no_of_objs
                    if population(1).skill_factor == 1
                        if population(i).objs_T1(k) < population(j).objs_T1(k)
                            better=1;
                        elseif population(i).objs_T1(k) > population(j).objs_T1(k)
                            worse=1;
                        end
                    else
                        if population(i).objs_T2(k) < population(j).objs_T2(k)
                            better=1;
                        elseif population(i).objs_T2(k) > population(j).objs_T2(k)
                            worse=1;
                        end
                    end
                end
                if worse==0 && better>0 %如果j在任何一个目标上都不比i好,并且i在一个目标上比j好  
                    population(i).dominatedset=[population(i).dominatedset j];
                    population(i).dominatedsetlength=population(i).dominatedsetlength+1;
                    population(j).dominationcount=population(j).dominationcount+1;
                elseif better==0 && worse>0%如果i在任何一个目标上都不比i好,并且j在一个目标上比j好  
                    population(i).dominationcount=population(i).dominationcount+1;
                    population(j).dominatedset=[population(j).dominatedset i];
                    population(j).dominatedsetlength=population(j).dominatedsetlength+1;
                end
            end
        end
        % 如果没有解可以支配当前解,则被认为是非支配前沿
        if population(i).dominationcount==0
            population(i).front=1;
            count=count+1;
        end                
    end  
    
  • 相关阅读:
    function to_timestamp(timestamp without time zone, unknown) does not exist
    Xshell连接不上Ubuntu解决方式
    怎样使用MobaXterm上传文件到远程Linux系统 MobaXterm怎么使用连接远程服务器?
    notepad++怎样删除空行
    思维脑图在线制作工具网址
    @ApiImplicitParams
    .bat批出处理文件
    主题模型及其在文本情感分析中的应用
    表达式求职JAVA(转)
    2013华为校园招聘java实现(大家水个回复啊)
  • 原文地址:https://www.cnblogs.com/cloud-ken/p/10994475.html
Copyright © 2011-2022 走看看