我是用神经网络理论进行编程的,线程代码如下:
procedure threadone.Execute;
var
i,j,count,count2:integer;
begin
freeOnTerminate:=true;
begin
{ Place thread code here }
//用hopfield网络计算选号;
///初始化
for i:=1 to 31do
for j:=1 to 31do
form4.distance[i,j]:=1-form4.distance[i,j];
randomize();
form4.caluWij();
for i:=1 to 31do
for j:=1 to 31do
begin
form4.S[i,j]:=0+random(10)/10000;
form4.Uc[i,j]:=0;
end;
count:=1;
count2:=1;
form4.randomRan(961,961);
for i:=1 to 961do
form4.ran:=form4.ran-1;
form9.Show;
////////////////////////////
repeat
if Terminated then
break;
if count=962 then
begin
form4.randomRan(961,961);
for i:=1 to 961do
form4.ran:=form4.ran-1;
count:=1;
end;
i:=(form4.ran[count] mod 31 )+1;//取余+1作为个位
j:=(form4.ran[count] div 31 )+1;//取整+1作为十位
form4.updateUc(j,i);
if form4.Uc[j,i]>0
then
form4.S[j,i]:=1
else
form4.S[j,i]:=0;
form4.caluE1();
form4.caluE2();
form4.caluE3();
form9.label3.caption:=inttostr(count);
if form4.S[i,j]=1 then
begin
form9.canvas.brush.Style := bsSolid;
form9.canvas.brush.Color := clBlack;
form9.Canvas.Ellipse((20+20*(j-1)),
(20+20*(i-1)),(30+20*(j-1)),(30+20*(i-1)));
end
else
if form4.S[i,j]=0 then
begin
form9.canvas.brush.Style := bsSolid;
form9.canvas.brush.Color := clwhite;
form9.Canvas.Ellipse((20+20*(j-1)),
(20+20*(i-1)),(30+20*(j-1)),(30+20*(i-1)));
end;
count:=count+1;
count2:=count2+1;
until
((form4.E1=0) and (form4.E2=0) and (form4.E3=0))
showmessage('计算完毕。');
for j:=1 to 31do
if form4.S[j,1]=1 then
form4.suiEdit8.Text :=inttostr(j);
for j:=1 to 31do
if form4.S[j,2]=1 then
form4.suiEdit9.Text :=inttostr(j);
for j:=1 to 31do
if form4.S[j,3]=1 then
form4.suiEdit10.Text :=inttostr(j);
for j:=1 to 31do
if form4.S[j,4]=1 then
form4.suiEdit11.Text :=inttostr(j);
for j:=1 to 31do
if form4.S[j,5]=1 then
form4.suiEdit12.Text :=inttostr(j);
for j:=1 to 31do
if form4.S[j,6]=1 then
form4.suiEdit13.Text :=inttostr(j);
for j:=1 to 31do
if form4.S[j,7]=1 then
form4.suiEdit14.Text :=inttostr(j);
if form4.fie=8 then
begin
for j:=1 to 31do
if form4.S[j,8]=1 then
form4.suiEdit24.Text :=inttostr(j);
end
else
form4.suiEdit24.Text:='';
end;
end;
有调用其它窗体的过程和变量,这样是否不行?