views:

356

answers:

6

HI I got this coursework question to solve.

This is the question:

Design a program to simulate vehicles at an intersection.

Assume that there is one lane going in each of four directions, with stoplights facing each direction. Vary the arrival time of vehicles randomly in each direction and set up a regular frequency of the light changes. Run your direction and set up a regular frequency of the light changes. Run your simulation for a set period of time to view the "behaviour" of the intersection.

Coursework Requirement:

  1. Should be coded in java
  2. Use of proper data structures

If any one has any clue of how to do it, please help; I have no idea.

+1  A: 

Read about queues you have to use to simulate each traffic light.

Each randomly generated car going in each lane will get pushed into the corresponding queue and then popped out of it when the light is green, and keep popping cars as long as (hint: you need to simulate time as well (subhint: look into finite state machines)) the light is green, of course. You process each queue in order.

Vinko Vrsalovic
+1  A: 

Some useful behaviors to monitor will include mean, max, and std. dev. of the number of cars waiting at each light.

John the Statistician
+1  A: 

For managing the Stop/Wait/Go light sequences look into "Finite State Machines"

Student for Life
You mean automata
Vinko Vrsalovic
Where automata is the plural of automaton, perhaps better to simply say Finite State Machine's.
Student for Life
@Davide - that would make the FSM own something :) (</pedantic-apostrophe-nut>
warren
+1  A: 

Read about discrete event simulation.

gimel
+1  A: 

Just a small hint. It wont be a propper simulation if you don't setup some constant to simulate the time the car accelerates until it reaches the intersection. If you have 10 cars queued up and the light goes green they don't all immediatly get to cross the intersection.

Asides from that you really need to get to know queues, especially FIFO and Event queues will help you avoid going into the realm of multithreading world.

I hope you dont need to start with Java before you go into the queues.

Caerbanog
A: 

If you have access to IEEE there is a journal about this topic here is the link

Ali Shulli