public void EvaluationTest()
        {
            EvaluationIF     e        = new ByteEvaluation_Zeros();
            GeneticAlgorithm target   = new GeneticAlgorithm(e);
            EvaluationIF     expected = e;
            EvaluationIF     actual;

            target.Evaluation = expected;
            actual            = target.Evaluation;
            Assert.AreEqual(expected, actual);
        }
コード例 #2
0
        /// <summary>
        /// GeneticAlgorithm constructor
        /// </summary>
        /// <param name="e">function to be optimized</param>
        public GeneticAlgorithm(EvaluationIF e)
        {
            Evaluation = e;

            if (e.Type == OperatorType.Byte)
            {
                SetByteDefaults();
            }
            else
            {
                SetDoubleDefaults();
            }
        }
コード例 #3
0
        public GeneticAlgorithm(Operator[] operat, InitializationIF initialization, EvaluationIF evaluation)
        {
            List <Operator> operators = operat.OfType <Operator>().ToList();

            Evaluation = evaluation;
            OperatorType type = evaluation.Type;

            bool ok = true;

            if (initialization.Type != type || initialization.Type != OperatorType.Both)
            {
                ok = false;
            }

            foreach (Operator o in operators)
            {
                if (o.Type != type || o.Type != OperatorType.Both)
                {
                    ok = false;
                }
            }

            if (ok)
            {
                Operations     = operators;
                Initialization = initialization;
            }
            else
            {
                Console.WriteLine("Wrong operator types, example operators added");
                if (evaluation.Type == OperatorType.Byte)
                {
                    SetByteDefaults();
                }
                else
                {
                    SetDoubleDefaults();
                }
            }
        }