public double[] LinearSystemSolver(string[] variables, string[] functions) { // creating nonlinear system instance - Analytical System NonlinearSystem system = new AnalyticalSystem(variables, functions); double[] x0; SolverOptions options; double[] result; SolutionResult actual; // creating nonlinear solver instance - Newton-Raphson solver. NonlinearSolver solver = new NewtonRaphsonSolver(); x0 = new double[] { 0.2, 0.2 }; // initial guess for variable values options = new SolverOptions() // options for solving nonlinear problem { MaxIterationCount = 100, SolutionPrecision = 1e-5 }; result = null; // solving the system actual = solver.Solve(system, x0, options, ref result); return(result); }
/// <summary>Attempts to solve the current puzzle, update the state in the grid, and return the results.</summary> /// <returns>The results from attempting to solve the puzzle.</returns> private SolverResults SolvePuzzle() { // If it's already solved, nothing to do if (State.Status == PuzzleStatus.Solved) { return(new SolverResults(PuzzleStatus.Solved, State, 0, null)); } // Otherwise, try to solve it. SolverOptions options = new SolverOptions(); options.MaximumSolutionsToFind = 1u; // this means that if there are multiple solutions, we'll find and use the first options.AllowBruteForce = true; options.EliminationTechniques = new List <EliminationTechnique> { new NakedSingleTechnique() }; SolverResults results = Solver.Solve(State, options); if (results.Status == PuzzleStatus.Solved && results.Puzzles.Count == 1) { SetUndoCheckpoint(); State = results.Puzzle; } return(results); }
private static void SolverTest() { Equation[] equations = new Equation[2]; // Normal forms eq(x) - c = 0 equations[0] = arg => arg[0] * arg[0] + arg[1] * arg[1] - 1; equations[1] = arg => arg[0] * arg[0] - arg[1]; NonlinearSystem system = new AnalyticalEquationSystem(equations); double[] x0; SolverOptions options; double[] result; double[] expected; SolutionResult actual; // creating nonlinear solver instance - Newton-Raphson solver. NonlinearSolver solver = new NewtonRaphsonSolver(); x0 = new double[] { 0.2, 0.2 }; // initial guess for variable values options = new SolverOptions() // options for solving nonlinear problem { MaxIterationCount = 100, SolutionPrecision = 1e-6 }; result = null; // solving the system actual = solver.Solve(system, x0, options, ref result); expected = new double[] { 0.7861513778, 0.6180339887 }; // expected values // printing solution result into console out PrintNLResult(system, actual, result, expected, options.SolutionPrecision); }
private static SolverOptions CreateOptions() { SolverOptions opt = new SolverOptions(); opt.MaxIterationCount = 100; opt.SolutionPrecision = 1e-5; //opt.Norm = new EuclidianNorm(); return(opt); }
/// <summary>Creates a checkpoint used to determine where cells are invalid in the puzzle.</summary> public void SetOriginalPuzzleCheckpoint(PuzzleState original) { _originalState = original; if (original != null) { SolverOptions options = new SolverOptions(); options.MaximumSolutionsToFind = 2; SolverResults results = Solver.Solve(original, options); if (results.Status == PuzzleStatus.Solved && results.Puzzles.Count == 1) { _solvedOriginalState = results.Puzzle; } else { _solvedOriginalState = null; } } }
public float[] Solve() { NonlinearSystem system = new AnalyticalSystem(_variables, _functions); _options = new SolverOptions() { MaxIterationCount = 100, SolutionPrecision = 1e-5 }; _result = null; // solving the system double[] guess = Array.ConvertAll(_initGuess, x => (double)x); _actual = _solver.Solve(system, guess, _options, ref _result); return(Array.ConvertAll(_result, x => (float)x)); // expected values // printing solution result into console out }
/// <summary>Attempts to solve the current puzzle, update the state in the grid, and return the results.</summary> /// <returns>The results from attempting to solve the puzzle.</returns> private SolverResults SolvePuzzle() { // If it's already solved, nothing to do if (State.Status == PuzzleStatus.Solved) return new SolverResults(PuzzleStatus.Solved, State, 0, null); // Otherwise, try to solve it. SolverOptions options = new SolverOptions(); options.MaximumSolutionsToFind = 1u; // this means that if there are multiple solutions, we'll find and use the first options.AllowBruteForce = true; options.EliminationTechniques = new List<EliminationTechnique>{new NakedSingleTechnique()}; SolverResults results = Solver.Solve(State, options); if (results.Status == PuzzleStatus.Solved && results.Puzzles.Count == 1) { SetUndoCheckpoint(); State = results.Puzzle; } return results; }
/// <summary>Creates a checkpoint used to determine where cells are invalid in the puzzle.</summary> public void SetOriginalPuzzleCheckpoint(PuzzleState original) { _originalState = original; if (original != null) { SolverOptions options = new SolverOptions(); options.MaximumSolutionsToFind = 2; SolverResults results = Solver.Solve(original, options); if (results.Status == PuzzleStatus.Solved && results.Puzzles.Count == 1) { _solvedOriginalState = results.Puzzle; } else _solvedOriginalState = null; } }
public static double[] GetRoots(double[] сoefficients, double precision = 0.00000000000001, double InitialStep = 1, double MinStep = 0.25, SolverOptions options = SolverOptions.StopIfNumberOfRootsCeasedIncrease) { RootsLimits Limits = GetRootsLimits(сoefficients); //отделение корнеЙ double h = InitialStep; Interval[] IntervalsWithNormalStep; Interval[] IntervalsWithHalfOfStep; //лямбда полинома с коефициентами var lambda = FormLambdaForPolinom(сoefficients.ToArray()); do { IntervalsWithNormalStep = GetIntervalsWithRoots(lambda, h, Limits.NLower, Limits.NUpper, Limits.PLower, Limits.PUpper); IntervalsWithHalfOfStep = GetIntervalsWithRoots(lambda, h / 2, Limits.NLower, Limits.NUpper, Limits.PLower, Limits.PUpper); h /= 2; }while (IntervalsWithNormalStep.Length != IntervalsWithHalfOfStep.Length); //уточнение корней double[] roots = ClarifyRoots(lambda, IntervalsWithHalfOfStep, precision); return(roots); }