How can I read this input data in this GA code?

Hi everyone! I am getting to know Matlab, but I have an assignment in which I have to use a genetic algorithm code for the flow shop scheduling problem and add a different parameter to it. I already have the code which I obtained from an author that made a paper about this topic. However, the code starts by running the input data from an external file. I retrieved this file but I don't know how can I make Matlab to recognize it as the input data and use it for running the code.
The file is named P5S8T02.dat. When I open it in notepad it looks like this:
jobs 5
stage 8
machines 3 4 1 2 3 5 4 5
*Pro_req*
1 1 3 1 2
3 1 1 2 2
1 1 1 1 1
2 1 1 2 1
1 3 2 1 1
3 5 2 2 4
3 1 4 3 4
3 3 3 2 1
*Pro_time*
75 91 32 49 21
43 12 14 2 27
16 38 52 25 84
51 64 21 42 59
67 63 62 35 11
80 47 6 59 89
86 85 46 83 71
95 84 44 32 48
I guess I have to change the variables name or change the file's format in order to Matlab to read it correctly and run the code.
I would really appreciate if you could help me with this. I know it should be something very simple, but once again, I have never used Matlab before.
Thanks for your help and patience.
Best regards
I attach the full code that I am trying to run just in case. Actually the code is divided in 3 sections (3 separate Matlab files) and I already fixed some errors that Matlab found. Right now the only error that Matlab gives me when I try to run the code is in the line that gets the input data:
run('P5S8T02')
Thanks!!
%************************************************************************
**% ALGORITMO GENÉTICO MODIFICADO DE CHU Y BEASLEY
*% APLICADO AL PROBLEMA DE FLOW-SHOP FLEXIBLE
*% Por: Ángela Patricia Jiménez Morales
*%***********************************************************************
*** clc
clear all To=cputime; tic
%************************************************************************
CARGA DE LA INFORMACIÓN DE ENTRADA
run('P5S8T02')
%************************************************************************
*
% INICIO DEL ALGORITMO GENÉTICO MODIFICADO DE CHU Y BEASLEY
%************************************************************************
*
%Parámetros del Proceso del AGCB rand('state',902345463); %Semilla 465897 78456 NPob=10; %Número de individuos de la población inicial NG=100000; %Número de Generaciones (Iteraciones) tMut=0.35; %Tasa de Mutación
tAcpt=0.10; %Tasa de Aceptación
%************************************************************************
*
% GENERACIÓN DE LA POBLACIÓN INICIAL
%Se usa Heuristica NEH? Si=1, No=0 Heuristica=1;
ini=1;
if Heuristica==1 [Scand,Fmin]=HeuristicaNEH(mT,mE); Pob(ini,:)=Scand;
Fobj(ini)=Fmin; ini=ini+1;
end
for i=ini:NPob Pob(i,1:T)=zeros; j=1;
while j<T+1
g=round((T-1)*rand+1); ver=sum(Pob(i,:)==g); if ver==0
Pob(i,j)=g; j=j+1;
end
end
end
Scand=Pob(i,:); [Cmax]=Makespan(mT,mE,Scand); Fobj(i,1)=Cmax;
Pob %Población Inicial (matriz)
Fobj %Cálculo de la función objetivo de la población inicial (vector)
%************************************************************************
*% PROCESO EVOLUTIVO
FOMejor=445; k=1;
FMejor=min(Fobj); Incumb(k)=FMejor;
while FMejor>FOMejor & k<=NG FMejor=min(Fobj); indMejor=find(Fobj==FMejor); indMejor=indMejor(1); FPeor=max(Fobj); indPeor=find(Fobj==FPeor); indPeor=indPeor(1); Incumb(k)=FMejor;
%*********************************************************************
% Proceso de Selección
%Selección por Torneo
%Primer Torneo ind1=round((NPob-1)*rand+1); ind2=round((NPob-1)*rand+1); F1=Fobj(ind1);
F2=Fobj(ind2); if F1<=F2
FG1=F1;
indG1=Pob(ind1,:); %Ganador del Torneo 1
else
end
FG1=F2;
indG1=Pob(ind2,:); %Ganador del Torneo 1
%Segundo Torneo ind1=round((NPob-1)*rand+1); ind2=round((NPob-1)*rand+1); F1=Fobj(ind1); F2=Fobj(ind2);
if F1<=F2
FG2=F1;
indG2=Pob(ind1,:); %Ganador del Torneo 2
else
end
FG2=F2;
indG2=Pob(ind2,:); %Ganador del Torneo 2
%*********************************************************************
% Proceso de Recombinación
%Recombinación Parcialmente Compatible (PMX Partially Matched Crossover)
clear Desend Desend(1,T)=zeros; r1=round((T-1)*rand+1); r2=round((T-1)*rand+1); while r1==r2
r2=round((T-1)*rand+1);
end
if r1<r2
p=r1; q=r2;
else
end
p=r2; q=r1;
Desend(p+1:q)=indG1(p+1:q); for i=1:T
if (i<p+1) | (i>q) j=1;
while Desend(i)==0 gi=indG2(j); vrf=gi==Desend;
if sum(vrf)==0 Desend(i)=gi;
end
end
end
end j=j+1;
%*********************************************************************
% Proceso de Mutación
%Mutación por Swap o Trueque mtc=rand;
if mtc<tMut
r1=round((T-1)*rand+1); r2=round((T-1)*rand+1); gm1=Desend(r1); gm2=Desend(r2); Desend(r1)=gm2; Desend(r2)=gm1;
end
FDesend=Makespan(mT,mE,Desend);
% FDesend=Cmax;
%*********************************************************************
% Aceptación
acpt=rand;
%Verificación de Diversidad (se controla que no hayan gemelos) Div=1;
j=1;
while Div~=0 & j<=NPob vrfD=sum(Desend~=Pob(j,:)); if vrfD==0
Div=0;
end
end j=j+1;
if Div==1
if FDesend<FPeor Pob(indPeor,:)=Desend; Fobj(indPeor)=FDesend;
else if acpt<tAcpt
Pob(indPeor,:)=Desend; Fobj(indPeor)=FDesend;
end
end
end
k=k+1;
end
FMejor=min(Fobj); indMejor=find(Fobj==FMejor); indMejor=indMejor(1); Sfinal=Pob(indMejor,:)
FOfinal=FMejor plot(Incumb) xlabel('Iteraciones') ylabel('Función Objetivo') toc
Tf=cputime-To
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%ALGORITMO PARA EL CÁLCULO DEL MAKESPAN
%%EN EL PROBLEMA DE FLOW-SHOP FLEXIBLE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function[Cmax]=Makespan(mT,mE,S)
[E T]=size(mT); %Número de Etepas y Número de Tareas M=sum(mE); %Número de Máquinas
%REORDENAMIENTO DE LA MATRIZ DE TIEMPOS DE ACUERDO CON LA SECUENCIA
mTO=mT(:,S); %Matriz de Tiempos Ordenada T=length(S); %El vector de tareas es de tamaño S
%INICIALIZACIÓN DE LA MATRIZ DE TIEMPOS DE TERMINACIÓN
mTT=zeros(M,T);
%CÁLCULO DE LOS TIEMPOS DE TERMINACIÓN DE LAS TAREAS
nmEa=0; for et=1:E
nmE=mE(et); %Número de máquinas en la etapa et tT=mTO(et,:); %Tiempos de las tareas para la etapa et t=0;
for m=1:nmE
t=t+1; if m<=T
máquina
anteriores tarea
end
end
%Se verifica si es mayor el tiempo de la tarea o de la
mTF=max(mTT(m+nmEa,:)); %Tiempo en que se desocupa la máquina mTC=max(mTT(:,t)); %Tiempo en que termina la tarea tTa=max(mTF,mTC); %Se selecciona la mayor entre las dos
%Al tiempo de ejecución se suma el tiempo acumulado de la mTT(m+nmEa,t)=tT(t)+tTa;
%Se verifica si quedan tareas pendientes por ejecutar nTF=T-t;
for m=1:nTF
for ms=1:nmE
if t<T %Se ejecutan solo las tareas pendientes t=t+1;
%Se verifica si es mayor el tiempo de la tarea o de la
máquina máquina
anteriores tarea
end
end
end
mTF=max(mTT(ms+nmEa,:)); %Tiempo en que se desocupa la
mTC=max(mTT(:,t)); %Tiempo en que termina la tarea tTa=max(mTF,mTC); %Se selecciona la mayor entre las dos
%Al tiempo de ejecución se suma el tiempo acumulado de la mTT(ms+nmEa,t)=tT(t)+tTa;
nmEa=nmEa+nmE;
end
%Cálculo del Cmax el cual es el mayor valor de la matriz de tiempos de
%terminación de las tareas correspondiente al tiempo de terminación de la
%última tarea en la última máquina CMF=max(mTT(end,:));
CMC=max(mTT(:,end)); Cmax=max(CMF,CMC); end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%HEURISTICA NEH PARA INICIALIZAR LA POBLACIÓN
%%EN EL PROBLEMA DE FLOW-SHOP FLEXIBLE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function[Scand,Fmin]=HeuristicaNEH(mT,mE)
[E T]=size(mT); %Número de Etepas y Número de Tareas
sTt=sum(mT); %Suma de los Tiempo de las Tareas en todas las Etapas Ord=sort(sTt,'descend'); %ordenamiento de mayor a menor Tiempo i=1;
%Construccion de la secuencia ordenada while i<=T
Si=find(Ord(i)==sTt); for k=1:length(Si)
So(i)=Si(k); i=i+1;
end
end
Sp=So(1); %Secuencia parcial inicial for i=2:T
Sp(i)=So(i); %Actualizacion de la secuencia parcial Tp=length(Sp); %Tamaño de la secuencia parcial Mp=zeros(Tp,Tp);
for j=Tp:-1:1
Mp(j,:)=Sp;
if j>1
Sp1=Sp(j); Sp2=Sp(j-1); Sp(j)=Sp2; Sp(j-1)=Sp1;
end Spr=Mp(j,:);
[Cmax]=Makespan(mT,mE,Spr); %Evaluacion de la FO de las sec. parciales
Fmin(j,1)=Cmax;
end
end
FmejorSp=min(Fmin); %Mejor secuancia parcial Sp=Mp(find(Fmin==FmejorSp),:);
Sp=Sp(1,:);
Scand=Sp; Fmin=FmejorSp;
end

Answers (0)

Asked:

on 22 Apr 2016

Edited:

on 22 Apr 2016

Community Treasure Hunt

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

Start Hunting!