Ejemplo n.º 1
0
    def run(self, export="log", verbose=False):
        """Execute runner.

        Arguments:
                export (str): Takes export type (e.g. log, json, xlsx, latex) (default: "log")
                verbose (bool): Switch for verbose logging (default: {False})

        Raises:
                TypeError: Raises TypeError if export type is not supported

        Returns:
                dict: Returns dictionary of results

        See Also:
                * :func:`NiaPy.Runner.useAlgorithms`
                * :func:`NiaPy.Runner.useBenchmarks`
                * :func:`NiaPy.Runner.__algorithmFactory`

        """

        for alg in self.useAlgorithms:
            if not isinstance(alg, "".__class__):
                alg_name = str(type(alg).__name__)
            else:
                alg_name = alg

            self.results[alg_name] = {}

            if verbose:
                logger.info("Running %s...", alg_name)

            for bench in self.useBenchmarks:
                if not isinstance(bench, "".__class__):
                    bench_name = str(type(bench).__name__)
                else:
                    bench_name = bench

                if verbose:
                    logger.info("Running %s algorithm on %s benchmark...",
                                alg_name, bench_name)

                self.results[alg_name][bench_name] = []
                for _ in range(self.nRuns):
                    algorithm = AlgorithmUtility().get_algorithm(alg)
                    benchmark_stopping_task = self.benchmark_factory(bench)
                    self.results[alg_name][bench_name].append(
                        algorithm.run(benchmark_stopping_task))
            if verbose:
                logger.info(
                    "---------------------------------------------------")
        if export == "log":
            self.__export_to_log()
        elif export == "json":
            self.__export_to_json()
        elif export == "xlsx":
            self.__export_to_xlsx()
        elif export == "latex":
            self.__export_to_latex()
        else:
            raise TypeError("Passed export type is not supported!")
Ejemplo n.º 2
0
class AlgorithmUtilityTestCase(TestCase):
	def setUp(self):
		self.algorithm_utility = AlgorithmUtility()

	def test_get_bad_algorithm_fine(self):
		self.assertRaises(TypeError, lambda: self.algorithm_utility.get_algorithm('hihihihihihihihihi'))
		self.assertRaises(TypeError, lambda: self.algorithm_utility.get_algorithm(MyFakeAlgorithm()))

	def test_get_algorithm_fine(self):
		algorithm = MyCustomAlgorithm()
		gwo = GreyWolfOptimizer()
		self.assertEqual(algorithm, self.algorithm_utility.get_algorithm(algorithm))
		self.assertEqual(gwo, self.algorithm_utility.get_algorithm(gwo))
		self.assertTrue(isinstance(self.algorithm_utility.get_algorithm("GreyWolfOptimizer"), GreyWolfOptimizer))
Ejemplo n.º 3
0
	def setUp(self):
		self.algorithm_utility = AlgorithmUtility()