Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
passenger waiting time at a bus stop when bus has limited carrying capacity of passengers

Subject: passenger waiting time at a bus stop when bus has limited carrying capacity of passengers

From: kamrul

Date: 3 Dec, 2010 00:56:06

Message: 1 of 9

I am new user of Matlab. I am trying to develop a program to calculate passenger waiting time at a bus stop when bus has limited carrying capacity of passengers. The concept is passenger arrive at stop and wait for a bus. When bus arrives at stop, passenger can board on the bus only if there are enough seats for a passenger. Other wise passengers wait for next bus.

For example, I have
Passenger arrival time (in minutes) at stop: = [ 1 2 3 4 5 7 8 9 10 11 12 13 15 18 19 ]
And bus arrival time at stop (in minutes):= [ 8 15 20 ] and
Bus has 5 seats.

I am not sure how to strat coding. Could any one can help me !

Subject: passenger waiting time at a bus stop when bus has limited

From: Rune Allnor

Date: 3 Dec, 2010 03:38:09

Message: 2 of 9

On Dec 3, 1:56 am, "kamrul " <kamrul...@yahoo.com> wrote:
> I am new user of Matlab.  I am trying to develop a program to calculate passenger waiting time at a bus stop when bus has limited carrying capacity of passengers. The concept is passenger arrive at stop and wait for a bus. When bus arrives at stop, passenger can board on the bus only if there are enough seats for a passenger. Other wise passengers wait for next bus.
>
> For example,  I have
> Passenger arrival time (in minutes) at stop: = [ 1 2 3 4 5 7 8  9 10 11 12 13 15 18 19 ]
> And bus arrival time at stop (in minutes):= [ 8  15  20 ] and
> Bus has 5 seats.
>
> I am not sure how to strat coding. Could any one can help me !

For this type of problem, make sure you use object oriented
programming techniques. Otherwise, the program will become
a mess very quickly.

Rune

Subject: passenger waiting time at a bus stop when bus has limited carrying

From: Walter Roberson

Date: 3 Dec, 2010 06:42:53

Message: 3 of 9

On 02/12/10 6:56 PM, kamrul wrote:
> I am new user of Matlab. I am trying to develop a program to calculate
> passenger waiting time at a bus stop when bus has limited carrying
> capacity of passengers. The concept is passenger arrive at stop and wait
> for a bus. When bus arrives at stop, passenger can board on the bus only
> if there are enough seats for a passenger. Other wise passengers wait
> for next bus.
> For example, I have Passenger arrival time (in minutes) at stop: = [ 1 2
> 3 4 5 7 8 9 10 11 12 13 15 18 19 ] And bus arrival time at stop (in
> minutes):= [ 8 15 20 ] and Bus has 5 seats.
>
> I am not sure how to strat coding. Could any one can help me !

Insufficient information in the problem for a solution. We need to know,
for each bus, how many passengers it is _already_ carrying when it
arrives at the stop, and how many of them get off before the new
passengers load.

You don't need object oriented programming for this problem. I speculate
that Rune was being funny because it is so easy to program. Now if you
had lots of randomization going on, perhaps to simulate the number of
buses needed to satisfy a desired maximum wait time, _then_ you might
want to use more complex processing.

Subject: passenger waiting time at a bus stop when bus has limited

From: Rune Allnor

Date: 3 Dec, 2010 07:00:07

Message: 4 of 9

On Dec 3, 7:42 am, Walter Roberson <rober...@hushmail.com> wrote:

> You don't need object oriented programming for this problem.

You don't *need* anything but assembler, but in this case
the object sematics help.

> I speculate
> that Rune was being funny because it is so easy to program.

I wasn't. Even if the complexity of this particular problem is small,
I find OO far superior to represent physical objects like these.

Rune

Subject: passenger waiting time at a bus stop when bus has limited carrying capacity of passengers

From: Darren Rowland

Date: 3 Dec, 2010 08:03:04

Message: 5 of 9


