-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver_simulation.py
More file actions
60 lines (43 loc) · 1.71 KB
/
Copy pathserver_simulation.py
File metadata and controls
60 lines (43 loc) · 1.71 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
import random
class ServerAgent(object):
def __init__(self, small_count = 10, medium_count = 10, large_count = 10):
self.small_count = small_count
self.medium_count = medium_count
self.large_count = large_count
def select_action(self, percept):
if 0 <= percept and percept <= 33:
if self.large_count > 0:
self.large_count = self.large_count - 1
return "large"
else:
return None
elif 34 <= percept and percept <= 66:
if self.medium_count > 0:
self.medium_count = self.medium_count - 1
return "medium"
else:
return None
elif 67 <= percept and percept <= 99:
if self.small_count > 0:
self.small_count = self.small_count - 1
return "small"
else:
return None
elif percept >= 100:
return None
def storage_empty(self):
if self.small_count == 0 and self.medium_count == 0 and self.large_count == 0:
return True
else:
return False
class ServerEnvironment(object):
def __init__(self, server_agent):
self.server_agent = server_agent
self.num_agent_actions = 0
def tick(self):
percept = random.randint(0, 130)
self.server_agent.select_action(percept)
self.num_agent_actions = self.num_agent_actions + 1
def simulate(self):
while self.server_agent.storage_empty() is not True:
self.tick()