Esempio n. 1
0
    def test_run(
        self,
        state_factory: Callable[[], State],
        state_count: int,
        limit: int,
        count: int,
        iteration: int,
        accepted_final_states: int,
    ) -> None:
        """Test running the annealing."""
        beam = Beam()
        state = state_factory()
        for _ in range(state_count):
            cloned_state = state.clone()
            cloned_state.iteration = state.iteration + 1
            beam.add_state(cloned_state)

        predictor = AdaptiveSimulatedAnnealing()
        context = flexmock(
            accepted_final_states_count=accepted_final_states,
            count=count,
            iteration=iteration,
            limit=limit,
            beam=beam,
        )
        with predictor.assigned_context(context):
            next_state, package_tuple = predictor.run()
            assert next_state in beam.iter_states()
            assert package_tuple is not None
            assert package_tuple[0] in next_state.unresolved_dependencies
            assert package_tuple in next_state.unresolved_dependencies[
                package_tuple[0]].values()
Esempio n. 2
0
    def test_pre_run(self) -> None:
        """Test pre-run initialization."""
        context = flexmock(limit=100)

        predictor = AdaptiveSimulatedAnnealing()
        assert predictor._temperature == 0.0
        predictor._temperature_history = [(0.1, False, 0.2, 3),
                                          (0.42, True, 0.66, 47)]

        with predictor.assigned_context(context):
            predictor.pre_run()

            assert predictor._temperature == context.limit, "Predictor's limit not initialized correctly"
            assert predictor._temperature_history == [], "Predictor's temperature history no discarded"