Пример #1
0
 private Func <bool> CreateIsUpdateDueFunction(UpdateScheme updateScheme)
 {
     return(updateScheme.UpdateMode switch
     {
         UpdateMode.None => () => false,
         UpdateMode.Generational => IsUpdateDue_Generational,
         UpdateMode.Timespan => IsUpdateDue_TimeSpan,
         _ => throw new ArgumentException("Unexpected UpdateMode."),
     });
Пример #2
0
        /// <summary>
        /// Constructs a new instance.
        /// </summary>
        /// <param name="ea">The <see cref="IEvolutionAlgorithm"/> to wrap.</param>
        /// <param name="updateScheme">Evolution algorithm update event scheme.</param>
        public EvolutionAlgorithmRunner(
            IEvolutionAlgorithm ea,
            UpdateScheme updateScheme)
        {
            _ea = ea ?? throw new ArgumentNullException(nameof(ea));

            // Init update scheme.
            _updateScheme  = updateScheme ?? throw new ArgumentNullException(nameof(updateScheme));
            _isUpdateDueFn = CreateIsUpdateDueFunction(_updateScheme);
        }
Пример #3
0
        /// <summary>
        /// Constructs a new instance.
        /// </summary>
        /// <param name="ea">The <see cref="IEvolutionAlgorithm"/> to wrap.</param>
        public EvolutionAlgorithmRunner(IEvolutionAlgorithm ea)
        {
            _ea = ea ?? throw new ArgumentNullException(nameof(ea));

            // Set to ready state.
            _runState = RunState.Ready;

            // Set a default update scheme of once per second.
            _updateScheme = UpdateScheme.CreateTimeSpanUpdateScheme(TimeSpan.FromSeconds(1));
        }
Пример #4
0
        private Func <bool> CreateIsUpdateDueFunction(UpdateScheme updateScheme)
        {
            switch (updateScheme.UpdateMode)
            {
            case UpdateMode.None:
                return(() => false);

            case UpdateMode.Generational:
                return(IsUpdateDue_Generational);

            case UpdateMode.Timespan:
                return(IsUpdateDue_TimeSpan);

            default:
                throw new ArgumentException("Unexpected UpdateMode.");
            }
        }