Hello Mat

 找回密码
 立即注册
查看: 6817|回复: 6

杂草算法(Invasive Weed Optimization, IWO)

[复制链接]

1294

主题

1520

帖子

110

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22633
发表于 2018-4-7 11:53:09 | 显示全部楼层 |阅读模式
杂草算法(Invasive Weed Optimization, IWO)
  1. % Developer: S. Mostapha Kalami Heris (Member of Yarpiz Team)
  2. %
  3. % Contact Info: sm.kalami@gmail.com, info@yarpiz.com
  4. %

  5. clc;
  6. clear;
  7. close all;

  8. %% Problem Definition

  9. CostFunction = @(x) Sphere(x);  % Objective Function

  10. nVar = 5;           % Number of Decision Variables
  11. VarSize = [1 nVar]; % Decision Variables Matrix Size

  12. VarMin = -10;       % Lower Bound of Decision Variables
  13. VarMax = 10;        % Upper Bound of Decision Variables

  14. %% IWO Parameters

  15. MaxIt = 200;    % Maximum Number of Iterations

  16. nPop0 = 10;     % Initial Population Size
  17. nPop = 25;      % Maximum Population Size

  18. Smin = 0;       % Minimum Number of Seeds
  19. Smax = 5;       % Maximum Number of Seeds

  20. Exponent = 2;           % Variance Reduction Exponent
  21. sigma_initial = 0.5;    % Initial Value of Standard Deviation
  22. sigma_final = 0.001;        % Final Value of Standard Deviation

  23. %% Initialization

  24. % Empty Plant Structure
  25. empty_plant.Position = [];
  26. empty_plant.Cost = [];

  27. pop = repmat(empty_plant, nPop0, 1);    % Initial Population Array

  28. for i = 1:numel(pop)
  29.    
  30.     % Initialize Position
  31.     pop(i).Position = unifrnd(VarMin, VarMax, VarSize);
  32.    
  33.     % Evaluation
  34.     pop(i).Cost = CostFunction(pop(i).Position);
  35.    
  36. end

  37. % Initialize Best Cost History
  38. BestCosts = zeros(MaxIt, 1);

  39. %% IWO Main Loop

  40. for it = 1:MaxIt
  41.    
  42.     % Update Standard Deviation
  43.     sigma = ((MaxIt - it)/(MaxIt - 1))^Exponent * (sigma_initial - sigma_final) + sigma_final;
  44.    
  45.     % Get Best and Worst Cost Values
  46.     Costs = [pop.Cost];
  47.     BestCost = min(Costs);
  48.     WorstCost = max(Costs);
  49.    
  50.     % Initialize Offsprings Population
  51.     newpop = [];
  52.    
  53.     % Reproduction
  54.     for i = 1:numel(pop)
  55.         
  56.         ratio = (pop(i).Cost - WorstCost)/(BestCost - WorstCost);
  57.         S = floor(Smin + (Smax - Smin)*ratio);
  58.         
  59.         for j = 1:S
  60.             
  61.             % Initialize Offspring
  62.             newsol = empty_plant;
  63.             
  64.             % Generate Random Location
  65.             newsol.Position = pop(i).Position + sigma * randn(VarSize);
  66.             
  67.             % Apply Lower/Upper Bounds
  68.             newsol.Position = max(newsol.Position, VarMin);
  69.             newsol.Position = min(newsol.Position, VarMax);
  70.             
  71.             % Evaluate Offsring
  72.             newsol.Cost = CostFunction(newsol.Position);
  73.             
  74.             % Add Offpsring to the Population
  75.             newpop = [newpop
  76.                       newsol];  %#ok
  77.             
  78.         end
  79.         
  80.     end
  81.    
  82.     % Merge Populations
  83.     pop = [pop
  84.            newpop];
  85.    
  86.     % Sort Population
  87.     [~, SortOrder]=sort([pop.Cost]);
  88.     pop = pop(SortOrder);

  89.     % Competitive Exclusion (Delete Extra Members)
  90.     if numel(pop)>nPop
  91.         pop = pop(1:nPop);
  92.     end
  93.    
  94.     % Store Best Solution Ever Found
  95.     BestSol = pop(1);
  96.    
  97.     % Store Best Cost History
  98.     BestCosts(it) = BestSol.Cost;
  99.    
  100.     % Display Iteration Information
  101.     disp(['Iteration ' num2str(it) ': Best Cost = ' num2str(BestCosts(it))]);
  102.    
  103. end

  104. %% Results

  105. figure;
  106. % plot(BestCosts,'LineWidth',2);
  107. semilogy(BestCosts,'LineWidth',2);
  108. xlabel('Iteration');
  109. ylabel('Best Cost');
  110. grid on;
复制代码
函数:
  1. function z = Sphere(x)
  2.     z = sum(x.^2);
  3. end
复制代码






算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

0

主题

15

帖子

1

金钱

新手上路

Rank: 1

积分
16
发表于 2019-2-26 21:56:55 | 显示全部楼层
回复一下,学习
回复 支持 反对

使用道具 举报

0

主题

15

帖子

1

金钱

新手上路

Rank: 1

积分
16
发表于 2019-2-26 21:57:12 | 显示全部楼层
回复一下,学习1111111111
回复 支持 反对

使用道具 举报

0

主题

18

帖子

1

金钱

新手上路

Rank: 1

积分
19
发表于 2020-5-2 11:31:29 | 显示全部楼层

回复一下,学习
回复 支持 反对

使用道具 举报

0

主题

23

帖子

0

金钱

注册会员

Rank: 2

积分
92
发表于 2023-8-15 16:30:21 | 显示全部楼层
谢谢楼主分享
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-4-25 09:00 , Processed in 0.262391 second(s), 27 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表