示例#1
0
        /// <summary>
        /// This is the method that invokes the operator. This should not normally be called explicitly.
        /// </summary>
        /// <param name="currentPopulation"></param>
        /// <param name="newPopulation"></param>
        /// <param name="fitnessFunctionDelegate"></param>
        public new virtual void Invoke(Population currentPopulation, ref Population newPopulation, FitnessFunction fitnessFunctionDelegate)
        {
            if (currentPopulation.Solutions == null || currentPopulation.Solutions.Count == 0)
            {
                throw new ArgumentException("There are no Solutions in the current Population.");
            }

            if (newPopulation == null)
            {
                newPopulation = currentPopulation.CreateEmptyCopy();
            }

            CurrentPopulation = currentPopulation;
            NewPopulation     = newPopulation;
            FitnessFunction   = fitnessFunctionDelegate;

            if (!Enabled)
            {
                return;
            }

            //need to store this as we cannot handle a change until once this generation has started
            _replacementMethodS = ReplacementMethod;

            this.Process();

            //TODO: Test this, we shouldn't need it.
            newPopulation = NewPopulation;
        }
示例#2
0
        /// <summary>
        /// This is the method that invokes the operator. This should not normally be called explicitly.
        /// </summary>
        /// <param name="currentPopulation"></param>
        /// <param name="newPopulation"></param>
        /// <param name="fitnessFunctionDelegate"></param>
        public void Invoke(Population currentPopulation, ref Population newPopulation, FitnessFunction fitnessFunctionDelegate)
        {
            //if the new population is null, create an empty population
            if (newPopulation == null)
            {
                newPopulation = currentPopulation.CreateEmptyCopy();
            }

            if (!Enabled)
            {
                return;
            }

            _fitnessFunctionDelegate = fitnessFunctionDelegate;
            _currentPopulation       = currentPopulation;
            _newPopulation           = newPopulation;

            //need to store this as we cannot handle a change until once this generation has started
            _replacementMethodS = ReplacementMethod;

            this.Process();

            //TODO: Test this, we shouldn't need it.
            newPopulation = _newPopulation;
        }
示例#3
0
        public TetrisCrossover(double crossOverProbability, ReplacementMethod replacementMethod)
        {
            CrossoverProbability        = crossOverProbability;
            AllowDuplicates             = true;
            ReplacementMethod           = replacementMethod;
            RequiresEvaluatedPopulation = true;

            Enabled = true;
        }
        void OnGUI()
        {
            Rect lastRect;

            GUILayout.BeginVertical();
            {
                GUILayout.Label("Object Replacer Settings", EditorStyles.boldLabel);

                replacementMethod = (ReplacementMethod)EditorGUILayout.EnumPopup("Method of Replacement", replacementMethod);

                objectTypeToReplace = (GameObject)EditorGUILayout.ObjectField("Object Type To Replace", objectTypeToReplace, typeof(GameObject), true);
                replaceWithThis     = (GameObject)EditorGUILayout.ObjectField("Replace With This Prefab", replaceWithThis, typeof(GameObject), true);

                if (GUILayout.Button("Replace Objects!"))
                {
                    if (objectTypeToReplace == null || replaceWithThis == null)
                    {
                        ShowNotification(new GUIContent("No object selected for searching"));
                        //   return;
                    }
                    else
                    {
                        ReplaceObjects();
                    }

                    lastRect = GUILayoutUtility.GetLastRect();
                }
            }
            GUILayout.EndVertical();
            lastRect = GUILayoutUtility.GetLastRect();    //button rect


            // GUILayout.BeginArea(new Rect(10, 10, 300, 500));
            //      replaceWithThis = (GameObject)EditorGUI.ObjectField(new Rect(3, 60, position.width - 6, 20), "Replace With This", replaceWithThis, typeof(GameObject));



            //       GUILayout.EndArea();
            // ApplyModifiedProperties();
        }
        ///// <summary>
        ///// Constructor.
        ///// </summary>
        //internal CrossoverBase ()
        //	: this (1.0)
        //{
        //}

        ///// <summary>
        ///// Constructor.
        ///// </summary>
        ///// <param name="crossOverProbability"></param>
        //public CrossoverBase (double crossOverProbability)
        //	: this (crossOverProbability, true)
        //{
        //}

        ///// <summary>
        ///// Constructor.
        ///// </summary>
        ///// <param name="crossOverProbability"></param>
        ///// <param name="allowDuplicates"></param>
        //public CrossoverBase (double crossOverProbability, bool allowDuplicates)
        //	: this (crossOverProbability, allowDuplicates, CrossoverType.SinglePoint)
        //{
        //}

        ///// <summary>
        ///// Constructor.
        ///// </summary>
        ///// <param name="crossOverProbability"></param>
        ///// <param name="allowDuplicates"></param>
        ///// <param name="crossoverType"></param>
        //public CrossoverBase (double crossOverProbability, bool allowDuplicates, CrossoverType crossoverType)
        //	: this (crossOverProbability, allowDuplicates, crossoverType, Operators.ReplacementMethod.GenerationalReplacement)
        //{
        //}

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="crossOverProbability"></param>
        /// <param name="allowDuplicates"></param>
        /// <param name="crossoverType"></param>
        /// <param name="replacementMethod"></param>
        public CrossoverBase(double crossOverProbability, bool allowDuplicates, CrossoverType crossoverType, ReplacementMethod replacementMethod)
        {
            this.CrossoverProbability = crossOverProbability;
            this.AllowDuplicates      = allowDuplicates;
            this.ReplacementMethod    = replacementMethod;
            this.CrossoverType        = crossoverType;

            Enabled = true;
        }
示例#6
0
 public CustomCrossover(double crossOverProbability, bool allowDuplicates, Crossover2DShape crossoverShape, ReplacementMethod replacementMethod)
 {
     this.CrossoverProbability = crossOverProbability;
     this.AllowDuplicates      = allowDuplicates;
     this.ReplacementMethod    = replacementMethod;
     this.CrossoverShape       = crossoverShape;
     this.Enabled = true;
 }
示例#7
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="crossOverProbability"></param>
 /// <param name="allowDuplicates"></param>
 /// <param name="crossoverType"></param>
 /// <param name="replacementMethod"></param>
 public Crossover(double crossOverProbability, bool allowDuplicates, CrossoverType crossoverType, ReplacementMethod replacementMethod)
     : base(crossOverProbability, allowDuplicates, crossoverType, replacementMethod)
 {
 }