/// <summary> /// Creates a <see cref="HillClimber{TState, TEvaluation}"/> from the current configuration /// </summary> /// <returns>The constructed <see cref="HillClimber{TState, TEvaluation}"/></returns> /// <exception cref="ConfigurationException">If the configuration is not valid at the time of execution</exception> public IHillClimber <TState, TEvaluation> Build() { if (!IsValid()) { throw new ConfigurationException(); } IComparer <TState> stateComparer = ResolveStateComperer(StateComparer); IClimberAlgorithm <TState, TEvaluation> algorithm = ResolveAlgorithm(stateComparer, SuccessorGenerationFunction); HillClimber <TState, TEvaluation> climber = new HillClimber <TState, TEvaluation>(algorithm); return(climber); }
/// <summary> /// Use a pre-existing <see cref="IClimberAlgorithm{TState, TEvaluation}" to build the <see cref="HillClimber{TState, TEvaluation}"/>/> /// </summary> /// <param name="algorithm">The <see cref="ClimberAlgorithm"/> to Hill Climb with</param> /// <returns>Teh modified configuration</returns> public ClimberConfiguration <TState, TEvaluation> UsingAlgorithm(IClimberAlgorithm <TState, TEvaluation> algorithm) { ClimberAlgorithm = algorithm; return(this); }
/// <summary> /// Creates a HillClimber that will perform an optimization from the given ClimberAlgrithm. /// </summary> /// <param name="algorithm">The climber algorithm to use for optimzation</param> public HillClimber(IClimberAlgorithm <TState, TEvaluation> algorithm) { this.algorithm = algorithm; this.algorithm.ClimbStepPerformedEvent += OnClimberStepEvent; }