简体   繁体   English

运行 Mesa 示例模型时,出现“NotImplementedError”

[英]When running Mesa example model, I get a "NotImplementedError"

I tried implementing the tutorial from [mesa][1].我尝试从 [mesa][1] 实施教程。 Here is the code that I have copied from there, split into two files, money_model.py, and server.py respectively:这是我从那里复制的代码,分别分为两个文件,money_model.py 和 server.py:

from mesa import Agent, Model
from mesa.time import RandomActivation
from mesa.space import MultiGrid
from mesa.visualization.modules import CanvasGrid
from mesa.visualization.ModularVisualization import ModularServer
class MoneyAgent(Agent):
    """ An agent with fixed initial wealth."""
    def __init__(self, unique_id, model):
        super().__init__(unique_id, model)
        self.wealth = 1

    def move(self):
        possible_steps = self.model.grid.get_neighborhood(
            self.pos,
            moore=True,
            include_center=False)
        new_position = self.random.choice(possible_steps)
        self.model.grid.move_agent(self, new_position)

    def give_money(self):
        cellmates = self.model.grid.get_cell_list_contents([self.pos])
        if len(cellmates) > 1:
            other_agent = self.random.choice(cellmates)
            other_agent.wealth += 1
            self.wealth -= 1

    def step(self):
        self.move()
        if self.wealth > 0:
            self.give_money()


class MoneyModel(Model):
    """A model with some number of agents."""
    def __init__(self, N, width, height):
        self.num_agents = N
        self.grid = MultiGrid(width, height, True)
        self.schedule = RandomActivation(self)
        # Create agents
        for i in range(self.num_agents):
            a = MoneyAgent(i, self)
            self.schedule.add(a)
            # Add the agent to a random grid cell
            x = self.random.randrange(self.grid.width)
            y = self.random.randrange(self.grid.height)
            self.grid.place_agent(a, (x, y))

    def step(self):
        self.schedule.step()

and

from money_model import *
from mesa.visualization.modules import CanvasGrid
from mesa.visualization.ModularVisualization import ModularServer


def agent_portrayal(agent):
    portrayal = {"Shape": "circle",
                 "Filled": "true",
                 "Layer": 0,
                 "Color": "red",
                 "r": 0.5}
    return portrayal

grid = CanvasGrid(agent_portrayal, 10, 10, 500, 500)
server = ModularServer(MoneyModel,
                       [grid],
                       "Money Model",
                       {"N":100, "width":10, "height":10})
server.port = 8521 # The default
server.launch()

When I run the example, it gives me the following error:当我运行该示例时,它给了我以下错误:

Interface starting at http://127.0.0.1:8521
Traceback (most recent call last):
  File "c:/Users/fisch/Desktop/mesa example/server.py", line 20, in <module>
    server.launch()
  File "C:\Program Files\villos\lib\site-packages\mesa\visualization\ModularVisualization.py", line 333, in launch
    self.listen(self.port)
  File "C:\Program Files\villos\lib\site-packages\tornado\web.py", line 2116, in listen
    server.listen(port, address)
  File "C:\Program Files\villos\lib\site-packages\tornado\tcpserver.py", line 152, in listen
    self.add_sockets(sockets)
  File "C:\Program Files\villos\lib\site-packages\tornado\tcpserver.py", line 165, in add_sockets
    self._handlers[sock.fileno()] = add_accept_handler(
  File "C:\Program Files\villos\lib\site-packages\tornado\netutil.py", line 279, in add_accept_handler
    io_loop.add_handler(sock, accept_handler, IOLoop.READ)
  File "C:\Program Files\villos\lib\site-packages\tornado\platform\asyncio.py", line 100, in add_handler
    self.asyncio_loop.add_reader(fd, self._handle_events, fd, IOLoop.READ)
  File "C:\Program Files\villos\lib\asyncio\events.py", line 501, in add_reader
    raise NotImplementedError
NotImplementedError
    

This also happens when I run the project I am currently working on using "mesa runserver" when I am in the project directory that contains the run.py file.当我在包含 run.py 文件的项目目录中时,当我使用“mesa runserver”运行当前正在处理的项目时,也会发生这种情况。 I have checked the environment variables and the path that contains mesa is present.我已经检查了环境变量,并且存在包含台面的路径。 Has anyone any idea where the problem may be?有谁知道问题可能出在哪里? Thank you!谢谢! [1]: https://mesa.readthedocs.io/en/master/tutorials/adv_tutorial.html [1]: https : //mesa.readthedocs.io/en/master/tutorials/adv_tutorial.html

I got “NotImplementedError” because my I had an outdated version of mesa.我收到了“NotImplementedError”,因为我有一个过时的台面版本。

pip install mesa --upgrade

solved that.解决了那个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NotImplementedError 运行 model.fit 时在 Tensorflow Keras - NotImplementedError when running model.fit in Tensorflow Keras 与SMTPServer一起运行时asyncore读取NotImplementedError - asyncore read NotImplementedError when running with SMTPServer 尝试使用mysql python连接器执行预准备语句时,我得到NotImplementedError - I get NotImplementedError when trying to do a prepared statement with mysql python connector tensorflow_hub 在保存 keras model 时返回 NotImplementedError - tensorflow_hub returns NotImplementedError when saving a keras model NotImplementedError: 当子类化`Model` class,你应该实现`call` 方法 - NotImplementedError: When subclassing the `Model` class, you should implement a `call` method 尝试在带有Azure存储的Django中获取image.size时出现NotImplementedError - NotImplementedError when trying to get image.size in Django with Azure Storage 如何从 sympy 中的 NotImplementedError 获取值? - How can I get values from NotImplementedError in sympy? 何时使用“引发 NotImplementedError”? - When to use 'raise NotImplementedError'? 当我将 isin 与 Dask 数据帧一起使用时抛出 NotImplementedError - NotImplementedError is thrown when I use isin with Dask data frames 运行web2py“图片博客”示例时出错 - get error when running web2py “image blog” example
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM