public void GetSolutionReport_UsingEmptyConstructor() { var dhs = new DownHillSimplex(); dhs.InitialGuess = new[] {1d, 7d}; IVertex initialVertex = new Vertex(dhs.InitialGuess); dhs.InitialSimplex = new Simplex(initialVertex); dhs.CurrentSimplex = dhs.InitialSimplex; dhs.ObjectiveFunction = vertex => ObjectiveMeasure.SumOfSquares(vertex); if (!dhs.IsValid()) { throw new Exception("Did not pass the IsValid method"); } var solution = dhs.GetSolution(); var isSolved = solution.ObjectiveMeasure.IsEqualTo(0d); Assert.IsTrue(isSolved); }
public void GetSolutionReport_UsingInitialParamsConstructor() { Func<IVertex, double> objFunction = vert => { var x = vert.Parameters[0]; var y = vert.Parameters[1]; return (x*x + y - 11)*(x*x + y - 11) + (x + y*y - 7)*(x + y*y - 7); }; var initialGuess = new[] { 1.0, 1.0 }; var dhs = new DownHillSimplex(initialGuess); dhs.ObjectiveFunction = objFunction; if (!dhs.IsValid()) { throw new Exception("Did not pass the IsValid method"); } var solution = dhs.GetSolution(); Assert.AreEqual(1.6368619236455376E-24, solution.ObjectiveMeasure); }