Traffic Simulator - Washington University in St. Louis



| |

|Traffic Simulator |

|Architecture Design Assignment |

| |

| |

| |

| |

| |

| |

| |

| |

| |

| |

| |

| |

| |

| |

| |

| |

|Khalid AlHokail |

|Luke Bay |

|James Grady |

|Michael Murphy |

| |

|Version 1.1 |

|2/4/2007 |

| |

Table of Contents

1. Architecture Diagram 3

2. Component’s Objects 4

2.1. Traffic Simulator 4

2.1.1. Data Display Plots 4

2.1.2. Data Storage 4

2.1.3. Assignment 4

2.1.4. Constraint Evaluator 5

2.1.5. User Interface 5

2.2. Map Model 6

2.2.1. Load_Graph 6

2.2.2. Load_Intersection_Rules 6

2.2.3. Load_Road_Properties 6

2.2.4. Segment_Divider 6

2.2.5. Draw_2D_Map 7

2.2.6. Start_End_Construction 8

2.2.7. Refresh_Map 8

2.3. Driving Model 9

2.3.1. Max_Population_Array 9

2.3.2. Current_Population_Array 9

2.3.3. Migration_Scheduler 10

2.3.4. Migration_Traffic_Generator 11

2.3.5. Random_Traffic_Generator 12

2.4. Traffic Light Control 12

2.4.1. Light Cycle Timer 12

2.4.2. Traffic Light Cycler 13

2.5. Decision Model 13

2.5.1. Route_Generator_General 13

2.5.2. Route_Generator_Blockage_Rerouter 13

2.5.3. Traffic_Incident_Generator 13

2.5.4. Traffic_Incident_Update_Map_Model 14

2.5.5. Traffic_Incident_Update_2D_Map 14

2.5.6. Traffic_Incident_Monitor_Collisions 14

2.5.7. Vehicle_Speed_Adapter 14

2.5.8. Map_Reader 15

3. Interface Specification 15

3.1. Traffic Simulator 15

51.1. Map Model 16

131.1. Driving Model 18

175.1. Traffic Light Control 19

223.1. Decision Model 20

Architecture Diagram

[pic]

Component’s Objects

1 Traffic Simulator

1 Data Display Plots

1 Objects

1. Display Car Data

• This object displays the selected car status and any information related to it.

• Mapped to requirement 1.5.3.1 in the SRS: By selecting a vehicle, an information box will appear that displays the real time status of the vehicle’s start node, current node, next node, end node, edge position, and speed.

2. Display Time

• This object is responsible of displaying the simulated time to the user.

• Mapped to requirement 2.1.3.2 in the SRS: The time shall be displayed as part of the legend in the format of mm/dd/yyyy hh:mm:ss.

3. Display Incident Information

• This object displays information of the incidents that currently exist in the traffic simulator.

• Mapped to requirement 4.2.6.3 in the SRS: Each traffic incident shall be displayed as a flashing red Ø.

2 Data Storage

1 Objects

1. Data Storage

• This object is responsible of storing and loading information from and to the graph.

3 Assignment

1 Objects

1. Consult Constraint Evaluator

• This object is the part of the assignment that calls the constraint evaluator and waits for its response.

• Mapped to requirement 1.1.2.4 in the SRS: Assignment must consult the constraint evaluator.

2. Decision Response

• After receiving the response in previous object, it is passed to this object to make the proper response.

• Mapped to requirement 1.1.2.5 in the SRS: If the constraint evaluator determines that the value is valid, assignment is performed.

• Also, mapped to requirement 1.1.2.6 in the SRS: If the constraint evaluator determines the value is invalid, an exception will be generated by the assignment and no assignment will be performed.

➢ The reason behind mapping the Decision Response to two requirements is that both requirements describe how to react to the constraint evaluator’s response and both of the requirements are simple enough that separating them has no meaning and they need to be included together.

4 Constraint Evaluator

1 Objects

1. Constraint Evaluator

• This is the object that is responsible of evaluating the value to be assigned and decides whether it is valid or not.

