⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fig.3&7.sln.cpp

📁 用于交通流研究的Wolfram模型的程序
💻 CPP
字号:
//FIG.3.and FIG.7. 
#include "stdafx.h"
#include<iostream.h>
int a[200],b[8], i,temp[200];
int match(int l,int m,int n);
int _tmain(int argc, _TCHAR* argv[])
{
	int j,n,time_steps;
	cout<<"Please enter the number of sites n:          "<<endl;
	cin>>n;
	cout<<"Please enter time_steps:          "<<endl;
	cin>>time_steps;
	int R,k=7;
	cout<<"Please enter the rule R:          "<<endl;
	cin>>R;
	cout<<"(";
	while(R>0)
	{
		b[k]=R%2;
		R=R/2;		
		k--;
	}
	for(k=0;k<8;k++)
		cout<<b[k];
	cout<<")"<<endl;
	//	将十进制R转化为二进制;
	cout.width(4);
	cout<<"0"<<":";
	for(i=0;i<n;i++)
	{ 
		if(i==int((n-1)/2))
		{
			a[i]=1;
			cout<<"*";
		}
		else
		{
			a[i]=0;
			cout<<" ";
		}		
	}
	cout<<endl;
	//初始时刻中间格点值为1,其它格点值为0;

	for(j=1;j<=time_steps;j++)
	{
		cout.width(4);
		cout<<j<<":";		
		for(i=0;i<n;i++)
			temp[i]=a[i];		
		for(i=0;i<n;i++)
		{			
			if(i==0)
				match(temp[n-1],temp[i],temp[i+1]);
			else 
			{
				if(i==(n-1))
					match(temp[i-1],temp[i],temp[0]);
				//周期性边界条件;
				else
					match(temp[i-1],temp[i],temp[i+1]);
			}
		}
		cout<<endl;    	
	}

	//每个格点同步地按局域规则进行演化;
	return 0;
}
int match(int l,int m,int n)
{
	if(l==1&&m==1&&n)
		a[i]=b[0];
	if(l==1&&m==1&&n==0)
		a[i]=b[1];
	if(l==1&&m==0&&n==1)
		a[i]=b[2];
	if(l==1&&m==0&&n==0)
		a[i]=b[3];
	if(l==0&&m==1&&n==1)
		a[i]=b[4];
	if(l==0&&m==1&&n==0)
		a[i]=b[5];
	if(l==0&&m==0&&n==1)
		a[i]=b[6];
	if(l==0&&m==0&&n==0)
		a[i]=b[7];
	if(a[i]==1)
		cout<<"*";
	else
		cout<<" ";
	return a[i];
}
//定义match函数;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -