-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepsilon_greedy_agent.py
63 lines (52 loc) · 2.17 KB
/
epsilon_greedy_agent.py
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
"""
/**
* Implementation of an agent that utilizes an epsilon-greedy algorithm to distribute test kits.
*
* @author Joe McCall; Chris Zahuranec
* @date 4/24/2020
* @info Course CAP5600
*/
"""
from random import random
from agent import Agent
class EpsilonGreedyAgent(Agent):
# Epsilon value that shows how much exploration is favored over exploitation.
# A value of 1 will always distribute the test kits evenly
# A value of 0 will always give all of the test kits to the county with the most positive cases the previous day
epsilon = 0.2
def __init__(self, counties, test_kit_capacity):
"""
Constructor
"""
super().__init__(counties, test_kit_capacity)
self.county_cases = dict.fromkeys(counties, 0)
self.trial_count = 0
self.highest_county = self.counties[0]
def distribute_test_kits(self):
"""
Distribute the test kits
:return:
"""
# The top county receives (1-epsilon) * test_kit_capacity test kits (Exploitation phase)
exploitation_kits = (1 - self.epsilon) * self.test_kit_capacity
# The remaining kits are distributed evenly among the remaining counties (Exploration phase)
exploration_kits = self.test_kit_capacity - exploitation_kits
exploration_kits_per_county = exploration_kits / len(self.counties)
# Distribute the test kits based on the internal map
for county in self.counties:
if county == self.highest_county:
county.receive_test_kits(int(exploitation_kits))
county.receive_test_kits(int(exploration_kits_per_county))
def consume_result(self, county, date, results):
"""
Update the results in our in-memory store
:param county: the county
:param date: the date (ignored by this implementation)
:param results: the number of positive cases
:return:
"""
self.county_cases[county] += county.score
# Update the highest county
for county in self.counties:
if self.county_cases[county] > self.county_cases[self.highest_county]:
self.highest_county = county