Policies
Greedy Policy
GraphGreedyPolicy
Bases: BasePolicy
Greedy policy for graph environment using shortest path.
Compatible only with graph_collector environment.
Note
This is very slow for non-static graphs as shortest paths are computed in O(V^3) time for every action search. Static graphs use cached shortest paths.
Attributes:
Name | Type | Description |
---|---|---|
env |
pettingzoo.utils.env.AECEnv
|
Environment used by policy. |
shortest_len_paths |
dict
|
Cached shortest paths including path lengths for all node pairs. |
cur_goals |
dict
|
Cached goals for each agent consisting of (path, collected, point_idx) tuples keyed by agent name. |
Source code in datadynamics/policies/greedy_policy/greedy_policy.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
GreedyPolicy
Bases: BasePolicy
Greedy policy for collector environment.
This policy computes the expected reward for every action in every step and chooses the one with the highest expected reward.
Compatible only with collector environment.
Note
This is only locally optimal and not globally. Best routes to collect all points are disregarded and we only search for the next best point for every step. The policy may degenerate and always sample the same point if the cost of cheating is lower than the reward for collecting a point.
Attributes:
Name | Type | Description |
---|---|---|
env |
pettingzoo.utils.env.AECEnv
|
Environment used by policy. |
Source code in datadynamics/policies/greedy_policy/greedy_policy.py
policy(**kwargs)
Creates a suitable greedy policy for a given environment.
Returns:
Name | Type | Description |
---|---|---|
BasePolicy | Greedy policy. |
Source code in datadynamics/policies/greedy_policy/greedy_policy.py
BFS-Greedy Policy
BFSGraphGreedyPolicy
Bases: BasePolicy
Greedy policy using a breadth-first search for every action retrieval.
This policy runs in O(V + E) time when finding a new goal for an agent and as such may slow down stepping through the environment.
Compatible only with graph_collector environment for graphs with equal edge weights between nodes.
Attributes:
Name | Type | Description |
---|---|---|
env |
pettingzoo.utils.env.AECEnv
|
Environment used by policy. |
graph |
nx.Graph
|
Graph used by environment. |
cur_goals |
dict
|
Cached goals for each agent consisting of (path, collected, point_idx) tuples keyed by agent name. |
Source code in datadynamics/policies/bfs_greedy_policy/bfs_greedy_policy.py
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
__init__(env, graph)
Initialize policy from environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
env |
pettingzoo.utils.env.AECEnv
|
Environment on which to base policy. |
required |
graph |
nx.Graph
|
Graph used by environment. |
required |
Source code in datadynamics/policies/bfs_greedy_policy/bfs_greedy_policy.py
policy(**kwargs)
Creates a suitable BFS-based greedy policy for a given environment.
Returns:
Name | Type | Description |
---|---|---|
BasePolicy | BFS-based greedy policy. |
Premade Policy
PremadePolicy
Bases: BasePolicy
Policy using a premade list of goals for each agent.
This policy runs in O(V + E) time when reaching a goal due to having to search for the shortest path to the given goal.
Compatible only with graph_collector environment for graphs with equal edge weights between nodes.
Attributes:
Name | Type | Description |
---|---|---|
env |
pettingzoo.utils.env.AECEnv
|
Environment used by policy. |
graph |
nx.Graph
|
Graph used by environment. |
cur_goals |
dict
|
Cached goals for each agent consisting of (path, collected, point_idx) tuples keyed by agent name. |
Source code in datadynamics/policies/premade_policy/premade_policy.py
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
__init__(env, graph, goal_dict)
Initialize policy from environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
env |
pettingzoo.utils.env.AECEnv
|
Environment on which to base policy. |
required |
graph |
nx.Graph
|
Graph used by environment. |
required |
goal_dict |
dict
|
Dictionary of goals for each agent (keys can be arbitrary). |
required |
Source code in datadynamics/policies/premade_policy/premade_policy.py
policy(**kwargs)
Creates a premade policy for a given environment
Returns:
Name | Type | Description |
---|---|---|
BasePolicy | Premade policy. |
Random Policy
RandomPolicy
Bases: BasePolicy
Policy that returns a random action.
Compatible with all environments.
Attributes:
Name | Type | Description |
---|---|---|
env |
pettingzoo.utils.env.AECEnv
|
Environment used by policy. |
Source code in datadynamics/policies/random_policy/random_policy.py
policy(**kwargs)
Creates a RandomPolicy for a given environment.
Returns:
Name | Type | Description |
---|---|---|
BasePolicy | Random policy. |
Dummy Policy
DummyPolicy
Bases: BasePolicy
Dummy policy that cycles through all actions.
Compatible with all environments.
Attributes:
Name | Type | Description |
---|---|---|
env |
pettingzoo.utils.env.AECEnv
|
Environment used by policy. |
Source code in datadynamics/policies/dummy_policy/dummy_policy.py
policy(**kwargs)
Creates a dummy policy for a given environment.
Returns:
Name | Type | Description |
---|---|---|
BasePolicy | Dummy policy. |