public void TestConstrainedFeasibleRegion() { // Test that the parameter set does not deal with its constraints, // because the URS should, to try to preserve uniformity of sampling with varying bounds. var p = new TwoParamsConstraints(); Assert.IsTrue(p.IsWithinBounds); var names = p.GetVariableNames(); Assert.AreEqual(5, p.GetValue(names[1])); Assert.AreEqual(5, p.GetMaxValue(names[1])); p.SetValue(names[1], 10); Assert.IsFalse(p.IsWithinBounds); Assert.AreEqual(10, p.GetValue(names[1])); var rng = new BasicRngFactory(0); var urs = new UniformRandomSamplingFactory <TwoParamsConstraints>(rng.CreateFactory(), new TwoParamsConstraints()); int n = 200; var pop = new TwoParamsConstraints[n]; for (int i = 0; i < n; i++) { pop[i] = urs.CreateRandomCandidate(); Assert.IsTrue(pop[i].IsWithinBounds); } var hcOps = urs.CreateNew(rng.CreateFactory()); var hcArray = Array.ConvertAll(pop, x => (IHyperCube <double>)x); for (int i = 0; i < n; i++) { p = (TwoParamsConstraints)hcOps.GenerateRandomWithinHypercube(hcArray); Assert.IsTrue(p.IsWithinBounds); } }
private static ShuffledComplexEvolution <TestHyperCube> createSce(ShuffledComplexEvolution <TestHyperCube> .CoefficientOfVariationTerminationCondition termination, BasicRngFactory rng, ObjEvalTestHyperCube evaluator, int maxShuffle = 15) { var engine = new ShuffledComplexEvolution <TestHyperCube>( evaluator, new UniformRandomSamplingFactory <TestHyperCube>(rng.CreateFactory(), new TestHyperCube(2, 0, -10, 10)), termination, 5, 20, 10, 3, 20, maxShuffle, rng, new DefaultFitnessAssignment()); return(engine); }
private static ShuffledComplexEvolution <ICloneableSystemConfiguration> createSce(IClonableObjectiveEvaluator <ICloneableSystemConfiguration> evaluator) { var rng = new BasicRngFactory(0); var engine = new ShuffledComplexEvolution <ICloneableSystemConfiguration>( evaluator, new UniformRandomSamplingFactory <IHyperCube <double> >(rng.CreateFactory(), new UnivariateReal(0)), new ShuffledComplexEvolution <ICloneableSystemConfiguration> .MaxShuffleTerminationCondition(), 5, 20, 10, 3, 20, 7, rng, new ZitlerThieleFitnessAssignment()); return(engine); }