• Mapped to requirement 1.1.2.2 in the SRS: A specific type of system entity called a constraint evaluator must determine the validity of each value.

5 User Interface

1 Objects

1. GUI

• The Graphical User Interface (GUI) is the object that is used by other object to display information to the user on the map.

• Mapped to requirement 1.5.1.1 in the SRS: This 2D map will be shown as a top-down view.

• Also, mapped to requirement 1.5.1.2 in the SRS: The 2D map shall be displayed using a 4:3 (length: width) ratio.

➢ Both requirements are related on how to display the map and it is impossible to separate them because they are basically the same thing

2 Map Model

1 Load_Graph

1 Objects

1. Create Nodes

• This object reads the file where the graph is stored and creates necessary nodes according to the nodes positions.

• Mapped to requirement 1.1.1.1 in the SRS: The graph must be a connected graph that can be traversed from any node to any node.

2. Create Edges

• This object reads the file where the graph is stored and creates necessary edges between the nodes that where created previously.

• Mapped to requirement 1.1.3.1 in the SRS: If a road is a two way street, then two different edges exist, one for each direction.

2 Load_Intersection_Rules

1 Objects

1. Assign Intersection Rules

• After creating the graph, this object assigns each node with its proper values according to what is stored in the graph file.

• Mapped to requirement 1.2.1.1 in the SRS: Legal turns are stored in each node.

3 Load_Road_Properties

1 Objects

1. Assign Road Properties

• After creating the graph, this object assigns each edge with its proper values according to what is stored in the graph file.

• Mapped to requirement 1.3.1 in the SRS: The lane capacity shall be represented by an integer greater than or equal to 1.

4 Segment_Divider

1 Objects

1. Segment Divider

• This object divides each edge within the graph into 8 feet segments.

• Mapped to requirement 1.3.2.2 in the SRS: A system entity called segment divider is responsible for dividing the lane into segments.

5 Draw_2D_Map

1 Objects

1. Draw Roads

• Drawing roads to the user is the responsibility of this object where each road will be drawn depending on its status, length and position.

• Mapped to requirement 1.5.1 in the SRS: The 2D map must display roadways, intersections, and traffic distributions (the number of cars at a specific position and time) or individual cars.

2. Draw Road Status

• Drawing road status to the user is the responsibility of this object where each road will show the traffic on it and shows whether there is an accident or a construction or not.

• Mapped to requirement 1.5.1 in the SRS: The 2D map must display roadways, intersections, and traffic distributions (the number of cars at a specific position and time) or individual cars.

3. Draw Intersections

• Drawing road intersections to the user is the responsibility of this object where each intersection will show the status of each intersection and will be drawn according to its type (T shaped intersection, normal intersection, roundabout…etc).

• Mapped to the requirement 1.5.1 in the SRS: The 2D map must display roadways, intersections, and traffic distributions (the number of cars at a specific position and time) or individual cars.

4. Draw Traffic Lights

• Drawing traffic lights to the user is the responsibility of this object where each intersection will show all the traffic lights associated with it.

• Mapped to requirement 1.5.1 in the SRS: The 2D map must display roadways, intersections, and traffic distributions (the number of cars at a specific position and time) or individual cars.

5. Draw Cars

• Drawing cars to the user is the responsibility of this object where each car that is currently moving will be drawn in its current position.

• Mapped to requirement 1.5.1 in the SRS: The 2D map must display roadways, intersections, and traffic distributions (the number of cars at a specific position and time) or individual cars.

➢ The reason that all the five objects map to the same requirement is that they are all closely related and are mentioned in the same requirement. Dividing them into five separate objects is to make the drawing of the map easier to handle, understand and implement.

6 Start_End_Construction

1 Objects

1. Start End Construction

• This object is responsible about starting or ending a construction on a specific lane on a specific roadway.

• Mapped to requirement 1.4.2.3 in the SRS: When a lane is closed, the number of drivable lanes is decreased by one, and when a lane is opened the number of drivable lanes is increased by one.

7 Refresh_Map

1 Objects

1. Observe Time

• This object the timer that waits for the refresh time to occur. When it’s time it triggers the refresh map object.

• Mapped to requirement 1.5.2 in the SRS: The map must provide real-time updates (the simulation display keeps up with actual time).

2. Refresh Map

• This object basically calls the five draw functions in part 2.2.5.1 to display the new information to the user.

• Mapped to requirement 1.5.2.1 in the SRS: With each real time update, for every object with a changed attribute, if that attribute is visually represented by a sprite (i.e. position, color, creation, or elimination) the refreshed screen will display this change.

3 Driving Model

1 Max_Population_Array

1 Objects

1. Max_pop_array

• This array represents the maximum residential and commercial values in a population’s node. The array is a two dimensional array. The rows represent the population node and the columns represent the residential and commercial values. The value in the second dimension cannot be greater than 2. E.g. The maximum commercial population of population node 0 is represented by the value at Max_pop_array [0][1] and the maximum residential population of population node is represented by the value at Max_pop_array [0][0].

• Mapped to requirement 2.2.1.2.a in the SRS: Each of these nodes shall be associated with 2 double arrays:

2 Current_Population_Array

1 Objects

1. Current _pop_array

• This array represents the current residential values, commercial values, and the percentage of the total population present in each population node. The array is a two dimensional array. The rows represent the population node and the columns represent the residential, commercial, and population percentage of a node. The value in the second dimension cannot be greater than 3. E.g. The current commercial population of population node 0 is represented by the value at Current_pop_array [0][1] and the maximum residential population of population node is represented by the value at Current_pop_array [0][0]. The population percentage of population node 0 is represented as Current_pop_array [0][2]. The maximum values in the Current_pop_array cannot be greater than their corresponding values in the Max_pop_array.

3 Migration_Scheduler

1 Objects

1. Migration_scheduler

• The Migration_scheduler watches the clock provided by the infrastructure team. The Migration_Scheduler holds two variables set by the user. The first is the toHome value which is the time when a migration from work to home is triggered. The second is the toWork value which is the time when a migration from home to work is triggered. A third variable, random_traffic_status, is a Boolean that enables and disables the random_traffic_generator. The two variables, toHome and toWork, are set by the user. When it is time for a migration the appropriate migration is started by the Migration_scheduler. When the Migration_scheduler starts a migration it pauses the random_traffic_generator and restarts it once the migration has completed. The two variables, toHome and toWork, are variables that can be set and modified by the user. The variable, random_traffic_status, can only be modified by the migration scheduler.

• Mapped to requirement 2.3.1.1 in the SRS: Throughout the day, there will be random traffic migrations chosen from random start nodes to random end nodes.

• Also, mapped to requirement 2.3.1.2 in the SRS: For each day there will be a traffic migration from home nodes to work nodes in the morning, and, in reverse, from work nodes to home nodes in the evening.

➢ Mapping to multiple requirements is appropriate in this case because the Migration_scheduler is managing the generation of traffic in the simulation. Migration traffic and random traffic are both populating the map with traffic so it is appropriate to have one object manage the two objects.

4 Migration_Traffic_Generator

1 Objects

1. Migration_Traffic_Generator

• The Migration_traffic_generator is responsible for moving populations from home to work or from work to home. When the Migration_Traffic_Generator is initialized, it is passed a variable to send traffic in the appropriate direction. If it is passed a toHome variable it will decrement the commercial population values of populations nodes and increment the residential population values of population nodes and vice versa if it is passed a toWork variable. When a population node is decremented and another is incremented, a car is created with a source of the decremented population node and the destination is the population node that was incremented. The current_pop_array is the array being incremented and decremented. The migration is complete when the Migration_traffic_generator has touched each population node once and the traffic has not been generated. Once migration has completed the population percentage of each population node is recalculated.

• Mapped to requirement 2.3.1.2 in the SRS: For each day there will be a traffic migration from home nodes to work nodes in the morning, and, in reverse, from work nodes to home nodes in the evening.

• Also, mapped to requirement 2.3.1.3 in the SRS: Every migration will have the following constraints.

