By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,156 Members | 1,069 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,156 IT Pros & Developers. It's quick & easy.

Need Guidance For a Project.

P: 2
I'm just looking for some guidance so that I get a start on a school project.


Need to write 3 kind of event for a Bus, Passenger, transit system in which:
-person: arrives at bus Q after random time (i already have a prog. to produce those random number) what indicates the arrival of a next passenger to bus Q.

-arrival: of bus at stop.
if no one in Q, bus continues to next stop and event of its arrival is generated. Else, the event to be gen. is the first person boarding the bus.

-person boarding: lenght of Q diminishes by 1. If Q is empty, bus continues to next stop. Else next passenger boards.

Syst. has 5 bus stop (5mins) dist. from eachother.
3 busses.
Boarding time is 10secs.
Person arrives at Stop avg of 5/min.


I don't need to do it for me; Just need some guidance regarding data structure to use.

thanks in adv.
Sep 18 '06 #1
Share this Question
Share on Google+
2 Replies


Banfa
Expert Mod 5K+
P: 8,916
I think you probably need 2 structures

1 for the Bus Stop holding the number of people waiting and which bus stop is next in the route (and could possible hold distence or time to next stop in case the system has to expand to a case where the bus stops are not all 5 minutes apart).

1 for the Bus holding it's current Bus Stop and possibly state (on route to or stopped at). Strangely the bus currently doesn't need to know anything about it's passengers as the problem assumes there is always room for 1 person to get on and therefore doesn't track people getting off.

I do not think you need any data structures for the people.

The Bus Stop can generate all the events

Person Arrived
Bus Arrived, no-one waiting
Bus Arrived, 1 person got on

But where are these events going to?

You problem description is not very clear, it is a bit muddled and you repeat bits. You will find it easier to solve the problem if you get your problem description written down clearly first.
Sep 18 '06 #2

P: 2
I want to start small because I'm interested on testing as I go along due to my limited C++ prog. exp.
Perhaps creating the structs or classes together with the main() to see how it will develop. Acquiring exp as I continue.
Should I use classes or structure?

Here is the description of project:
Type of events suggested:
person: arrives@bus stop Q.
Action: After random time, another person is sched
to arrive in the Q.
arrival: bus arrives@stop
Action: If (Q==empty)
bus goes to the next stop,
(this creates arrival event.
otherwise, the event generated is
first person in Q boarding the bus;
boarder: person boards the bus
Action: Q_length diminishes by 1; If (Q==empty), bus goes to next stop,
otherwise the next passenger boards the bus
Possible data structure (a balanced tree, or simply a
doubly-linked ring)
(THE INTEREST HERE IS TO SORT THE EVENTS BY TIME)
(HOW TO GO ABOUT INITIALIZING USING)
A dummy event scheduled for time 0

Exec prog by repeating the following steps:
until simulated current time exceeds the defined time limit
Take next event from the event structure and update
the current time
Process the event; (generating others)

HOW-TO:
CIN >>number of buses, the number of stops, the driving time
between stops, the boarding time, the stop time, and the mean
arrival rate from a file.

START: assuming there are 5 bus stops, 3 buses, the
time between two stops is 5 min, avg arrival rate at each stop is 5 persons/min,
and boarding time is 10 seconds


Start with the buses distributed uniformly along the root
(HOW TO GEN ARRIVAL EVENTS?) and AND AN EVENT THAT PUTS A SINGLE PERSON AT EACH Q.

When the bus arrival event occurs, if the queue is empty,
gen. the arrival at the next bus stop at clock + drive_time.
If the queue is not empty, gen. the boarder event (at clock + boarding_time)
When the boarder event occurs, if the queue is empty
(i.e., the last person boarded), generate the arrival at
the next bus stop at clock + drive_time. If the queue is not
empty, gen. the boarder event (at clock + boarding_time)
At the person event, generate the next person event at the same
stop at clock + (mean_inter-arrival_rate) * random (exponential)
Note: Keep time in float or double (a better way of doing things).
The mean_inter-arrival_rate = 1/ mean_arrival_rate

Thanks very much...


I think you probably need 2 structures

1 for the Bus Stop holding the number of people waiting and which bus stop is next in the route (and could possible hold distence or time to next stop in case the system has to expand to a case where the bus stops are not all 5 minutes apart).

1 for the Bus holding it's current Bus Stop and possibly state (on route to or stopped at). Strangely the bus currently doesn't need to know anything about it's passengers as the problem assumes there is always room for 1 person to get on and therefore doesn't track people getting off.

I do not think you need any data structures for the people.

The Bus Stop can generate all the events

Person Arrived
Bus Arrived, no-one waiting
Bus Arrived, 1 person got on

But where are these events going to?

You problem description is not very clear, it is a bit muddled and you repeat bits. You will find it easier to solve the problem if you get your problem description written down clearly first.
Sep 21 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.