-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomer.py
More file actions
87 lines (76 loc) · 4.65 KB
/
Copy pathCustomer.py
File metadata and controls
87 lines (76 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import math, random
from Hotel import *
""" bank01_OO: The single non-random Customer """
from simpy import *
from Menu import *
from HotelController import *
from GlobalDeclaration import *
class Customer():
def __init__(self,env,name):
self.env = env
self.name = name
#for hotel customer, the stay_duration is how many days they'll stay in a hotel room.
#Also need to add in the type of room that they're checking in, etc. Namely, more complicated features that works in Hotel Model
def visit(self,resource,stay_duration,hotel,roomtype,hc):
"""wait in line and get the resource.
For reference,see http://simpy.readthedocs.org/en/latest/simpy_intro/shared_resources.html"""
#may need to change here to reflect that customers leave once they can't find a room
with resource.request() as req:
yield req
print "%s arrives at %d" %(self.name,self.env.now)
#Added a check before every yeild report to make sure the weeklyreport doesn't happen during the yield
if (self.env.now + math.ceil(stay_duration) ) %7 < math.ceil(stay_duration) :
yield self.env.timeout(math.ceil(stay_duration)-(self.env.now + math.ceil(stay_duration)) %7)
yield self.env.process(Menu.WeeklyReport(self.env,hc))
yield self.env.timeout((self.env.now + math.ceil(stay_duration)) %7)
else :
yield self.env.timeout(math.ceil(stay_duration))
print "%s leaves at %d" %(self.name,self.env.now)
hotel.revenue += hotel.room_price[roomtype]*math.ceil(stay_duration) #math.ceil(),get the upper rounded number
def rand_hotel_room(self, hotel_array):
#Loop through hotels randomly
random.shuffle(hotel_array)
#randomly produce a customer preference for rooms
rand_type_number = random.randint(0,len(Hotel.ROOM_TYPES)-1)
init_rand_type_number = rand_type_number
adder = -1 # by default, choose cheaper one if the prefered type is not available
if rand_type_number == 0:
adder = 1 #if is already choosing cheaper one, choose a slightly more expensive one
for hotel in hotel_array:
#check if the room is full -- if it is, try a different type
#after two tries, will just give up and go to another hotel
for i in xrange(2): #only have two tries
room_type = Hotel.ROOM_TYPES[rand_type_number]
if hotel.simpy_rooms[room_type].level > 0:
room_type = Hotel.ROOM_TYPES[rand_type_number]
return [hotel, room_type]
rand_type_number += adder
#Code to always select the cheapest next available room
rand_type_number = init_rand_type_number #go back to old preference and choose room in another hotel
#If there is no hotel/room selected, return nothing
return None
#for hotel customer, the stay_duration is how many days they'll stay in a hotel room.
#Also need to add in the type of room that they're checking in, etc. Namely, more complicated features that works in Hotel Model
def visit_hotel(self, stay_duration,hc,player,menu):
"""wait in line and get the resource.
For reference,see http://simpy.readthedocs.org/en/latest/simpy_intro/shared_resources.html"""
#randomly sample and select a hotel
hotel_room_array = self.rand_hotel_room(hc.hotels)
if hotel_room_array is None:
pass #do nothing and give up this customer
else:
hotel = hotel_room_array[0]
roomtype = hotel_room_array[1]
#may need to change here to reflect that customers leave once they can't find a room
print "%s arrives at time %d at %s " %(self.name,self.env.now,hotel.name)
yield hotel.simpy_rooms[roomtype].get(1)
#Added a check before every yeild report to make sure the weeklyreport doesn't happen during the yield
if (self.env.now + math.ceil(stay_duration) ) %7 < math.ceil(stay_duration) :
yield self.env.timeout(math.ceil(stay_duration)-(self.env.now + math.ceil(stay_duration)) %7)
yield self.env.process(menu.WeeklyReport())
yield self.env.timeout((self.env.now + math.ceil(stay_duration)) %7)
else :
yield self.env.timeout(math.ceil(stay_duration))
yield hotel.simpy_rooms[roomtype].put(1)
print "%s leaves at time %d from %s" %(self.name,self.env.now,hotel.name)
hotel.revenue += hotel.room_price[roomtype]*math.ceil(stay_duration) #math.ceil(),get the upper rounded number