1 · web viewamax = c + dv (2) the average values of their parameters for cars, c = 3.705 and d =...

42
Does excessive lane changing on multilane motorways cause delays? Robert James Sutton 10106333 CSC 450, Eastern Connecticut State University January 19, 2016

Upload: others

Post on 29-Jan-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

1

Does excessive lane changing on multilane motorways cause delays?

Robert James Sutton 10106333

CSC 450, Eastern Connecticut State University

January 19, 2016

Does excessive lane changing on multilane motorways cause delays?

Robert James Sutton

ABSTRACT

INTRODUCTION

The excessive use of motorcars (Wilson, 2012) in the United States has created a plethora of global political (Rooke, 2008; Paterson, 2007; Schwartz; Hub Pages, 2012; Kepel, 2006), environmental(Rajan; Paterson, 2007; Schwartz; Hub Pages, 2012), economic (Paterson, 2007; Schwartz; Hub Pages, 2012; Kepel, 2006; USDOT-FHWA, 2015 ), social (Schwartz; Foner and Garraty, 1991; Hub Pages, 2012; Messer-Kruse, 2006; USDOT-FHWA, 2015), and religious (Kepel, 2006; Messer-Kruse, 2006) problems. Looking at the economic problems, a major one is the loss of productivity due to lost time sitting in stalled traffic (USDOT-FHWA, 2014, 2015; Schrank and Lomax, 2009) and psychological stress (Stokols et al, 1978, USDOT- FHWA, 2015). A contributing factor to these problems is the additional delay caused by drivers needlessly changing lanes (Brown and Dia, 2006). Their experimentation involved a real world peak hour commute in Sydney, Australia. One driver, the control, stayed in lane as much as possible. The other driver, the treatment, changed lanes aggressively. The lane changing driver was only able to do about 1 km hr-1 better than the control. However, they report “The aggressive driver used 2 and a half times as much fuel.” Drivers can be ticketed for excessive lane changing in several states (Acurazine 2001; New Jersey; Parks and Braxton, 2015). Beaty (1998) observed the backward moving wave of congestion. His real world experimentation and observations were made on SR-250, a motorway in Seattle. His treatment was “Rather than repeatedly rushing ahead with everyone else, only to come to a halt, I decided to try to move at the average speed of the traffic. I let a huge gap open up ahead of me, and timed things so I was arriving at the next ‘stop-wave’ just as the last red brakelights were turning off ahead of me.” The response was most impressive, that the cars behind him were all travelling at a steady speed, albeit much slower than the posted limit. His conclusion was “That ‘nice’ noncompetitive driver can erase traffic waves.” This author suspects that the converse is also true: normal highway competition CREATES the traffic waves. A simulation of traffic flow becomes necessary to see what may happen if the aggregate of driving behaviours is changed. What would happen if everyone stayed in lane as much as possible?

Many attempts have been made to simulate traffic congestion and identify its causes. Nagel and Schreckenberg (1992) use a cellular approach. Each cell or “site” may or may not contain a car. They use one dimensional array of “sites” with open (linear) or periodic (circular) boundary conditions. Bando et al (1995) use a “Dynamical” model of traffic congestion using a “legal velocity” value for each vehicle and use both analytical and numerical methods, see Figure 1. Macal and North (2006) provide a broad view of agent based modelling and simulation. Bremer et al (2008) focus on real time observation and reporting of traffic problems to the general public. They report a qualitative model of congestion based on pouring dry rice through a funnel, a model developed by an entry in a contest by Washington State DOT. Flynn et al (2009) take a fluid dynamic approach and liken traffic jams to “detonation waves” propagating through the air. They use the term “jamitrons”, or particles of jam. To me it seems valid since a shock wave would be a travelling wave of compressed air molecules akin to cars being packed bumper to bumper. Tuzo et al (2011) extend “the original N-S (Nagel and Schreckenberg 1992) model by casting it as an agent-based model and adding a heterogeneous population, multiple lanes, and lane changing behaviors.” Mehar et al (2013) model and derive formulas for calculating vehicle accelerations. The aim of this project is to use a simplified agent-based model following the methodology of Tuzo et al (2011) in order to reproduce the backward moving traffic waves described in previous works and demonstrate the slowing of traffic by excessive lane changing.

Figure 1: Backward moving congestion waves (Bando et al, 1995)

MATERIALS AND METHODS

Software for the simulation was developed mainly in Microsoft® Visual Studio® 2008 running in the Microsoft® Windows® XP [Version 5.1.2600] system on a HP Pavilion with an AMD Athlon™ XP 3000+ 2.10 GHz processor and 1.43GB of RAM. The software was transferred for further runs to computers on the Eastern Connecticut State University campus running various versions of Visual Studio in a Windows® 7 environment. The C# language is used since it is an OO language with graphic capabilities.

