Effacer les filtres
Effacer les filtres

Genetic Algorithm Stuck to the Same Results

3 vues (au cours des 30 derniers jours)
Fatih Yigit
Fatih Yigit le 14 Avr 2022
Commenté : Fatih Yigit le 16 Avr 2022
Hello. I have an optimization problem, that aims to schedule the machinery to redue the travelling distance of 5 parts. The problems consists of 8 machines and 5 parts. The machines should be organized in a serial way.
I created the functions that calculates the distances.
The two function work fine. If I enter a feasible sılution it comes with the right output.
Whereas the genetic algorithm part given below, always ends with the results of 79 and schedule to be converted in 5-4-3-2-1-8-7-6 in machine orders.
a(1:9:64)=1; Even this solution is better than 79 as it gives 67. Practically it is 1-2-3-4-5-6-7-8 in machine orders.
No matter how many runs, it always ends with the same results.
I don't know the reason but even manually I have multiple better solutions. Would you please help me figure the reason why it is stuck with a single solution?
++
clc; clear all; close all;
lb = zeros(1, 64);
ub = ones(1, 64);
beq=[1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1]; %Equal Part of the Equality Constraint
j=0;
for j=1:8
Aeq(j, 1+j-1:8:64+j-1)=1; %Equality Constraint
end
for j=1:8
Aeq(j+8, (j-1)*8+1:(j-1)*8+8)=1;
end
options = optimoptions('ga','PlotFcn', @gaplotbestf);
[x,fval,exitflag,output,population,scores] = ga(@TotalDistanceTravelledv2,64, [], [], Aeq, beq, lb, ub, [], 1, options)
z=0;
for s=1:8
z=z+1;
Results(z) = find(x((s-1)*8+1:(s-1)*8+8)==1);
end
++
%The first function that uses binary values as inputs.
function [TotalDistanceTravelled] = TotalDistanceTravelledv2(MachineInput)
ProductSchedule = readmatrix("UrunSira.xlsx");
z=0;
for s=1:8
z=z+1;
MachineRevised(z) = find(MachineInput((s-1)*8+1:(s-1)*8+8)==1);
end
MachineInput = MachineRevised;
for j=1:8
Sequence = MachineInput(j);
MachineLayout(j,Sequence)= 1;
end
TotalDistanceTravelled = DistanceTravelledCalculation(ProductSchedule, MachineLayout);
end
%The second function to calculate the distance
function [TotalDistanceTravelled] = DistanceTravelledCalculation(ProductSchedule, MachineLayout)
%Machine Layout eye(8) Dersteki Örnek
%ProductSchedule ise Dosyadan Alınıyor excel dosyası
%Machine Index
for s=1:8
MachineIndex(s) = find(MachineLayout(s,:)==1);
end
%Sure Hesabı
for i=1:5
for j=1:8
t = ProductSchedule(i, j); %Verinin Al?nmas?
if t==0
t=Schedule(i,j-1); %Arada "0" Varsa Onun Duzeltilmesi
end
Schedule(i,j)= find(MachineLayout(t,:)==1);
end
end
ScheduleBackup = Schedule;
%Distance Travelled Calculation
for j=1:5
for i=1:7
if Schedule(j,i+1)==0
Schedule(j,i+1)= Schedule(j,i);
end
DistanceTravelled(j,i) = abs(Schedule(j,i+1) - Schedule(j,i));
end
end
TotalDistanceTravelled = sum(DistanceTravelled,"all");
end

Réponses (1)

Xinzhi Jiang
Xinzhi Jiang le 15 Avr 2022
Hi Fatih,
I didn't go through your code, but one tip that may help avoid a previous solution is to formulate that solution as constraints in your next run,
e.g.
abs(x(i) - your_undesirable_value_of_x(i)) - tolerence <= 0
Hope that helps.
  3 commentaires
Xinzhi Jiang
Xinzhi Jiang le 16 Avr 2022
Hi,
I ran the files and it showed the error "GA does not solve problems with integer and equality constraints." If I understand correctly, the 64 variables are binary and there is Aeq at the same time. Did that not give an error as you ran your file?
Fatih Yigit
Fatih Yigit le 16 Avr 2022
I believe it is the version of Matlab. Mine didn't give such feedback and there is no such information in Matlab website.
Thanks anyway.

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by