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

Extend Wolf Sheep example to include PropertyLayer #2564

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

mgemaakbar
Copy link

@mgemaakbar mgemaakbar commented Dec 22, 2024

This pull request is in response to @tpike3 's reply on Matrix discussion: https://matrix.to/#/!CAAdpmuJhdNJkxurrp:matrix.org/$sSOIip3pT1L5C6wrpzhvoM64Y4wYcpSsUHZSZXKwfFE?via=matrix.org&via=gitter.im

At the time this PR is created (Dec 22) the changes are still not that well tested. I would like to hear what you think first about my idea to extend this Wolf Sheep example, before testing it more and possibly adding more changes to it.

My idea of extending the Wolf Sheep is pretty simple: use PropertyLayer to store information which cells that are cliff cells. If an animal (wolf or sheep) steps into a cliff cell, then the animal dies. The coordinate in the PropertyLayer is set true if the cell is a cliff, false if it is not.

Please let me know what you think :) Thank you in advance.

Copy link

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -2.3% [-3.4%, -1.1%] 🔵 -0.9% [-1.0%, -0.8%]
BoltzmannWealth large 🔵 -0.3% [-1.0%, +0.3%] 🔵 +0.7% [-0.2%, +1.7%]
Schelling small 🔵 -0.4% [-0.7%, -0.1%] 🔵 +0.3% [+0.1%, +0.5%]
Schelling large 🔵 -0.2% [-0.6%, +0.2%] 🔵 +1.0% [+0.5%, +1.3%]
WolfSheep small 🔵 +2.8% [+2.4%, +3.2%] 🟢 -54.7% [-55.3%, -54.3%]
WolfSheep large 🔴 +6.4% [+5.7%, +7.1%] 🟢 -61.8% [-62.2%, -61.5%]
BoidFlockers small 🔵 -2.0% [-2.6%, -1.3%] 🔵 +0.4% [-0.4%, +1.3%]
BoidFlockers large 🔵 -2.6% [-3.2%, -2.0%] 🔵 +0.2% [-0.3%, +0.6%]

@EwoutH
Copy link
Member

EwoutH commented Dec 22, 2024

Thanks for your PR!

I just merged #2503, which also modified this example. You rebase your branch and resolve any conflicts? If you need any help with that let me know!

@mgemaakbar
Copy link
Author

Thanks for your PR!

I just merged #2503, which also modified this example. You rebase your branch and resolve any conflicts? If you need any help with that let me know!

Yes I already did rebase and resolved the conflict.

@mgemaakbar mgemaakbar marked this pull request as ready for review December 23, 2024 13:26
Copy link

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 -3.6% [-4.7%, -2.5%] 🔵 +0.3% [+0.1%, +0.5%]
BoltzmannWealth large 🔵 -0.0% [-0.5%, +0.4%] 🔵 -2.9% [-4.2%, -1.8%]
Schelling small 🔵 -0.3% [-0.6%, +0.0%] 🔵 -0.1% [-0.2%, -0.0%]
Schelling large 🔵 +1.3% [+0.9%, +1.6%] 🔵 +0.8% [-0.7%, +2.0%]
WolfSheep small 🔴 +4.8% [+4.4%, +5.2%] 🟢 -65.5% [-66.8%, -64.4%]
WolfSheep large 🔴 +7.2% [+6.6%, +8.0%] 🟢 -76.4% [-76.8%, -76.0%]
BoidFlockers small 🔵 +1.2% [+0.6%, +1.9%] 🔵 +0.8% [+0.0%, +1.6%]
BoidFlockers large 🔵 -0.3% [-1.1%, +0.5%] 🔵 +0.8% [+0.2%, +1.3%]

@EwoutH
Copy link
Member

EwoutH commented Dec 23, 2024

Thanks! like the idea of barriers / cliffs, it's widely discussed at the moment:

I don't think the model dynamics will be nice if animals just walk like they currently do and suddenly die because a cell is marked as a cliff. Either, I would like the cliff to be inaccessible, so they don't even consider moving there, and choose another cells. This of course can mean they walk into a dead end (surrounded by cliffs), don't have any movement options anymore, and thus get eaten.

@mgemaakbar
Copy link
Author

mgemaakbar commented Dec 23, 2024

Thanks! like the idea of barriers / cliffs, it's widely discussed at the moment:

I don't think the model dynamics will be nice if animals just walk like they currently do and suddenly die because a cell is marked as a cliff. Either, I would like the cliff to be inaccessible, so they don't even consider moving there, and choose another cells. This of course can mean they walk into a dead end (surrounded by cliffs), don't have any movement options anymore, and thus get eaten.