R Programming is used to generate a normal distribution of desired speeds. The mean of 30.8 m sec-1 was picked as the midpoint between the posted speed limit of 29.1 m sec-1 and Miller’s (2014) reported cruise control setting of 32.7 m sec-1.

Acceleration, provided sufficient headway, was the average acceleration, a function of speed as reported by Mehar et al (2013).

aave = AeBv (1)

The average values of their parameters for cars, A = 1.915 and B = -0.375 were used to obtain the average acceleration in m sec-2. Their maximum acceleration, also a function of velocity, which is given by:

amax = C + Dv (2)

The average values of their parameters for cars, C = 3.705 and D = -0.0525 were used.

Deceleration was proportional using an arbitrary constant of 300 m sec-2 and was based on headway related to the two second rule (modified for aggression) or if the vehicle was travelling faster than the desired velocity. The maximum deceleration of -5.19 m sec-2 was derived from the New Jersey Driver Manual.

Other factors are considered. Serving drinks to the various drivers can be simulated by adding a BAC (Blood Alcohol Content) variable. The value of BAC is used to slow the reaction time and increase the aggression factor of the driver. The aggression factor is varied randomly. It is used to decrease the following distance from the two second rule. For example, a driver with an aggression factor of 1.5 will follow 1.333 seconds behind the preceding vehicle. Since the baseline reaction time of 1.5 seconds described in the New Jersey Driver Manual seemed too long and resulted in so many accidents that usable data could not be extracted, a reaction time of 0.5375 seconds, an average derived from Austin (2009), was selected. This time is adjusted for alcohol based on the report from University of Texas at San Antonio, “How Alcohol Can Affect Safe Driving Skills”.

treact = 0.5375 (1 + BAC)2 (3)

This relationship is shown graphically in Figure A-1. Results are analysed using R-Programming and Microsoft® Excel®.

RESULTSModel Description

The model is linear, continuous, and represents a single lane of traffic. It can simulate traffic flow in one direction on a bidirectional two lane motorway such as US Route 6 between Columbia and Bolton, CT or of a single lane of traffic on a multilane motorway such as Interstate 84. This allows for a one-dimensional, linear system. MKSA (Metre-Second-Kilogram-Ampere, the international standard) units are used for all measurements. For example, a posted speed limit (maximum) of 105 km hr-1 is converted to 29 m sec-1. See Table A-1 for expression of speeds in various units of measure. The terms “speed” (a scalar value) and “velocity” are used interchangeably since only velocities in the +x direction are of concern. An agent-based model is used (Dancik, 2015; Macal and North, 2006). Such a model is valid for a traffic simulation in that it considers the stochastic behaviour of cars with drivers on a motorway (Macal and North, 2006). Tuzo et al. (2011) take an object oriented (OO) approach in that we can create objects (agents) with various attributes, and rules of behaviour.

Attributes:Desired Velocity

Reaction Time

Blood Alcohol Content

Acceleration/Deceleration

Aggression

Velocity

Rules of Behaviour:Two Second Rule (New Zealand, 1998; Ontario 2009)

Alcohol slows reaction time and increases aggression.

Allow “lane changes”: None, overtaking, increasing frequency.

