/// <summary> /// Sets the options and other configuration used in the ACO. /// </summary> private void ApplyOptions() { /*** setting the stopping criteria for the algorithm ***/ var stoppingCriteriaOptions = AcoOptions.StoppingCriteriaOptions; var stoppingCriteriaType = stoppingCriteriaOptions.StoppingCriteriaType; switch (stoppingCriteriaType) { case StoppingCriteriaType.TimeBased: var minutesPassed = stoppingCriteriaOptions.MinutesPassed; if (minutesPassed <= 0) { throw new Exception($"When using {stoppingCriteriaType}, the minutes passed must be larger than 0."); } _stoppingCriteria = new TimeBaseStoppingCriteria(minutesPassed); break; case StoppingCriteriaType.SpecifiedIterations: var maximumIterations = stoppingCriteriaOptions.MaximumIterations; if (maximumIterations <= 0) { throw new Exception($"When using {stoppingCriteriaType}, the max iterations must be larger than 0."); } _stoppingCriteria = new IterationStoppingCriteria(maximumIterations); break; } /*** setting the stopping criteria for the algorithm ***/ }
private SecantSolver(Function function, IStoppingCriteria stoppingCriteria, int maxIterations) { if (maxIterations < 0) { throw new ArgumentOutOfRangeException("MaxIterations", "The number of iteractions must be non-negative"); } this.maxIterations = maxIterations; this.function = function; this.stoppingCriteria = stoppingCriteria; }
private NewtonSolver(Function function, Function derivative, IStoppingCriteria stoppingCriteria, int maxIterations = 50) { this.function = function; this.derivative = derivative; this.stoppingCriteria = stoppingCriteria; this.maxIterations = maxIterations; }
/// <summary> /// Sets the options and other configuration used in the GA. /// </summary> private void ApplyOptions() { /*** setting the selection operator to the specified type ***/ var selectionType = GaOptions.SelectionType; if (selectionType == SelectionType.None) { throw new Exception("Selection method cannot be none when setting the method."); } var populationSize = Population.PopulationSize; switch (selectionType) { case SelectionType.Rws: SelectionOperator = new RouletteWheelSelection <T>(populationSize, Random); break; case SelectionType.Tos: // the tournamnet selection percentage is hardcoded for now to 2%, TODO => this must be passed in the GA Options SelectionOperator = new TournamentSelection <T>(populationSize, Random, 0.02); break; } /*** setting the selection operator to the specified type ***/ /*** setting the crossover operator to the specified type ***/ var crossoverType = GaOptions.CrossoverType; if (crossoverType == CrossoverType.None) { throw new Exception("Crossover method cannot be none when setting the method."); } switch (crossoverType) { case CrossoverType.OrderOne: CrossoverOperator = new OrderOne <T>(Random); break; case CrossoverType.Cycle: CrossoverOperator = new CycleCrossover <T>(Random); break; } /*** setting the crossover operator to the specified type ***/ /*** setting the mutation operator to the specified type ***/ var mutationType = GaOptions.MutationType; if (mutationType == MutationType.None) { throw new Exception("Mutation method cannot be none when setting the method."); } switch (mutationType) { case MutationType.SingleSwap: MutationOperator = new SingleSwapMutation <T>(Random); break; case MutationType.InversionMutation: MutationOperator = new InversionMutation <T>(Random, GaOptions.MutationRate); break; } /*** setting the mutation operator to the specified type ***/ /*** setting the stopping criteria for the algorithm ***/ var stoppingCriteriaOptions = GaOptions.StoppingCriteriaOptions; var stoppingCriteriaType = stoppingCriteriaOptions.StoppingCriteriaType; switch (stoppingCriteriaType) { case StoppingCriteriaType.TimeBased: var minutesPassed = stoppingCriteriaOptions.MinutesPassed; if (minutesPassed <= 0) { throw new Exception($"When using {stoppingCriteriaType}, the minutes passed must be larger than 0."); } StoppingCriteria = new TimeBaseStoppingCriteria(minutesPassed); break; case StoppingCriteriaType.SpecifiedIterations: var maximumIterations = stoppingCriteriaOptions.MaximumIterations; if (maximumIterations <= 0) { throw new Exception($"When using {stoppingCriteriaType}, the max iterations must be larger than 0."); } StoppingCriteria = new IterationStoppingCriteria(maximumIterations); break; } /*** setting the stopping criteria for the algorithm ***/ }
public static BisectionSolverFunction MakeSolver(Function function, IStoppingCriteria stoppingCriteria, int maxIterations = 50) { return(new BisectionSolver(function, stoppingCriteria, maxIterations).Solve); }
public static SecantSolverFunction SecantSolver(this Function function, IStoppingCriteria stoppingCrieria, int maxIterations = 50) { return(RootFinding.SecantSolver.MakeSolver(function, stoppingCrieria, maxIterations)); }
public static Vector2D BisectionSolve(this Function function, double inf, double sup, IStoppingCriteria stoppingCriteria, int maxIterations = 50) { return(RootFinding.BisectionSolver.MakeSolver(function, stoppingCriteria, maxIterations)(inf, sup)); }
public static NewtonSolverFunction NewtonSolver(this Function function, Function derivative, IStoppingCriteria stoppingCriteria, int maxIterations = 50) { return(RootFinding.NewtonSolver.MakeSolver(function, derivative, stoppingCriteria, maxIterations)); }
public static Vector2D NewtonSolve(this Function function, double x0, IStoppingCriteria stoppingCriteria, int maxIterations = 50) { return(RootFinding.NewtonSolver.MakeSolver(function, stoppingCriteria, maxIterations)(x0)); }
public static Vector2D NewtonSolve(this Function function, double x0, int multiplicity, Function derivative, IStoppingCriteria stoppingCriteria, int maxIterations = 50) { return(RootFinding.NewtonSolver.MakeSolver(function, derivative, stoppingCriteria, maxIterations)(x0, multiplicity)); }
public static Vector2D SecantSolve(this Function function, double x0, double x1, IStoppingCriteria stoppingCriteria, int maxIterations = 50) { return(RootFinding.SecantSolver.MakeSolver(function, stoppingCriteria, maxIterations)(x0, x1)); }
public static NewtonSolverFunction MakeSolver(Function function, IStoppingCriteria stoppingCriteria, int maxIterations = 50) { return(new NewtonSolver(function, CentralDerivative.MakeDerivative(function, 0.0001), stoppingCriteria, maxIterations).Solve); }
public static NewtonSolverFunction MakeSolver(Function function, Function derivative, IStoppingCriteria stoppingCriteria, int maxIterations = 50) { return(new NewtonSolver(function, derivative, stoppingCriteria, maxIterations).Solve); }