在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的计算指标的代码,以保证与这节修改代码的接口相同。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值