The simplest case is with no lane such as would occur in the real world on a two lane, undivided motorway, (Example: U.S. Route 6) where overtaking is forbidden (double yellow line). Lane changing on a multilane, divided motorway can be set to overtaking only (when a car leaves the lane, the agent is “destroyed”, and a flag is set to allow creation a new agent at some x > 0. Increased frequencies of lane changing (lane changes ∙ km-1 · sec-1), where x is the distance from an arbitrarily determined starting point expressed in meters, will be studied. With these increased frequencies, agents are destroyed and created randomly. The frequencies of lane changing are described as “Low”, “Medium”, “High”, “Aggressive” and “Extreme”. Quantitatively they are 0.2, 0.4, 0.6, 0.8, and 1.0 lane changes per kilometre per second. Vehicles were fed into the model at a rate of 1 vehicle every 3 seconds at x = 0.

Model Output and Analysis

Model runs using no lane changing resulted in the “parade” phenomenon described by Miller (2014) and observed by the author is shown in Figure 2. The “parade” phenomenon occurs when a slow driver (“parade leader”) has a long line of vehicles behind, resembling a parade. Each following vehicle travels at a fixed following distance (two seconds, baseline) regardless of his or her desired velocity. The inclusion of an aggression factor results in some drivers following closer than others which is more akin to the real world.

Figure 2: Parade phenomenon

Vehicle trajectories for various runs show the backward moving waves of congestion in Figure 3. The thick, vertical lines are accidents with resulting traffic jams behind them. It is interesting to note that some of the accidents occur at the end of such a traffic wave. There is much white space on the plot since the model is linear in contrast to that of Bando et al (1995) who used a circular model. In addition, Figure 3 represents the base case with alcohol and aggression added. With only serene, sober drivers the model can run accident free indefinitely (Figure 5).

Figure 3: Vehicle trajectories

The model was run with a control (no lane changing), necessary lane changing (overtaking) only, and increasing frequencies of random lane changing. Representative vehicles were chosen since this project’s objective is to look at delays caused by lane changing alone and not by accidents. Their speeds are tabulated in Table 1 and plotted in Figure 4.

Table 1: Speeds (m sec-1) under various conditions

Confounding Variables

Aggression

Treatment

None

Alcohol

Aggression

+ Alcohol

Control

26.6

26.6

26.9

27.0

Overtake

28.8

29.7

28.5

29.5

Low

29.3

29.9

29.9

30.1

Moderate

30.4

29.5

27.7

28.0

High

30.8

28.1

30.8

30.2

Aggressive

28.6

24.3

28.3

28.9

Extreme

29.8

23.2

29.8

27.2

Vehicle Speed

20.0

22.0

24.0

26.0

28.0

30.0

32.0

Control

Overtake

Low

Moderate

High

Aggressive

Extreme

Treatment

Speed (meters/second)

None

Alcohol

Aggression

Aggression + Alcohol

Figure 4: Vehicle speeds with various conditions

Figure 5: Base case

Figure 6: Overtaking

Figure 7: Low -- 0.2 Lane Changes per km per second

Figure 8: High -- 0.6 Lane changes per km per second

DISCUSSION

The results, contrary to the beliefs of this author, actually show somewhat of an increase in speed with increased lane changing. The exception to this is where there is alcohol but no aggression. This could be due to the fact that the drinking drivers with their slowed reaction times miss opportunities to get ahead.

One problem which remains is the increased frequency of accidents in the various simulations. (See Figures 5 through 8.) This makes it difficult to get an aggregate of vehicles and calculate a mean velocity or do further statistical analysis. The high frequency of accidents is exemplified in Figure 9. The representative vehicle’s trajectory is shown in red. However, it, too, becomes stuck in a traffic jam behind an accident at 2,500 metres which occurred at barely over a minute into the run.

With the bumper to bumper jams behind accidents, it was impossible to get meaningful vehicle density data from the results.

Figure 9: Extreme lane changing (1.0 lane changes per km per second) with drinking, aggressive drivers

Figure 9 is an example of what these simulations were intended to demonstrate. When the representative vehicle entered the lane, the following vehicles had so slow down to maintain safe distance. There also is yet another vehicle which did not slow down and came dangerously close to the preceding vehicle.

Figure 10: Detail from Figure 9 showing slowing for vehicles entering the lane

The high frequencies of accidents in these simulations led the author to place further constraints on the system. However, while considering preventing certain behaviours, the author has observed many of the same in the real world. Therefore, it is necessary to further “fine tune” the model to achieve desired results. It is interesting to see the apparent increase in accident occurrence with increased lane changing. Although delays caused by lane changing alone could not be clearly demonstrated, accidents do occur on the highways and will certainly ruin everyone’s day.

Initially, the feed rate of vehicles into the model at x = 0 was 1 vehicle every 2 seconds. The resultant pileups made this rate unacceptable. Therefore, as mentioned in the model description, a rate of 1 vehicle every 3 seconds was chosen. This would provide for an initial vehicle density of approximately 11 vehicles per km.

REFERENCES CITED

Acurazine (2001)

Internet: http://acurazine.com/forums/second-generation-cl-discussion-2000-2003-50/got-ticket-today-excessive-lane-changing-407047/

Bando, M., K. Hasebe, A. Nakayama, A. Shibata, and Y. Sugiyama. Dynamical model of traffic congestion and numerical simulation. Physical Review E 51:2, 1035-1042 (1995).

Beaty, William. Traffic Waves: Sometimes one driver can vastly improve traffic. Science Hobbiest, (1998) website http://trafficwaves.org/

Bremmer, Daniela, MPA, James H. Bryan, Jr., MPA, Cole T.E. Fitzpatrick, MA.

Maximizing Highway System Capacity: Measuring and Communicating System

Performance in an Evolving Field, Transportation Research Forum, (2008).

Internet: http://www.wsdot.wa.gov/NR/rdonlyres/5FF329ED-A840-4F8A-A798-468948BEE80B/0/Maximizing_Highway_Capacity_PM_finalvsn.pdf

Brown, David, Dr. Hussein Dia. Lane Change Challenge, Catalyst, ABC (2006, 2014).

Internet: http://www.abc.net.au/catalyst/stories/s1698662.htm

Dancik, Dr. Garrett. Personal communication, Eastern Connecticut State University (2015).

Flynn, M. R., A. R. Kasimov, J.-C. Nave, R. R. Rosales, and B. Seibold Self-sustained nonlinear waves in traffic flow. Physical Review E 79.5 (2009) 056113, The American Physical Society.

Internet: http://dspace.mit.edu/handle/1721.1/51741

Foner, Eric and John A. Garraty (eds.). The Reader’s Companion to American History (1991). Houghton Mifflin Harcourt Publishing Company.

Internet: http://www.history.com/topics/automobiles

Grant, S. A., K. Millar and G. N. C. Kenny. Blood alcohol concentration and psychomotor effects, British Journal of Anaesthesia 85 (3): 401-6 (2000).

Internet: http://bja.oxfordjournals.org/content/85/3/401.full.pdf

HubPages. The Automobile - Effects / Impact on Society and Changes in Cars Made by Generation, (2012, 2015). Internet: http://leisurelife.hubpages.com/hub/Affects-of-the-Automobile-on-Society-and-Changes-Made-by-Generation

Kepel, Gilles Anthony F. Roberts (tr.). Jihad: The Trail of Political Islam, I.B. Tauris, London, New York, Chapter 3, “Building Petro-Islam on the Ruins of Arab Nationalism.” (2006)

Macal, Charles M. and Michael J. North. Introduction to Agent-based Modeling and Simulation. Center for Complex Adaptive Agent Systems Simulation (CAS2), Decision & Information Sciences Division, Argonne National Laboratory, MCS LANS Informal Seminar, (2006).

Internet: http://www.mcs.anl.gov/~leyffer/listn/slides-06/MacalNorth.pdf

Mehar, Arpan, Satish Chandra, and Senathipathi Velmurugan. Speed and Acceleration Characteristics of Different Types of Vehicles on Multi-Lane Highways. European Transport \ Trasporti Europei Issue 55, Paper n° 1, ISSN 1825-3997 (2013)

Internet: http://www.istiee.org/te/papers/N55/ET_2013_55_1_Mehar.pdf

Messer-Kruse, Timothy F. “Societal Impact of the Industry” in Kevin Hillstrom and Laurie Collier Hillstrom (eds.), Industrial Revolution in America: Automobiles, ABC-CLIO, Inc. Santa Barbara (2006), pp 177-

Miller, Stephen. Personal communication, Benistar confidential (2014).

Nagel, Kai and Michael Schreckenberg. A cellular automaton model for freeway traffic. Journal de Physique I, EDP Sciences, 2 (12), pp.2221-2229 (1992).

Internet: https://hal.archives-ouvertes.fr/jpa-00246697/document

<10.1051/jp1:1992277>.

National Highway Traffic Safety Administration. “A Review of the Literature on the Effects of Low Doses of Alcohol on Driving-Related Skills” (2000)

http://www.nhtsa.gov/people/injury/research/pub/HS809028/index_.htm

New Jersey Driver Manual Chapter 5: “Defensive Driving”

Internet: http://www.state.nj.us/mvc/pdf/Licenses/Driver%20Manual/Chapter_5.pdf

New Zealand Transport Agency. The Official New Zealand Road Code

“Key driving skills: Following distance: The two-second rule” (1998, 2015).

https://www.nzta.govt.nz/resources/roadcode/about-driving/following-distance/

Ontario Ministry of Transportation. Driver's Handbook II. “Driving along: Maintaining space” (2009).

Internet: http://www.mto.gov.on.ca/english/dandv/driver/handbook/section2.2.6.shtml

This site is maintained by the Government of Ontario

© Queen's Printer for Ontario, 2009

Parks & Braxton, PA - Fort Lauderdale Criminal Defense Attorney, Fort Lauderdale (2015).

Internet: http://www.ftlauderdalecriminaldefensefirm.com/Traffic-Offenses/Excessive-Lane-Changing.aspx

Paterson, Matthew. Automobile Politics Ecology and Cultural Political Economy.

Chapter 4, “Automobile political economy”, Cambridge University Press (2007) pp 91- 120.

Rajan, Sudhir Chella, The enigma of automobility: democratic politics and pollution control Collection: University of Pittsburgh Press Digital Editions,

Internet: http://digital.library.pitt.edu/cgi-bin/t/text/pageviewer-idx?c=pittpress;cc=pittpress;idno=31735057896205;rgn=full%20text;didno=31735057896205;view=image;seq=0019;node=31735057896205%3A1.8.1

Rooke, Rob. Corporate System: History of the Automobile, its impact. (2008)

Internet: http://www.skeptically.org/cs/id2.html

Schrank, David and Tim Lomax. 2009 URBAN MOBILITY REPORT:

Six Congestion Reduction Strategies and Their Effects on Mobility, Texas Transportation Institute, The Texas A&M University System, (2009).

Internet: http://d2dtl5nnlpfr0r.cloudfront.net/tti.tamu.edu/documents/TTI-2008-10.pdf

Schwartz, Joel. The Social Benefits and Costs of the Automobile.

Internet: https://www.joelschwartz.com/pdfs/Schwartz_Automobile.pdf

Siliquini, Roberta , Fabrizio Bert, Francisco Alonso, Paola Berchialla, Alessandra Colombo, Axel Druart, Marcin Kedzia, Valeria Siliquini, Daniel Vankov, Anita Villerusa, Lamberto Manzoli, and TEN-D Group (TEN-D by Night Group). Correlation between driving-related skill and alcohol use in young-adults from six European countries: the TEN-D by Night Project, BMC Public Health. 11: 526. (2011).

Published online 2011 Jul 1. doi:  10.1186/1471-2458-11-526

PMCID: PMC3145590 http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3145590/

Stokols, Daniel, Raymond W. Novaco, Jeanette Stokols, and Joan Campbell. Traffic Congestion, Type-A Behavior and Stress. Institute of Transportation Studies, University of California, Irvine (1978).

Internet: http://www.its.uci.edu/its/publications/papers/ITS/UCI-ITS-WP-78-5.pdf

TTI. As Traffic Jams Worsen, Commuters Allowing Extra Time for Urgent Trips, Texas A&M Transportation Institute · Texas A&M University System · 3135 TAMU · College Station, Texas (2013).

Internet: http://tti.tamu.edu/2013/02/05/as-traffic-jams-worsen-commuters-allowing-extra-time-for-urgent-trips/

Tuzo, Joseph, John Seymour, and Marie desJardins. “Using Agent-Based Simulation to Determine an Optimal Lane-Changing Strategy on a Multi-Lane Highway”

Complex Adaptive Systems: Energy, Information and Intelligence: Papers from the 2011 AAAI Fall Symposium (FS-11-03) (2011).

United States Department of Transportation - Federal Highway Administration.

Congestion Pricing — A Primer: Overview (2014).

Internet: http://ops.fhwa.dot.gov/publications/fhwahop08039/cp_prim1_02.htm

United States Department of Transportation - Federal Highway Administration – Office of Operations. Traffic Congestion and Reliability: Trends and Advanced Strategies for Congestion Mitigation (2015).

Internet: http://www.ops.fhwa.dot.gov/congestion_report/chapter2.htm

University of Texas at San Antonio “How Alcohol Can Affect Safe Driving Skills” Internet: https://www.utsa.edu/utsapd/Crime_Prevention/Crime_prevention%20pdf/How%20Alcohol%20Can%20Affect%20Safe%20Driving%20Skills.pdf

Wilson, Lindsay Shrink! Which nations drive, fly, cycle and take the train most? (ça 2012). Internet: http://shrinkthatfootprint.com/travels-most#7gHpfeKM7826RMkV.99

APPENDICES

Table A1: Velocities in various units, MKSA far right

mph

km hr-1

m sec-1

4

6.4

1.8

8

12.9

3.6

25

40.2

11.2

35

56.3

15.6

45

72.4

20.1

55

88.5

24.6

65

104.6

29.1

70

112.7

31.3

75

120.7

33.5

0.50

0.52

0.54

0.56

0.58

0.60

0.62

0.64

0.66

0.68

0.70

0.000.020.040.060.080.100.120.14

BAC (%)

Reaction Time (s)

Fig A1: Reaction Time vs Blood Alcohol Content

PROGRAMME LISTINGS

# // Major Project

# // Programmer:Robert J. Sutton

# // Course:

CSC450, Section 1, Fall 2015

# // Date:

16.11.2015

# // Description:This programme is designed to provide a simple, but as true to life

# //

as possible traffic model to answer the question:

# //

# //

Does excessive lane changing on multilane motorways cause delays?

# //

# //

# R Programme to generate tables of desired driver velocities and blood alcohol contents.

# Generate a normal distribution around an arbitrary midpoint between the statutory speed

# limit (105 km/hr) and the "safe" cruising speed (118 km/hr) described by Miller (2014).

v = rnorm(10000, mean = 30.8, sd = 1.8)

v

write.csv(v, file = "C:/Documents and Settings/Owner/My Documents/Eastern/CSC 450/V.csv", quote = TRUE,

eol = "\n", na = "NA", row.names = FALSE,

fileEncoding = "")

# Generate a normal distribution around zero BAC (Most drivers don't drink at all.)

# Those who do drink will have 1 or 2 drinks, so a .03 standard deviation is used.

# Negative values will be converted to zero

bac = rnorm(10000, mean = 0, sd = .03)

bac

write.csv(bac, file = "C:/Documents and Settings/Owner/My Documents/Eastern/CSC 450/bac.csv", quote = TRUE,

eol = "\n", na = "NA", row.names = FALSE,

fileEncoding = "")

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.IO;

using System.Linq;

using System.Text;

using System.Windows.Forms;

// Major Project

// Programmer: Robert J. Sutton

// Course: CSC450, Section 1, Fall 2015

// Date: 16.11.2015

// Description: This programme is designed to provide a simple, but as true to life as

// possible traffic model to answer the question:

//

// Does excessive lane changing on multilane motorways cause delays?

//

//

namespace Project_1

{

public partial class Form1 : Form

{

const decimal TIMESTEP = 0.01m; // Run in 0.01 second time intervals.

const decimal MAXDECEL = -5.19m; // Value derived from NJ Driver Manual.

//const decimal MAXDECEL = -40.00m; // An arbirtary value I chose

car[] cars = new car[10000];

decimal[] vDesired = new decimal[10000];

decimal[] BAC = new decimal[10000];

StreamReader sr = new StreamReader("v.csv");

StreamReader sr1 = new StreamReader("bac.csv");

StreamWriter sw = new StreamWriter("Output_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".csv");

/************ Constant factors from Mehar et al (2013)****************/

/***** Used to calculate acceleration as a function of velocity ******/

const decimal A = 1.915m; //

const decimal B = -0.0375m; //

const decimal C = 3.705m; //

const decimal D = -0.0525m; //

/*********************************************************************/

public Form1()

{

InitializeComponent();

}

private void btnQuit_Click(object sender, EventArgs e)

{

this.Close();

}

private void btnGo_Click(object sender, EventArgs e)

{

decimal t = 0;

int ID = 0;

int changeFreq = 0; // "Treatment" is changing this value.

decimal cTime = 0; // Time of last change

decimal dTime = 1; // Time till next change

bool permitInsert = false;

Bitmap BM = new Bitmap(pictureBox1.ClientSize.Width, pictureBox1.ClientSize.Height);

pictureBox1.Image = BM;

string trash = sr.ReadLine(); // Trash column titles from R code.

trash = sr1.ReadLine();

// Read data arrays generated by R programme

for (int i = 0; i < 10000; i++)

{

vDesired[i] = Convert.ToDecimal(sr.ReadLine());

string line = sr1.ReadLine();

if (line.IndexOf('E') > 0 || line.IndexOf('e') > 0) BAC[i] = 0; // Small quantities in e-xx format

else BAC[i] = Convert.ToDecimal(line);

if (BAC[i] < 0) BAC[i] = 0; // BAC cannot be negative.

}

// Close input files

sr.Close();

sr1.Close();

// Head the Output file

string oLine = cbPermitLaneChange.Text;

if (cbAggressive.Checked) oLine += ",aggressive";

if (cbAlcohol.Checked) oLine += ",drinking";

sw.WriteLine(oLine);

oLine = "t, car, x(m), car, x(m), car, x(m), car, x(m), car, x(m), car, x(m), car, x(m), car, x(m), car";

sw.WriteLine(oLine);

// Random Lane Change

switch (cbPermitLaneChange.Text)

{

case "LOW":

{

changeFreq = 1; // Lane changes per km per sec.

break;

}

case "MODERATE":

{

changeFreq = 2;

break;

}

case "HIGH":

{

changeFreq = 3;

break;

}

case "AGGRESSIVE":

{

changeFreq = 4;

break;

}

case "EXTREME":

{

changeFreq = 5;

break;

}

case "NONE":

case "OVERTAKE ONLY":

default:

{

changeFreq = 0;

break;

}

}

//while (1 == 1)

while(ID < 1500) // End run after 1500 cars

{

// Create a car at x = 0 at 3 second intervals.

if (Math.Abs(t / 3 - Math.Floor(t / 3)) < 0.001m)

{

cars[ID] = new car();

initCar(cars[ID], ID, 0);

ID++;

}

// Let's move the cars

for (int i = 0; i < ID; i++)

{

cars[i].x += TIMESTEP * cars[i].v;

cars[i].v += TIMESTEP * cars[i].a;

// Cars may not go backwards.

if (cars[i].v < 0)

{

cars[i].v = 0;

cars[i].a = 0;

}

if (i != 0)

{

cars[i].headway = cars[cars[i].precedingCar].x - cars[i].x - 5;

// Accident

if (cars[i].headway < 0)

{

accident(i, cars[i].precedingCar, cars[i].x);

}

else

{

if (cars[i].headway < 2 / cars[i].aggFac * cars[i].v || cars[i].v > cars[i].vDesired)

{

if (cars[i].brake && t >= cars[i].deTime + cars[i].reactTime)

{

if (cars[i].headway < 2 / cars[i].aggFac * cars[i].v)

{

cars[i].a = 300 * (cars[i].headway - 2 / cars[i].aggFac * cars[i].v) / cars[i].headway;

}

else if (cars[i].v > cars[i].vDesired)

{

cars[i].a = 300 * (cars[i].vDesired - cars[i].v) / cars[i].vDesired;

}

if (cars[i].a < MAXDECEL) cars[i].a = MAXDECEL;

}

else if (!cars[i].brake)

{

cars[i].brake = true;

cars[i].gas = false;

cars[i].deTime = t;

}

}

else if (cars[i].headway > 2 / cars[i].aggFac * cars[i].v + 10 && cars[i].v < cars[i].vDesired)

{

if (cars[i].gas && t >= cars[i].acTime + cars[i].reactTime)

{

cars[i].a = aAve(cars[i].v);

if (cars[i].a > aMax(cars[i].v)) cars[i].a = aMax(cars[i].v);

}

else if (!cars[i].gas)

{

cars[i].brake = false;

cars[i].gas = true;

cars[i].acTime = t;

}

}

else

{

cars[i].brake = false;

cars[i].gas = false;

cars[i].a = 0;

}

}

// Emergency stop situation

if ((cars[i].headway < 600 && cars[cars[i].precedingCar].v < 0.75m * cars[i].v) || cars[cars[i].precedingCar].emergStop)

{

if (!cars[i].emergStop) cars[i].esTime = t;

cars[i].emergStop = true;

}

if (cars[i].emergStop && t > cars[i].esTime + cars[i].reactTime)

{

cars[i].a = MAXDECEL;

}

if (cars[i].v <= cars[cars[i].precedingCar].v) cars[i].emergStop = false;

}

// Draw the car

int offset = 0;

switch (cmbDisplay.Text)

{

case " 0 to 1 km":

offset = 0;

lblStart.Text = "km 0 ";

lblEnd.Text = "km 1 ";

break;

case " 1 to 2 km":

offset = 1000;

lblStart.Text = "km 1 ";

lblEnd.Text = "km 2 ";

break;

case " 2 to 3 km":

offset = 2000;

lblStart.Text = "km 2 ";

lblEnd.Text = "km 3 ";

break;

case " 3 to 4 km":

offset = 3000;

lblStart.Text = "km 3 ";

lblEnd.Text = "km 4 ";

break;

case " 4 to 5 km":

offset = 4000;

lblStart.Text = "km 4 ";

lblEnd.Text = "km 5 ";

break;

case " 5 to 6 km":

offset = 5000;

lblStart.Text = "km 5 ";

lblEnd.Text = "km 6 ";

break;

case " 6 to 7 km":

offset = 6000;

lblStart.Text = "km 6 ";

lblEnd.Text = "km 7 ";

break;

case " 7 to 8 km":

offset = 7000;

lblStart.Text = "km 7 ";

lblEnd.Text = "km 8 ";

break;

case " 8 to 9 km":

offset = 8000;

lblStart.Text = "km 8 ";

lblEnd.Text = "km 9 ";

break;

case " 9 to 10 km":

offset = 9000;

lblStart.Text = "km 9 ";

lblEnd.Text = "km 10 ";

break;

case "10 to 11 km":

offset = 10000;

lblStart.Text = "km 10 ";

lblEnd.Text = "km 11 ";

break;

case "11 to 12 km":

offset = 1000;

lblStart.Text = "km 11 ";

lblEnd.Text = "km 12 ";

break;

default:

offset = 0;

lblStart.Text = "km 0 ";

lblEnd.Text = "km 1 ";

break;

}

lblStart.Refresh();

lblEnd.Refresh();

int xPlot = Convert.ToInt32(cars[i].x);

xPlot -= offset;

if (cars[i].exists)

{

for (int x = xPlot; x >= xPlot - 5; x--)

{

if (x > 0 && x < 1000)

{

for (int y = 16; y < 19; y++)

{

BM.SetPixel(x, y, Color.LightGreen);

}

}

}

for (int x = xPlot - 6; x >= xPlot - 11; x--)

{

if (x > 0 && x < 1000)

{

for (int y = 16; y < 19; y++)

{

BM.SetPixel(x, y, SystemColors.ControlDarkDark);

}

}

}

}

}

pictureBox1.Refresh();

// Output our results

if (t - Math.Floor(t) < 0.001m)

{

oLine = t.ToString();

int n = ID;

if (n > 126) n = 126;

for (int i = 0; i <= n; i++)

{

oLine += "," + i.ToString() + "," + cars[i].x.ToString();

}

sw.WriteLine(oLine);

}

string timer = t.ToString();

if (t < 0.001m) timer += ".00";

lblClock.Text = "SIMULATED TIME = " + timer;

lblClock.Refresh();

t += TIMESTEP;

}

sw.Close();

}

public decimal aAve(decimal v)

{

return A * Convert.ToDecimal(Math.Exp(Convert.ToDouble(B * v)));

}

public decimal aMax(decimal v)

{

return C + D * v;

}

public void initCar(car auto, int ID, decimal x)

{

auto.ID = ID;

auto.x = x;

//auto.vDesired = 30;

auto.BAC = 0;

int j = ID;

while (j >= 10000) j -= 10000;

auto.vDesired = vDesired[j];

if (cbAlcohol.Checked) auto.BAC = BAC[j];

auto.a = 0;

if (ID == 0)

{

auto.precedingCar = -1; // The first car has no preceding car;

auto.headway = 1000; // arbitrarily set its headway to 1 km.

}

else

{

decimal xMin = x + 1000;

decimal xMax = 1;

for (int i = 0; i < ID; i++)

{

// Find the preceding car

if (cars[i].x > x)

{

if (cars[i].x < xMin)

{

auto.precedingCar = i;

auto.headway = cars[i].x - x - 5; // 5 meters for the car length

cars[i].followingCar = ID; // We're following the preceding car.

xMin = cars[i].x;

} // End if

} // End if

// Find the following car

if (cars[i].x < x)

{

if (cars[i].x > xMax)

{

auto.followingCar = i;

cars[i].headway = x - cars[i].x - 5; // 5 meters for the car length

cars[i].precedingCar = ID; // We're preceding the following car.

xMax = cars[i].x;

}

}

} // End for

} // End else

auto.v = auto.vDesired;

auto.exists = true;

auto.aggFac = 1; // 1 = no aggression

if (cbAggressive.Checked)

{

Random random = new Random();

int randomNumber = random.Next(0, 100);

auto.aggFac += Convert.ToDecimal(randomNumber) / 200; //

auto.aggFac *= (1 + 10 * auto.BAC);

}

auto.reactTime = 1.5m; // From the New Jersey Driver Manual, Chapter 5

//auto.reactTime = 0.5375m; // Average Baseline from Austin (2009)

//auto.reactTime = 0.25m; // An arbitrary value I chose.

double martini = 1 + Convert.ToDouble(auto.BAC);

auto.reactTime *= Convert.ToDecimal(Math.Pow(martini, 2));

auto.brake = false;

auto.gas = false;

auto.acTime = 0;

auto.deTime = 0;

auto.crashed = false;

auto.emergStop = false;

} // End Method

public void accident(int vehicle1, int vehicle2, decimal x)

{

cars[vehicle1].v = 0;

cars[vehicle1].a = 0;

cars[vehicle1].crashed = true;

cars[vehicle2].v = 0;

cars[vehicle2].a = 0;

cars[vehicle2].crashed = true;

lblAccident.Visible = true;

lblAccident.Refresh();

}

public void insertCar(int ID, decimal x)

{

cars[ID] = new car();

initCar(cars[ID], ID, x);

}

public void deleteCar(int ID)

{

cars[ID].exists = false;

decimal x1 = cars[cars[ID].precedingCar].x;

decimal x2 = cars[cars[ID].followingCar].x;

cars[cars[ID].followingCar].headway = x1 - x2 - 5;

cars[cars[ID].followingCar].precedingCar = cars[ID].precedingCar;

cars[cars[ID].precedingCar].followingCar = cars[ID].followingCar;

}

}

public class car

{

public int ID; // Unique identifier, incremented by 1 for each agent created

public decimal x; // Position of the car in meters

public decimal v; // Velocity of the car (meters/second in +x direction)

public decimal a; // Change in velocity of car (meters/sec/sec)

public int precedingCar; // The car ahead

public int followingCar; // The car behind

public bool exists; // Set to true when agent is created, false when destroyed

public decimal BAC; // Driver's blood alcohol content (% w/v)

public decimal aggFac; // Driver's aggression factor

public decimal reactTime; // Driver's reaction time (seconds)

public decimal vDesired; // Driver's desired velocity

public decimal headway; // Distance between the car and the rear of the preceding car (meters)

public bool brake; // Driver decelerates

public bool gas; // Driver accelerates

public decimal deTime; // Time driver needs to start decelerating

public decimal acTime; // Time driver has clearance to accelerate

public bool crashed; // Has the car been involved in an accident?

public bool emergStop; // The car in front is stopped.

public decimal esTime; // Time driver needs to slow down or stop for stopped traffic ahead.

}

}

# // Major Project

# // Programmer: Robert J. Sutton

# // Course: CSC450, Section 1, Fall 2015

# // Date: 16.11.2015

# // Description: This programme is designed to provide a simple, but as true to life as

# // possible traffic model to answer the question:

# //

# // Does excessive lane changing on multilane motorways cause delays?

# //

# Analysis of output results.

cars = read.csv("~/Eastern/CSC 450/Project_1/Project_1/bin/Debug/Output_201511231129.csv")

# Plot vehicle trajectories

y=cars[,1]

x=cars[,2]

plot(x,y, type="l", main="Vehicle Trajectories",sub="No Lane Changing",xlab="Distance (m)", ylab="Time (s)")

n=ncol(cars)

for (i in 3:n) {

x=cars[,i]

#if(i %% 10 == 0) lines(x,y)

lines(x,y)

}

# Calculate vehicle densities

dist = max(cars[,2])

m = nrow(cars)/60

density <- matrix(0, m, n)

for (i in 1:nrow(cars)) {

if (i%%60==0){ # One minute intervals

minute = i/60

for (j in 2:n){

for (k in 1:dist/100)

{

if (cars[i,j]> 100*k && cars[i,j]<= 100*k+1000){

density[minute,k] = density[minute,k]+ 1

}

}

}

}

}

END NOTES

Variant spellings and grammatical constructions are retained in titles and direct quotes.