-
Notifications
You must be signed in to change notification settings - Fork 865
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
Make cell connections public and named #2296
Conversation
Performance benchmarks:
|
Performance benchmarks:
|
I like this PR. I am just wondering whether using a string as key in connections is the way to go (and in voronoi it is not done correctly as far as I can tell). Any idea about the performance benchmarks? Slower inits make sense because the data structure is a bit more involved to built up. I fail to see why runs are slower? |
The initial idea was to make the connection names completely arbitrary, so users could call them for example "up", "north", "top", etc., whatever seems most appropriate in the specific context. But probably it makes sense to have that abstraction somewhere else. Relative directions seem to make the most sense. That's unambiguous for grids, for network it kind of makes sense (the direction of node xy) and for voronoi I have to think about it. So I am probably going to change it to type tuple |
Interesting PR, coordinates seem more scalable then names. Probably related: Something like a |
I guess Voronoi is a network with some interesting properties (e.g., you can lay it out in 2d without any crossing edges). |
5ceb0b9
to
64bb4f7
Compare
for more information, see https://pre-commit.ci
rebased and ready to be reviewed again |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few really minor things that if addressed would be nice. Good stuff.
self.random = random | ||
|
||
def connect(self, other: Cell) -> None: | ||
def connect(self, other: Cell, name: Coordinate | None = None) -> None: | ||
"""Connects this cell to another cell. | ||
|
||
Args: | ||
other (Cell): other cell to connect to | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please complete the docstring. Name is not defined as one of the arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, because I rebased the PR and not merged main into it, my precommit hooks did not fire locally, so I didn't catch this. Next time I am going to merge again.
Also note that this is indeed an error and happily catched by our CI :) pre-commit.ci
@@ -123,30 +132,34 @@ def __repr__(self): # noqa | |||
|
|||
# FIXME: Revisit caching strategy on methods | |||
@cache # noqa: B019 | |||
def neighborhood(self, radius=1, include_center=False): | |||
def neighborhood(self, radius: int = 1, include_center: bool = False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be possible to add a docstring.
Also, and not perse necessary for this PR, but the name of this method has been tripping me up. The name suggests that it is an attribute, so perhaps at some point we should change this to something like get_neighborhood
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, there is some revisiting to be done here. I think at one point the idea was that this basically is an attribute/property for the default case, which is just a CellCollection of the the connections. Maybe we could actually have something like
def get_neighborhood(self, radius: int = 1, include_center: bool = False):
...
@property
def neighborhood(self):
return self.get_neighborhood()
So for the "normal" neighborhood you could do cell.neighborhood
and for everything more complex cell.get_neighborhood(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this makes good sense. The most common case is indeed getting the direct neighborhood and it would be good if that is just a property. Naming-wise, what about direct_neighborhood
and get_neighborhood
? It would be nice if the names were a bit more distinctive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes more distinctive names sounds good. I'll have to think about direct_neighborhood
cause I think its a bit verbose. But lets leave that and adding a docstring to a different PR
…nections' of https://github.com/projectmesa/mesa into cellspace-named-connections
This PR changes the formerly private attribute
_connections
from theCell
class to be public and to be no longer a list, but a dictionary that includes a name for each connections. For Grids this defaults to the relative direction ((0, 1)
,(-1, -1)
, etc.). For Network this is the node name of the "other" cell.This allows more powerful and direct agent movements, because you no longer need to query the connection to see where it leads or be dependent on the order in which directions were created. +
This PR also includes some type improvements