/// <summary> /// Use a concrete SuccessorGenerator object to generate successor states. /// </summary> /// <param name="successorGenerator">A successor generator that will create neighbor states for any given state</param> /// <returns>The modified configuration</returns> public ClimberConfiguration <TState, TEvaluation> GeneratesSuccessorsWith(ISuccessorGenerator <TState, TEvaluation> successorGenerator) { if (successorGenerator == null) { throw new ArgumentNullException("SuccessorGenerator cannot be null"); } return(GeneratesSuccessorsWith(c => successorGenerator.GetSuccessors(c))); }
public TState Next(TState current) { TState bestSuccessor = generator.GetSuccessors(current).Extrema(comparer); if (comparer.Compare(current.GetEvaluation(), bestSuccessor.GetEvaluation()) <= 0 || encounteredStates.Contains(bestSuccessor)) { return(current); } encounteredStates.Add(bestSuccessor); return(bestSuccessor); }
public void TestRandomRestartHillClimberIncrementingRestartPoint() { comparer = new MaximizingComparer <TestIntegerEvaluableState>(); generator = new TestExponentialIntegerSuccessorGenerator(); var climberConfiguration = new ClimberConfiguration <TestIntegerEvaluableState, int>() .ComparesUsing(comparer) .GeneratesSuccessorsWith((c) => generator.GetSuccessors(c)); randomizer = new TestIntegerRandomizerSimulator(); climber = new RandomRestartHillClimber <TestIntegerEvaluableState, int>(5, randomizer, climberConfiguration); RunTest(climber, 1, 10000); }
public void TestRandomRestartHillClimberSameRestartPointEachTime() { comparer = new MaximizingComparer <TestIntegerEvaluableState>(); generator = new TestLinearIntegerSuccessorGenerator(); randomizer = new TestIntegerEvaluableStateNonRandomizer(); var climberConfiguration = new ClimberConfiguration <TestIntegerEvaluableState, int>() .ComparesUsing(comparer) .GeneratesSuccessorsWith((c) => generator.GetSuccessors(c)); randomizer = new TestIntegerEvaluableStateNonRandomizer(); climber = new RandomRestartHillClimber <TestIntegerEvaluableState, int>(5, randomizer, climberConfiguration); RunTest(climber, 2, 100); }
/// <summary> /// Creates a <see cref="ClimberSuccessorSelector{TState, TEvaluation}" that will create neighbor states using the given /// <see cref="ISuccessorGenerator{TState, TEvaluable}"/>/> /// </summary> /// <param name="generator">The complex SuccessorGenerator that will be used to generate neighbor states</param> /// <param name="evaluationComparer">The comparison strategy to determine which successor state is most optimal</param> public ClimberSuccessorSelector(ISuccessorGenerator <TState, TEvaluation> generator, IComparer <TState> evaluationComparer) : this(evaluationComparer, (c) => generator.GetSuccessors(c)) { }