Ejemplo n.º 1
0
    def add_aggregated(self, new_star, hylaa_settings):
        'add a state to the aggregated map'

        assert isinstance(new_star, Star)
        assert new_star.basis_matrix is not None

        mode_name = new_star.mode.name

        existing_state = self.aggregated_mode_to_state.get(mode_name)

        if existing_state is None:
            self.aggregated_mode_to_state[mode_name] = new_star
        else:
            # combine the two stars
            cur_star = existing_state

            cur_star.total_steps = min(cur_star.total_steps,
                                       new_star.total_steps)

            # if the parent of this star is not an aggregation, we need to create one
            # otherwise, we need to add it to the list of parents

            if isinstance(cur_star.parent, AggregationParent):
                # parent is already an aggregation. add it to the list of parents and eat it
                cur_star.parent.stars.append(new_star)
                cur_star.eat_star(new_star)
            else:
                # create the aggregation parent
                hull_star = make_aggregated_star([cur_star, new_star],
                                                 hylaa_settings)

                self.aggregated_mode_to_state[mode_name] = hull_star
Ejemplo n.º 2
0
    def deaggregate_star(self, star, steps_in_cur_star):
        'split an aggregated star in half, and place each half into the waiting list'

        Timers.tic('deaggregate star')

        assert isinstance(star.parent, AggregationParent)

        elapsed_aggregated_steps = steps_in_cur_star - star.total_steps - 1

        if elapsed_aggregated_steps < 0:  # happens on urgent transitions
            elapsed_aggregated_steps = 0

        mode = star.parent.mode
        all_stars = star.parent.stars

        # fast forward stars
        for s in all_stars:
            s.total_steps += elapsed_aggregated_steps
            s.fast_forward_steps += elapsed_aggregated_steps

        mid = len(all_stars) / 2
        left_stars = all_stars[:mid]
        right_stars = all_stars[mid:]

        for stars in [left_stars, right_stars]:
            discrete_post_star = stars[0]
            assert isinstance(discrete_post_star.parent, DiscretePostParent)
            discrete_pre_star = discrete_post_star.parent.prestar
            assert isinstance(discrete_pre_star.parent, ContinuousPostParent)

            if len(stars) == 1:
                # this might be parent of parent
                cur_star = discrete_post_star
            else:
                cur_star = make_aggregated_star(stars, self.settings)

            cur_star.mode = mode
            self.waiting_list.add_deaggregated(cur_star)

        Timers.toc('deaggregate star')