Toilets and engineers

Posted in Ruby by sausheong on June 7, 2010

It started with a lunch conversation that slowly turned into a coffee time mini-debate. You see, I moved into a new job recently at the Applied Cloud Computing Lab in HP Labs Singapore. My first task was to hire engineers to staff the lab and while the final numbers were not absolute, the number 70 was bandied around for the population of the facilities. We have half a floor at Fusionopolis, plenty of space really but the bone of contention was more delicately focused on more sanitary facilities i.e. the toilets.

The problem was that the whole floor shares a single pair of toilets (one for male and another for female of course). I was totally convinced that with 70 people in the office, we will reach bladder or bowel apocalypse, a disaster in the waiting. My other colleagues however were less worried — the other floors seem to be doing fine. It wasn’t as if we could do anything about it, no one’s going to magically add in new toilets for us no matter how long the toilet queue was; but I had to know. I was also curious of course — what is the algorithm used to determine the number of toilets per square meter of occupancy?

Looking up building regulations found nothing (at least not online) in Singapore but UK has some regulations covered by the Health and Safety Executive.

Looking at facilities used by men only:

Number of men at work Number of toilets Number of urinals
1-15 1 1
16-30 2 1
31-45 2 2
46-60 3 2
61-75 3 3
76-90 4 3
91-100 4 4

Well, the toilets seem to almost fit into the UK regulations, but these are just regulations. How did these numbers come about and how realistic are they? To better model the usage scenarios, I did a Monte Carlo simulation on the usage pattern of the toilets, based on a simple set of assertions.

Taking an educated guess of 1 in 7 of engineers to be female, that leaves us with 60 male engineers sharing a single toilet facility. The toilet facility has 3 urinals and 2 stalls, one of which is a flush toilet, the other is a squat toilet (which in general no one uses any more).

An important piece of information is to find out how many times an average person need to urinate a day. It turns out that our bladder will signal us to make a trip to the toilet when it fills up to about 200ml. Combine with the information that an average urine output of an adult is 1.5 liters a day, this means that we roughly need to go about 8 times a day. This in turn means 8 times in 24 hours or 1 time in 3 hours on an average. The normal working hours in HP are 8:30am – 5:30pm, which is 9 hours, so this means on an average a person makes a beeline to the toilet 3 times during the course of the working day in the office.

I modeled the scenario discretely, per minute. This means a person in the office would make a decision to go to the loo or not every minute within the 9 hours in the office, or 540 minutes. Coupled with an average of 3 times in 540 minutes, this means the probability that a person would go to the toilet every count of the minute is 3 out of 540. In the case of urinating, my estimate is that a person will be able to complete the necessary job within 2 minute on an average and vacate the facility.

Armed with this model, let’s look at the simulation code:

require 'rubygems'
require 'faster_csv'

# population of 60 people on the same floor
population = 60
# period of time from 8:30am -> 5:30pm is 9 hours
period = 9
# 8 times a day -> 8 times in 24 hours -> 1 time every 3 hours
# within a period of 9 hours -> 3 times
# probability in every min -> 3 out of 9 * 60
times_per_period = 3
# rate of servicing
mu = 2
# number of people in the queue
queue = 0
# number of stalls available
stalls = 3
# number of occupied stalls
occupied = 0

# total of all queue sizes for calculating average queue size
queue_total = 0
# max queue size for the day
max_queue_size = 0'queue.csv', 'w') do |csv|
  csv << %w(t queue occupied)
  (period * 60).times do |t|
   # at every rate of service interval, vacate any and all people from the toilet and replace them with people in the queue
    if t % mu == 0
      occupied = 0
      while occupied < stalls and queue > 0
        occupied += 1
        queue -= 1
    population.times do
      # does the engineer want to relieve himself?
      if (rand(period * 60) + 1) <= times_per_period
        if occupied < stalls
          occupied += 1
          queue += 1

    csv << [t, queue, occupied]
    max_queue_size = queue if queue > max_queue_size
    queue_total = queue_total + queue

puts "** Max queue size : #{max_queue_size}"
puts "** Total mins in queue by all : #{queue_total} mins"

Most of the code are quite self explanatory. However notice that mu is 3 (minutes) instead of 2 as we have discussed earlier. The reason for this is that in keeping the simulation code simple, I’ve not factored in that if we clear the toilets every 2 minutes, people who entered during the 2nd minute (according to the simulation) will be cleared in just 1 minute. To compensate for this, I use a mu variable that is 1.5 times the service rate.

The simulation writes to queue.csv, which contains the queue size and toilet occupancy at every interval. This are the results:

** Max queue size : 3
** Total mins in queue by all : 17 mins

I opened the CSV up and used the data to create a simple histogram:

Queue size
Number of minutes
0 526 97.6%
1 9 1.8%
2 3 0.4%
3 2 0.2%

From the results it’s pretty obvious that the architect and engineers who built Fusionopolis knew their stuff. These were the quantitative conclusions:

  1. Queues were formed less than 3% of the time of the day
  2. The maximum number of people in the queue were 3 people and that happened for only less than 2 minutes in a day
  3. The total time spent by everyone in the office, in a queue to the toilet was 17 mins

This is for the men’s urinals, let’s look at the stalls now. The same simulation script can be used, just changing the parameters a bit. Instead of mu = 3, we use mu = 8. Instead of 3 urinals, we have 2 stalls and instead of 3 times over the period, we use 1 time over the working period.

These are the results:

** Max queue size : 3
** Total mins in queue by all : 81 mins
Queue size
Number of minutes
0 485 89.8%
1 33 6.1%
2 21 3.9%
3 1 0.2%

The problem seems a bit more serious now though not significantly so, though the chances of being in a a queue are higher now (10%).

In conclusion, I was wrong but I’m glad to be wrong in this case. Waiting in a toilet queue is seriously not a fun thing to do.

About these ads

26 Responses

