現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Output is not as expected
3 ビュー (過去 30 日間)
古いコメントを表示
Sahithi Kandhukuri
2024 年 1 月 8 日
I m trying to do ant colony optimisation based upqc but the out is not as expected 

I am getting above output i.e, zeroes but the required one is as shown below

13 件のコメント
Sam Chak
2024 年 1 月 8 日
I haven't tested everything yet, but I experimented with a basic quadratic function and observed that the optimal solution obtained through Ant Colony Optimization does not yield the lowest cost. Until this issue is addressed, it does not make sense to proceed with the current optimization problem.
format long g
%% ACO parameters
n_iter = 5; % number of iteration
NA = 5; % Number of Ants
alpha = 0.8;
beta = 0.2;
roh = 0.7; % Evaporation rate
n_param = 1; % Number of parameters
LB = 0.1*ones(1,n_param); % lower band
UB = 2.0*ones(1,n_param); % upper band
n_node = 1000; % number of nodes for each param
%% intilalizing some variables
cost_best_prev = inf;
ant = zeros(NA,n_param);
cost = zeros(NA,1);
tour_selected_param = zeros(1,n_param);
param_mat = zeros(n_iter,n_param);
Nodes = zeros(n_node,n_param);
prob = zeros(n_node,n_param);
%% Generating nodes
T = ones(n_node, n_param).*eps;
dT = zeros(n_node, n_param);
for i = 1:n_param
Nodes(:,1) = linspace(LB(i), UB(i), n_node);
end
%% iteration loop
for iter = 1:n_iter
for tour_i = 1:n_param
prob(:,tour_i) = (T(:,tour_i).^alpha).*((1./Nodes(:,tour_i)).^beta);
prob(:,tour_i) = prob(:,tour_i)./sum(prob(:,tour_i));
end
for A = 1:NA
for tour_i = 1:n_param
node_se1 = rand;
node_ind = 1;
prob_sum = 0;
for j = 1:n_node
prob_sum = prob_sum + prob(j,tour_i);
if prob_sum >= node_se1
node_ind = j;
break
end
end
ant(A,tour_i) = node_ind;
tour_selected_param(tour_i) = Nodes(node_ind, tour_i);
%%
end
%% Put the Cost function here:
% cost(A) = cost_func(tour_selected_param);
cost(A) = costume(tour_selected_param);
disp(['Ant number: ' num2str(A)])
disp(['Ant Cost: ' num2str(cost(A))])
disp(['Ant parameters: ' num2str(tour_selected_param)])
if iter~=1
disp(['iteration:' num2str(iter)])
disp('________________')
disp(['Best cost:' num2str(cost_best)])
for i=1:n_param
tour_selected_param(i) = Nodes(ant(cost_best_ind,1), i);
end
disp(['Best parameters:' num2str(tour_selected_param)])
end
end
[cost_best, cost_best_ind] = min(cost);
% Elistem
if (cost_best > cost_best_prev) && (iter ~= 1)
[cost_worst, cost_worst_ind] = max(cost);
ant(cost_worst_ind,:) = best_prev_ant;
cost_best = cost_best_prev;
cost_best_ind = cost_worst_ind;
else
cost_best_prev = cost_best;
best_prev_ant = ant(cost_best_ind,:);
end
dT = zeros(n_node,n_param); % Change of Phormone
for tour_i = 1:n_param
for A = 1:NA
dT(ant(A, tour_i), tour_i) = dT(ant(A, tour_i), tour_i) + cost_best/cost(A);
end
end
T = roh.*T + dT;
end
Ant number: 1
Ant Cost: 1.4451
Ant parameters: 1.6672
Ant number: 2
Ant Cost: 1.0667
Ant parameters: 1.2583
Ant number: 3
Ant Cost: 1.5524
Ant parameters: 1.7432
Ant number: 4
Ant Cost: 1.9254
Ant parameters: 1.962
Ant number: 5
Ant Cost: 1.7482
Ant parameters: 1.865
Ant number: 1
Ant Cost: 1.5524
Ant parameters: 1.7432
iteration:2
________________
Best cost:1.0667
Best parameters:1.2583
Ant number: 2
Ant Cost: 1.4451
Ant parameters: 1.6672
iteration:2
________________
Best cost:1.0667
Best parameters:1.6672
Ant number: 3
Ant Cost: 1.0667
Ant parameters: 1.2583
iteration:2
________________
Best cost:1.0667
Best parameters:1.6672
Ant number: 4
Ant Cost: 1.0667
Ant parameters: 1.2583
iteration:2
________________
Best cost:1.0667
Best parameters:1.6672
Ant number: 5
Ant Cost: 1.9254
Ant parameters: 1.962
iteration:2
________________
Best cost:1.0667
Best parameters:1.6672
Ant number: 1
Ant Cost: 1.7482
Ant parameters: 1.865
iteration:3
________________
Best cost:1.0667
Best parameters:1.2583
Ant number: 2
Ant Cost: 1.0667
Ant parameters: 1.2583
iteration:3
________________
Best cost:1.0667
Best parameters:1.2583
Ant number: 3
Ant Cost: 1.7482
Ant parameters: 1.865
iteration:3
________________
Best cost:1.0667
Best parameters:1.865
Ant number: 4
Ant Cost: 1.0667
Ant parameters: 1.2583
iteration:3
________________
Best cost:1.0667
Best parameters:1.865
Ant number: 5
Ant Cost: 1.4451
Ant parameters: 1.6672
iteration:3
________________
Best cost:1.0667
Best parameters:1.865
Ant number: 1
Ant Cost: 1.5524
Ant parameters: 1.7432
iteration:4
________________
Best cost:1.0667
Best parameters:1.2583
Ant number: 2
Ant Cost: 1.4451
Ant parameters: 1.6672
iteration:4
________________
Best cost:1.0667
Best parameters:1.6672
Ant number: 3
Ant Cost: 1.0667
Ant parameters: 1.2583
iteration:4
________________
Best cost:1.0667
Best parameters:1.6672
Ant number: 4
Ant Cost: 1.0667
Ant parameters: 1.2583
iteration:4
________________
Best cost:1.0667
Best parameters:1.6672
Ant number: 5
Ant Cost: 1.4451
Ant parameters: 1.6672
iteration:4
________________
Best cost:1.0667
Best parameters:1.6672
Ant number: 1
Ant Cost: 1.5524
Ant parameters: 1.7432
iteration:5
________________
Best cost:1.0667
Best parameters:1.2583
Ant number: 2
Ant Cost: 1.0667
Ant parameters: 1.2583
iteration:5
________________
Best cost:1.0667
Best parameters:1.2583
Ant number: 3
Ant Cost: 1.9254
Ant parameters: 1.962
iteration:5
________________
Best cost:1.0667
Best parameters:1.962
Ant number: 4
Ant Cost: 1.0667
Ant parameters: 1.2583
iteration:5
________________
Best cost:1.0667
Best parameters:1.962
Ant number: 5
Ant Cost: 1.9254
Ant parameters: 1.962
iteration:5
________________
Best cost:1.0667
Best parameters:1.962
%% ACO Result
k = tour_selected_param
k =
1.96196196196196
J = costume(k)
J =
1.92537081626171
%% Compare with other Optimizer
[kopt, fval] = fminunc(@costume, 2)
Local minimum found.
Optimization completed because the size of the gradient is less than
the value of the optimality tolerance.
kopt =
1
fval =
1
%% Custom Optimization Solution for Targeted User Minimum Equation
function J = costume(k)
J = (k - 1)^2 + 1;
end
Sahithi Kandhukuri
2024 年 1 月 8 日
Sorry I am unbale to understand could you please describ it clearly
Sam Chak
2024 年 1 月 8 日
Okay, I gave it a shot. I experimented with your Ant Colony Optimization algorithm (ACO) using a basic quadratic function. See the graph below. The minimum value occurs when
, and at that point, the cost is
. If the ACO works well, it should return
after numerous iterations.
J = @(k) (k - 1).^2 + 1;
k = 0:0.01:2;
plot(k, J(k)), hold on
plot(1, 1, 'ro', 'markersize', 12, 'linewidth', 2), grid
xlabel k, ylabel J

Sahithi Kandhukuri
2024 年 1 月 8 日
Can you please suggest me a way forward
How to make that ACO code work fine
Torsten
2024 年 1 月 8 日
編集済み: Torsten
2024 年 1 月 8 日
Why not asking the author of the code ?
I don't know exactly what it means in the code description under the above address:
MATLAB implementation of ACO for Discrete and Combinatorial Optimization Problems
Maybe it's not suited for your (and the OP's) continuous optimization problem.
Sam Chak
2024 年 1 月 9 日
Upon reviewing the code, Yarpiz developed an iteration of Ant Colony Optimization (ACO) designed for addressing Combinatorial Optimization Problems, such as the well-known Travelling Salesman and Binary Knapsack problems. Overall, I am of the opinion that the ACO concept can be applied to optimize specific control design parameters within continuous-time dynamical systems.
This problem involves numerous design factors that impact the solution, especially when there are no error messages. It's not as straightforward as a simple equation like 1 + 2 = 3. For instance, at the 11:40 timestamp in the video, the optimal solution is presented as follows:

If the Simulink parameters are configured appropriately,
%% Best solution by ACO
k = [77 230 193 30 330 290];
%% Parameters in Simulink
ke = k(1,1);
kce = k(1,2);
ku = k(1,3);
X = k(1,4);
z_a = abs(k(1,5));
v_a = abs(k(1,6));
%% Fuzzy Logic parameters in Simulink
% negative big
NB = -X;
% negative medium
NM = -X/2;
% positive medium
PM = X/2;
% positive big
PB = X;
% Sam: Zero
Z = 0; % set by User
we would anticipate witnessing identical results (for deterministic systems) as demonstrated in the YouTube video:

However, the outcomes (Load Voltage and Injected Voltage) I achieved in R2023b are evidently different.

Sam Chak
2024 年 1 月 11 日
In theory, yes. The keys to achieving the same results lie in your contributions to this work. The test suggests that despite using the same optimal values, your Simulink model may differ from the YouTube version.
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Particle Swarm についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
