diff --git a/CruzayMutacion.m b/CruzayMutacion.m index 243c7b6..b250339 100644 --- a/CruzayMutacion.m +++ b/CruzayMutacion.m @@ -1,4 +1,4 @@ -function offspring=CruzayMutacion(p,m,M,N,NP,orden) +function offspring=CruzayMutacion(p,m,M,N,NP,CR,orden) %En la cruza se elige la información en común %entre ambos padres, se elige con proabilidad CR %a uno de los padres como "plantilla", y se permutan @@ -16,7 +16,9 @@ %Aquí se puede utilizar CR %proba CR para el padre %y 1-CR para la madre, por ejemplo... - offspring=p; + if unifrnd(0,1)>=CR + offspring=permutarTrabajos(p,M,N,orden); + end %Aquí se permutan las entradas que son distintas %entre los padres %len=length(c) @@ -28,13 +30,14 @@ %Si el orden se toma en cuenta, no se permutan los trabajos %se sigue el mismo procedimiento mencionado arriba, pero para %cada trabajo, respetando el orden de los mismos + size(p); p=reshape(p,M,N); m=reshape(m,M,N); offspring=reshape(offspring,M,N); %size(offspring) for i=1:N %i, size(p), size(m) - offspring(:,i)==CruzayMutacion(p(:,i),m(:,i),M,1,NP,false); + offspring(:,i)=CruzayMutacion(p(:,i),m(:,i),M,1,NP,false); end offspring=offspring(:); end diff --git a/EvoDif_scheduling.m b/EvoDif_scheduling.m index 1c28134..0c7547d 100644 --- a/EvoDif_scheduling.m +++ b/EvoDif_scheduling.m @@ -1,4 +1,4 @@ -function [mejorindividuo, nfeval] = EvoDif_scheduling(NP,J,orden,generaciones) +function [mejorindividuo, nfeval] = EvoDif_scheduling(NP,J,CR,orden,generaciones) %Minimización con Evolución diferencial %Salidas %-------------------- @@ -68,25 +68,27 @@ while((generacion < generaciones) && (mejorval>1.e-5)) % generacion - poblacion_vieja = poblacion; + %poblacion_vieja = poblacion; %"barajar" población - ind = randperm(4); - a1 = randperm(NP); - rt = rem(rot+ind(1),NP); - a2 = a1(rt+1); + %ind = randperm(4); +% a1 = randperm(NP); +% rt = rem(rot+ind(1),NP); +% a2 = a1(rt+1); % rt = rem(rot+ind(2),NP); % a3 = a2(rt+1); % rt = rem(rot+ind(3),NP); % a4 = a3(rt+1); % rt = rem(rot+ind(4),NP); % a5 = a4(rt+1); - - mp1 = poblacion_vieja(:,a1); - mp2 = poblacion_vieja(:,a2); +% mp1 = poblacion_vieja(:,a1); +% mp2 = poblacion_vieja(:,a2); % mp3 = poblacion_vieja(:,a3); % mp4 = poblacion_vieja(:,a4); % mp5 = poblacion_vieja(:,a5); - + for i=1:NP + mp1(:,i)=permutarTrabajos(J,M,N,orden); + mp2(:,i)=permutarTrabajos(J,M,N,orden); + end for i=1:NP mi(:,i)=mejorinditeracion; end @@ -98,7 +100,7 @@ %----------Mutación/Perturbación---------------- for i=1:NP %offsprings - ui(:,i)=CruzayMutacion(mp1(:,i),mp2(:,i),M,N,NP,orden); + ui(:,i)=CruzayMutacion(mp1(:,i),mp2(:,i),M,N,NP,CR,orden); end % if (estrategia == 1) % DE/best/1 % ui = mi+F*(mp1-mp2); @@ -129,10 +131,10 @@ end mejorinditeracion = mejorindividuo; %-----Salida--------------------------------------------- - if (rem(generacion,1)==0) + if (rem(generacion,20)==0) fprintf(1,'Iteracion: %d, Mejor: %f, NP %d\n ',generacion, mejorval, NP); - reshape(mejorindividuo,M,N) - scheduleCost(reshape(mejorindividuo,M,N)) + %scheduleCost(mejorindividuo,M,N) +% scheduleCost(reshape(mejorindividuo,M,N)) %for n=1:(M*N) % fprintf(1,'Mejor(%d) = %f\n\n', n,mejorindividuo(n)); %end diff --git a/costoSchedule.m b/costoSchedule.m index bea43f4..a0277b0 100644 --- a/costoSchedule.m +++ b/costoSchedule.m @@ -8,5 +8,7 @@ %máxima de las máquinas %http://www2.informatik.hu-berlin.de/alcox/lehre/lvws1011/coalg/makespan_scheduling.pdf J=reshape(J,M,N); + Jmax=repmat(max(J),M,1); + W = Jmax-J c=max(sum(J,2)); end \ No newline at end of file diff --git a/scheduleCost.m b/scheduleCost.m index 2421707..682499b 100644 --- a/scheduleCost.m +++ b/scheduleCost.m @@ -1,3 +1,7 @@ -function c=scheduleCost(J) - c=sum(max(J)); +function c=scheduleCost(J,M,N) + J=reshape(J,M,N); + %Jmax=repmat(max(J),M,1); + %W = max(sum(Jmax-J,2)); + %c=max(sum(J,2)); + c=sum(max(J)); end