资源简介
2车道交通流模拟元胞自动机换道模型代码,是学习换道模型的基础.
代码片段和文件信息
// 2 Roads Merging NaSch CA model
// By David Clarke ( dave@maths.tcd.ie )
// Original source available at www.maths.tcd.ie/~dave/traffic/
//Compile with cc -o traffic traffic.c
#include
#include
#include
#define leadin_d 500
#define overlap_d 10
#define leadout_d 500
#define max_length 2100 // greater then leadin+overlap+leadout
#define speed_limit1_d 5
#define speed_limit2_d 5
#define steps_d 20000 //Number of Steps updates
#define cars1_d 0 // cars to start with (0 is empty road)
#define cars2_d 0
#define cars0_d 0 // leadout cars
#define prob_d 0.5 // probability of stopping
#define slow_start_d 0.0
#define relax_d 600 // steps ignore before measuring
#define flux_time_d 2000 //steps flux measured over
#define print_d 0
#define split 10000000
#define once 0 // if 1 run for only one density for scatter plot.
#define max_density 1 // limiter 0->1 can stop program for a lower density
typedef struct {
int car;
int vel;
int moved;
int pre_vel; //previous velocity used in slow to start
int jtime;
int origin;
int num;
} road_t;
FILE *out1;
FILE *outScatter1 *outScatter2;
FILE *out_jtime1 *out_jtime2;
//Function definitions
void print_road (int);
void print_jams ();
void print_flow_density();
void print_scatter (int c int tstep);
void setup (int);
void setup_leadout ();
void setspeed (int);
void update (int c int tstep);
void measure_density();
void variables (int argc char *argv[]);
//global variables
road_t Road1[max_length]Road2[max_length];
int leadinoverlapleadout speed_limit[3] steps cars[3] relax density_width flux_timetot_lengthprint;
double prob slow_start;
int count[3]density_start[3]density_stop[3] time_count density[3] jtimeMax[3]jtimeMin[3];
int main (int argc char *argv[])
{ /* Start up */
int ij n dpr;
road_t *roadP;
variables (argc argv); //take in variables from command line
tot_length=leadin+overlap+leadout;
//density measurement parameters.
density_start[1]=density_start[2]=leadin/2;
density_start[0]=leadin+overlap+leadout/2;
density_stop[1]=density_stop[2]=leadin;
density_stop[0]=leadin+overlap+leadout;
out1 = fopen (“density_flow.dat“ “w“);
outScatter1 = fopen (“trafficYScatter1.dat“ “w“);
outScatter2 = fopen (“trafficYScatter2.dat“ “w“);
out_jtime1 = fopen (“jtime1.dat“ “w“);
out_jtime2 = fopen (“jtime2.dat“ “w“);
srand (time (0)); // random seed
while(cars[1] /* Set Up */
n = 0;
setup (1); // initial positioning of cars
setup (2); // initial positioning of cars
setup_leadout();
count[1]=count[2]=1;
if(print){ print_road(1); // initial print
print_road(2); // initial print
}
/* Relax */
while(n < relax) {n++; //allow system to settle
setspeed(1);
update(1-1);
setspeed(2);
update(2-1);}
// Give each car a number:
for(i=0;i if(Road1[i].c
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 14553 2008-10-16 17:05 tarc\traffic.c
目录 0 2009-03-04 21:49 tarc
----------- --------- ---------- ----- ----
14553 2
- 上一篇:一种改进的类人足球机器人的目标识别算法
- 下一篇:分布式风电源选址定容规划研究
评论
共有 条评论