用于交通流研究的程序
源代码在线查看: fi model.cpp
// FI model.cpp
#include "stdafx.h"
#include
#include
#include
using namespace std;
int x[50000],i,v[50000],gap[50000],V,x1[50000],v1[50000],a[50000],b[50000],sum=0,N[10],Q;
float p2;
int rule(int l,int m);
int Max(int a,int b);
int Min(int d,int e);
int _tmain(int argc, _TCHAR* argv[])
{
int L,j,flg,time_steps,c[50000],q;
float p1;
cout cin>>L;
cout cin>>p1;
cout cin>>V;
cout cin>>p2;
cout cin>>time_steps;
srand( (unsigned)time( NULL ) );
for(i=0;i {
c[i]=0;
}
for(i=0;i {
q=int(rand()*(L-1)/RAND_MAX);
if(c[q]==0)
c[q]=1;
else
i=i-1;
}
for(i=0;i {
if(c[i]==1)
{
sum=sum+1;
x[sum]=i;
v[sum]=0;
cout }
else
cout }
cout /* for(i=0;i {
N[i]=0;
}
for(j=1;j {
for(i=0;i {
if(v[j]==i)
N[i]=N[i]+1;
}
}
for(i=0;i cout cout */
for(int k=1;k {
for(i=1;i {
a[i]=x[i];
b[i]=v[i];
}
for(i=1;i {
if(i==sum)
gap[i]=a[1]-a[i]-1;
else
gap[i]=a[i+1]-a[i]-1;
if(gap[i] gap[i]=gap[i]+L;
//cout }
for(i=1;i {
rule(b[i],gap[i]);
}
for(i=1;i {
if((x[i]+v[i])>=L)
x[i]=x[i]+v[i]-L;
else
x[i]=x[i]+v[i];
}
for(j=0;j {
flg=0;
for(i=1;i {
if(j==x[i])
{
cout flg=1;
}
}
if(flg==0)
cout
}
cout /* for(i=0;i {
N[i]=0;
}
for(j=1;j {
for(i=0;i {
if(v[j]==i)
N[i]=N[i]+1;
}
}
Q=0;
for(i=0;i cout cout */
}
return 0;
}
int rule(int l,int m)
{
if(m>=V)
{
l=V;
if((float)(rand())/(float)(RAND_MAX) l=Max((l-1),0);
}
else
l=m;
v[i]=l;
return v[i];
}
int Max(int a,int b)
{
int c;
c=a>b?a:b;
return c;
}
int Min(int d,int e)
{
int f;
f=d return f;
}