You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Output is not as expected
1 view (last 30 days)
Show older comments
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 Comments
Sahithi Kandhukuri
on 8 Jan 2024
sorry..... below are the attached files required
Sam Chak
on 8 Jan 2024
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
on 8 Jan 2024
Sorry I am unbale to understand could you please describ it clearly
Sam Chak
on 8 Jan 2024
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
on 8 Jan 2024
Can you please suggest me a way forward
How to make that ACO code work fine
Torsten
on 8 Jan 2024
Edited: Torsten
on 8 Jan 2024
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.
Sahithi Kandhukuri
on 8 Jan 2024
I have taken this ACO algorithm as reference
Sahithi Kandhukuri
on 9 Jan 2024
just to know..how did he get the output using same ACO algorithm
Sam Chak
on 9 Jan 2024
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.
Sahithi Kandhukuri
on 11 Jan 2024
Will changing the parameters help us in getting those results?
Sam Chak
on 11 Jan 2024
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.
Answers (0)
See Also
Categories
Find more on Particle Swarm in Help Center and File Exchange
Tags
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)