Language: Python Program: Processing 3.0 The program Processing 3.0 is used to b
ID: 3865923 • Letter: L
Question
Language: Python
Program: Processing 3.0
The program Processing 3.0 is used to build and initialize. For the burgers and fries, it does not necessary need to be images, a rect() shape with a fill() color can be used to represent the burger and fries. Burgers and fries should increase and decrease with the keyPressed() function. Burgers and fries should never be less than 1, and if burgers and fries start to fill up one line, a new line should be made automatically, without overlapping each other.
For this question, you will create a Processing program that visualizes placing a simple fast food order at a drive-thru restaurant. Our restaurant in this question serves only two items: hamburgers and fries. Your program should allow the user to select how many of each item they want and should update its canvas with pictures of the appropriate number of items. Your program should have the following specific behaviour: Use a 600 times 600 white canvas as the backdrop Initially the number of burgers and fries in the order are both O. Pressing the 'b' key increases the number of burgers in the order by 1: 'V' decreases it by 1. Make sure the number of burgers in the order cannot go negative. Pressing the "f" key increases the number of fries in the order by 1: "d" decreases it by 1. Again, no negatives. At all times, the program should visually display the order, i.e. there should be 1 hamburger on the screen for each hamburger in the order and similarly for the fries. You will need to use loops to do this. Start displaying the items in the order near the top-left corner of the canvas and fill up the canvas one row of items at a time. If a row fills up, start displaying the items on the next row and continue doing so as needed. If there are both burgers and fries in the order, the burgers should be displayed first. Begin displaying fries on a separate row from the burgers (even if the burgers don't entirely fill up a row: see example below) It is okay if the order gets so big that it starts going off the bottom of the canvas: you do not need to handle this case. Here is an example of what your program might look like: Your burgers and fries don't have to look exactly the same as in the sample, but a reasonable attempt at visual appeal should be made.Explanation / Answer
import os
import sys
import random
import datetime
import simpy
global STATE, TEMP, SUM_ALL
STATE = 0
TEMP = 0
SUM_ALL = 0.00
CALC = [0]*500 # Input capacity
RANDOM_SEED = 42 # Random helper
# Simulation time in minutes
HOUR_OPEN = 7 # Morning
HOUR_CLOSE = 23 # Night
START = HOUR_OPEN*60
SIM_TIME = HOUR_CLOSE*60
print(START)
print(SIM_TIME)
SIM_FACTOR = 1/60 # Simulation realtime factor
PEAK_START = 11
PEAK_END = 13
PEAK_TIME = 60*(PEAK_END-PEAK_START) # Range of peak hours
NUM_COUNTERS = 1 # Number of counters in the drive-thru
# Minutes it takes in each counters
TIME_COUNTER_A = 2
TIME_COUNTER_B = 1
TIME_COUNTER_C = 3
# Create a customer every [min, max] minutes
CUSTOMER_RANGE_NORM = [5,10] # in normal hours
CUSTOMER_RANGE_PEAK = [1,5] # in peak hours
CUSTOMER_RANGE = CUSTOMER_RANGE_PEAK
"""
Define clear screen function
"""
def clear():
os.system(['clear','cls'][os.name == 'nt'])
"""
Define exact clock format function
"""
def toc(raw):
clock = ('%02d:%02d' % (raw/60, raw%60))
return clock
def cr(string):
return "[1;31m%s[1;m" % string
def cy(string):
return "[1;33m%s[1;m" % string
def cg(string):
return "[1;32m%s[1;m" % string
def cb(string):
return "[1;34m%s[1;m" % string
def cm(string):
return "[1;35m%s[1;m" % string
def cgray(string):
return "[1;47m%s[1;m" % string
global ic_in, ic_go, ic_lv, ic_info, ic_ask, ic_mon, ic_stop, ic_dang
ic_in = cy("[w]")
ic_go = cy("[v]")
ic_lv = cy("[^]")
ic_info = cb("[i]")
ic_ask = cm("[?]")
ic_mon = cg("[$]")
ic_stop = cr("[#]")
ic_dang = cr("[!]")
"""
Waiting lane class
"""
class waitingLane(object):
def __init__(self, env):
self.env = env
self.lane = simpy.Resource(env, 3)
def serve(self, cust):
yield self.env.timeout(0)
print("%s (%s) %s entered the area" % (ic_in, toc(env.now), cust))
"""
First+Second counter class
"""
class counterFirstSecond(object):
def __init__(self, env):
self.env = env
self.employee = simpy.Resource(env, 1)
def serve(self, cust):
yield self.env.timeout(random.randint(TIME_COUNTER_A-1, TIME_COUNTER_A+1))
print("%s (%s) %s ordered the menu" % (ic_ask, cgray(toc(env.now)), cust))
yield self.env.timeout(random.randint(TIME_COUNTER_B-1, TIME_COUNTER_B+1))
print("%s (%s) %s paid the order" % (ic_mon, toc(env.now), cust))
"""
First counter class
"""
class counterFirst(object):
def __init__(self, env):
self.env = env
self.employee = simpy.Resource(env, 1)
def serve(self, cust):
yield self.env.timeout(random.randint(TIME_COUNTER_A-1, TIME_COUNTER_A+1))
print("%s (%s) %s ordered the menu" % (ic_ask, toc(env.now), cust))
"""
Second counter class
"""
class counterSecond(object):
def __init__(self, env):
self.env = env
self.employee = simpy.Resource(env, 1)
def serve(self, cust):
yield self.env.timeout(random.randint(TIME_COUNTER_B-1, TIME_COUNTER_B+1))
print("%s (%s) %s paid the order" % (ic_mon, toc(env.now), cust))
"""
Third counter class
"""
class counterThird(object):
def __init__(self, env):
self.env = env
self.employee = simpy.Resource(env, 1)
def serve(self, cust):
yield self.env.timeout(random.randint(TIME_COUNTER_C-1, TIME_COUNTER_C+1))
print("%s (%s) %s took the order" % (ic_stop, toc(env.now), cust))
"""
The customer process (each customer has a name)
arrives at the drive-thru lane, counter, then serviced by the empoyee (ce).
It then starts the service process for each counters then leaves.
"""
"""
(Type 2) Define customer behavior at first counter
"""
def customer2A(env, name, wl, ce12, ce3):
with wl.lane.request() as request:
if (env.now >= SIM_TIME):
print("%s Not enough time! %s cancelled" % (ic_dang, name))
env.exit()
yield request
yield env.process(wl.serve(name))
print("%s (%s) %s is in waiting lane" % (ic_in, toc(env.now), name))
# Start the actual drive-thru process
print("%s (%s) %s goes into drive-thru counter" % (ic_go, toc(env.now), name))
with ce12.employee.request() as request:
if (env.now + TIME_COUNTER_A + TIME_COUNTER_B >= SIM_TIME):
print("%s Not enough time! Assumed %s is quickly finished" % (ic_dang, name))
yield env.timeout(0.5)
env.exit()
yield request
CALC[int(name[5:])] = env.now
yield env.process(ce12.serve(name))
print("%s (%s) %s choose the order" % (ic_ask, toc(env.now), name))
yield env.process(ce12.serve(name))
print("%s (%s) %s is paying and will take the order" % (ic_mon, toc(env.now), name))
env.process(customer2B(env, name, ce12, ce3))
"""
(Type 2) Define customer behavior at second counter
"""
def customer2B(env, name, ce12, ce3):
with ce3.employee.request() as request:
if (env.now + TIME_COUNTER_C >= SIM_TIME):
print("%s Not enough time! Assumed %s is quickly finished" % (ic_dang, name))
yield env.timeout(0.5)
env.exit()
yield request
yield env.process(ce3.serve(name))
print("%s (%s) %s leaves" % (ic_lv, toc(env.now), name))
global TEMP
TEMP = int(name[5:])
CALC[int(name[5:])] = env.now - CALC[int(name[5:])]
"""
(Type 3) Define customer behavior at first counter
"""
def customer3A(env, name, wl, ce1, ce2, ce3):
with wl.lane.request() as request:
if (env.now >= SIM_TIME):
print("%s Not enough time! %s cancelled" % (ic_dang, name))
env.exit()
yield request
yield env.process(wl.serve(name))
print("%s (%s) %s is in waiting lane" % (ic_in, toc(env.now), name))
# Start the actual drive-thru process
print("%s (%s) %s goes into drive-thru counter" % (ic_go, toc(env.now), name))
with ce1.employee.request() as request:
if (env.now + TIME_COUNTER_A >= SIM_TIME):
print("%s Not enough time! Assumed %s is quickly finished" % (ic_dang, name))
yield env.timeout(0.5)
env.exit()
yield request
CALC[int(name[5:])] = env.now
yield env.process(ce1.serve(name))
print("%s (%s) %s choose the order" % (ic_ask, toc(env.now), name))
print("[2] (%s) %s will pay the order" % (toc(env.now), name))
env.process(customer3B(env, name, ce1, ce2, ce3))
"""
(Type 3) Define customer behavior at second counter
"""
def customer3B(env, name, ce1, ce2, ce3):
with ce2.employee.request() as request:
if (env.now + TIME_COUNTER_B >= SIM_TIME):
print("%s Not enough time! Assumed %s is quickly finished" % (ic_dang, name))
yield env.timeout(0.5)
env.exit()
yield request
yield env.process(ce2.serve(name))
print("%s (%s) %s is paying the order" % (ic_mon, toc(env.now), name))
print("[3] (%s) %s will take the order" % (toc(env.now), name))
env.process(customer3C(env, name, ce1, ce2, ce3))
"""
(Type 3) Define customer behavior at third counter
"""
def customer3C(env, name, ce1, ce2, ce3):
with ce3.employee.request() as request:
if (env.now + TIME_COUNTER_C >= SIM_TIME):
print("%s Not enough time! Assumed %s is quickly finished" % (ic_dang, name))
yield env.timeout(0.5)
env.exit()
yield request
yield env.process(ce3.serve(name))
print("%s (%s) %s leaves" % (ic_lv, toc(env.now), name))
global TEMP
TEMP = int(name[5:])
CALC[int(name[5:])] = env.now - CALC[int(name[5:])]
"""
Define detail of 2 counters setup environment
"""
def setup2(env, cr):
# Create all counters
wl = waitingLane(env)
ce12 = counterFirstSecond(env)
ce3 = counterThird(env)
i = 0
# Create more customers while the simulation is running
while True:
yield env.timeout(random.randint(*cr))
i += 1
env.process(customer2A(env, "Cust %d" % i, wl, ce12, ce3))
"""
Define detail of 3 counters setup environment
"""
def setup3(env, cr):
# Create all counters
wl = waitingLane(env)
ce1 = counterFirst(env)
ce2 = counterSecond(env)
ce3 = counterThird(env)
i = 0
# Create more customers while the simulation is running
while True:
yield env.timeout(random.randint(*cr))
i += 1
env.process(customer3A(env, "Cust %d" % i, wl, ce1, ce2, ce3))
"""
Run the main program, execute via editor or terminal.
"""
if __name__ == "__main__":
clear()
print("""
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>> Restaurant Queuing Model Simulation
>> Drive-Thru Fast Food Restaurant Design Model Evaluation
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>""")
# Check if the number of counters is specified
if len(sys.argv) < 2:
nc = 3
else:
nc = int(sys.argv[1])
# random.seed(RANDOM_SEED) # Helps reproducing the results
# Has the environment in realtime (wall clock)
# env = simpy.RealtimeEnvironment(factor=SIM_FACTOR)
# Has the environment in manual step through
env = simpy.Environment(initial_time=START)
print("Environment created!")
# Decide the counter model setup
if nc == 2:
env.process(setup2(env, CUSTOMER_RANGE))
elif nc == 3:
env.process(setup3(env, CUSTOMER_RANGE))
print("Setup initialized!")
print("Start simulation!")
env.run(until=SIM_TIME)
for i in range(TEMP+1):
SUM_ALL += CALC[i]
averageTimeService = SUM_ALL/(TEMP+1)
servicePerSecond = 1.00/(averageTimeService*60)
servicePerMinute = servicePerSecond*60
print("The end!")
print("%s Model: %d counters" % (ic_info, nc))
print("%s Average time: %.4f" % (ic_info, averageTimeService))
print("%s Service per minute: %f" % (ic_info, servicePerMinute))
# print(CALC)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.