➢ The two requirements are related because 2.3.1.3 is how traffic is generated and the requirement 2.3.1.2 is requiring a migration.

5 Random_Traffic_Generator

1 Objects

1. Random_Traffic_Generator

• The Random_traffic_generator produces random traffic between migrations. The Random_traffic_generator can only run when the random_traffic_status Boolean is set to true. The random traffic generator does not modify any variables. Using the population percentages of the Current_pop_array, traffic is generated randomly but is weighted to generate more traffic between areas with higher population percentages.

• Mapped to requirement 2.3.1.1 in the SRS: Throughout the day, there will be random traffic migrations chosen from random start nodes to random end nodes.

4 Traffic Light Control

1 Light Cycle Timer

1 Objects

1. Traffic Light

• A Traffic Light holds an instance of a Light Cycle Timer, enumerations for each light color, and timings for each light color.

• Mapped to requirement 3.2.1.1. in the SRS: The enumeration shall contain the colors Red, Yellow, and Green.

2. Light Cycle Timer

• The Light Cycle Timer counts down from each light color’s current light color to zero. Once it reaches zero it advances the traffic light’s enumeration to the next color in the light cycle.

• Mapped to requirement 3.2.2.1. in the SRS: Each light color shall have a separate timing associated with it.

• Mapped to requirement 3.2.2.2 in the SRS: The timing shall be expressed as cycle time in milliseconds.

➢ Mapping to multiple requirements is appropriate because the Light Cycle timer needs an increment of time to associate with each light color and that increment needs be expressed in milliseconds. These are closely related requirements and can be satisfied by one object.

2 Traffic Light Cycler

1 Objects

1. Traffic Light Cycler

• The Traffic Light cycler changes the traffic light current enumeration when the Light Cycle Timer has expired. When it is initialized it begins to listen to the timer and when the timer reaches zero it will modify a current light color variable.

• Mapped to requirement 3.2.2.3. in the SRS: When the cycle time has passed, the stored color of the light will change.

5 Decision Model

1 Route_Generator_General

1 Objects

1. Route_Generator_General

• Route_Generator_General is responsible for SRS requirements 4.4.1.1 - 4.4.1.4. These closely related requirements select and store nodes as waypoints, which represent a path that is both legal and shortest in length.

2 Route_Generator_Blockage_Rerouter

1 Objects

1. Route_Generator_Blockage_Rerouter

• Route_Generator_Blockage_Rerouter is responsible for SRS requirements 4.2.1.1 and 4.4.1.5 - 4.4.1.7. These requirements are all closely related to changing a (possibly empty) subset of the path. A blocked vehicle will choose a new path to its destination or wait until segment becomes available to move to.

3 Traffic_Incident_Generator

1 Objects

1. Traffic_Incident_Generator

• Traffic_Incident_Generator is responsible for SRS requirements 4.2.4.1 and 4.2.4.2. These closely related requirements randomly assign accidents using probabilities that depend on whether a car is on an intersection or not on an intersection.

4 Traffic_Incident_Update_Map_Model

1 Objects

1. Traffic_Incident_Update_Map_Model

• Traffic_Incident_Update_Map_Model is responsible for SRS requirements 4.2.5.1 - 4.2.5.4. These closely related requirements block traffic flow over a graphically marked accident site.

5 Traffic_Incident_Update_2D_Map

1 Objects

1. Traffic_Incident_Update_2D_Map

• Traffic_Incident_Update_2D_Map is responsible for SRS requirement 4.2.6.3. This requirement is a one-to-one mapping.

6 Traffic_Incident_Monitor_Collisions

1 Objects

1. Traffic_Incident_Monitor_Collisions

• Traffic_Incident_Monitor_Collisions is responsible for SRS requirements 4.2.6.1 and 4.2.6.2. These closely related requirements represent a traffic incident -- when two or more cars from adjacent road segments occupy the same segment.

7 Vehicle_Speed_Adapter

1 Objects

1. Vehicle_Speed_Adapter

