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)
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'])
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])
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)
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)
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())
def setUp(self): self.F = Functional('F', 'min')
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)