Would you like me to implement that in this PR? It's actually the initial idea that came to my mind, but decided to make it 'stepping into a cliff = dies'.

Also there might be a case where an animal (wolf or sheep) is randomly generated in the middle of 4 neighboring cliff (hence not being able to move at all forever).

Or, if you have another idea (that might be completely different to this cliff cell idea) to demonstrate PropertyLayer in this Wolf Sheep example and you would like me to implement it, please feel free to tell me. This cliff idea is just an idea that I came up with.

@EwoutH
Copy link
Member

EwoutH commented Dec 23, 2024

Would you like me to implement that in this PR?

Yes

Also there might be a case where an animal (wolf or sheep) is randomly generated in the middle of 4 neighboring cliff (hence not being able to move at all forever).

Was also thinking about this. Ideally cliffs are not generated fully random, but I'm not sure on a simple and elegant solution yet.

@mgemaakbar
Copy link
Author

mgemaakbar commented Dec 25, 2024

Either, I would like the cliff to be inaccessible, so they don't even consider moving there, and choose another cells. This of course can mean they walk into a dead end (surrounded by cliffs), don't have any movement options anymore, and thus get eaten.

I already updated the PR with this, please let me know what you think. But I changed the name cliff -> wall, since I think it fits better.

I have a question about your PR. In this code, we exit move() if a sheep is surrounded by wolves (which in this case the sheep doesn't move at all) https://github.com/projectmesa/mesa/pull/2503/files#diff-a075828ed0ee3952964600d1f989ef36da3673f0a8e5a170ec124f6510581e8dR72

But in that case. the energy still gets decremented here -- even when the sheep doesn't move at all. Returning early in move() doesn't stop it from running self.energy -= 1 (and also the lines of code after that) in step(). Am I correct about this? https://github.com/projectmesa/mesa/pull/2503/files#diff-a075828ed0ee3952964600d1f989ef36da3673f0a8e5a170ec124f6510581e8dR42

My question: Is it a bug, or is it an intended behavior?

@EwoutH
Copy link
Member

EwoutH commented Dec 26, 2024

Okay, maybe take a step back here, before you invest too much in the current approach. Because:

  1. I'm not 100% sure if walls add value to this implementation
  2. If you purely want to demonstrate PropertyLayers, it might be more useful to add something like "soil fertility" (makes grass grow faster/slower) or elevation (takes more/less energy to move).
  3. If we add walls, I think they should be added more deliberately then just "random noise". Maybe like you place ships in Battleship, or procedurally (learn something from Factorio: FFF 219 and 401).

So, we have to take a step back, and determine your goal:

  • Do you want to demonstrate the PropertyLayer (in a simple and elegant way)?
  • Do you want to demonstrate how to make cells inaccessible for Agents (#2534)?

The approach we often take when things

  1. Get the problem sharply and neatly defined
  2. Propose a solution
  3. Discuss and agree on a conceptual approach for the solution
  4. Explore the implementation for the solution (API, data structures, whatever is needed)
  5. Implement it

The first 4 can best happen in a Discussion. If you have those first 4 very clearly defined, 5 becomes often trivial (or at least straightforward).

@mgemaakbar
Copy link
Author

mgemaakbar commented Dec 26, 2024

Do you want to demonstrate the PropertyLayer (in a simple and elegant way)?

Yes, I think my goal is this.

If you purely want to demonstrate PropertyLayers, it might be more useful to add something like "soil fertility" (makes grass grow faster/slower) or elevation (takes more/less energy to move).

This is a good idea, should I try this?

The first 4 can best happen in a Discussion. If you have those first 4 very clearly defined, 5 becomes often trivial (or at least straightforward).

Should I create a discussion about the "soil fertility" idea there?

Thank you for your feedback

@quaquel
Copy link
Member

quaquel commented Dec 26, 2024

Having a separate discussion on soil fertility sounds like a good idea. However, with sugarscape, we already have a simple property layer example. So, at a minimum, this example should add value and be different from what is show cased there.

@EwoutH
Copy link
Member

EwoutH commented Dec 26, 2024

Should I create a discussion about the "soil fertility" idea there?

Yes, let's do this.

However, with sugarscape, we already have a simple property layer example. So, at a minimum, this example should add value and be different from what is show cased there.

It could demonstrate how two PropertyLayers interact: The soil layer is static (stays the same during the run), and the grass layers is updated based on the soil layer.

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

Successfully merging this pull request may close these issues.

3 participants