【优化调度】基于协方差矩阵自适应贪心搜索实现配水系统优化附matlab代码

简介: 【优化调度】基于协方差矩阵自适应贪心搜索实现配水系统优化附matlab代码

✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法  神经网络预测雷达通信 无线传感器

信号处理图像处理路径规划元胞自动机无人机

⛄ 内容介绍

协方差矩阵自适应进化策略(CMA–ES)局部搜索能力强,具备旋转不变性,采用此策略结合贪心搜索算法实现配水系统优化。

⛄ 部分代码

function  Pipe=BN_DGS(Pipe,Network_Number,PipeLength,inopts,Iter)


global G_NYTP;


count=0;

PL=PipeLength/Iter;

Type='U';

for h=1:size(Pipe.UGS_Sols,1)

   if Pipe.UGS_Cost(h,end)==0

       count=count+1;

   end

end

if count==size(Pipe.UGS_Sols,1)

   disp('There is not proper solution for applying Downward Greedy Search')

   return

end

Sort_Index=Sorting_BN(Pipe);

ss=1;

for cc=Sort_Index(ss,1):size(Pipe.UGS_Sols,1)

   

   if ss > round(size(Sort_Index,1)*0.1)

       break

   end

   

   if Pipe.UGS_Cost(cc,end)~=0

       

       for k1=1:inopts.NS

           if round(Pipe.UGS_Cost(cc,k1)/10^6,3)==round((inopts.BestC/10^6),3) % saving the runtime

               disp('---------Best known pipe design-----------------')

               disp(['Pipe size =',mat2str(Pipe.UGS_Sols(cc,(k1-1)*(PL)+1:k1*(PL)))])

               disp(['Cost Pipe =',num2str(round( Pipe.UGS_Cost(cc,k1)))])

               Pipe.DGS_Sols(cc,(k1-1)*(PL)+1:k1*(PL))= Pipe.UGS_Sols(cc,(k1-1)*(PL)+1:k1*(PL));

               Pipe.DGS_Cost(cc,k1)                   =  Pipe.UGS_Cost(cc,k1);

               if k1==inopts.NS

                   Pipe.DGS_Cost(cc,inopts.NS+1) = sum(Pipe.DGS_Cost(cc,1:inopts.NS))   ;

               end

               continue

           end

           Best_Pipe=Pipe.UGS_Sols(cc,(k1-1)*(PL)+1:k1*(PL));

           [Cost_All,Cost_BS,Pressure_BS,Length_Pipes] = feval(inopts.CostF, Best_Pipe);

           Sum_violation_BS = 0;

           

           for ii=1:size(Pressure_BS ,2)-4

               if Pressure_BS(ii)<inopts.CV

                   Sum_violation_BS=Sum_violation_BS+ abs(inopts.CV-Pressure_BS(ii));

               end

           end

           disp('-----------------------------------')

           disp(['Pipe size before applying the DGS=',mat2str(Best_Pipe)])

           disp(['Cost Pipe before applying the DGS=',num2str(round( Cost_BS))])

           disp(['Sum violation Pressure=',num2str(Sum_violation_BS)])

           Sum_violation=Sum_violation_BS;

           i=1;

           

           while (Sum_violation ==0 )

               

               Temp_Sol=Best_Pipe;

               j=1;

               

               while j<=size(Best_Pipe,2) % the number of pipe

                   

                   Temp_Sol=Best_Pipe;

                   

                   if Temp_Sol(j)==126.6

                       Temp_Sol(j)=113;

                   elseif Temp_Sol(j)==144.6

                       Temp_Sol(j)=126.6;

                   elseif Temp_Sol(j)==162.8

                       Temp_Sol(j)=144.6;

                   elseif Temp_Sol(j)==180.8

                       Temp_Sol(j)=162.8;

                   elseif Temp_Sol(j)==226.2

                       Temp_Sol(j)=180.8;

                   elseif Temp_Sol(j)==285

                       Temp_Sol(j)=226.2;

                   elseif Temp_Sol(j)==361.8

                       Temp_Sol(j)=285;

                   elseif Temp_Sol(j)==452.2

                       Temp_Sol(j)=361.8;

                   elseif Temp_Sol(j)==581.8

                       Temp_Sol(j)=452.2;

                   end

                   Solution(i,j).Pipe          = Temp_Sol; % recording the solutions

                   [~,Solution(i,j).CostPipe,Solution(i,j).Pressure,Length_Pipes] = feval(inopts.CostF, Temp_Sol);

                   

                   Table(j,1)                  = Solution(i,j).CostPipe;

                   Solution(i,j).Delta_Cost    = abs(Solution(i,j).CostPipe-Cost_BS);

                   Table(j,2)                  = Solution(i,j).Delta_Cost;

                   Solution(i,j).Delta_Pre     = 0;

                   Sum_violation               = 0;

                   

                   for ii=1:size(Pressure_BS ,2)-4

                       if Solution(i,j).Pressure (ii)<inopts.CV

                           Sum_violation=Sum_violation+ abs(inopts.CV-Solution(i,j).Pressure (ii));

                       end

                   end

                   

                   Solution(i,j).Sum_violation     = Sum_violation;

                   Table(j,3)                      = Solution(i,j).Sum_violation;

                   

                   for ii=1:size(Pressure_BS ,2)-4

                       

                       if Solution(i,j).Pressure(ii)>inopts.CV  && Pressure_BS(ii)>inopts.CV

                           Solution(i,j).Delta_Pre=Solution(i,j).Delta_Pre+ abs(Pressure_BS(ii)-Solution(i,j).Pressure(ii));

                       end

                       

                       if Solution(i,j).Pressure(ii)<=inopts.CV  && Pressure_BS(ii)>inopts.CV

                           Solution(i,j).Delta_Pre=Solution(i,j).Delta_Pre+ abs(Solution(i,j).Pressure(ii));

                       end

                       Table(j,4)                 =  Solution(i,j).Delta_Pre;

                       

                   end

                   

                   if Solution(i,j).Delta_Pre==0 && Solution(i,j).Delta_Cost==0

                       Solution(i,j).rate_im =0;

                   elseif Solution(i,j).Delta_Pre==0

                       Solution(i,j).rate_im = 0;

                   else

                       Solution(i,j).rate_im = Solution(i,j).Delta_Cost/Solution(i,j).Delta_Pre ;

                   end

                   Table(j,5)                 =  Solution(i,j).rate_im;

                   j=j+1;

               end  % end while

               % selecting the feasible solutions

               k=1;

               for ii=1:size(Best_Pipe,2)

                   if Solution(i,ii).Sum_violation==0 && Solution(i,ii).CostPipe < Cost_BS

                       Feasible(k)=Solution(i,ii);

                       k=k+1;

                   end

               end

               

               %finding the best candidate

               if k==1

                   % i=i+1;

                   break

               end

               BestSol(i)=Feasible(1);

               

               for i1=2:k-1

                   if Feasible(i1).rate_im > BestSol(i).rate_im

                       BestSol(i)=Feasible(i1);

                   end

               end

               Best_Pipe             = BestSol(i).Pipe;

               Pressure_BS           = BestSol(i).Pressure;

               Sum_violation_BS      = BestSol(i).Sum_violation;

               Cost_BS               = BestSol(i).CostPipe;

               

               disp(['Best solution sum Pressure violation after applying the DGS=',num2str(BestSol(i).Sum_violation)])

               disp(['The pipe cost after applying the DGS=',num2str([BestSol(i).CostPipe])]);

               disp(['The pipe sizes after applying the DGS=',mat2str(Best_Pipe)])

               disp(['Number of feasiable solutions=',num2str(size(Feasible,2))])

               if i > 1

                   if round(BestSol(i).CostPipe,2)== round(BestSol(i-1).CostPipe,2)

                       disp('---------- Upward Greedy Search is stopped ----------')

                       break % there is not any improvement

                   end

               end

               i=i+1;

               clear Feasible

           end  % end while

           

           PipeCost                               = Cost_BS;

           Pipe.DGS_Sols(cc,(k1-1)*(PL)+1:k1*(PL))= Best_Pipe;

           Pipe.DGS_Cost(cc,k1)                   = PipeCost;

           if k1==inopts.NS

               Pipe.DGS_Cost(cc,inopts.NS+1) =sum(Pipe.DGS_Cost(cc,1:inopts.NS))   ;

           end

           

           clear Solution

           clear BestSol

           clear Table

       end % end for k1=1:inopts.NS

       

       

   end % end if

   ss=ss+1;