• Vehicle_Speed_Adapter is responsible for SRS requirements 4.2.2.1, 4.2.3.1, and 4.3.1.1. - 4.3.1.3. These closely related requirements determine a vehicle's speed. All vehicles are mechanically perfect, always fully fueled, and instantly accelerate to the maximum speed allowable for a given segment, unless they encounter a red traffic light or traffic nearby.

8 Map_Reader

1 Objects

1. Map_Reader

• Map_Reader is responsible for SRS requirements 4.1.1.1 - 4.1.1.4. These requirements are all closely related to traveling along a path. This object recognizes a path as series of nodes connected by edges. Every edge has a length, and no driver will travel on an edge that does not belong to his assigned path.

Interface Specification

1 Traffic Simulator

1. public class Traffic_Simulator

2. {

3. public class Data_Display_Plots

4. {

5. public void Display_Car_Data(Car c)

6. {

7. //this function displays the data for the car object c

8. }

9.

10. public void Display_Time()

11. {

12. //this function displays the current simulation time

13. }

14.

15. public void Display_Incident_Information()

16. {

17. //this function displays incdidents that are available now

18. }

19. }

20.

21. public void Data_Storage(Object o, Graph g)

22. {

23. //this function assigns object o to graph g

24. }

25.

26. public class Assignment

27. {

28. public void Consult_Constraint_Evaluator(Object o, Graph g)

29. {

30. //this function consults the constraint evaluator whether to assign object o to graph g

31. }

32.

33. public void Decision_Response(Object o, Graph g, boolean Response)

34. {

35. //depending the Response, this function either assigns o to g or not

36. }

37. }

38.

39. public boolean Constraint_Evaluator(Object o)

40. {

41. //this function tests object o for validity. if it is valid then return true, otherwise return false

42. }

43.

44. public class GUI

45. {

46. //this class will implement the user interface to display the interface to the user

47. }

48. }

2 Map Model

49. public class Map_Model

50. {

51. public class Load_Graph()

52. {

53. //this class is responsible about creating the graph from the file

54.

55. Graph g; //this is the variable pointer that will point to the graph

56.

57. public Graph Create_Nodes()

58. {

59. //this function opens the graph file and reads the nodes information and create all the nodes and assign them to the graph

60. }

61.

62. public Graph Create_Edges()

63. {

64. //this function opens the graph file and reads the edges information and create all the edges and assign them to the graph

65. }

66. }

67.

68. public Graph Assign_Intersection_Rules()

69. {

70. //this function opens the graph file and reads the rules of intersections and assigns them to the intersections within the graph

71. }

72.

73. public Graph Assign_Road_Properties()

74. {

75. //this function opens the graph file and reads the properties of roads and assigns them to the roads within the graph

76. }

77.

78. public RoadSegment Segment_Dividor(Edge e)

79. {

80. //this function takes edge e and divides it into segments and returns the segments to the caller

81. }

82.

83. public class Draw_2D_Map

84. {

85. public void Draw_Roads(Graph g)

86. {

87. //this function takes the graph g and draws the roads on the user interface

88. }

89.

90. public void Draw_Road_Status(Graph g)

91. {

92. //this function only reads road status from g and draws them on the user interface

93. }

94.

95. public void Draw_Intersections(Graph g)

96. {

97. //this function takes the graph g and draws all the intersections withing that graph on the user interface

98. }

99.

100. public void Draw_Traffic_Lights(Graph g)

101. {

102. //this function takes the graph g and draws all traffic lights along with their current colors on the user interface

103. }

104.

105. public void Draw_Cars(Graph g)

106. {

107. //this function takes the graph g and draws all cars within this graph on the user interface

108. }

109. }

110.

111. public void Start_End_Construction(Graph g, Edge e, Lane l, boolean flag)

112. {

113. //this function takes the graph g, edge e and the lane l and depending on the flag we either start the constcution or end it on lane l on edge e

114. }

115.

116. public class Refresh_Map

117. {

118. public void Observe_Time()

119. {

120. //this function watchs for times to refresh the map

121. }

122.

123. public void Refresh_Map()

124. {

125. //this function calls the Draw_2D_Map class to redraw the map with all updates

126. }

127. }

128. }

3 Driving Model

129. public class Driving_Model

130. {

131. // this array is the maximum residential and commercial populations in a population node

132. public class max_pop_array

133. {

134.

135. // getter and setters

136.

137. }

138.

139. // the current_pop_array inherits the max_pop_array. The current_pop_array is used to determine the population distribution and the dynamic population of each population node

140. public class current_pop_array extends max_pop_array

141. {

142.

143. //getters,setters, incrementers, decrementers

144.

145. }

146.

147. //manages the migration_traffic_generator and random_traffic_generator

148. public class migration_scheduler extends current_pop_array

149. {

150.

151. //if a migration is not in progress allow random traffic generation

152. //if a migration if triggered, pass the migration type to the migration_traffic_generator

153.

154. }

155.

156. //moves population to work or to home dependent on the direction it is passed by the migration scheduler

157. public class migration_traffic_generator extends current_pop_array

158. {

159.

160. //randomly iterate through the current_pop_array and move drivers until the appropriate population nodes are filled and emptied.

161. //recalculate the population percentages and restart the random_traffic_generator

162.

163. }

164.

165. //generates traffic between migrations

166. public class random_traffic_generator extends migration_scheduler

167. {

168.

169. //reads the population percentages of the current_pop_array and generated traffic in accordance to the population dristribution.

170.

171. }

172. }

4 Traffic Light Control

173. public interface Traffic_Light {

174. //This variable holds all the possible light colors.

175. enum LightColor{

176. GREEN,

177. YELLOW,

178. RED

179. };

180.

181. //This method changes the light color to a new light color

182. void changeCurrentLightColor(int col);

183.

184. //This method changes the timing associated the green light

185. void changeGreenTiming(float GreenTimer);

186.

187. //This method changes the timing associated the yellow light

188. void changeYellowTiming(float YellowTimer);

189.

190. //This method changes the timing associated the red light

191. void changeRedTiming(float RedTimer);

192.

193. }

194.

195.

196.

197. import java.beans.*;

198.

199. public interface Traffic_Light_Cycler extends PropertyChangeListener{

200.

201. //This method is called when the timer has expired

202. public void TimerExpired(PropertyChangeEvent e);

203.

204. //This method is called by TimerExpired to change the light color

205. public void ChangeColor();

206. }

207.

208.

209.

210.

211. public interface Light_Cycle_Timer {

212.

213. //This method counts down from the time given to zero.

214. void counter(float time);

215.

216. //This method is used to fire a property change saying that the timer

217. //has expired.

218. void counterExpired();

219. }

220.

5 Decision Model

221. //

222. //these classes will all have full method names once

223. //the infrastructure team has chosen the final names

224. //for their classes and methods

225. //

226. //

227. //calls Map_Reader

228. //is called by Route_Generator_Blockage_Rerouter

229. public class Route_Generator_General {

230.

231. }

232.

233. //calls Map_Reader, Route_Generator_General

234. //is called by Refresh_Map

235. public class Route_Generator_Blockage_Rerouter {

236.

237. }

238.

239. //calls Map_Reader

240. //is called by Traffic_Incident_Update_Map_Model, //Traffic_Incident_Update_2D_Map

241. public class Traffic_Incident_Generator {

242.

243. }

244.

245. //calls Traffic_Incident_Generator, Traffic_Incident_Monitor_Collisions

246. //is called by Refresh_Map

247. public class Traffic_Incident_Update_Map_Model {

248.

249. }

250.

251. //calls Traffic_Incident_Generator, Traffic_Incident_Monitor_Collisions

252. //is called by Refresh_Map

253. public class Traffic_Incident_Update_2D_Map {

254.

255. }

256.

257.

258. //calls Detect Object Collisions

259. //is called by Traffic_Incident_Update_Map_Model, Traffic_Incident_Update_2D_Map

260. public class Traffic_Incident_Monitor_Collisions {

261.

262. }

263.

264.

265. //calls Data Storage

266. //is called by Refresh Map

267. public class Vehicle_Speed_Adapter {

268.

269. }

270.

271.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download