示例#1
0
    def step(self) -> None:
        """Process the next event after enough real-time has passed for the
        event to happen.

        The delay is scaled according to the real-time :attr:`factor`. With
        :attr:`strict` mode enabled, a :exc:`RuntimeError` will be raised, if
        the event is processed too slowly.

        """
        evt_time = self.peek()

        if evt_time is Infinity:
            raise EmptySchedule()

        real_time = self.real_start + (evt_time - self.env_start) * self.factor

        if self.strict and monotonic() - real_time > self.factor:
            # Events scheduled for time *t* may take just up to *t+1*
            # for their computation, before an error is raised.
            delta = monotonic() - real_time
            raise RuntimeError(
                f'Simulation too slow for real time ({delta:.3f}s).')

        # Sleep in a loop to fix inaccuracies of windows (see
        # http://stackoverflow.com/a/15967564 for details) and to ignore
        # interrupts.
        while True:
            delta = real_time - monotonic()
            if delta <= 0:
                break
            sleep(delta)

        Environment.step(self)
示例#2
0
    def step(self):
        """Waits until enough real-time has passed for the next event to
        happen.

        The delay is scaled according to the real-time :attr:`factor`. If the
        events of a time step are processed too slowly for the given
        :attr:`factor` and if :attr:`strict` is enabled, a :exc:`RuntimeError`
        is raised.

        """
        evt_time = self.peek()

        if evt_time is Infinity:
            raise EmptySchedule()

        sim_delta = evt_time - self.env_start
        real_delta = time() - self.real_start
        delay = sim_delta * self.factor - real_delta

        if delay > 0:
            sleep(delay)
        elif self.strict and -delay > self.factor:
            # Events scheduled for time *t* may take just up to *t+1*
            # for their computation, before an error is raised.
            raise RuntimeError('Simulation too slow for real time (%.3fs).' %
                               -delay)

        return Environment.step(self)
示例#3
0
    def step(self):
        """Waits until enough real-time has passed for the next event to
        happen.

        The delay is scaled according to the real-time :attr:`factor`. If the
        events of a time step are processed too slowly for the given
        :attr:`factor` and if :attr:`strict` is enabled, a :exc:`RuntimeError`
        is raised.

        """
        evt_time = self.peek()

        if evt_time is Infinity:
            raise EmptySchedule()

        sim_delta = evt_time - self.env_start
        real_delta = time() - self.real_start
        delay = sim_delta * self.factor - real_delta

        if delay > 0:
            sleep(delay)
        elif self.strict and -delay > self.factor:
            # Events scheduled for time *t* may take just up to *t+1*
            # for their computation, before an error is raised.
            raise RuntimeError(
                'Simulation too slow for real time (%.3fs).' % -delay)

        return Environment.step(self)
示例#4
0
    def step(self):
        """Process the next event after enough real-time has passed for the
        event to happen.

        The delay is scaled according to the real-time :attr:`factor`. With
        :attr:`strict` mode enabled, a :exc:`RuntimeError` will be raised, if
        the event is processed too slowly.

        """
        evt_time = self.peek()

        if evt_time is Infinity:
            raise EmptySchedule()

        real_time = self.real_start + (evt_time - self.env_start) * self.factor

        if self.strict and time() - real_time > self.factor:
            # Events scheduled for time *t* may take just up to *t+1*
            # for their computation, before an error is raised.
            raise RuntimeError('Simulation too slow for real time (%.3fs).' % (
                time() - real_time))

        # Sleep in a loop to fix inaccuracies of windows (see
        # http://stackoverflow.com/a/15967564 for details) and to ignore
        # interrupts.
        while True:
            delta = real_time - time()
            if delta <= 0:
                break
            sleep(delta)

        return Environment.step(self)
示例#5
0
                    ignore_start_islands=set(g[START_ISLAND].keys()) - entry_locations,
                    tick_size=TICK_SIZE,
                    move_propensity=2,
                    consumption_rate=2
                ) for i, (origin, entry_locations) in enumerate(entries)]
            i = 0
            t = env.now
            if pop_cls == VaryingPopulation:
                cond = lambda s, e: s.num_in_aus < MAX_FINISHERS and e.now < years
            else:
                cond = lambda s, e: s.num_in_aus < MAX_FINISHERS and s.finished < len(pops) and e.now < years

            while cond(stats, env):
                if env.now != t:
                    stats.update_populations(min(env.now, years - 1))
                    env.rainfall = max(1, np.random.normal(RAINFALL, RAINFALL_SD))
                    t = env.now
                    COUNTER += 1
                    done = (COUNTER / float(TOTAL)) * 100.0
                    # logger.info("%02.4f%% Entry: %s Sim Run: %04d Year: %04d Populations: %04d Total Pop: %04d",
                    #             done, sim_name, sim_number, env.now, stats.num_populations(), stats.total_population())
                try:
                    env.step()
                except EmptySchedule:
                    break
                i += 1
            logger.warning('stats.finished: %s, env.now %s', stats.finished, env.now)
            stats.finish(run_number=sim_number)
            nx.write_gpickle(g, join(save_path, 'traversal_path.gpickle'))
    logger.info("TOTAL TIME TAKEN %0.1f", time.time() - start_overall)