Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

please add move function in class Agent #845

Open
ivaquero opened this issue May 15, 2020 · 4 comments
Open

please add move function in class Agent #845

ivaquero opened this issue May 15, 2020 · 4 comments

Comments

@ivaquero
Copy link

What's the problem this feature will solve?

For models like langton ant and other more complex model, a function of move can simplify much of work.

Describe the solution you'd like

The following is the codes I suppose to have:

from mesa import Agent
import numpy as np

class ModelAgent(Agent):
     def __init___(self):
         self.pos = [0,0]
          
     def move(self, forward, angle):
         # suppose the agent is facing north
        self.new_pos = [self.pos[0]+np.sin(angle)*forward, self.pos[1]+np.cos(angle)*forward]

Additional context

@bastiaanzwanenburg
Copy link

Would this be substantially simpler than the built-in move_agent function in the model? To me, it seems that what you desire can be done quite elegantly already using, for example, the code below. However, please correct me if I don't fully understand your problem.

from mesa import Agent
import numpy as np

class ModelAgent(Agent):
     def __init___(self):
         self.pos = [0,0]
          
     def move(self, forward, angle):
         # suppose the agent is facing north
        self.new_pos = [self.pos[0]+np.sin(angle)*forward, self.pos[1]+np.cos(angle)*forward]
        self.model.grid.move_agent(self, next_point)

@ivaquero
Copy link
Author

Thank you for your advice. I realized I hadn't correctly described what was bothering me.
As a NetLogo user, I'm used to turtles (agents) with directional signs (like arrows), as well as its turn and forward command. So what I exactly desire is something can help to show an agent's move intuitively and visually (both direction and displacement). It is not that important for coding, but it helps a lot in presentations (such as when teaching). Maybe I should have opened this issue as a demand for enhancements in visualization module.
Again, thanks for your time.

@bastiaanzwanenburg
Copy link

Now I better understand your question, that is indeed a feature that I would appreciate as well. It would be especially useful for those who are new to ABM!

@ivaquero
Copy link
Author

Nice to hear from you. I checked the Agents.jl of Julia and it has a good implementation (Here is an Example). However, I prefer Python's versatility and I believe Mesa can make it too, though it may need much work to implement a more flexible version of turtle in the visualization module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants