示例#1
0
    def test_method_init_with_wrong_parameters(self):
        parameters = [DiscreteParameter('y', range(10)), 'wrong_parameter']
        functionals = Functionals(
            [Functional('F', 'min'),
             Functional('G', 'max')])

        with self.assertRaises(TypeError):
            OptimizationMethod(parameters, functionals)
示例#2
0
    def test_functionals(self):
        self.assertEqual(len(Functionals(Functional('F', 'min')).functionals),
                         1)
        self.assertEqual(
            len(
                Functionals([Functional('F', 'min'),
                             Functional('G', 'max')]).functionals), 2)

        with self.assertRaises(TypeError):
            Functionals([Functional('F', 'min'), 'G'])
示例#3
0
    def test_evaluate_two_functional(self):
        model = binh_korn_function.BinhKornFunction()
        model.parameters['x'] = 2.5
        model.parameters['y'] = 1.5
        model.solve()
        model.process()

        functionals = Functionals(
            [Functional('F1', 'min'),
             Functional('F2', 'min')])
        self.assertEqual(functionals.evaluate(model), [34.0, 18.5])
示例#4
0
    def test_method_init(self):
        parameters = [
            ContinuousParameter('x', 0, 1),
            DiscreteParameter('y', range(10))
        ]
        functionals = Functionals(
            [Functional('F', 'min'),
             Functional('G', 'max')])

        method = OptimizationMethod(parameters, functionals, ModelBase)
        self.assertEqual(method.parameters, parameters)
        self.assertEqual(method.functionals, functionals)
示例#5
0
    def test_evaluate_one_functional(self):
        model = booths_function.BoothsFunction()
        model.parameters['x'] = 1
        model.parameters['y'] = 3
        model.solve()
        model.process()

        self.assertEqual(
            Functionals(Functional('F', 'min')).evaluate(model), 0)
示例#6
0
    def test_multicriteria(self):
        functionals = Functionals(Functional('F', 'min'))
        self.assertFalse(functionals.multicriteria())

        functionals = Functionals(
            [Functional('F', 'min'),
             Functional('G', 'max')])
        self.assertTrue(functionals.multicriteria())

        functionals = Functionals([
            Functional('F', 'min'),
            Functional('G', 'max'),
            Functional('H', 'max'),
            Functional('I', 'max')
        ])
        self.assertTrue(functionals.multicriteria())
示例#7
0
 def setUp(self):
     self.F = Functional('F', 'min')
示例#8
0
from variant.optimization import ContinuousParameter, Functionals, Functional
from variant.genetic import GeneticOptimization
import pythonlab

parameters = [ContinuousParameter('left', 0, 0.02),
                ContinuousParameter('right', 0.03, 0.05),
                ContinuousParameter('bottom', 0, 0.02),
                ContinuousParameter('top', 0.03, 0.05),
                ContinuousParameter('eps', 5, 10)]

functionals = Functionals([Functional("C", "max")])

optimization = GeneticOptimization(parameters, functionals)
optimization.directory = pythonlab.datadir('/data/sweep/simple_capacitor/solutions/')
optimization.modelSetManager.solver = pythonlab.datadir('agros2d_solver')
optimization.populationSize = 25
optimization.run(10, False)