7 Replies - 5826 Views - Last Post: 20 April 2013 - 02:23 PM Rate Topic: -----

#1 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7564
  • View blog
  • Posts: 12,688
  • Joined: 19-March 11

Python Challenge: Loo Queue

Post icon  Posted 02 February 2013 - 12:53 AM

Here's the latest in our series of Python Challenges. This week's is a slightly silly premise, but hopefully the topic is interesting.

Consider this situation: an office with 100 employees and two restrooms.

Taken literally, it is not possible for the office described to function if we assume that each employee visits the loo once per day, and the average time per visit is >= 10 minutes. This is easily proved with simple arithmetic. (8 hour workday*60 minutes per hour = 480 minutes per workday, 10 minutes per visit * 100 employees/2 johns = 500 minutes per crapper required)

However, it should be evident that since calls of nature cannot be scheduled to the convenience of the workplace, the actual breakdown point comes at a much lower average time per visit, still assuming one visit per employee per day.

In this challenge, your task is to to simulate this unfortunate workplace, and similar situations. Since this is an effectively bottomless problem, we're not giving you a specification, but here are some ideas you might consider:
  • Basic: Model the situation as described in the post: 100 employees in a building with two restrooms. Assume that each visit takes exactly the average time, which for convenience we'll say is ten minutes. Assume visits are random impulses, evenly distributed throughout the day. Assume one visit per employee per day. Assume that toilets are unisex, and that one line serves both toilets.
    As output, provide a list of employees and the time each one spent in the queue.*
  • Intermediate: Get a little more realistic. "Visits" now vary in length, distributed around the average time in some reasonable fashion. (Does this change make a difference to the result?) The average time per visit can be configured.
    Do a little more analysis on the output: assuming everyone leaves the building at 5:00, how long did employees spend in the queue? How many went home with bladders bursting?
  • Advanced: More realistic: Toilets are gendered. (implying that employees must be gendered). "Visits" are now variable in length, clustered around two distinct averages, or perhaps four (ie, these times may vary by gender). Visits are now clustered in a more reasonable distribution. (use your imagination: consider lunch times, break times, and ordinary human psychology)
    Provide visualizations of your results. Graphs would be cool. Animations of the line would be awesome.