Subscribe to comments with RSS.

  1. goodwind89 said, on June 8, 2010 at 10:01 am

    What if a group of engineers went out to have lunch and the food was spoiled? :P

  2. achates said, on June 9, 2010 at 5:36 am

    For comparison, our site has somewhat more male engineers (probably around 100 between our company and two others that share the floor), with just two stalls and two urinals. This leads to more contention than the example. Fortunately, the floor above is underutilized and the facilities are right next to the stairs, so actual queuing is relatively rare…

  3. Akomba said, on June 10, 2010 at 4:47 pm

    goodwind89: yeah, I was wondering about a DOS attack as well.

    In order to make the calculation worthy for the Applied Cloud Computing Lab, it should include a case with the average number of food poisoning taken into account. Then it should determine wether the resources on the other floors are sufficient to take care of the worst-case scenario.

    This is a case where fighting for resources must be avoided by all costs.

    Even when calculating with the resources on the other floors, we will end up with a very finite number of “servers” here.

    It is because you need to take the routing time very seriously. Reaching the backup server must be possible within a very short period of time.

    Dropping packets is absolutely not an accepted scenario.

    I think I should stop now.

  4. Robert said, on June 13, 2010 at 10:58 pm

    I think your assumptions are flawed.

    Firstly, toilet trips are most definitely not randomly distributed over the course of the day. There will be a “run” on the facilities (if you’ll excuse the expression) around half an hour after lunch. You’ll have seen this if you’ve ever taken an intercontinental flight.

    Secondly, having to wait for a #1 is most often a non-issue. But having to wait for a #2 is best case quite uncomfortable and worst case quite messy.

    There’s also the cleanliness issue. Four toilets cleaned once a day are half as dirty on average as two toilets cleaned once a day.

    • sausheong said, on June 14, 2010 at 10:36 am

      Hi Robert, you’re right. My assumptions is unrealistic as you’ve pointed out. The simulation can be tweaked to take that into account. I’ve considered this point when I was writing this up but I only had a couple of hours to burn at night so I took the easy way out. Will be putting that in the next chance I have and re-post my findings.

      Thanks for the tip!

  5. Robert said, on June 14, 2010 at 4:01 pm

    And of course, my assumption that individual urinals are used with equal frequency is false, because of this:

    How much time do nerds need to spend thinking about toilet habits, anyhow? :-)

  6. Amsk said, on June 17, 2010 at 11:01 am

    I think you had a little too much time. :P

  7. Arun said, on May 29, 2012 at 4:24 am

    Aggie #1 is using the outhouse when a quraetr falls from his pocket into the pit.He moans and gnashes his teeth to Aggie #2 about the loss, then turns around and tosses a 20 dollar bill into the pit. Why did you do that? Aggie #2 asks. You don’t think I’m going in there for just a quraetr! Aggie #1 answers.

  8. Underworld Przebudzenie Caly Film said, on February 11, 2013 at 6:15 pm

    Another advantage is no grunting noise, just pure silence of the electric engine! They can be put together with many different methods.

  9. The Fighter Caly Film said, on February 11, 2013 at 6:15 pm

    Extremely excellent blog post. Document only happened at your current weblog and additionally needed expressing which i need very loved studying your own blog articles. Anyways I will come to be following for the blog and additionally Hopefully you will write once again immediately.

  10. Listy do M Online said, on February 11, 2013 at 6:16 pm

    I like the website layout . How was it made. Its rather nice

  11. The Fighter Online said, on February 11, 2013 at 6:16 pm

    Have you ever considered writing an ebook or guest authoring on other websites? I have a blog based on the same information you discuss and would love to have you share some stories/information. I know my visitors would enjoy your work. If you are even remotely interested, feel free to send me an e-mail

  12. Oszukac Przeznaczenie 5 Caly Film said, on February 11, 2013 at 6:16 pm

    Hi there, i just wanted to drop you a line to say that i thoroughly enjoyed this particular post of yours, I have subscribed to your RSS feeds and have skimmed a few of your posts before but this one really stood out for me. I know that I am just a stranger to you but I figured you might appreciate the appreciation Take care and keep blogging.

  13. Harry Potter i Kamien Filozoficzny Online said, on February 11, 2013 at 6:18 pm

    Great list of resources! Honored to be listed so many times. Thanks for spreading the good word about mobile SEO!

  14. Oszukac Przeznaczenie 5 Online said, on February 11, 2013 at 6:19 pm

    Remarkable! Its genuinely amazing article, I have got much clear idea concerning from this post.

  15. SAM Caly Film said, on February 11, 2013 at 6:19 pm

    Most states and communities don’t require them to be licensed. From the perspective of the electric engine

  16. Prosto w serce Caly Film said, on February 11, 2013 at 6:20 pm

    As I website possessor I conceive the subject matter here is real superb , thanks for your efforts.

  17. Underworld Przebudzenie Caly Film said, on February 11, 2013 at 6:20 pm

    I like this site very much, Its a really nice position to read and find information. “If at first you don’t succeed, you’re running about average.” by M. H. Alderson.

  18. PSY Online said, on February 11, 2013 at 6:20 pm

    Tolles Thema. Ich bin zwar nicht ganz eurer Meinung, aber das ist ja auch kein Forum hier. Bleib am Ball.

  19. Harry Potter i Wiezien Azkabanu Online said, on February 11, 2013 at 6:22 pm

    Youre so cool! I dont suppose Ive read anything like this before. So good to seek out anyone with some original ideas on this subject. realy thanks for starting this up. this website is one thing that’s wanted on the internet, somebody with just a little originality. useful job for bringing one thing new to the web!

  20. Harry Potter i Ksiaze Polkrwi Online said, on February 11, 2013 at 6:22 pm

    I will right away snatch your rss feed as I can’t in finding your email subscription link or newsletter service. Do you’ve any? Please let me realize in order that I may subscribe. Thanks.

  21. Ghost Rider Online said, on February 11, 2013 at 6:23 pm

    I just want to mention I am all new to weblog and actually loved this blog site. More than likely I’m want to bookmark your blog . You definitely have awesome posts. Thanks a lot for sharing with us your website page.

  22. Project X Online said, on February 11, 2013 at 6:25 pm

    I enjoy you because of your entire work on this web page. Betty really loves conducting research and it’s simple to grasp why. Most of us notice all concerning the powerful means you give great ideas on this website and as well as cause contribution from other people on this theme then our favorite simple princess is actually studying a lot of things. Have fun with the rest of the year. You have been performing a glorious job.

  23. Herkules Online said, on February 11, 2013 at 6:26 pm

    I am very happy with all the variations that exist on this site. its all made ??it exciting, and the article is also very easy to understand and very useful,

  24. Jeden dzien Online said, on February 11, 2013 at 6:27 pm

    Hello fellas! I am asking yourself if somebody may possibly aid me out! Actually I would like to look at this unique web blog at my completely new iPad, nevertheless it does not display up appropriately, So I used to be pondering if another person can advise me any optimal solution? I don’t know but really should I try and locate out an update for my application plan or anything at all else? I am aware this can be something kinda off the subject, but please replace me and many thanks upfront for the support! Sophie

  25. transport materiałów said, on July 6, 2013 at 1:59 am

    Hi Dear, are you really visiting this website daily, if so
    afterward you will definitely get fastidious experience.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

Join 444 other followers

%d bloggers like this: