forked from tokenspice/tokenspice
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGrantGivingAgent.py
48 lines (38 loc) · 1.65 KB
/
GrantGivingAgent.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
import logging
log = logging.getLogger('agents')
from enforce_typing import enforce_types
from engine.AgentBase import AgentBase
@enforce_types
class GrantGivingAgent(AgentBase):
"""
Disburses funds at a fixed # evenly-spaced intervals.
Same amount each time.
"""
def __init__(self, name: str, USD: float, OCEAN: float,
receiving_agent_name: str,
s_between_grants: int, n_actions: int):
super().__init__(name, USD, OCEAN)
self._receiving_agent_name: str = receiving_agent_name
self._s_between_grants: int = s_between_grants
self._USD_per_grant: float = USD / float(n_actions)
self._OCEAN_per_grant: float = OCEAN / float(n_actions)
self._tick_last_disburse = None
def takeStep(self, state):
do_disburse = False
if self._tick_last_disburse is None:
do_disburse = True
else:
n_ticks_since = state.tick - self._tick_last_disburse
n_s_since = n_ticks_since * state.ss.time_step
n_s_thr = self._s_between_grants
do_disburse = (n_s_since >= n_s_thr)
if do_disburse:
self._disburseFunds(state)
self._tick_last_disburse = state.tick
def _disburseFunds(self, state):
#same amount each time
receiving_agent = state.getAgent(self._receiving_agent_name)
USD = min(self.USD(), self._USD_per_grant)
self._transferUSD(receiving_agent, USD)
OCEAN = min(self.OCEAN(), self._OCEAN_per_grant)
self._transferOCEAN(receiving_agent, OCEAN)