Beispiel #1
0
    def test_external_solver(self):
        model = quadratic_function.QuadraticFunction()
        model.parameters['a'] = 2
        model.parameters['x'] = 2

        self.md.add_model(model)
        self.md.save()

        self.md.solve()
        self.assertEqual(2 * 2**2, self.md.models[-1].variables['F'])
Beispiel #2
0
    def test_defaults(self):
        model = ModelBase()
        model.defaults['b'] = 0
        self.assertEqual(0, model.parameters['b'])

        model = quadratic_function.QuadraticFunction()
        model.parameters['x'] = 4
        model.create()
        model.solve()
        model.process()
        self.assertEqual(4**2, model.variables['F'])
Beispiel #3
0
    def test_solve(self):
        variants = [(1, 2), (2, 3), (3, 4)]
        for a, x in variants:
            model = quadratic_function.QuadraticFunction()
            model.parameters['a'] = a
            model.parameters['x'] = x
            self.md.add_model(model)

        self.md.solve()
        for a, x in variants:
            model = self.md.find_model_by_parameters({'a': a, 'x': x})
            self.assertEqual(a * x**2, model.variables['F'])
Beispiel #4
0
    def test_solve_models_by_mask(self):
        for a, x in [(1, 2), (2, 3), (3, 4)]:
            model = quadratic_function.QuadraticFunction()
            model.parameters['a'] = a
            model.parameters['x'] = x
            self.md.add_model(model)

        self.md.solve(mask='model_00000[0, 2]')
        self.assertEqual(len(self.md.models), 3)
        self.assertEqual(len(self.md.solved_models), 2)

        for a, x in [(1, 2), (3, 4)]:
            model = self.md.find_model_by_parameters({'a': a, 'x': x})
            self.assertEqual(a * x**2, model.variables['F'])
Beispiel #5
0
    def test_save_and_load(self):
        file_name = '{0}/model.pickle'.format('{0}'.format(
            pythonlab.tempname()))

        model = quadratic_function.QuadraticFunction()
        model.parameters['x'] = 7
        model.create()
        model.solve()
        model.process()
        model.save(file_name)

        model.clear()
        model.load(file_name)
        self.assertEqual(7**2, model.variables['F'])
Beispiel #6
0
    def setUp(self):
        md = ModelDict()
        variants = [1e-3, 1e-2, 1e2, 1e-4, 1e-1, 
                    1e-5, 1e-8, 1e3, 1e6, 1e-8]

        for x in variants:
            model = quadratic_function.QuadraticFunction()
            model.parameters['x'] = x
            GeneticInfo.set_population_from(model, 0)
            GeneticInfo.set_population_to(model, 0)
            md.add_model(model)

        md.solve(save=False)

        self.functionals = Functionals(Functional('F', 'min'))
        self.selector = SingleCriteriaSelector(self.functionals)
        self.selector.recomended_population_size = len(variants)
        self.population = md.models