can anyone help me? `
class MyAgent(Agent):
def __init__(self, unique_id,pos, model):
super().__init__(unique_id, model)
self.unique_id = unique_id
self.pos = pos
self.state = State.Not_adopter
self.RA = random.random()
self.Acc = random.random()
self.Uncer = random.random()
self.Infl = random.random()
self.Compat= random.ranom()
def communication(self):
neighbors = self.model.grid.get_neighborhood(self.pos,include_center=False)#to include the center cell itself as one of the neighbors or not.
adopter_neighbors = [
agent
for agent in self.model.grid.get_cell_list_contents(neighbors)
if agent.state is State.Adopter
]
`
class MyModel(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)
self.running = True
# Create agents
for i in range(self.num_agents):
a = MyAgent(i, self, Model)
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()
`
def agent_portrayal(agent):
portrayal = {"Shape": "circle", "r": 0.5, "Filled": "true", "Layer": 0}
if agent.state == State.Not_adopter:
portrayal["Color"] = ["#FF0000", "#FF9999"]
portrayal["stroke_color"] = "#00FF00"
else:
portrayal["Color"] = ["#0000FF", "#9999FF"]
portrayal["stroke_color"] = "#000000"
return portrayal
grid = CanvasGrid(agent_portrayal,10,10,500,500)
server= ModularServer(MyModel, [grid],
" Model", {"N":100,"width":10,"height":10}
)
server.port = 8521 # The default
server.launch()`
I want to get the agent neighbors from the communication method, but, I am getting below error AttributeError: type object 'Model' has no attribute 'grid'
I want to get the agent neighbors from the communication method, but, I am getting below error AttributeError: type object 'Model' has no attribute 'grid'