Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. 4. Creating a Tickets Sale Simulation
  2. Use the Queue class defined in part 1 of this lab to write a program to simulate the process of people buying tickets from a single ticket counter. Assume that:
  3.  
  4. The simulatioin runs in increments on 1 minute (that is, each iteration of the simulation loop represents 1 minute of real time).
  5. It takes exactly 1 minute for a customer at the ticket counter to buy tickets --regardless of the quantity.
  6. At each minute, there is a 50% chance that one person joins the ticket line, a 30% chance that two people join the ticket line, and a 20% chance that three people join the ticket line.
  7. Each customer will buy a random number of tickets, ranging from 1 to 4. Ticket availability ultimately determines the maximun number of tickets a customer can buy.
  8. There is a total of 200 tickets for sell. The simulation should stop as soon as all tickets are sold.
  9. The pseudo code for the simulation is as follows:
  10.  
  11. Create queue ticketLine
  12. Set variable minutes to zero
  13. Set variable tickets_left to 200
  14. WHILE there are tickets left for sale DO
  15. Add new customers to ticketLine (based on probabilities) [*]
  16. IF the ticketLine is not empty, THEN
  17. Get next customer from ticketLine queue
  18. IF the tickets neeeded by the customer is larger than the tickets left, THEN
  19. Customer can only buy the number of tickets left
  20. END IF
  21. Subtract from tickets_left the number of tickets needed by the customer.
  22. END IF
  23. Increase minutes by one
  24. Print the number of minutes, the queue and the number of tickets left
  25. END WHILE
  26. Print the number of customers left without tickets.
  27. Print the total number of minutes it took the simulation to run
  28. How do I "Add a new customers to ticketLine (based on probabilities)"?
  29. We are assuming that at each simulation minute, a number of customers will join the ticket line. This number depends on the probability distribution given above.
  30.  
  31. One approach is the following:
  32.  
  33. Draw a random number r between 0 and 1 (use random.random())
  34. IF r < 0.5 then
  35. Add an integer random number between 1 and 4 to the queue
  36. ELSE IF r < 0.8 then
  37. Draw two random numbers between 1 and 4 and add them to the queue
  38. ELSE
  39. Draw three random numbers between 1 and 4 and add them to the queue
  40. Save the test program as csc102_lab12_ticketssale.py. Save a transcript as csc102_lab12_ticketssale.txt
  41.  
  42. [*] For each customer, the value added to ticketLine is the number of tickets that customer intends to buy.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement