Ejemplo n.º 1
0
    def update(self):
        """Update the Population: update the topology stochastically

        During each update, a number of nodes in the topology are selected at
        random, and the update method of the Cells in the selected nodes is
        called.  By default, the number of nodes selected is equal to the
        number of nodes in the topology (so each node's Cell will be updated,
        on average, each epoch.  This number can be changed by setting the
        events_per_epoch parameter in the Experiment section of the
        configuration.
        
        """

        # Reset the transitions count.  Long-term transitions data can be
        # obtained by using the PrintCellTypeTransitions action
        num_types = self._cell_class.max_types
        self.experiment.data['population']['transitions'] = [
            [0] * num_types for i in range(num_types)
        ]

        # Select a set of cells to update and update them
        events = self.experiment.config.getint(section=self.config_section,
                                               name='events_per_epoch',
                                               default=len(
                                                   self.topology.graph))
        nodes_to_update = sample_with_replacement(self.topology.graph.nodes(),
                                                  k=events)
        [self.topology.graph.node[n]['cell'].update() for n in nodes_to_update]
Ejemplo n.º 2
0
    def update(self):
        """Update the Resource

        During each update, a number of nodes in the topology are selected at
        random, and the update method of the ResourceCell in the selected nodes
        is called.  By default, the number of nodes selected is equal to the
        number of nodes in the topology (so each node's ResourceCell will be
        updated, on average, each epoch.  This number can be changed by setting
        the events_per_epoch parameter in the Experiment section of the
        configuration.
                                                                        
        """

        events = self.experiment.config.getint(
            section=self.config_section, name="events_per_epoch", default=len(self.topology.graph)
        )
        nodes_to_update = sample_with_replacement(self.topology.graph.nodes(), k=events)
        [self.topology.graph.node[n]["resource"].update() for n in nodes_to_update]
Ejemplo n.º 3
0
    def update(self):
        """Update the Population: update the topology stochastically

        During each update, a number of nodes in the topology are selected at
        random, and the update method of the Cells in the selected nodes is
        called.  By default, the number of nodes selected is equal to the
        number of nodes in the topology (so each node's Cell will be updated,
        on average, each epoch.  This number can be changed by setting the
        events_per_epoch parameter in the Experiment section of the
        configuration.
        
        """

        # Reset the transitions count.  Long-term transitions data can be
        # obtained by using the PrintCellTypeTransitions action
        num_types = self._cell_class.max_types
        self.experiment.data['population']['transitions'] = [[0]*num_types for i in range(num_types)]

        # Select a set of cells to update and update them
        events = self.experiment.config.getint(section=self.config_section,
                                               name='events_per_epoch',
                                               default=len(self.topology.graph))
        nodes_to_update = sample_with_replacement(self.topology.graph.nodes(), k=events)
        [self.topology.graph.node[n]['cell'].update() for n in nodes_to_update]