이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
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
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!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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 (한국어)
