⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flowshop.m

📁 离散算法
💻 M
📖 第 1 页 / 共 3 页
字号:
            stAllPop = allPop(idx, :);              % 用 被优越数 列的游标顺序重排列 allPop
            [ParetoOptimal pOCount] = getStBests(stAllPop, dCInd, jobCount, dCInd, nDInd, fitInd, pBInd);
% %                             %%------------------------------------------%% 
% % 							%      7. 将种群中适应度最小的pOCount_before个粒子替换成新的全局最优,!!!!先不作替换
% %                                 pOCount_before = pOCount;
% % 							    for (repPop = popSize+1 : popSize + pOCount_before)
% % 							        repRan = 1;%rand(1);
% % 							        if (repRan >= replaceRate) % 只有大于替换概率replaceRate时,才替换(为了最后的多样性,可进一步考虑变replaceRate)
% % 							            badInd = stAllPop(repPop, pBInd);
% % 							            if (badInd >= 1) && (badInd <= popSize) % 在正常范围,参见getStGBest中对全局最优解的粒子号定义(为-1)
% % 							                if (pOCount==1)
% % 							                    selOPInd=1;
% % 							                else  
% % 							                    selOPInd=ceil(rand(1)*(pOCount-1));
% % 							                end
% % 							                %strcat('Replace: ', num2str(badInd), ' to ', num2str(selGBInd))
% % 							                newPop(repPop, 1: jobCount + funCount) = ParetoOptimal(selOPInd, 1: jobCount + funCount);  
% %                                             % 更新个体最优
% %                                             if (newPop(badInd, funInd) <= pBest(badInd, funInd)) && (newPop(badInd, funInd + 1) <= pBest(badInd, funInd + 1)) && ...
% %                                                ((newPop(badInd, funInd) + newPop(badInd, funInd + 1))<(pBest(badInd, funInd) + pBest(badInd, funInd + 1)))
% %                                                 pBest(badInd, :) = newPop(badInd,:);
% %                                              end
% % 							            end
% % 							        end % end of if (repRan >= replaceRate)
% % 							    end
			%%------------------------------------------%% 
			%     9.将种群newPop按适应度升序排序,存为 stPop 
            [stFit, idx] = sort(newPop(:, fitInd)); % 按适应度这一列升序排序
            stPop = newPop(idx, :);              % 使用适应度列的游标顺序重排列 newPop
		       
            %%------------------------------------------%% 
		    %       10.中间迭代的画图显示 

            % --10.2 中间图输出          
            if (mod(eval, midShowStep) == 0) % (mod(eval, 1)==0)%
                tNO = round(eval / midShowStep);
                strcat(proDes, ' 第',num2str(runTime), ' - ',num2str(iRunTime),'轮,第',...
                    num2str(evaluations), ' - ',num2str(eval),'次迭代', '--:',DATESTR(NOW),'--上次:', beforeEvalTimeStr)
                beforeEvalTimeStr = DATESTR(NOW);
