uses io.printi, io.print, io.InputStream, file.read, conv.stoi, file.FileInput
randomFile:FileInput
size:int
Pm:int
Pc:int
G:int
M:int
rcount:int
best:array[bool]
Jbest:int
randomArray:array[int]
readRandom():int=(
rcount=rcount+1;
if (rcount>=100000) (
rcount=0;
);
r:int=randomArray[rcount];
return r;
)
//Get a random number between 0 and s
rand(s:int):int=(
r:int=readRandom();
r*s/100;
)
//Returns true if a random number is less than p
prob(p:int):bool=(
r:int=readRandom();
return r
=M) (
mate=rand(M-1);
)
else (
mate=i+1;
);
offspring1:array[bool]=new bool[size](false);
offspring2:array[bool]=new bool[size](false);
j:int=0;
while(jJbest) (
Jbest=fitnesses[minIndex];
best=s[minIndex];
);
//print("Current population\n");
//displayPopulation(s);
s=select(s);
//print("Selected population\n");
//displayPopulation(s);
s=crossover(s);
//print("Crossed population\n");
//displayPopulation(s);
s=mutate(s);
//print("Mutated population\n");
//displayPopulation(s);
//Do some elitism
s[min(fitnesses)]=best;
//Display some status
/*print("Iteration ");
printi(i);
print(" : ");
printi(fitnesses[minIndex]);
print("\n");
print("\n");*/
i++;
);
return best;
)
//Get the maximum value an array
max(a:array[int]):int=(
i:int=0;
index:int;
high:int=a[0];
while (ihigh) (
index=i;
high=a[i];
);
i++;
);
return index;
)
//Get the minimum value an array
min(a:array[int]):int=(
i:int=0;
index:int;
low:int=a[0];
while (i \n");
return 1;
);
size=stoi(args[0],10);
Pm=stoi(args[1],2);
Pc=stoi(args[2],70);
G=stoi(args[3],5000);
M=stoi(args[4],100);
//Read the 'random' number file
print("Reading in random number file\n");
randomFile=read("random.in");
randomArray=new int[100000](0);
a:int=0;
while (a<100000) (
randomArray[a]=randomFile.getc();
a++;
);
randomFile.close();
rcount=0;
print("Initializing population\n");
//Set up an initial assignment
sinitial:array[array[bool]]=new array[bool][M](new bool[size](false));
i:int=0;
j:int=0;
while (i