Implementation hints:
  • The obvious data structure for modelling this problem is the queue (the name sorta gives it away, doesn't it?). However, there are other approaches.
  • Novice Python programmers who have not explored object-oriented python might find this a convenient opportunity to do so.


If you have questions about the challenge, post them here and Simown or I will come up with some sort of answer.

Have fun!

EDIT: * Having worked the problem, I think this might not be the most useful or interesting output. For the basic challenge, it would be acceptable to simply produce a running report of the state, or to report some interesting statistics. For example, average wait time would be interesting, and also the number of employees who were still in line at the close of business. Further analysis is up to your imagination: part of the challenge here is to figure out what sorts of information you'd like to get from this kind of model.

Is This A Good Question/Topic? 3
  • +

Replies To: Python Challenge: Loo Queue

#2 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7564
  • View blog
  • Posts: 12,688
  • Joined: 19-March 11

Re: Python Challenge: Loo Queue

Posted 02 February 2013 - 10:53 PM

So I have to admit, I added this to the list partly because, well, it's funny, but mostly because I'd never really played with python's objects and I wanted an excuse to do that. So I put in a couple of hours this afternoon and here's what I got.


Spoiler



Turns out it was a really interesting exercise. I ended up looking up a few things and making up most of it, so there may be a lot of completely silly stuff in here. If there's anything that's really goofy, I'd like to hear about it - this is a pure learning exercise for me.

EDIT: Having written the basic challenge, I've amended the requested output somewhat. As always, Simown and I are happy to take suggestions for improvements, even from ourselves. :)/>
Was This Post Helpful? 1
  • +
  • -

#3 Nykc  Icon User is offline

  • Gentleman of Leisure
  • member icon

Reputation: 725
  • View blog
  • Posts: 8,638
  • Joined: 14-September 07

Re: Python Challenge: Loo Queue

Posted 04 February 2013 - 10:54 AM

A new twist in the challenge would be the company has since re-located to a place that contains 3 toilets and company size has decreased to 60 - which does make a more comfortable situation and the ability to eat more Indian cuisine without the fear of being stranded.

This post has been edited by Nykc: 04 February 2013 - 10:56 AM

Was This Post Helpful? 1
  • +
  • -

#4 AdamSpeight2008  Icon User is online

  • MrCupOfT
  • member icon


Reputation: 2240
  • View blog
  • Posts: 9,411
  • Joined: 29-May 08

Re: Python Challenge: Loo Queue

Posted 04 February 2013 - 12:11 PM

What about if the person want a #1 or #2 or a #3( #1 + #2 combo)?
More urinals or more stalls?
Was This Post Helpful? 0
  • +
  • -

#5 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7564
  • View blog
  • Posts: 12,688
  • Joined: 19-March 11

Re: Python Challenge: Loo Queue

Posted 04 February 2013 - 12:19 PM

View PostAdamSpeight2008, on 04 February 2013 - 02:11 PM, said:

What about if the person want a #1 or #2 or a #3( #1 + #2 combo)?
More urinals or more stalls?



That would be a good scenario to cover in the advanced case. I hinted (delicately) at the possibility in the writeup:

Quote

"Visits" are now variable in length, clustered around two distinct averages, or perhaps four (ie, these times may vary by gender).

but you're right, you could make this more nuanced if you wanted. Indeed, you might want to account for the fact that there's a new Indian restaurant in the neighborhood, and some of the employees take their lunch there.

As I say, part of the fun here is considering what needs to be modeled, and how true to life you need/want to get.
Was This Post Helpful? 0
  • +
  • -

#6 SwiftStriker00  Icon User is offline

  • No idea why my code works
  • member icon

Reputation: 432
  • View blog
  • Posts: 1,596
  • Joined: 25-December 08

Re: Python Challenge: Loo Queue

Posted 04 February 2013 - 06:21 PM

I think you all bring up great points on bathroom simulation, as anything in real life there are numerous factors that could effect the daily usage of any system. However I think your creeping a bit into the realm of human conditions versus modeling a working bathroom.

I'd say you want to focus on creating a simulator around the attributes and services of the bathroom. Model a small amount of human AI as to how they go from the office to the queue (if any) to using a component. Now that you have that in place then you can have fun testing that system with different scenarios.

If you want to simulate Taco-Surprise day at lunch, you can translate that to a high frequency / high capacity visit around 1-2, and just sit back and watch to see the results. But in terms of scope of the challenge that just sounds like a test case not a requirement.

I'm just getting started with python so we'll see how long it takes for me to try this, but it is an amusing challenge to say the least
Was This Post Helpful? 1
  • +
  • -

#7 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7564
  • View blog
  • Posts: 12,688
  • Joined: 19-March 11

Re: Python Challenge: Loo Queue

Posted 05 February 2013 - 01:30 PM

Quote

I think you all bring up great points on bathroom simulation, as anything in real life there are numerous factors that could effect the daily usage of any system. However I think your creeping a bit into the realm of human conditions versus modeling a working bathroom.


You're absolutely right, of course. There's a few aspects to this "challenge", and as I say it's largely about exploring how to construct informative models, and produce useful results. Part of that is, how much do you need to build in, and how does it affect the outcome?

Quote

I'm just getting started with python so we'll see how long it takes for me to try this, but it is an amusing challenge to say the least


That's the main thing, in my book. If you have fun and you learn something from it, that's a win.
Was This Post Helpful? 0
  • +
  • -

#8 xGeovanni  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 02-September 12

Re: Python Challenge: Loo Queue

Posted 20 April 2013 - 02:23 PM

I went ever-so-slightly overboard and made a graphical representation. You won't really be able to harvest much in the way of data, but it's fun to just watch the stupidity. You can download it here(Source Included).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1