Exemplo n.º 1
0
    def on_begin(self):
        log.info("Randomizing...")
        self.random = numpy.random.RandomState()
        self.random.seed(self.parameters.seed)

        log.info("Clearing Landscape...")
        self.landscape = self.parameters.landscape
        self.landscape.clear()

        # Make the agents
        log.info("Constructing Agents...")
        self.next_serial = 0
        self.agents = []
        self.default_placement = placement.random_placement()
        self.default_placement.sim = self
        self.placements = set([self.default_placement])

        for cls, num, pc in self.parameters.agents_to_create:
            new_agents = [cls(self) for i in range(num)]
            if pc is None:
                pc = self.default_placement
            elif pc not in self.placements:
                pc.sim = self
                self.placements.add(pc)

            # Add to simulation and to the placement algorithm
            self.agents.extend(new_agents)
            pc.agents.extend(new_agents)

        for p in self.placements:
            p.place()
Exemplo n.º 2
0
 def __init__(self, seed, treatment_name, replicate_seq, parameters):
     pytreatments.Simulation.__init__(
         self, seed, treatment_name, replicate_seq)
     self.parameters = parameters
     log.info("Randomizing...")
     self.random = numpy.random.RandomState()
     self.random.seed(self.parameters.seed)
     self.landscape = self.parameters.landscape
     self.patch_controller = patch_control.PatchController(
         patches=self.landscape.patches,
         depth=self.parameters.neighbourhood_size,
         random_state=self.random
     )
     self.agents = []
     self.next_serial = 0
     self.default_placement = placement.random_placement()
     self.default_placement.sim = self
     self.placements = {self.default_placement}