/// <summary> /// Performs a Monte Carlo optimization on the given initial state. /// </summary> /// <param name="initialState"></param> /// <returns>The most optimal state encountered after performing the specified evaluations</returns> public override TState PerformOptimization(TState initialState) { if (initialState == null) { throw new ArgumentException("Initial state cannot be null"); } TState bestState = initialState; TState nextState; for (int i = 0; i < NumRandomizations && bestState > initialState; i++) // Test this { nextState = successorPicker.Next(bestState); bestState = EvaluationComparer.Compare(bestState.GetEvaluation(), nextState.GetEvaluation()) > 0 ? bestState : nextState; } return(bestState); }
/// <summary> /// Performs a Monte Carlo optimization on the given initial state. /// </summary> /// <param name="initialState"></param> /// <returns>The most optimal state encountered after performing the specified evaluations</returns> public override TState Optimize(TState initialState) { if (initialState == null) { throw new ArgumentException("Initial state cannot be null"); } TState bestState = initialState; TState nextState; for (int i = 0; i < NumRandomizations; i++) { nextState = SuccessorPicker.Next(bestState); bestState = EvaluationComparer.Compare(bestState, nextState) > 0 ? bestState : nextState; } return(bestState); }