使用Agentpy,如何在模拟过程中创建代理

发布于 2025-01-31 14:50:08 字数 429 浏览 2 评论 0原文

我使用 Agentpypy 。它在建模促销方面做得很好,但我也希望能够为加入并离开公司的人们建模。

离开很容易,我可以将标志设置为 之类的东西,但是加入更为复杂。我是否需要在设置过程中制作一堆代理,并将其状态设置为尚未知道的,还是可以在一步中创建代理并添加它们?

这样的人的班级是这样的:

class PersonAgent(ap.Agent):

    def setup(self):
        p = PEOPLE_DF.iloc[self.id] # 
              

I have a simple simulation of a company using agentpy. It is doing a great job of modelling promotions, but I'd also like to be able to model people joining and leaving the company.

Leaving is easy, I can just set a flag to inactive or something, but joining is more complicated. Do I need to make a bunch of agents during setup and set their state to as yet unknown, or can I create an agent during a step and add them in?

The person class is defined like this:

class PersonAgent(ap.Agent):

    def setup(self):
        p = PEOPLE_DF.iloc[self.id] # ???? the existing people are in a spreadsheet
        self.name = p.full_name
        self.gender = get_gender(p.gender)
        self.bvn_rank = get_rank(p.b_rank)
        # self.capability = float(p.capability)
        print()

    def rank_transition(self):
        self.bvn_rank = transition(self.b_rank, self.gender)

I'm guessing I'd do something with the __init__, but I've had no luck figuring that out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨后咖啡店 2025-02-07 14:50:10

是的,您可以在模拟步骤中启动新代理。

这里有一些例子:

class MyModel(ap.Model):

    def setup(self):

        # Initiate agents at the start of the simulation
        self.agents = ap.AgentList(self, 10, PersonAgent)

    def step(self):
        
        # Create new agents during a simulation step
        self.single_new_agent = PersonAgent(self)
        self.list_of_new_agents = ap.AgentList(self, 10, PersonAgent)
        
        # Add them to the original list (if you want)
        self.agents.append(self.single_new_agent)
        self.agents.extend(self.list_of_new_agents)

Yes, you can initiate new agents during a simulation step.

Here are some examples:

class MyModel(ap.Model):

    def setup(self):

        # Initiate agents at the start of the simulation
        self.agents = ap.AgentList(self, 10, PersonAgent)

    def step(self):
        
        # Create new agents during a simulation step
        self.single_new_agent = PersonAgent(self)
        self.list_of_new_agents = ap.AgentList(self, 10, PersonAgent)
        
        # Add them to the original list (if you want)
        self.agents.append(self.single_new_agent)
        self.agents.extend(self.list_of_new_agents)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文