Hopefully you have already made a start but if not this may help. I suggest highlighting segments and executing with F9 to see what each part does.

pArrive = [ 1 2 3 4 5 7 8 9 10 11 12 13 15 18 19 ];
bArrive = [ 8 15 20 ];

pWait = nan(size(pArrive));

for nBus = 1:length(bArrive)
    pCanBoard = find(pArrive <= bArrive(nBus) & isnan(pWait));
    pCanBoard(6:end) = [];
    pWait(pCanBoard) = bArrive(nBus) - pArrive(pCanBoard);
end


Rune's suggestion is a good one if you eventually want to look at multiple buses and busstops, but at this stage I wouldn't bother.

Darren

Subject: passenger waiting time at a bus stop when bus has limited carrying capacity of passengers

From: kamrul

Date: 4 Dec, 2010 00:26:05

Message: 6 of 9

"Darren Rowland" <darrenjremovethisrowland@hotmail.com> wrote in message <ida87o$bug$1@fred.mathworks.com>...
>
> Hopefully you have already made a start but if not this may help. I suggest highlighting segments and executing with F9 to see what each part does.
>
> pArrive = [ 1 2 3 4 5 7 8 9 10 11 12 13 15 18 19 ];
> bArrive = [ 8 15 20 ];
>
> pWait = nan(size(pArrive));
>
> for nBus = 1:length(bArrive)
> pCanBoard = find(pArrive <= bArrive(nBus) & isnan(pWait));
> pCanBoard(6:end) = [];
> pWait(pCanBoard) = bArrive(nBus) - pArrive(pCanBoard);
> end
>
>
> Rune's suggestion is a good one if you eventually want to look at multiple buses and busstops, but at this stage I wouldn't bother.
>
> Darren


Hi,
 
Thank your very much for all of your kind help. It's a great help for me !!!
Now, I have generated random arrival time of passengers and bus at stop and I have used your code to find passengers waiting time as given below . As it is now random arrival of passengers and bus, passenger waiting time (pwt) is showing different result in every run. So, I need to repeat the simulation; say 1000 times or 1000000 times to find the average for each element of "pwt" and plot the distribution of "pwt". But I am facing difficulties how to do this. would you be kind to help for this problem
 
Regards,
Kamrul
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
sot=14400;% operation time of simulation (second)
c=60;
ap=rand(1,10000);%[0.1 0.3 0.2 0.6];%arrival probabiliy of passengers
par= 5/60; % arrival rate of passengers (pax/second)
i=1:length(ap);
 pint(i)=expinv(ap,1/par);%passenger inter arrival time
k=1;
 pat(k)=0;%arrival time of passengers at stop
 
while pat(k)<sot
    k=k+1; %2:length(ap)
    pat(k)=pat(k-1)+pint(k-1);
    
end
No_Pax= length(pat);
%bus genetation at stop
 bf=1/600;%10 min headway
 sqc= 1;%%square of coeffient of variation of bus headway
 bp=rand(1,100);%bus arrival probability
 i=1:length(bp);
 bint=gaminv(bp,1/sqc,sqc/bf);%bus interarrival time at stop
  
 k=1;
 bat(k)=0;%bus arrival time at stop
 while bat(k)<sot
   
    bat(k+1)=bat(k)+bint(k);
    k=k+1;
 end
No_bus=length(bat);
%waiting time calculation
pwt = nan(size(pat));%pax waiting time
for nBus = 1:length(bat)
    pcanboard = find(pat <= bat(nBus) & isnan(pwt));
    pcanboard (c+1:end) = [];
    pwt(pcanboard) = bat(nBus) - pat(pcanboard);
end

pwt(find(isnan(pwt)))=sot
pwt

Subject: passenger waiting time at a bus stop when bus has limited carrying capacity of passengers

From: Darren Rowland

Date: 6 Dec, 2010 02:55:06

Message: 7 of 9

Kamrul,

Try this code. I put the separate parts into functions so the biggest change is that there is now a loop which maintains a sum of the wait times for each passenger.
The average is calculated once the number of trials is complete.

You could view a histogram of the waiting times using hist(averageWait). Another plot you could try is plot(sort(averageWait))

Hth
Darren

function averageWait = simulateBus(sTime,maxPassengers,nTrials)
% SIMULATEBUS - determine average waiting times for passengers at bus stop
% sTime: operation time of simulation (seconds)
% maxPassengers: max. no. of passengers to arrive at stop
% nTrials: no. of simulation runs to perform

nSeats = 60;
par = 5/60; % arrival rate of passengers (pax/second)
bf = 1/600; % 10 min headway
sqc = 1; % square of coefficient of variation of bus headway
TotalWait = zeros(1,maxPassengers);
WaitCount = zeros(1,maxPassengers);

for nT = 1:nTrials
    pat = getPassengerTimes(sTime,maxPassengers,par);
    bat = getBusTimes(sTime,bf,sqc);
    %waiting time calculation
    pwt = nan(size(pat)); % pax waiting time
    for nBus = 1:length(bat)
        pcanboard = find(pat <= bat(nBus) & isnan(pwt));
        pcanboard (nSeats+1:end) = [];
        pwt(pcanboard) = bat(nBus) - pat(pcanboard);
    end
    pwt(isnan(pwt)) = sTime;
    % Accumulate waiting times
    TotalWait(1:length(pwt)) = TotalWait(1:length(pwt)) + pwt;
    WaitCount(1:length(pwt)) = WaitCount(1:length(pwt)) + 1;
end
iWait = WaitCount>0;
% Find average wait time per passenger
averageWait = TotalWait(iWait)./WaitCount(iWait);

function pat = getPassengerTimes(sTime,maxPassengers,par)
% Returns an array of passenger arrival times (seconds)
% sTime: operation time of simulation
% maxPassengers: max. no. of passengers to arrive at stop
% par: arrival rate of passengers (pax/second)
ap = rand(1,maxPassengers); % arrival probability of passengers
pint = expinv(ap,1/par); % passenger inter arrival time
pat = cumsum(pint);
pat(pat>sTime) = []; % actual passenger arrival time

function bat = getBusTimes(sTime,bf,sqc)
% Returns an array of bus arrival times (seconds)
% sTime: operation time of simulation
% bf: bus headway
% sqc: square of coeffient of variation of bus headway
bp = rand(1,100); % bus arrival probability
bint = gaminv(bp,1/sqc,sqc/bf); % bus inter arrival time at stop
bat = cumsum(bint);
bat(bat>sTime) = []; % actual bus arrival time

Subject: passenger waiting time at a bus stop when bus has limited carrying capacity of passengers

From: kamrul

Date: 28 Dec, 2010 01:40:20

Message: 8 of 9

"Darren Rowland" wrote in message <idhjaa$d07$1@fred.mathworks.com>...
> Kamrul,
>
> Try this code. I put the separate parts into functions so the biggest change is that there is now a loop which maintains a sum of the wait times for each passenger.
> The average is calculated once the number of trials is complete.
>
> You could view a histogram of the waiting times using hist(averageWait). Another plot you could try is plot(sort(averageWait))
>
> Hth
> Darren
>
> function averageWait = simulateBus(sTime,maxPassengers,nTrials)
> % SIMULATEBUS - determine average waiting times for passengers at bus stop
> % sTime: operation time of simulation (seconds)
> % maxPassengers: max. no. of passengers to arrive at stop
> % nTrials: no. of simulation runs to perform
>
> nSeats = 60;
> par = 5/60; % arrival rate of passengers (pax/second)
> bf = 1/600; % 10 min headway
> sqc = 1; % square of coefficient of variation of bus headway
> TotalWait = zeros(1,maxPassengers);
> WaitCount = zeros(1,maxPassengers);
>
> for nT = 1:nTrials
> pat = getPassengerTimes(sTime,maxPassengers,par);
> bat = getBusTimes(sTime,bf,sqc);
> %waiting time calculation
> pwt = nan(size(pat)); % pax waiting time
> for nBus = 1:length(bat)
> pcanboard = find(pat <= bat(nBus) & isnan(pwt));
> pcanboard (nSeats+1:end) = [];
> pwt(pcanboard) = bat(nBus) - pat(pcanboard);
> end
> pwt(isnan(pwt)) = sTime;
> % Accumulate waiting times
> TotalWait(1:length(pwt)) = TotalWait(1:length(pwt)) + pwt;
> WaitCount(1:length(pwt)) = WaitCount(1:length(pwt)) + 1;
> end
> iWait = WaitCount>0;
> % Find average wait time per passenger
> averageWait = TotalWait(iWait)./WaitCount(iWait);
>
> function pat = getPassengerTimes(sTime,maxPassengers,par)
> % Returns an array of passenger arrival times (seconds)
> % sTime: operation time of simulation
> % maxPassengers: max. no. of passengers to arrive at stop
> % par: arrival rate of passengers (pax/second)
> ap = rand(1,maxPassengers); % arrival probability of passengers
> pint = expinv(ap,1/par); % passenger inter arrival time
> pat = cumsum(pint);
> pat(pat>sTime) = []; % actual passenger arrival time
>
> function bat = getBusTimes(sTime,bf,sqc)
> % Returns an array of bus arrival times (seconds)
> % sTime: operation time of simulation
> % bf: bus headway
> % sqc: square of coeffient of variation of bus headway
> bp = rand(1,100); % bus arrival probability
> bint = gaminv(bp,1/sqc,sqc/bf); % bus inter arrival time at stop
> bat = cumsum(bint);
> bat(bat>sTime) = []; % actual bus arrival time

Hi Darren,

