主题:跪求帮助
program wen !这个程序是断开重连的以前的概率费米分布学习!
integer,parameter::l=1000
real u,idum1,idum2,idum3,idum4,idum5,idum6,idum7
real x1(l),x(l)
integer kk,i2,i1,i3,i4,i5,i6,i7,i8,i9,x2(l,l),k(l),k1(20)
integer nc,nd,nc1,nd1,j3,t1,j5
real pa,pb
u=0.2
call random_seed()
open(1,file='w=0.0.dat')
open(2,file='w=0.05.dat')
open(3,file='w=0.1.dat')
open(4,file='w=0.5.dat')
!do u=0.1,1.0,0.02
! do t2=1,20
! n=0
! sum=0.0
! do i=1,l
! do j=1,l
! x2(i,j)=0
! enddo
! enddo
do i=1,l
k(i)=0
enddo
do i=1,l
call random_number(idum1)
if(idum1.le.0.5)then
x1(i)=1 !cooper
else
x1(i)=-1 !defecter
endif
enddo
do I=1,L
CALL bianjie(l,i,im,ip,im1,ip1)
K(I)=K(I)+1
X2(I,K(I))=IM
enddo
do I=1,L
CALL bianjie(l,i,im,ip,im1,ip1)
K(I)=K(I)+1
X2(I,K(I))=IM1
enddo
do I=1,L
CALL bianjie(l,i,im,ip,im1,ip1)
K(I)=K(I)+1
X2(I,K(I))=Ip
enddo
do I=1,L
CALL bianjie(l,i,im,ip,im1,ip1)
K(I)=K(I)+1
X2(I,K(I))=Ip1
enddo
! do t=1,10000
do t1=1,1000000
do i=1,l
x(i)=0
enddo
call random_number(idum2)
i1=int(idum2*l)+1
if(i1.gt.l)i1=l
call random_number(idum3)
kk=int(idum3*k(i1))+1
do i2=1,k(i1)
if(x1(x2(i1,i2)).eq.1)then
nc=nc+1
else !这个是判断这个点的收益!
nd=nd+1
endif
enddo
if(x1(i1).eq.1) pa=nc
if(x1(i1).eq.-1) pa=nc*(1.0+u)+nd*u
! do j=1,k(x2(i1,kk))
! if(x1(x2(x2(i1,kk),j)).eq.1)then
! nc1=nc1+1
! else
! nd1=nd1+1
! endif
! enddo
! if(x1(x2(i1,kk)).eq.1) pb=nc1 !这个是判断这个点挑选的最近邻的收益!
! if(x1(x2(i1,kk)).eq.-1) pb=nc1*(1.0+u)+nd1*u
! j6=x2(i1,kk)
!if(x2(i1,kk).eq.0) pause
!do i=1,k(j6)
!write(*,*)x2(j6,i)
!if(x2(j6,i).eq.0) pause
!enddo
!pause
!if(pa.lt.pb)then
!write(*,*)J6,K(J6)
!write(*,*)k(x2(i1,kk))!kk,i1,i5,x2(i1,kk),k(i1),
call conglai(i1,l,k1)
13 call random_number(idum4)
j3=int(idum4*20)+1
if(j3.gt.20)j3=20
i3=k1(j3)
if(i3.gt.l)i3=l
do j=1,k(i1)
if(i3.eq.x2(i1,j).or.i3.eq.i1)then
goto 13
endif !这个是断开后重新重连的!
enddo
if(k(x2(i1,kk)).gt.1)then
do i4=1,k(x2(i1,kk))
if(x2(x2(i1,kk),i4).eq.i1)then
x2(x2(i1,kk),i4)=0
i5=i4
endif
!
enddo
do i6=1,k(x2(i1,kk))
if(x2(x2(i1,kk),i6).ne.0)then
x(i6)=x2(x2(i1,kk),i6)
else
goto 17
endif
enddo
17 do i8=i5,k(x2(i1,kk))
x(i8)=x2(x2(i1,kk),i8+1)
enddo
k(x2(i1,kk))=k(x2(i1,kk))-1
do i9=1,k(x2(i1,kk))
x2(x2(i1,kk),i9)=x(i9)
enddo
x2(i1,kk)=i3
k(i3)=k(i3)+1
x2(i3,k(i3))=i1
!endif
elseif(k(x2(i1,kk)).eq.1)then
!if(k(x2(i1,kk)).eq.1)then
x2(x2(i1,kk),k(x2(i1,kk)))=0
k(x2(i1,kk))=0
call conglai(i1,l,k1)
16 call random_number(idum5)
j4=int(idum5*20)+1
if(j4.gt.20)j4=20
j5=k1(j4)
if(j5.gt.l)j5=l
do j=1,k(i1)
if(j5.eq.x2(i1,j).or.j5.eq.i1)then
goto 16
endif !这个是断开后重新重连的!
enddo
k(j5)=k(j5)+1
x2(j5,k(j5))=i1
x2(i1,kk)=j5
endif
!elseif(k(x2(i1,kk)).eq.0)then
! cycle
!endif
!i5,k(j5),t1
! if(k(x2(i1,kk)).eq.0)exit
write(*,*)t1 !k(i1),j5,k(j5)
!pause
!pause
! if(k(i1).lt.1)exit
!J6,K(J6),i5,x2(j6,i5)
!if(i3.eq.0)
!k(x2(i1,kk)) !kk,i1,i5,x2(i1,kk),k(i1)
!write(1,*)i1,k1(j3)
enddo
end
subroutine bianjie(l,i,im,ip,im1,ip1)
integer i,im,ip,im1,ip1
im=i+1
ip=i-1
im1=i+2
ip1=i-2
if(i.eq.1)then
iP=L
ip1=L-1
endif
if(i.eq.L)then
iM=1
IM1=2
endif
if(i.eq.2)then
ip1=l
endif
if(i.eq.L-1)then
IM1=1
endif
return
end
!subroutine payoff(x1,l,i,u,k(l),pa)
!real x1(l),i,k(l)
!do j=1,k(i)
!if(x2(i,j).eq.1)then
! nc=nc+1
! else
!nd=nd+1
!endif
!e!nddo
!if(x1(i).eq.1)then
!pa=nc
!else
!pa=nd*u
!endif
!return
! end
subroutine conglai(i,l,k1)
integer k1(20)
integer a,b,c
do j=-10,-1
b=i+j
if(i.le.10)then
if(b.lt.0)then
c=abs(b)
k1(j+11)=l-c
elseif(b.eq.0)then
k1(j+11)=l
else
k1(j+11)=b
endif
else
k1(j+11)=b
! if(b.eq.0)k1(j+11)=l
endif
enddo
do j=11,20
a=i+j-10
if(a.gt.l)then
k1(j)=a-l
else
k1(j)=a
endif
enddo
return
end
subroutine tongji(x1,l,nc2)
real x1(l)
integer nc2
nc2=0
do i=1,l
if(x1(i).eq.1)then
nc2=nc2+1
endif
enddo
return
end
!if(j5.gt.l)exit
! write(*,*)j5
!pause
!endif
! if(k(j5).gt.l)exit
! if(k(i1).gt.l)exit
! if(k(j5).lt.1)exit
! if(k(6).gt.l)exit
! if( x2(i1,kk).le.0)exit
! if(k(x2(i1,kk)).lt.1)exit
! if(k1(j4).le.0)exit
! if(x2(j5,k(j5)).le.0)exit
integer,parameter::l=1000
real u,idum1,idum2,idum3,idum4,idum5,idum6,idum7
real x1(l),x(l)
integer kk,i2,i1,i3,i4,i5,i6,i7,i8,i9,x2(l,l),k(l),k1(20)
integer nc,nd,nc1,nd1,j3,t1,j5
real pa,pb
u=0.2
call random_seed()
open(1,file='w=0.0.dat')
open(2,file='w=0.05.dat')
open(3,file='w=0.1.dat')
open(4,file='w=0.5.dat')
!do u=0.1,1.0,0.02
! do t2=1,20
! n=0
! sum=0.0
! do i=1,l
! do j=1,l
! x2(i,j)=0
! enddo
! enddo
do i=1,l
k(i)=0
enddo
do i=1,l
call random_number(idum1)
if(idum1.le.0.5)then
x1(i)=1 !cooper
else
x1(i)=-1 !defecter
endif
enddo
do I=1,L
CALL bianjie(l,i,im,ip,im1,ip1)
K(I)=K(I)+1
X2(I,K(I))=IM
enddo
do I=1,L
CALL bianjie(l,i,im,ip,im1,ip1)
K(I)=K(I)+1
X2(I,K(I))=IM1
enddo
do I=1,L
CALL bianjie(l,i,im,ip,im1,ip1)
K(I)=K(I)+1
X2(I,K(I))=Ip
enddo
do I=1,L
CALL bianjie(l,i,im,ip,im1,ip1)
K(I)=K(I)+1
X2(I,K(I))=Ip1
enddo
! do t=1,10000
do t1=1,1000000
do i=1,l
x(i)=0
enddo
call random_number(idum2)
i1=int(idum2*l)+1
if(i1.gt.l)i1=l
call random_number(idum3)
kk=int(idum3*k(i1))+1
do i2=1,k(i1)
if(x1(x2(i1,i2)).eq.1)then
nc=nc+1
else !这个是判断这个点的收益!
nd=nd+1
endif
enddo
if(x1(i1).eq.1) pa=nc
if(x1(i1).eq.-1) pa=nc*(1.0+u)+nd*u
! do j=1,k(x2(i1,kk))
! if(x1(x2(x2(i1,kk),j)).eq.1)then
! nc1=nc1+1
! else
! nd1=nd1+1
! endif
! enddo
! if(x1(x2(i1,kk)).eq.1) pb=nc1 !这个是判断这个点挑选的最近邻的收益!
! if(x1(x2(i1,kk)).eq.-1) pb=nc1*(1.0+u)+nd1*u
! j6=x2(i1,kk)
!if(x2(i1,kk).eq.0) pause
!do i=1,k(j6)
!write(*,*)x2(j6,i)
!if(x2(j6,i).eq.0) pause
!enddo
!pause
!if(pa.lt.pb)then
!write(*,*)J6,K(J6)
!write(*,*)k(x2(i1,kk))!kk,i1,i5,x2(i1,kk),k(i1),
call conglai(i1,l,k1)
13 call random_number(idum4)
j3=int(idum4*20)+1
if(j3.gt.20)j3=20
i3=k1(j3)
if(i3.gt.l)i3=l
do j=1,k(i1)
if(i3.eq.x2(i1,j).or.i3.eq.i1)then
goto 13
endif !这个是断开后重新重连的!
enddo
if(k(x2(i1,kk)).gt.1)then
do i4=1,k(x2(i1,kk))
if(x2(x2(i1,kk),i4).eq.i1)then
x2(x2(i1,kk),i4)=0
i5=i4
endif
!
enddo
do i6=1,k(x2(i1,kk))
if(x2(x2(i1,kk),i6).ne.0)then
x(i6)=x2(x2(i1,kk),i6)
else
goto 17
endif
enddo
17 do i8=i5,k(x2(i1,kk))
x(i8)=x2(x2(i1,kk),i8+1)
enddo
k(x2(i1,kk))=k(x2(i1,kk))-1
do i9=1,k(x2(i1,kk))
x2(x2(i1,kk),i9)=x(i9)
enddo
x2(i1,kk)=i3
k(i3)=k(i3)+1
x2(i3,k(i3))=i1
!endif
elseif(k(x2(i1,kk)).eq.1)then
!if(k(x2(i1,kk)).eq.1)then
x2(x2(i1,kk),k(x2(i1,kk)))=0
k(x2(i1,kk))=0
call conglai(i1,l,k1)
16 call random_number(idum5)
j4=int(idum5*20)+1
if(j4.gt.20)j4=20
j5=k1(j4)
if(j5.gt.l)j5=l
do j=1,k(i1)
if(j5.eq.x2(i1,j).or.j5.eq.i1)then
goto 16
endif !这个是断开后重新重连的!
enddo
k(j5)=k(j5)+1
x2(j5,k(j5))=i1
x2(i1,kk)=j5
endif
!elseif(k(x2(i1,kk)).eq.0)then
! cycle
!endif
!i5,k(j5),t1
! if(k(x2(i1,kk)).eq.0)exit
write(*,*)t1 !k(i1),j5,k(j5)
!pause
!pause
! if(k(i1).lt.1)exit
!J6,K(J6),i5,x2(j6,i5)
!if(i3.eq.0)
!k(x2(i1,kk)) !kk,i1,i5,x2(i1,kk),k(i1)
!write(1,*)i1,k1(j3)
enddo
end
subroutine bianjie(l,i,im,ip,im1,ip1)
integer i,im,ip,im1,ip1
im=i+1
ip=i-1
im1=i+2
ip1=i-2
if(i.eq.1)then
iP=L
ip1=L-1
endif
if(i.eq.L)then
iM=1
IM1=2
endif
if(i.eq.2)then
ip1=l
endif
if(i.eq.L-1)then
IM1=1
endif
return
end
!subroutine payoff(x1,l,i,u,k(l),pa)
!real x1(l),i,k(l)
!do j=1,k(i)
!if(x2(i,j).eq.1)then
! nc=nc+1
! else
!nd=nd+1
!endif
!e!nddo
!if(x1(i).eq.1)then
!pa=nc
!else
!pa=nd*u
!endif
!return
! end
subroutine conglai(i,l,k1)
integer k1(20)
integer a,b,c
do j=-10,-1
b=i+j
if(i.le.10)then
if(b.lt.0)then
c=abs(b)
k1(j+11)=l-c
elseif(b.eq.0)then
k1(j+11)=l
else
k1(j+11)=b
endif
else
k1(j+11)=b
! if(b.eq.0)k1(j+11)=l
endif
enddo
do j=11,20
a=i+j-10
if(a.gt.l)then
k1(j)=a-l
else
k1(j)=a
endif
enddo
return
end
subroutine tongji(x1,l,nc2)
real x1(l)
integer nc2
nc2=0
do i=1,l
if(x1(i).eq.1)then
nc2=nc2+1
endif
enddo
return
end
!if(j5.gt.l)exit
! write(*,*)j5
!pause
!endif
! if(k(j5).gt.l)exit
! if(k(i1).gt.l)exit
! if(k(j5).lt.1)exit
! if(k(6).gt.l)exit
! if( x2(i1,kk).le.0)exit
! if(k(x2(i1,kk)).lt.1)exit
! if(k1(j4).le.0)exit
! if(x2(j5,k(j5)).le.0)exit