%                 output2PopFigure(tNO ,proDes, stPop(:, funInd: funInd + 1), otherParetoOptimalFun, 1,popSize,eval, mid_figBounds);
% % 							        filename = strcat('mid_',proShotDes,'p',num2str(popSize),'_',num2str(iRunTime),'_e',num2str(eval)); % 
% % 							        saveas(gcf,filename,'bmp');
% %                                 t_pop=strcat('pop=',num2str(popSize));
% %                                 t_evals=strcat('evaluations=',num2str(eval));
% %                                 output2figure(10,stPop,jobCount,t_pop,t_evals);
% % 						% %         filename = strcat('output',num2str(eval));%'\outPic\',num2str(eval),'(',num2str(pop),')');
% % 						% %         saveas(gcf,filename,'bmp');
            end
            %%------------------------------------------%% 
		    %       11.判断结束条件是否满足
            averD = mean(stPop(:, dCInd: dCInd));
            if (averD == 0) %&& (eval > 200)
                findAllD0 = 1;
                if  (eval > endEval)
                    allPareto = 1;
                end
            end

            eval = eval + 1;
		end % end of while (eval <= evaluations) && (allPareto == 0)
		%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		%%                  结束 每一轮的 PSO进化                   %%
		%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        
		% -- 得到最终图输出的边界
        f1Max = max(f1OPOMax, max(ParetoOptimal(:, funInd: funInd)));
        f2Max = max(f2OPOMax, max(ParetoOptimal(:, funInd+1: funInd+1)));
        f1Min = min(f1OPOMin, min(ParetoOptimal(:, funInd: funInd)));
        f2Min = min(f2OPOMin, min(ParetoOptimal(:, funInd+1: funInd+1)));
        
		figF1Step = round((f1Max - f1Min) / (figDiv - 2 ));
		figF1Min = f1Min - figF1Step;
		figF1Max = f1Max + figF1Step/4 ; % f1Min + figF1Step * figDiv;
		figF1Len = figF1Max - figF1Min;
		figF2Step = round((f2Max - f2Min) / (figDiv - 2 ));
		figF2Min = f2Min - figF2Step;
		figF2Max = f2Max + figF2Step/4;
		figF2Len = figF2Max - figF2Min;
		figBounds = [figF1Min, figF1Max, figF1Step;
                     figF2Min, figF2Max, figF2Step];
		%%------------------------------------------%% 
		%     画图输出 最终种群 的情况,并存为 eps 文件
		actEvals = eval - 1;
        output2PopFigure(100,proDes,stPop(:, funInd: funInd + 1), otherParetoOptimalFun, 1,popSize,actEvals, figBounds);

		%%------------------------------------------%% 
		%     画图输出 Pareto最优解 的情况,并存为 bmp 文件
        output2PopFigure(101, proDes,ParetoOptimal(:, funInd: funInd + 1), otherParetoOptimalFun, 1,popSize,actEvals, figBounds);
        filename = strcat('final_',proShotDes,'_p',num2str(popSize),'_',num2str(iRunTime),'_e',num2str(evaluations),...
            '_w',num2str(w_now),'up_',num2str(upd_now), 'c1_',num2str(c1_now),'_gB.eps'); % 
        print('-depsc2', filename);
		%%------------------------------------------%% 
		%     合并每一轮计算 获得的 最优解
        runTimeParetoOptimals = [runTimeParetoOptimals; ParetoOptimal]; 
        %%------------------------------------------%%
		%     实时保存 运行结果 
        resultFileName = ['result_', proFileName, '_p',num2str(popSize),'_me', num2str(evaluations),...
                '_w',num2str(w_now),'_up',num2str(upd_now), '_c1',num2str(c1_now), '_gB.mat'];
        save(resultFileName);% all
    end % 结束 	for (iRunTime = 1: runTime)
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	%%               结束 多轮 进化                             %%
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    %%------------------------------------------%%
	%      处理 runTime 轮得到的最优解,去掉重复的部分
    [uni_runTimeParetoOptimals, uni_rTPOCount] = getUniqueVals(runTimeParetoOptimals(:, funInd: funInd + funCount - 1));
    uni_runTimeParetoOptimals(:, funCount+1) = 5;    % 给自己的算法 定 算法编号
    %%------------------------------------------%%
	%      输出 runTime 次得到的结果,并保存
		% -- 得到最终图输出的边界
    f1Max = max(f1OPOMax, max(uni_runTimeParetoOptimals(:, 1)));
    f2Max = max(f2OPOMax, max(uni_runTimeParetoOptimals(:, 2)));
    f1Min = min(f1OPOMin, min(uni_runTimeParetoOptimals(:, 1)));
    f2Min = min(f2OPOMin, min(uni_runTimeParetoOptimals(:, 2)));
    
	figF1Step = round((f1Max - f1Min) / (figDiv - 2 ));
	figF1Min = f1Min - figF1Step;
	figF1Max = f1Max + figF1Step/4 ; % f1Min + figF1Step * figDiv;
	figF1Len = figF1Max - figF1Min;
	figF2Step = round((f2Max - f2Min) / (figDiv - 2 ));
	figF2Min = f2Min - figF2Step;
	figF2Max = f2Max + figF2Step/4;
	figF2Len = figF2Max - figF2Min;
	figBounds = [figF1Min, figF1Max, figF1Step;
                 figF2Min, figF2Max, figF2Step];
             
	output2PopFigure(102, proDes,uni_runTimeParetoOptimals(:, 1: 2), otherParetoOptimalFun, 1,popSize,actEvals, figBounds);
	filename = strcat('final_',proShotDes,'_p',num2str(popSize),'_all',num2str(runTime), '_e',num2str(evaluations),...
        '_w',num2str(w_now),'up_',num2str(upd_now), 'c1_',num2str(c1_now), '_gB.eps'); % 
    print('-depsc2', filename);
    
    %%------------------------------------------%%
	%     与其他算法的最优解 合并,和其它算法得到的最优解 比较优劣, 得到最优解 和 自己算法 在 最优解 中的 个数 
    mixPOFun = [uni_runTimeParetoOptimals; otherParetoOptimalFun];
    [curProParetoOptimalFun, myAlgCount] = getAllParetoOptimal(mixPOFun, 1, funCount+1, 5);
    curProPOFunCount = size(curProParetoOptimalFun, 1);
    proPOFunCount(iSelProInd, 1) = curProPOFunCount;
    proParetoOptimalFun(1:curProPOFunCount, 1:3,  iSelProInd) = curProParetoOptimalFun; %    
    proMyPSOPOFunCounts(iSelProInd, 1) = myAlgCount;
    proMyPSOPOFunCounts'
    %%------------------------------------------%%
	%     实时保存 运行结果 
    resultFileName = ['result_', proFileName, '_p',num2str(popSize),'_me', num2str(evaluations),...
            '_w',num2str(w_now),'_up',num2str(upd_now), '_c1',num2str(c1_now), '_gB.mat'];
    save(resultFileName);% all
end % 结束 多个问题 for (iSelProInd = 1: selProCount)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%          结束    各个 测试问题计算                       %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% % proParetoOptimalFun
% % proPOFunCount'
% % proMyPSOPOFunCounts'

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -