📄 _evec3v5.pas
字号:
program devec3;
{* About devec3 *}
{* Differential Evolution for MATLAB *}
{* Copyright (C) 1996, 1997 R. Storn *}
{* International Computer Science Institute (ICSI) *}
{* 1947 Center Street, Suite 600 *}
{* Berkeley, CA 94704 *}
{* E-mail: storn@icsi.berkeley.edu *}
{* WWW: http://www.icsi.berkeley.edu/~storn/ *}
{* Translated into Pascal by Piotr A. Gauden gaudi@cc.uni.toun.pl *}
{* and *}
{* Hubert Geldon hgeldon@wp.pl *}
{* N. Copernicus Univ. *}
{* Department of Chemistry *}
{* 87-100 Torun *}
{* *}
{* the file !!!! deter.de must be changed !!!! *}
{* to return the objective function *}
{* *}
{* *}
{* *}
{* *}
{* *}
{GetTime.pas}
{GetData.pas}
{$IFDEF CPU87}
{$N+}
Uses Crt,Dos,Printer,Graph;
Type Real = Extended;
{$ELSE}
Uses Crt,Dos,Printer;
{$ENDIF}
{ Include definitions and declarations }
{$I d:\dysk_13\decl.de }
{ Include procedures and functions for generating random }
{$I d:\dysk_13\genps.de }
{ Include procedures and functions for calculating DC }
{$I d:\dysk_13\deter.de }
{ Include procedures and functions for printing output and files with final data }
{$I d:\dysk_13\out_proc.de }
{############################################################################}
BEGIN {* main program *}
clrscr;
{*------input variables------------------------------------------------------------------ *}
assign(xs,'d:\dysk_13\x.txt');
assign(ys,'d:\dysk_13\y.txt');
reset(xs);
reset(ys);
readln(xs,FDX);
readln(ys,FDY);
if FDX <> FDY then
begin
writeln('Number of data points in data files is different. Correct it.');
halt;
end;
if FDX <> XY then
begin
writeln('Number of data points in data files is different then XY value');
writeln('in "const" part of program. Correct it.');
halt;
end;
for datnum := 1 to XY do
begin
readln(xs,xdata[datnum]);
readln(ys,ydata[datnum]);
end;
close(xs);
close(ys);
{*------Enter seed random number (0.000 ... 1.000)----------------*}
randomseed:=rand_time_date;
warmup_random(randomseed);
{*------Evaluate the best member after initialization-----------------------------*}
{*------pop is a matrix of size NPxD. It will be initialized with random values---*}
{*------between the min and max values of the parameters--------------------------*}
cur_gen := 1;
for i := 1 to NP do
for j := 1 to D do
begin
pop[i,j] := XVmin[j] + (rand * (XVmax[j] - XVmin[j]));
end;
n_pop := 1; {*------check the first member-----------------*}
odch_st:=Determination(n_pop,pop);
DC:=1-odch_st;
memberval[1] := odch_st;
bestval := memberval[1];
tempmemberval:=memberval[1];
ClrScr;
Print_Out;
Print_File;
for i := 1 to D do
bestmemiter[1,i] := pop[1,i]; {*------check the first member-----------------*}
for j := 2 to NP do {*------check the rest of members--------------*}
begin
n_pop := j;
odch_st:=Determination(n_pop,pop);
DC:=1-odch_st;
memberval[j] := odch_st;
tempmemberval:=memberval[j];
if tempmemberval < bestval then
begin
bestval := memberval[j];
for k := 1 to D do
bestmemiter[1,k] := pop[j,k];
Print_Out;
Print_File;
end;
end;
for k := 1 to D do
bestmem[1,k] := bestmemiter[1,k]; {*-best member ever, after first generation*}
bestvalev := bestval; {*------check the rest of members----------*}
{*------DE-Minimization-------------------------------------------------------------------*}
{*------popold is the population which has to compete. It is------------------------------*}
{*------static through one iteration. pop is the newly------------------------------------*}
{*------emerging population.--------------------------------------------------------------*}
cur_gen := 2;
while cur_gen <= itermax do
begin
for i := 1 to NP do
for j := 1 to D do
popold[i,j] := pop[i,j]; {*-------save the old population--------------*}
{%%%%%% ind}
for i := 1 to 4 do
begin
randmatrix[i] := rand;
randmatrixint[i] := i;
end;
for j := 1 to 4 do
begin
valmin := 1.0;
for i := 1 to 4 do
begin
if randmatrix[i] < valmin
then
begin
valmin := randmatrix[i];
ind[j] := randmatrixint[i] {*-------shuffle locations of vectors-*}
end;
end;
for k := 1 to 4 do
begin
if randmatrix[k] = valmin
then randmatrix[k] := 1;
end;
end;
{%%%%%% ind}
{%%%%%% rot}
for i := 1 to NP do
rot[i] := i-1; {*-------rotating index array (size NP)-------------------*}
{%%%%%% rot}
{%%%%%% a1}
for i := 1 to NP do
begin
randmatrixnp[i] := rand;
randmatrixnpint[i] := i;
end;
for j := 1 to NP do
begin
valmin := 1.0;
for i := 1 to NP do
begin
if randmatrixnp[i] < valmin
then
begin
valmin := randmatrixnp[i];
a1[j] := randmatrixnpint[i];{*-------shuffle locations of vectors*}
end;
end;
for k := 1 to NP do
begin
if randmatrixnp[k] = valmin
then randmatrixnp[k] := 1;
end;
end;
{%%%%%% a1}
{%%%%%% a2}
for i := 1 to NP do
begin
transmata[i] := rot[i] + ind[1];
tempmata[i] := transmata[i]/NP;
rt[i] := trunc(tempmata[i]);
rt[i] := transmata[i] - NP * rt[i];{*--rotate indices by ind[1] position*}
end;
for i := 1 to NP do
begin
k := rt[i] + 1;
a2[i] := a1[k]; {*-------rotate vector locations----------------------*}
end;
{%%%%%% a2}
{%%%%%% a3}
for i := 1 to NP do
begin
transmata[i] := rot[i] + ind[2];
tempmata[i] := transmata[i]/NP;
rt[i] := trunc(tempmata[i]);
rt[i] := transmata[i] - NP * rt[i];{*--rotate indices by ind[1] position*}
end;
for i := 1 to NP do
begin
k := rt[i] + 1;
a3[i] := a2[k];
end;
{%%%%%% a3}
{%%%%%% a4}
for i := 1 to NP do
begin
transmata[i] := rot[i] + ind[3];
tempmata[i] := transmata[i]/NP;
rt[i] := trunc(tempmata[i]);
rt[i] := transmata[i] - NP * rt[i];{*--rotate indices by ind[1] position*}
end;
for i := 1 to NP do
begin
k := rt[i] + 1;
a4[i] := a3[k];
end;
{%%%%%% a4}
{%%%%%% a5}
for i := 1 to NP do
begin
transmata[i] := rot[i] + ind[4];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -