在PlatEMO v2.9中增加多模态多目标算法(2)

上小节(在PlatEMO v2.9中增加多模态多目标算法(1))中,我已经在PlatEMO v2.9的框架中增加了属性和方法,在该小节我们需要改调用计算指标那部分代码,以保证PlatEMO v2.9中增加多模态多目标算法后,不会影响其他算法的运行。

了解传入参数情况

GUI文件夹中Modulesmodule_testcb_metricList()方法传入的参数是PopObjPF,对应的代码分别是obj.data(current).result{end,2}obj.data(current).Global.PF

 %% Calculate the metric value of the final population
        function cb_metricList(obj,hObject,eventdata)
            current = obj.control.resultList.index;
            if current > 0 && ~isempty(obj.data(current).result)
                metric = obj.control.metricList.string;
                if ~isfield(obj.data(current).metric,metric)
                    obj.data(current).metric.(metric) = obj.Metric(str2func(metric),obj.data(current).result{end,2},obj.data(current).Global.PF);
                end
                obj.control.metricLabel.handle.String = sprintf('%.4e',obj.data(current).metric.(metric));
            else
                obj.control.metricLabel.handle.String = '';
            end
        end

增加传入参数

GUI文件夹中Modulesmodule_testcb_metricList()方法中我们需要传入PopObjPFPopDecPSfnamerepoint,增加的代码如下:

 %% Calculate the metric value of the final population
        function cb_metricList(obj,hObject,eventdata)
            current = obj.control.resultList.index;
            if current > 0 && ~isempty(obj.data(current).result)
                metric = obj.control.metricList.string;
                if ~isfield(obj.data(current).metric,metric)
                    obj.data(current).metric.(metric) = obj.Metric(str2func(metric),{obj.data(current).result{end,2},obj.data(current).Global.PF,obj.data(current).result{end,3},obj.data(current).Global.PS,obj.data(current).Global.fname,obj.data(current).Global.repoint});
                end
                obj.control.metricLabel.handle.String = sprintf('%.4e',obj.data(current).metric.(metric));
            else
                obj.control.metricLabel.handle.String = '';
            end
        end

更改module中的代码

由于module_testcb_metricList()方法会跳到module类的Metric()方法中,我们需要对Metric()中的内容进行更改,更改情况如下:

 %% Calculate the specified metric value of a population
        function value = Metric(obj,metric,Parameter)
            [PopObj,PF,PopDec,PS,fname,repoint] = deal(Parameter{:});
            if isa(PopObj,'INDIVIDUAL')
                PopObj = PopObj(all(PopObj.cons<=0,2)).objs;
            end
            NonDominated = NDSort(PopObj,1) == 1;
            try
                value = metric({PopObj(NonDominated,:),PF,PopDec(NonDominated,:),PS,fname,repoint});
            catch
                value = NaN;
            end
        end
    end

下一个小节我会展示更改后PlatEMO v2.9的计算指标的代码,以保证与这节修改代码的接口相同。

上一篇:FSL-GNN代码解读


下一篇:python23_Django入门_预备知识 HTTP协议 HTTP请求方式 MVC模式 MTV模式