资源简介
C++ 元胞自动机 人员疏散 仿真 模拟自动化
代码片段和文件信息
#include “stdafx.h“
#include “iVPS.h“
#include “math.h“
#include “time.h“
#include “iostream.h“
int Np=50; //初始化人数
int timestep=0;
LNode *s;
int count=0;
fstream vfile;//open file to save density data;
fstream ffile;// open file to save flow rate data;
fstream cfile; //open file to save the count of each type of pedestrians;
//=================链表操作================================
bool ListInsert(LNode *sint iint xint y)
{
int peoplenum=s->per.index;
LNode *p_temp=s;
while(p_temp->next!=NULL)//error
{
p_temp=p_temp->next;
}
LNode *news;
if((news=(LNode*)malloc(sizeof(LNode)))!=NULL)
{
p_temp->next=news;
news->next=NULL;
news->per.index=i;
news->per.location.x=x;
news->per.location.y=y;
news->per.s=0;
s->per.index=i;
return true;
}
else
return false;
}
struct LNode *ListFind(LNode *s int index)
{
LNode *p_temp=s;
while(p_temp->next!=NULL)
{
if(p_temp->next->per.index==index)
return p_temp->next;
else
p_temp=p_temp->next;
}
return p_temp;
}
struct LNode * Listdelete(LNode *sint xint y)
{
int pernum=s->per.index;
LNode *p_temp=s->next ;
LNode *p_pre=s;//p_temp
while(p_temp->per.location.x != x || p_temp->per.location.y!=y)
{
p_pre=p_temp;
p_temp=p_temp->next;
}
p_pre->next =p_temp->next;
p_temp->next=NULL;
free(p_temp);
p_temp=NULL;
s->per.index=pernum-1;
return p_pre;
}
bool randomseq(LNode *s)
{
LNode *p_temp=s;
while(p_temp->next!=NULL)//error
{
int rand1=(int)(rand()/(double)RAND_MAX)*(Np-1);
struct LNode *p;
LNode temp;
p=ListFind(srand1);
p_temp->next->per.s=0;//清空方向记录;
p->per.s=0;
temp.per.index=p_temp->next->per.index;
temp.per.location.x=p_temp->next->per.location.x;
temp.per.location.y=p_temp->next->per.location.y;
p_temp->next->per.index=p->per.index;
p_temp->next->per.location.x=p->per.location.x;
p_temp->next->per.location.y=p->per.location.y;
p->per.index=temp.per.index;
p->per.location.x=temp.per.location.x;
p->per.location.y=temp.per.location.y;
p_temp=p_temp->next;
}
return true;
}
//==============================================================
bool initparam()
{//20
int ij;
//========初始化通道==============
for( i=0;i {//3
if(i==0||i==RoomWidth-1)
{//1
for (j=0;j Ch[i][j]=-1;
Ch[RoomWidth-1][RoomLength/2]=0;
Ch[RoomWidth-1][RoomLength/2-1]=0;
Ch[RoomWidth-1][RoomLength/2+1]=0;
Ch[RoomWidth-1][RoomLength/2+2]=0;
}//1
else
{//2
for(j=0;j if(j==0||j==RoomLength-1)
{
Ch[i][j]=-1;
}
else
Ch[i][j]=0;
}//2
}//3
//========初始化人群==============
if((s = (LNode*) malloc (sizeof(LNode)))!=NULL)
{//6
s->per.index=0;
s->next=NULL;
}//6
for( i=1;i<=Np;i++)
{//8
int xy;
do
{
double rand1=(rand()/(double)RAND_MAX);
double rand2=(rand
相关资源
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
- FTP客户端源码(c++)
- c++ 画图(14Qt-XPS)
- c++多边形交并差运算
- VC++基于OpenGL模拟的一个3维空间模型
评论
共有 条评论