-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpolicies.py
55 lines (54 loc) · 1.55 KB
/
policies.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
from pd_main import *
import random
# # random policy #
# def PRandom(possible_actions):
# return random.choice(possible_actions)
#
# # exploit policy #
# def PExploit(possible_actions, agent, row, col):
# duplicate = []
#
# q_table = dropoff_q_table if agent.hasBlock() else pickup_q_table
#
# # choose action with best q-value 80% of the time
# if random.random() <= 0.8:
# max_action = possible_actions[0]
# for num in possible_actions:
# q_value = q_table[row][col][num]
# max_q_value = q_table[row][col][max_action]
#
# if q_value > max_q_value:
# max_action = num
# duplicate.clear()
# duplicate.append(num)
# if q_value == max_q_value:
# duplicate.append(num)
#
# exploit_choice = random.choice(duplicate) if len(duplicate) > 1 else max_action
# else:
# exploit_choice = random.choice(possible_actions)
#
# return exploit_choice
#
# # greedy policy #
# def PGreedy(possible_actions, agent, row, col):
# duplicate = []
#
# q_table = dropoff_q_table if agent.hasBlock() else pickup_q_table
#
# # choose action with best q-value 100% of the time
# max_action = possible_actions[0]
# for num in possible_actions:
# q_value = q_table[row][col][num]
# max_q_value = q_table[row][col][max_action]
#
# if q_value > max_q_value:
# max_action = num
# duplicate.clear()
# duplicate.append(num)
# if q_value == max_q_value:
# duplicate.append(num)
#
# greedy_choice = random.choice(duplicate) if len(duplicate) > 1 else max_action
#
# return greedy_choice