public void GlobalSetup() { // prepare some functions AllSections sections = new AllSections() { DimensionSection = new DimensionSection(), ParametersSection = new ParametersSection() { Content = "" }, CostFunctionSection = new CostFunctionSection(), ConstraintsSection = new ConstraintsSection() }; TaskParser parser = new TaskParser(); sections.DimensionSection.Dim = 1; sections.CostFunctionSection.Function = "pow2(x[0]) + 10"; funcRank1Simple = parser.compileCostFunction(sections).Function; sections.DimensionSection.Dim = 4; sections.CostFunctionSection.Function = "x[0] + x[1] + x[2] + x[3]"; funcRank4Simple = parser.compileCostFunction(sections).Function; sections.DimensionSection.Dim = 1; sections.CostFunctionSection.Function = "sin(x[0]) * exp(x[0]) + ln(x[0]) * x[0]"; funcRank1Complex = parser.compileCostFunction(sections).Function; sections.DimensionSection.Dim = 4; sections.CostFunctionSection.Function = "sin(x[0]) * exp(x[1]) + ln(x[2]) * x[3]"; funcRank4Complex = parser.compileCostFunction(sections).Function; Random r = new Random(); x0 = r.NextDouble(); x1 = r.NextDouble(); x2 = r.NextDouble(); x3 = r.NextDouble(); point = new DenseVector(new double[] { x0, x1, x2, x3 }); }
public void CompileCostFunction_simple() { testSections.CostFunctionSection.Function = "x[0] + 2.0 * x[1]"; var func = parser.compileCostFunction(testSections).Function; Assert.AreEqual(0.0, func(makePoint(0.0, 0.0))); Assert.AreEqual(1.0, func(makePoint(1.0, 0.0))); Assert.AreEqual(-2.0, func(makePoint(0.0, -1.0))); Assert.AreEqual(8.0, func(makePoint(2.0, 3.0))); testSections.CostFunctionSection.Function = "x[0] * x[0] + 3.0"; func = parser.compileCostFunction(testSections).Function; Assert.AreEqual(3.0, func(makePoint(0.0))); Assert.AreEqual(3.0, func(makePoint(0.0))); Assert.AreEqual(7.0, func(makePoint(2.0))); }