end % end for

disp('Downward Greedy Search is finished')

[MinCost]= min(nonzeros(Pipe.DGS_Cost(:,end)));

index      = find(round(Pipe.DGS_Cost(:,end))==round(MinCost));

Pipe.XminD = Pipe.DGS_Sols(index(1),:);

Pipe.FminD = MinCost;

disp(['The best design of Downward Greedy Search =',num2str(MinCost)])

disp(['Pipe sizes 1=',mat2str([Pipe.DGS_Sols(index(1),:)]),',Pipe cost=',num2str(Pipe.DGS_Cost(index(1),end))])

end

⛄ 运行结果

⛄ 参考文献

[1]张梦蓓, 乔帅. WSN中节点分布的协方差矩阵自适应优化策略[J]. 仪表技术与传感器, 2016(2):4.

❤️ 关注我领取海量matlab电子书和数学建模资料
❤️部分理论引用网络文献,若有侵权联系博主删除


相关文章
|
1天前
|
数据安全/隐私保护
地震波功率谱密度函数、功率谱密度曲线,反应谱转功率谱,matlab代码
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
|
1天前
|
数据安全/隐私保护
耐震时程曲线,matlab代码,自定义反应谱与地震波,优化源代码,地震波耐震时程曲线
地震波格式转换、时程转换、峰值调整、规范反应谱、计算反应谱、计算持时、生成人工波、时频域转换、数据滤波、基线校正、Arias截波、傅里叶变换、耐震时程曲线、脉冲波合成与提取、三联反应谱、地震动参数、延性反应谱、地震波缩尺、功率谱密度
基于混合整数规划的微网储能电池容量规划(matlab代码)
基于混合整数规划的微网储能电池容量规划(matlab代码)
|
1天前
|
算法 调度
考虑需求响应的微网优化调度模型【粒子群算法】【matlab】
考虑需求响应的微网优化调度模型【粒子群算法】【matlab】
|
1天前
|
算法 调度
面向配电网韧性提升的移动储能预布局与动态调度策略(matlab代码)
面向配电网韧性提升的移动储能预布局与动态调度策略(matlab代码)
|
1天前
|
算法 调度
含多微网租赁共享储能的配电网博弈优化调度(含matlab代码)
含多微网租赁共享储能的配电网博弈优化调度(含matlab代码)
|
1天前
|
运维 算法
基于改进遗传算法的配电网故障定位(matlab代码)
基于改进遗传算法的配电网故障定位(matlab代码)
|
1天前
|
Serverless
基于Logistic函数的负荷需求响应(matlab代码)
基于Logistic函数的负荷需求响应(matlab代码)
|
1天前
|
供应链 算法
基于分布式优化的多产消者非合作博弈能量共享(Matlab代码)
基于分布式优化的多产消者非合作博弈能量共享(Matlab代码)
|
1天前
|
算法 调度
基于多目标粒子群算法冷热电联供综合能源系统运行优化(matlab代码)
基于多目标粒子群算法冷热电联供综合能源系统运行优化(matlab代码)

热门文章

最新文章