Страница: 8/9
procedure setmarker(m : scr_mod; i : integer);
begin
gotoxy(marker_place[m,i].x,marker_place[m,i].y);
end;
procedure wri_val(x : real; i : integer; old : boolean);
begin
if old
then begin textbackground(Black);
textcolor(LightGray)
end
else begin textbackground(LightGray);
textcolor(Black)
end;
setmarker(fun_edit,i+1);
write(' ':4);
setmarker(fun_edit,i+1);
write(x:4:1);
setmarker(fun_edit,i+1);
end;
procedure edit_prob(index : par_typ);
var
st : real;
j : integer;
a : char;
begin
with step_distri[index] do
begin
readscreen('distrib.scr',LightGray,Red);
gotoXY(name_place.x,name_place.y);
case index of
g_shift : write('Глобальный шаг');
l_shift : write('Локальный шаг');
angle : write('Угол');
end;
st:=max_step/10;
for j:=0 to 10 do
begin
step[j]:=j*st;
gotoXY(marker_place[arg_edit,j+1].x,marker_place[arg_edit,j+1].y);
write(step[j]:4:1);
gotoXY(marker_place[fun_edit,j+1].x,marker_place[fun_edit,j+1].y);
write(manual[j]:4:1);
end;
j:=0;
repeat
setmarker(fun_edit,j+1);
wri_val(manual[j],j,false);
setmarker(fun_edit,j+1);
a:=readkey;
if a=#0 then
begin
a:=readkey;
wri_val(manual[j],j,true);
case a of
rightarrow, downarrow : j:=j+1;
leftarrow, uparrow : j:=j-1;
end;
if j>10 then j:=10;
if j<0 then j:=0;
end;
if ((a>='0') and (a<='9')) or (a='-')
then
begin
readreal(st,a,4,marker_place[fun_edit,j+1]);
manual[j]:=st;
end;
until ((a=chr(27)) or (a=' '));
end;
end;
procedure normalize;
var
j : word;
s : par_typ;
x : real;
begin
for s:=g_shift to angle do
begin
x:=0;
for j:=0 to 10 do x:=x+step_distri[s].manual[j];
for j:=0 to 10 do
begin
step_distri[s].cent[j]:=round(100*step_distri[s].manual[j]/x);
end;
step_distri[s].cummulate[0]:=step_distri[s].cent[0];
for j:=1 to 10 do
begin step_distri[s].cummulate[j]:=
step_distri[s].cummulate[j-1]+
step_distri[s].cent[j];
end;
end;
end;
procedure make_population;
var
i, j, x : word;
begin
clrscr;
for i:=1 to 30 do
begin
x:=random(100);
j:=0;
while x>step_distri[g_shift].cummulate[j] do j:=j+1;
step_len:=step_distri[g_shift].step[j];
max_shift[i]:=step_len;
cell[i].x[1]:=500+random(1000);
cell[i].y[1]:=500+random(1000);
cell[i].angle[1]:=random(180);
if random(100)<50 then cell[i].angle[1]:=-cell[i].angle[1];
if max_shift[i]>=15 then cell[i].speed:=fast;
if (max_shift[i]>=7) and (max_shift[i]<15) then cell[i].speed:=mean;
if max_shift[i]<=7 then cell[i].speed:=slow;
end;
end;
procedure init;
var
j : word;
s : par_typ;
x : real;
c : cell_typ;
begin
step_distri[g_shift].max_step:=30;
step_distri[g_shift].cell_name:='Глобальный';
step_distri[l_shift].max_step:=30;
step_distri[l_shift].cell_name:='Локальный';
step_distri[angle].max_step:=180;
step_distri[angle].cell_name:='Углы';
s:=g_shift;
for j:=0 to 10 do step_distri[s].manual[j]:=100*sin(pi*j/10)*sin(pi*j/10);
s:=l_shift;
for j:=0 to 10 do step_distri[s].manual[j]:=100*sin(pi*j/10)*sin(pi*j/10);
s:=angle;
for j:=0 to 10 do step_distri[s].manual[j]:=100*exp(-j/2);
edit_prob(g_shift);
edit_prob(l_shift);
edit_prob(angle);
clrscr;
normalize;
make_population;
end;
procedure calc_step(i : word);
var
x, j : word;
begin
x:=random(100);
j:=0;
while x>step_distri[l_shift].cummulate[j] do j:=j+1;
step_len:=step_distri[l_shift].step[j]*max_shift[i]/30;
x:=random(100);
j:=0;
while x>step_distri[angle].cummulate[j] do j:=j+1;
step_ang:=step_distri[angle].step[j];
x:=random(100);
if x>50 then sign:=-1 else sign:=1;
end;
procedure make_all_steps;
var i, j : word;
begin
for i:=1 to 30 do
with cell[i] do
for j:=2 to 100 do
begin
calc_step(i);
angle[j]:=angle[j-1]+step_ang*sign;
x[j]:=x[j-1]+step_len*cos(angle[j]*pi/180);
y[j]:=y[j-1]+step_len*sin(angle[j]*pi/180);
end;
end;
procedure print_coord;
var i, j, k : word;
f : text;
begin
for i:=1 to 30 do
with cell[i] do
for j:=1 to 100 do
begin
writeln(i:5,x[j]:9:2,y[j]:9:2);
if j mod 20 = 0 then readln(k);
end;
end;
procedure speed_meas;
var
i,j : word;
z : real;
shift : array[1..30] of real;
begin
clrscr;
for i:=1 to 30 do shift[i]:=0;
for i:=1 to 30 do
with cell[i] do
for j:=2 to 100 do
begin
z:=sqrt((x[j]-x[j-1])*(x[j]-x[j-1])+(y[j]-y[j-1])*(y[j]-y[j-1]));
shift[i]:=shift[i]+z;
end;
for i:=1 to 30 do
begin shift[i]:=shift[i]/100;
end;
end;
Реферат опубликован: 23/05/2005 (31481 прочтено)