Thanks for your kind help. The current code is applicable to calculated passenger waiting time at first stop only. I have included a code to calculate passenger load inside bus ( i, e. number of passenger in bus). I assume each passenger take 3 second time to board the bus and calculated bus departure time from a stop 1. Now, I am trying to find the passenger waiting time for next stops assuming there are 4 stops in the route. I have calculated bus arrival time at stop 2 as bus departure time from stop2+travel time of bus from stop 1 to stop2. I assume some portion of passenger inside bus will alight at stop 2 and 3. (As example, when bus arrives at 2nd stop, 40 % of passengers carried by bus from 1st stop alight at second stop. Similarly, when bus arrives at 3rd stop, 80 % of passengers carried by bus from 2nd stop alight at 3rd stop. When buses arrive at last stop (stop 4), all
passengers inside bus will alight at stop 4. Then, buses again pick passenger from stop 4 and run toward stop 1 similar way as they come from stop 1 to 4. I have tried a code but it is not working. Could you please, help me ?



function averageWait = simulateBus(sTime,maxPassengers,nTrials)
% SIMULATEBUS - determine average waiting times for passengers at bus stop
% sTime: operation time of simulation (seconds)
% maxPassengers: max. no. of passengers to arrive at stop
% nTrials: no. of simulation runs to perform

nSeats = 60;
par = 5/60; % arrival rate of passengers at stop 1(passenger/second)

par2=3/60;%% arrival rate of passengers at stop 2(passenger/second
par3=2/60;%passenger arrival time at stop 3
par4=0/60;%passenger arrival time at stop 4(no passenger arrive at stop 4)

ap1=0;% alighting proportion of passenger 1st stop is zero (no passenger alight at first stop)
ap2=0.4;%alighting proportion of passenger at stop2 arriving from previous stop (stop 1)
ap3=0.8;%alighting proportion of passenger at stop3 arriving from previous stop (stop 2)
ap4=1.0;%alighting proportion of passenger at stop4 arriving from previous stop (stop 3).All passenger will alight

t=300; %bus travel time from one stop to next stop(second)
b=3;%boarding time for each passenger(second)

 nstop=4;
 maxPassengers=30;
 nTrials=3;
 sTime=7200;%(sec)
bf = 1/600; % 10 min headway
sqc = 1; % square of coefficient of variation of bus headway
TotalWait = zeros(1,maxPassengers);
WaitCount = zeros(1,maxPassengers);

% nap2=pl1*ap2;% number alighting passenger at stop2
% nSeats2=(nSeats-pl1+nap2);% number of space avaiable in bus when it arrives at stop2
% nSeats2=round(c2);
for nT = 1:nTrials
    pat = getPassengerTimes(sTime,maxPassengers,par);
    bat = getBusTimes(sTime,bf,sqc);
    %waiting time calculation
    pwt = nan(size(pat)); % passenger waiting time
    for nBus = 1:length(bat)
        pcanboard = find(pat <= bat(nBus) & isnan(pwt));
        pcanboard (nSeats+1:end) = [];
        
        pl1(nBus)=length(pcanboard);%pl1 = passenger load inside a bus leaving stop 1
        bdt1(nBus)=bat(nBus)+length(pcanboard)*b; % bdt1 =bus departure time from stop 1
        bat2(nBus)=bdt1(nBus)+t ;% bat2 =bus arrival time time at stop 2 from stop 1
        pwt(pcanboard) = bat(nBus) - pat(pcanboard);
    end
    pwt(isnan(pwt)) = sTime;
    % Accumulate waiting times
    TotalWait(1:length(pwt)) = TotalWait(1:length(pwt)) + pwt;
    WaitCount(1:length(pwt)) = WaitCount(1:length(pwt)) + 1;
end
iWait = WaitCount>0;
% Find average wait time per passenger
averageWait = TotalWait(iWait)./WaitCount(iWait);
pl1
bdt1
bat2
 hist(averageWait)
function pat = getPassengerTimes(sTime,maxPassengers,par,nstop)
% Returns an array of passenger arrival times (seconds)
% sTime: operation time of simulation
% maxPassengers: max. no. of passengers to arrive at stop
% par: arrival rate of passengers (passenger/second)
ap = rand(1,maxPassengers); % arrival probability of passengers
pint = expinv(ap,1/par);% passenger inter arrival time

pat = cumsum(pint);

pat(pat>sTime) = []; % actual passenger arrival time

function bat = getBusTimes(sTime,bf,sqc)
% Returns an array of bus arrival times (seconds)
% sTime: operation time of simulation
% bf: bus headway
% sqc: square of coeffient of variation of bus headway
bp = rand(1,3); % bus arrival probability
bint = gaminv(bp,1/sqc,sqc/bf);% bus inter arrival time at stop
bat = cumsum(bint);

bat(bat>sTime) = []; % actual bus arrival time

Subject: passenger waiting time at a bus stop when bus has limited carrying capacity of passengers

From: kamrul

Date: 2 Jan, 2011 09:13:04

Message: 9 of 9

Hi Darren,

Thanks for your kind help. The current code is applicable to calculated passenger waiting time at first stop only. I have included a code to calculate passenger load inside bus ( i, e. number of passenger in bus). I assume each passenger take 3 second time to board the bus and calculated bus departure time from a stop 1. Now, I am trying to find the passenger waiting time for next stops assuming there are 4 stops in the route. I have calculated bus arrival time at stop 2 as bus departure time from stop2+travel time of bus from stop 1 to stop2. I assume some portion of passenger inside bus will alight at stop 2 and 3. (As example, when bus arrives at 2nd stop, 40 % of passengers carried by bus from 1st stop alight at second stop. Similarly, when bus arrives at 3rd stop, 80 % of passengers carried by bus from 2nd stop alight at 3rd stop. When buses arrive at last stop (stop 4), all
passengers inside bus will alight at stop 4. Then, buses again pick passenger from stop 4 and run toward stop 1 similar way as they come from stop 1 to 4. I have tried a code but it is not working. Could you please, help me ?



function averageWait = simulateBus(sTime,maxPassengers,nTrials)
% SIMULATEBUS - determine average waiting times for passengers at bus stop
% sTime: operation time of simulation (seconds)
% maxPassengers: max. no. of passengers to arrive at stop
% nTrials: no. of simulation runs to perform

nSeats = 60;
par = 5/60; % arrival rate of passengers at stop 1(passenger/second)

par2=3/60;%% arrival rate of passengers at stop 2(passenger/second
par3=2/60;%passenger arrival time at stop 3
par4=0/60;%passenger arrival time at stop 4(no passenger arrive at stop 4)

ap1=0;% alighting proportion of passenger 1st stop is zero (no passenger alight at first stop)
ap2=0.4;%alighting proportion of passenger at stop2 arriving from previous stop (stop 1)
ap3=0.8;%alighting proportion of passenger at stop3 arriving from previous stop (stop 2)
ap4=1.0;%alighting proportion of passenger at stop4 arriving from previous stop (stop 3).All passenger will alight

t=300; %bus travel time from one stop to next stop(second)
b=3;%boarding time for each passenger(second)

 nstop=4;
 maxPassengers=30;
 nTrials=3;
 sTime=7200;%(sec)
bf = 1/600; % 10 min headway
sqc = 1; % square of coefficient of variation of bus headway
TotalWait = zeros(1,maxPassengers);
WaitCount = zeros(1,maxPassengers);

% nap2=pl1*ap2;% number alighting passenger at stop2
% nSeats2=(nSeats-pl1+nap2);% number of space avaiable in bus when it arrives at stop2
% nSeats2=round(c2);
for nT = 1:nTrials
    pat = getPassengerTimes(sTime,maxPassengers,par);
    bat = getBusTimes(sTime,bf,sqc);
    %waiting time calculation
    pwt = nan(size(pat)); % passenger waiting time
    for nBus = 1:length(bat)
        pcanboard = find(pat <= bat(nBus) & isnan(pwt));
        pcanboard (nSeats+1:end) = [];
        
        pl1(nBus)=length(pcanboard);%pl1 = passenger load inside a bus leaving stop 1
        bdt1(nBus)=bat(nBus)+length(pcanboard)*b; % bdt1 =bus departure time from stop 1
        bat2(nBus)=bdt1(nBus)+t ;% bat2 =bus arrival time time at stop 2 from stop 1
        pwt(pcanboard) = bat(nBus) - pat(pcanboard);
    end
    pwt(isnan(pwt)) = sTime;
    % Accumulate waiting times
    TotalWait(1:length(pwt)) = TotalWait(1:length(pwt)) + pwt;
    WaitCount(1:length(pwt)) = WaitCount(1:length(pwt)) + 1;
end
iWait = WaitCount>0;
% Find average wait time per passenger
averageWait = TotalWait(iWait)./WaitCount(iWait);
pl1
bdt1
bat2
 hist(averageWait)
function pat = getPassengerTimes(sTime,maxPassengers,par,nstop)
% Returns an array of passenger arrival times (seconds)
% sTime: operation time of simulation
% maxPassengers: max. no. of passengers to arrive at stop
% par: arrival rate of passengers (passenger/second)
ap = rand(1,maxPassengers); % arrival probability of passengers
pint = expinv(ap,1/par);% passenger inter arrival time

pat = cumsum(pint);

pat(pat>sTime) = []; % actual passenger arrival time

function bat = getBusTimes(sTime,bf,sqc)
% Returns an array of bus arrival times (seconds)
% sTime: operation time of simulation
% bf: bus headway
% sqc: square of coeffient of variation of bus headway
bp = rand(1,3); % bus arrival probability
bint = gaminv(bp,1/sqc,sqc/bf);% bus inter arrival time at stop
bat = cumsum(bint);

bat(bat>sTime) = []; % actual bus arrival time

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us