-
Notifications
You must be signed in to change notification settings - Fork 906
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
Voronoi Tessellation based Discrete Space #2084
Conversation
Thanks, it's a great start! Using DelaunayTri is a smart approach. I guess Another thing that it's needed in the long term is a method to check in which cell a point (and thus an agent) is. @wang-boyu I would also appreciate a review from your mesa-geo expertise. For the currently functionality, I would like some additional docstring and unittests. Then you can decide if you want to add further functionality to this PR, or merge this first and follow up with new PRs. Edit: One thought, also for the other maintainers: Would we need separate Discrete and Continuous Voronoi spaces? |
class VoronoiGrid(DiscreteSpace): | ||
def __init__( | ||
self, | ||
centroids_coordinates: Sequence[Sequence[float]], |
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 this work with Shapely Points? That might be very useful for Mesa geo applications (cc @wang-boyu).
Just add with adding a simple test case for this, maybe it will just work.
Thanks for the PR. I have to say that I'm still a bit confused about why this is based on discrete space, not continuous space (as I mentioned in #1895 (comment) and #1895 (comment)). As a concrete example, consider this simple space:
If it is a Voronoi space, should Cell 2 be split into halves, where left half belongs to agent of type O and right half belongs to agent of type X? How does this work in discrete space? |
Apologies, a little late to this discussion, this is really cool @vitorfrois. As dependencies and keeping Mesa lightweight is a constant struggle, but form a very superficial look is there a reason we wont use networkx (https://networkx.org/documentation/stable/reference/algorithms/voronoi.html) and this has a corresponding example that may work for mesa_geo (https://networkx.org/documentation/stable/auto_examples/geospatial/plot_delaunay.html)? Let me know what you think/ what I am missing? |
I'm considering the discrete space for Voronoi Tesselation as a static/non changing graph, where neighbors are obtained by Delaunay Triangulation. As @EwoutH said, it is only a special case for HexGrid where cell are not equally spaced. I think its more about a choice of implementation where I considered mainly the Cholera example. As I suggested yesterday,
Does that make sense? |
@tpike3 thanks for the comment. That's more or less what I'm thinking. In Mesa Geo, we have opportunity to do it better with Shapely |
Thanks for clarifying. Appreciate it. Question: Is the Delaunay Triangulation done in continuous space? |
Yes, it is |
While it might be desired in a specific model to have the same agent be placed in multiple spots simultaneously, the typical use case is that one agent has one position at every given moment. This commit decorates the place_agent() method in a way that it emits a warning when called with an agent which already has a location. Fixes: projectmesa#1522
uv is a fast drop-in pip, pip-compile, virtualenv etc replacement created by the creator of Ruff.
* Update Ruff to 0.3.4; apply ruff format . * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…ojectmesa#2087) This fixes - some minor grammatical errors, - an incorrect header indentation level,
updates: - [github.com/astral-sh/ruff-pre-commit: v0.3.4 → v0.3.5](astral-sh/ruff-pre-commit@v0.3.4...v0.3.5) - [github.com/asottile/pyupgrade: v3.15.0 → v3.15.2](asottile/pyupgrade@v3.15.0...v3.15.2)
* Jupyter Viz: Don't avoid interactive backend We were avoiding the interactive backend, but that isn't recommended anymore and Solara should take care of that itself. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sets the version to 3.0.0a0 for the first Mesa 3.0 pre-release, and updates the release notes with 2.3.1 and 3.0.0a0 changelog
Don't track virtual environment files in Git
for more information, see https://pre-commit.ci
Updates
|
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.
This is really outstanding, Vítor. That space visualization especially, it really offers a lot of value.
Small minor comments. I would also like to see more test coverage, if you have the chance.
I’m going to approve conceptually, especially considering the cell space is still experimental. @rht are you able to do a technical code review and merge if it looks good?
CC @quaquel, you might also find this interesting (and have some comments).
Omg, sorry I did not notice the license. I copied like 70% of it's
implementation, changing variables, function names and other minor things.
…On Sun, Jul 21, 2024, 08:44 rht ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In mesa/experimental/cell_space/voronoi.py
<#2084 (comment)>:
> @@ -0,0 +1,264 @@
+from collections.abc import Sequence
+from itertools import combinations
+from random import Random
+
+import numpy as np
+
+from mesa.experimental.cell_space.cell import Cell
+from mesa.experimental.cell_space.discrete_space import DiscreteSpace
+
+
+class Delaunay:
+ """
+ Class to compute a Delaunay triangulation in 2D
+ ref: http://github.com/jmespadero/pyDelaunay2D
How much percentage of the code is based on this GitHub repo? Their
license is GPLv3, and we actually can't copy their code because there will
be a licensing issue.
—
Reply to this email directly, view it on GitHub
<#2084 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALBWUBC63DYQCEJC5TPSGOLZNONJHAVCNFSM6AAAAABFAPRYMCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDCOJQGMYDSMZXGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
There are 2 ways to proceed:
I'm more in favor of option 2, because option 1 is rather shady. |
Yeah the license issue is a big one. Another (far fetched) option is to contact the maintainer to see if he’s willing to publish on another, more permissive license. |
@vitorfrois I would like to try to contact the maintainers. Do you want to write them a message or would you like me to do it? |
I can do it tomorrow, then hopefully we can move this forward next week! I would like to include it in the next 3.0 alpha release. |
I reached out Tuesday, hopefully we will get an answer soon: jmespadero/pyDelaunay2D#7 |
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.
You know what, I think this is fine. It's just math in a specific order.
Also, this is in the experimental space. We can break or remove anything from here, and iterate fast on it.
Let's get this moving. If you remove the dependency we're good to go, and I will merge.
Edit: There are a few minor open comments. Would be nice to have those resolved.
Merged! Congratulations @vitorfrois your first PR is in Mesa - and it's a remarkable one. Thanks for your effort and patience. It will be included in the Mesa |
First version of Voronoi Tesselation based Discrete Space,
described on issue #1895 . This feature allows the user to build a discrete space based on a random sample of points, where neighbors are defined by Delaunay Triangulation.
More specifically, Delaunay Triangulation is a dual-graph representation of the Voronoi Tesselation. Using this algorithm, we can easily find nearest neighbors without delimiting cells edges.
The library chosen for the triangulation algorithm implementation was PyHull, a wrapper of qhull C library, which deals with spatial calculations. The choice was made considering performance, size and usability (SciPy has a similar module but much heavier).
Based on my discussion with @EwoutH on the issue thread, i thought it would be useful to inherit DiscreteSpace class.
Example
Users can input cells centroids
and cells neighborhoods are defined by Delaunay triangulation
Next Steps
Definitely, next steps involve computing the boundaries of each cell using Voronoi Tesselation. This allow us to define capacity of each cell based on its area/volume.