Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Barber Shop Simulation
Old
chris42k
Junior Member
 
Status: Offline
Posts: 1
Join Date: May 2014
Default Barber Shop Simulation - 05-13-2014, 09:01 AM

Hey so im working on a final project where I simulating a barbershop. With four chairs, I assign the first four patrons to each seat. This is where i get stuck: I must have a random patron move from the seat at a random duration so the next available client fills the seat. I have 6 patrons for now (4 in the chair, 2 waiting) . Help please.
   
Reply With Quote
Sleeping barber
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default Sleeping barber - 05-13-2014, 10:36 AM

Quote:
Originally Posted by chris42k View Post
Hey so im working on a final project where I simulating a barbershop. With four chairs, I assign the first four patrons to each seat. This is where i get stuck: I must have a random patron move from the seat at a random duration so the next available client fills the seat. I have 6 patrons for now (4 in the chair, 2 waiting) . Help please.
This is the classic sleeping barber producer/consumer problem. Google and Wikipedia have lots of information on it. I am not sure how to set this up in Alice other than you need to do two things "at the same time." Which to me screems Events! In the absolute simplest case you would write two sets of methods, one for the patrons showing up and one for the barber cutting the hair. Each set of methods could be started by a while the world is running event and random wait times used to control when the next patron goes to the shop.
At this point I think your description is wrong. You would start out with the barber asleep and the waiting chairs empty.
The patrons methods would randomly have a patron show up, if there is an empty chair the patron would sit down and wait. At the same time the barber thread would randomly wake the barber if the chairs are empty he or she would go back to sleep otherwise the customer in the first chair would go to the barber's chair and the other patrons would move down one seat toward the first chair. When the barber is done with a haircut she or he would check to see if there was a customer waiting and the newly shorn patron would go back to the patron queue. As long as the first chair was not empty, the next patron would move to the barber chair and the others would shift toward the first chair. When all the chairs are empty the barber would go back to sleep.
The fact that you have six patrons and four chairs suggests to me that the goal is to never use the last patron. In the worst case you have one customer in the barber chair and four in the waiting chairs (5 total) if the last patron attempts to go to the shop before the barber can finish his current patron and start on the next then the last patron would find the shop full and go somewhere else. This would usually end the simulation.


There use to be a great java applet demonstrating all this. The patrons were represented as cousin It from the Addams family and when the barber was finished and turned to get the next customer, the chair was empty


Mark Henwood
mhenwood@ieee.org

Last edited by chickentree; 05-13-2014 at 10:40 AM.
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2018, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.