$30.00

## Description

Sweeny Todd has a barbershop on Fleet Street. In this humble establishment, Sweeny Todd is the only barber and can only tend to 1 customer at any given time. There is exactly one Barber chair which the active customer sits in & **n regular chairs **for subsequent customers to sit in as they wait for their turn. At any point, Sweeny Todd is either giving a customer a haircut or is sleeping in the Barber Chair while waiting for customers.

A regular day at Sweeny Todd’s barber shop is as follows:

● Sweeny Todd opens the Barber shop. Since there are no customers at that point, he goes to sleep on the Barber Chair.

● When the first customer arrives, they wake up Sweeny Todd and take the spot on the

Barber Chair.

● Sweeny Todd at this point proceeds to cut the customer’s hair.

● If other customers arrive while Sweeny Todd is cutting someone’s hair, one of two conditions is satisfied:

○ If there are regular chairs available, they sit down in one and wait their turn

○ If all the regular chairs are full, they leave.

● When Sweeny Todd finishes cutting the current customer’s hair, one of two conditions is satisfied:

○ If there are waiting customers, Sweeny Todd proceeds to cut the next customer’s hair.

○ If there are no waiting customers, Sweeny Todd goes back to sleep on the

Barber Chair.

Using the idea of Mutex/Semaphores implement the entire Barbershop Process. You can do this is any programming language of your choice.

**Please submit your files on Google Classroom ONLY**

There are 5 cases that you will need to implement. Details and examples follow on the next pages. There are 6 pages in total in this assignment.

**CASE-1**

Assume:

1. All haircuts take the same amount of time P (in seconds) to complete.

2. There are N regular chairs for waiting at the shop.

Assume that each customer’s arrival at the barbershop is determined by the mathematical function:

f(x) = x (mod 3) , where is x is a large randomly generated number (>10^5) Generate 1 random value of x per second

**IF f(x) == 0, then the customer will visit the barbershop else: they don’t.**

Print the sequence of events are they happen in Sweeny Todd’s Barbershop as the output

For example:

**INPUT:**

P=7

N=2

Customer Arrival Order:

1

0

0

1

0

0

0

1

1

0

0

1

**OUTPUT:**

Sweeny Todd has opened the Barber Shop

Sweeny Todd is sleeping

Customer-1 has arrived

Customer-1 has woken up Sweeny Todd Customer-1 is sitting in the Barber Chair Sweeny Todd is cutting Customer-1’s Hair Customer-2 has arrived

Sweeny Todd is busy, Customer-2 is waIting on Chair-1

Customer-3 has arrived

Sweeny Todd is busy, Customer-3 is waiting on Chair-2

Customer-1’s haircut is complete Customer-2 is sitting in the Barber Chair Sweeny Todd is cutting Customer-2’s hair Customer-3 is waiting on Chair-1

Customer-4 has arrived

Sweeny Todd is busy, Customer-4 is waiting on Chair-2

Customer-5 has arrived

Barbershop is full, Customer-5 has left Customer-2’s haircut is complete Customer-3 is sitting in the Barber Chair Sweeny Todd is cutting Customer-3’s hair Customer-4 is waiting on Chair-1

Customer-3’s haircut is complete Customer-4 is sitting in the Barber Chair Sweeny Todd is cutting Customer-4’s hair Customer-4’s haircut is complete

Sweeny Todd is sleeping

**FILE INSTRUCTIONS**

Save your file as case1.<extension> (eg: case1.py, case1.c etc)

**CASE-2**

Seeing his business grow, Sweeny Todd hires Davy Collins as his assistant to share the workload. There are now 2 Barber Chairs.

Assume:

1. All haircuts take the same amount of time P (in seconds) to complete.

2. There are N regular chairs for waiting at the shop.

Assume that each customer’s arrival at the barbershop is determined by the mathematical function:

f(x) = x (mod 3) , where is x is a large randomly generated number (>10^5) Generate 1 random value of x per second

**IF f(x) == 0, then the customer will visit the barbershop else: they don’t.**

Print the sequence of events are they happen in Sweeny Todd’s Barbershop as the output. Be sure to mention who the barber is for each case, Sweeny Todd or Davy Collins.

**FILE INSTRUCTIONS**

Save your file as case2.<extension> (eg: case2.py, case2.c etc)

**CASE-3**

Sweeny Todd soon realises that each customer will require differing amounts of time for their haircut to be completed. He decides to ask for your help in keeping a log the entire process in the barbershop.

Assume:

1. Each haircut takes random amount of time between 5-25 seconds to complete.

Randomly generate the amount of time for each customer.

2. There are N regular chairs for waiting at the shop.

3. Davy Collins is unavailable, hence there is only 1 Barber chair at the moment.

Assume that each customer’s arrival at the barbershop is determined by the mathematical function:

f(x) = x (mod 4) , where is x is a large randomly generated number (>10^5) Generate 1 random value of x per second

**IF f(x) == 0, then the customer will visit the barbershop else: they don’t.**

Print the sequence of events are they happen in Sweeny Todd’s Barbershop as the output.

**FILE INSTRUCTIONS**

_{Save your file as case3.<extension> (eg: case3.py, case3.c etc)}

**CASE-4**

Same as Case-3, just that Davy Collins is back at the shop. So now there are 2 Barber Chairs.

Print the sequence of events are they happen in Sweeny Todd’s Barbershop as the output. Be sure to mention who the barber is for each case, Sweeny Todd or Davy Collins

**FILE INSTRUCTIONS**

Save your file as case4.<extension> (eg: case4.py, case4.c etc)

**CASE-5**

Sweeny Todd notices that a few customers end up taking up a lot of time compared to others. A statistician friend tells Sweeny Todd that these possibly end up following __Zipf’s____ ____Law__. Curious, Sweeny Todd again seeks your help to investigate this.

Assume:

1. Each haircut takes random amount of time to complete. Generate the amount of time for each customer takes that follows a Zipfian Distribution.

a. __You____ ____can____ ____use____ ____NumPy____ ____to____ ____generate____ ____this____ ____distribution__.

b. If you’re not coding in Python, you can generate the sequence in Python and hard-code it into your program.

2. There are N regular chairs for waiting at the shop.

3. Davy Collins is unavailable, hence there is only 1 Barber chair at the moment.

Assume that each customer’s arrival at the barbershop is determined by the mathematical function:

f(x) = x (mod 7), where is x is a large randomly generated number (>10^5) Generate 1 random value of x per second

**IF f(x) == 0, then the customer will visit the barbershop else: they don’t.**

Print the sequence of events are they happen in Sweeny Todd’s Barbershop as the output.

**FILE INSTRUCTIONS**

Save your file as case5.<extension> (eg: case5.py, case5.c etc)

**GENERAL NOTE: Your program should work for various values of P, N and number of customers.**

**FINAL SUBMISSION GUIDELINES**

1. Create a zip file that contains all your 5 cases (following the naming convention specified)

2. Name this zip file as **GroupNumber_FirstNameOfAllTeamMembers.zip**

3. Submit this before the deadline on Google Classroom Only. E-Mail submissions will not be accepted.