NetLogo banner

Home
Download
Help
Forum
Resources
Extensions
FAQ
NetLogo Publications
Contact Us
Donate

Models:
Library
Community
Modeling Commons

Beginners Interactive NetLogo Dictionary (BIND)
NetLogo Dictionary

User Manuals:
Web
Printable
Chinese
Czech
Farsi / Persian
Japanese
Spanish

  Donate

NetLogo User Community Models

(back to the NetLogo User Community Models)

[screen shot]

Download
If clicking does not initiate a download, try right clicking or control clicking and choosing "Save" or "Download".(The run link is disabled for this model because it was made in a version prior to NetLogo 6.0, which NetLogo Web requires.)

WHAT IS IT?

The Sleeping Barber Problem (or Barbershop Problem) is a synchronization problem which was first proposed by Edsger W. Dijkstra in 1968.

A barbershop usually consists of a waiting room with several chairs and the barber room containing the barber chair. Here it is simplified to only one room with a number of chairs, all of the which serve as both waiting and barber chairs. When a customer enters the shop to be served, if the shop is full, he leaves without being served.

HOW IT WORKS

There are two types of agents: the barber, who serves the customers, and the customers themselves.
If there are no customers to be served, the barber goes to sleep.
If a customer enters the barbershop and all chairs are occupied, then the customer leaves the shop.
If the barber is busy but chairs are available, the customer sits in one of the free chairs and waits.
If the barber is asleep, the customer wakes him.

HOW TO USE IT

Initial settings - by default :
number-chairs: how many chairs are there in total?
probability_of_entrance: How high is the probability that the customer will enter? The slider has an interval (0-100) percent.
probability_of_exit: How high is the probability that the customer will leave? How long it will take to process the customer. The interval of the slider is (0-100)%.

Plots:
number_of_rejected: total number of customers, who had to leave without being served due to full chairs
number_of_processed: total number of customers, who were served
Processing customers: chart shows the number of customers in the shop at a certain time - number of engaged chairs.

THINGS TO NOTICE

Observe the line chart and the number of processed/rejected customers, when modifying probability_of_entrance and probability_of_exit.

THINGS TO TRY

Play with the settings of the the sliders to change the probability of entrance or exit.

EXTENDING THE MODEL

There exists several versions of this problem. One modification could be to add more than one barber.
Another possibility is to limit the time, for which the customers are willing to wait before being served.

RELATED MODELS

Related model from the NetLogo library: Computer Science - Dining Philosophers

CREDITS AND REFERENCES

E. W. Dijkstra, "Co-operating Sequential Processes", in F. Genuys (ed.), Programming Languages, Academic Press, 1968, pp. 43-112.

(back to the NetLogo User Community Models)