how to embed a schedule within another one?

15 views
Skip to first unread message

Yaniv Proselkov

unread,
Feb 4, 2021, 8:57:57 PM2/4/21
to ProjectMesa
Hi all,
I'm very new to mesa (<1 month). I'm trying to make a network system with an infection process and sensors at each node.

The infection happens randomly, while the sensors are always on. With that in mind, I wwant to randomly activate 1 infection step, and then simultaneously activate all sensors. 1 infection, all sensors, 1 infection, all sensors.

I've tried this:
        self.infection_schedule = RandomActivation(self)
        self.detection_schedule = BaseScheduler(self)
...
        def step(self):
            self.datacollector.collect(self)
            self.infection_schedule.step()
            for i in range(len(self.num_nodes)):
                self.detection_schedule.step()

but apparently self.schedule is a key term.

Can anyone think of how to manage this? please?

Jeremy Foote

unread,
Feb 5, 2021, 9:38:21 AM2/5/21
to Yaniv Proselkov, ProjectMesa
Hi,

If all that the sensors are doing is gathering information about the nodes, then the simplest is to just create data collectors instead of putting this logic on the nodes themselves. Data collecting really is basically a simultaneous sensing step.

The second simplest is to not use a scheduler at all.

You could just do something like define a data-gathering method in the node Class like get_data(), and then something like:

    nodes = []
    n = Node()
    self.schedule.add(n)
    nodes.append(n)
   ....
        def step(self):
            self.datacollector.collect(self)
            self.schedule.step()
            for node in nodes:
                node.get_data()


Finally, there is a way to have nodes do different things at different times - StagedActivation (https://mesa.readthedocs.io/en/stable/apis/time.html)

In order to do a random step followed by a simultaneous step, you'd need three stages defined for each node:
- an infection stage which would run the infection
- a staging stage which would calculate and store the results from the sensing method
- an activation stage which would move the results from the staging stage into the instance attribute where you want to store them

Good luck!,
Jeremy

--
Project repos: github.com/projectmesa
---
You received this message because you are subscribed to the Google Groups "ProjectMesa" group.
To unsubscribe from this group and stop receiving emails from it, send an email to projectmesa...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/projectmesa/745b8753-5000-4945-9873-d19134fba47bn%40googlegroups.com.

Yaniv Proselkov

unread,
Feb 5, 2021, 10:24:58 AM2/5/21
to ProjectMesa
Thank you so much! This is excellent.
Reply all
Reply to author
Forward
0 new messages