-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3814b61
commit cbed90f
Showing
28 changed files
with
3,784 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from .societyagent import SocietyAgent | ||
from .firmagent import FirmAgent | ||
from .bankagent import BankAgent | ||
from .nbsagent import NBSAgent | ||
from .governmentagent import GovernmentAgent | ||
from .memory_config import memory_config_societyagent, memory_config_government, memory_config_firm, memory_config_bank, memory_config_nbs | ||
|
||
__all__ = [ | ||
"SocietyAgent", | ||
"FirmAgent", | ||
"BankAgent", | ||
"NBSAgent", | ||
"GovernmentAgent", | ||
"memory_config_societyagent", | ||
"memory_config_government", | ||
"memory_config_firm", | ||
"memory_config_bank", | ||
"memory_config_nbs", | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import asyncio | ||
from typing import Optional | ||
|
||
import numpy as np | ||
from pycityagent import Simulator, InstitutionAgent | ||
from pycityagent.llm.llm import LLM | ||
from pycityagent.economy import EconomyClient | ||
from pycityagent.message import Messager | ||
from pycityagent.memory import Memory | ||
import logging | ||
|
||
logger = logging.getLogger("pycityagent") | ||
|
||
class BankAgent(InstitutionAgent): | ||
def __init__(self, | ||
name: str, | ||
llm_client: Optional[LLM] = None, | ||
simulator: Optional[Simulator] = None, | ||
memory: Optional[Memory] = None, | ||
economy_client: Optional[EconomyClient] = None, | ||
messager: Optional[Messager] = None, | ||
avro_file: Optional[dict] = None, | ||
) -> None: | ||
super().__init__(name=name, llm_client=llm_client, simulator=simulator, memory=memory, economy_client=economy_client, messager=messager, avro_file=avro_file) | ||
self.initailzed = False | ||
self.last_time_trigger = None | ||
self.time_diff = 30 * 24 * 60 * 60 | ||
self.forward_times = 0 | ||
|
||
async def month_trigger(self): | ||
now_time = await self.simulator.get_time() | ||
if self.last_time_trigger is None: | ||
self.last_time_trigger = now_time | ||
return False | ||
if now_time - self.last_time_trigger >= self.time_diff: | ||
self.last_time_trigger = now_time | ||
return True | ||
return False | ||
|
||
async def gather_messages(self, agent_ids, content): | ||
infos = await super().gather_messages(agent_ids, content) | ||
return [info['content'] for info in infos] | ||
|
||
async def forward(self): | ||
if await self.month_trigger(): | ||
citizens = await self.memory.get("citizens") | ||
while True: | ||
agents_forward = await self.gather_messages(citizens, 'forward') | ||
if np.all(np.array(agents_forward) > self.forward_times): | ||
break | ||
await asyncio.sleep(1) | ||
self.forward_times += 1 | ||
for uuid in citizens: | ||
await self.send_message_to_agent(uuid, f"bank_forward@{self.forward_times}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from .mobility_block import MobilityBlock | ||
from .cognition_block import CognitionBlock | ||
from .plan_block import PlanBlock | ||
from .needs_block import NeedsBlock | ||
from .social_block import SocialBlock | ||
from .economy_block import EconomyBlock | ||
from .other_block import OtherBlock | ||
from .time_block import TimeBlock | ||
|
||
__all__ = [ | ||
"MobilityBlock", | ||
"CognitionBlock", | ||
"PlanBlock", | ||
"NeedsBlock", | ||
"SocialBlock", | ||
"EconomyBlock", | ||
"OtherBlock", | ||
"LongTermDecisionBlock", | ||
"TimeBlock", | ||
] |
Oops, something went wrong.