Пример #1
0
        /// <summary>
        /// CONSTURCTOR for CollectionView
        /// </summary>
        /// <param name="pAddImage"> a StrategyDelegate passed in </param>
        public CollectionView(StrategyDelegate pAddImage)
        {
            // SET CollectionView StrategyDelegate to the StrategyDelegate passed in
            _addImg = pAddImage;

            InitializeComponent();
        }
        private static IEnumerable <Chromosome <TGene, TFitness> > GetImprovement(StrategyDelegate newChild,
                                                                                  GenerateParentDelegate generateParent)
        {
            var bestParent = generateParent();

            yield return(bestParent);

            while (true)
            {
                var child = newChild(bestParent);
                if (bestParent.Fitness.CompareTo(child.Fitness) > 0)
                {
                    continue;
                }
                if (bestParent.Fitness.CompareTo(child.Fitness) == 0)
                {
                    bestParent = child;
                    continue;
                }

                bestParent = child;
                yield return(child);
            }

            // ReSharper disable once IteratorNeverReturns
        }
Пример #3
0
        /// <summary>
        /// CONSTRUCTOR for DisplayView Class
        /// </summary>
        /// <param name="pFlipH"> StrategyDelegate passed in, flips horizontally</param>
        /// <param name="pExecute"></param>
        /// <param name="pResize"></param>
        /// <param name="pFlipV"> StrategyDelegate passed in, flips vertically </param>
        /// <param name="pRCW"> StrategyDelegate passed in, rotates clockwise </param>
        /// <param name="pRACW"> StrategyDelegate passed in, rotates anti clockwise </param>
        /// /// <param name="pRACW"> StrategyDelegate passed in, saves image </param>
        public DisplayView(StrategyDelegate pFlipH, ExecuteDelegate pExecute, SizeDelegate pResize, StrategyDelegate pFlipV,
                           StrategyDelegate pRCW, StrategyDelegate pRACW, StrategyDelegate pSave)
        {
            InitializeComponent();

            // SET _flipH delegate to StrategyDelegate passed in (pFlipH)
            _flipH = pFlipH;
            // SET ExecuteDelegate to ExecuteDelegate passed in
            _execute = pExecute;
            // SET ResizeDelegate to ResizeDelegate passed in
            _resize = pResize;
            // SET _flipV delegate to StrategyDelegate passed in (pFlipV)
            _flipV = pFlipV;
            // SET _rotateCW delegate to StrategyDelegate passed in (pRCW)
            _rotateCW = pRCW;
            // SET _rotateACW delegate to StrategyDelegate passed in (pRACW)
            _rotateACW = pRACW;
            // SET _save StrategyDelegat to StrategyDelegate passed in (pSave)
            _save = pSave;
            // SET _minSize as a new Size, the width being the far most right button position (save button)
            // + its width and some extra width, same with height but y position and the save buttons height
            _minSize = new Size(SaveBtn.Location.X + SaveBtn.Width + 20, SaveBtn.Location.Y + SaveBtn.Height + 20);
            // SET the minimum size property of the DisplayView to _minSize variable
            this.MinimumSize = _minSize;
            // SET this windows visibility to true upon creation
            this.Visible = true;
        }
        private static IEnumerable <Chromosome <TGene, TFitness> > GetImprovement(
            StrategyDelegate newChild, GenerateParentDelegate generateParent, int?maxAge, int poolSize, int?maxSeconds)
        {
            var watch      = Stopwatch.StartNew();
            var bestParent = generateParent();

            if (maxSeconds != null && watch.ElapsedMilliseconds > maxSeconds * 1000)
            {
                throw new SearchTimeoutException(bestParent);
            }

            yield return(bestParent);

            var parents = new List <Chromosome <TGene, TFitness> > {
                bestParent
            };
            var historicalFitnesses = new List <TFitness> {
                bestParent.Fitness
            };

            while (parents.Count < poolSize)
            {
                var parent = generateParent();
                if (maxSeconds != null && watch.ElapsedMilliseconds > maxSeconds * 1000)
                {
                    throw new SearchTimeoutException(parent);
                }

                if (parent.Fitness.CompareTo(bestParent.Fitness) > 0)
                {
                    yield return(parent);

                    bestParent = parent;
                    historicalFitnesses.Add(parent.Fitness);
                }

                parents.Add(parent);
            }

            var lastParentIndex = poolSize - 1;
            var pIndex          = 1;

            while (true)
            {
                if (maxSeconds != null && watch.ElapsedMilliseconds > maxSeconds * 1000)
                {
                    throw new SearchTimeoutException(bestParent);
                }

                pIndex = pIndex > 0 ? pIndex - 1 : lastParentIndex;
                var parent = parents[pIndex];
                var child  = newChild(parent, pIndex, parents);
                if (parent.Fitness.CompareTo(child.Fitness) > 0)
                {
                    if (maxAge == null)
                    {
                        continue;
                    }

                    parent.Age++;
                    if (parent.Age < maxAge)
                    {
                        continue;
                    }

                    var index = historicalFitnesses.BinarySearch(child.Fitness);
                    if (index < 0)
                    {
                        index = ~index;
                    }
                    var difference        = historicalFitnesses.Count - index;
                    var proportionSimilar = (double)difference / historicalFitnesses.Count;
                    var exp = Math.Exp(-proportionSimilar);
                    if (Rand.Random.NextDouble() < exp)
                    {
                        parents[pIndex] = child;
                        continue;
                    }

                    bestParent.Age  = 0;
                    parents[pIndex] = bestParent;
                    continue;
                }

                if (parent.Fitness.CompareTo(child.Fitness) == 0)
                {
                    child.Age       = parent.Age + 1;
                    parents[pIndex] = child;
                    continue;
                }

                child.Age       = 0;
                parents[pIndex] = child;
                if (bestParent.Fitness.CompareTo(child.Fitness) >= 0)
                {
                    continue;
                }

                bestParent = child;
                historicalFitnesses.Add(bestParent.Fitness);
                yield return(bestParent);
            }

            // ReSharper disable once IteratorNeverReturns
        }
Пример #5
0
 public void InjectLevelSwitcher(StrategyDelegate pVoid)
 {
     _switch = pVoid;
 }
Пример #6
0
 public void SubscribeClose(StrategyDelegate pClose)
 {
     openDoors.Add(pClose);
 }
Пример #7
0
 public void SubscribeDoor(StrategyDelegate pDoorDel)
 {
     doors.Add(pDoorDel);
 }
Пример #8
0
 /// <summary>
 /// CONSTRUCTOR for ImageCommand
 /// </summary>
 /// <param name="pAction"> a strategy delegate passed in </param>
 public ImageCommand(StrategyDelegate pAction)
 {
     // SET ImageCommand StrategyDelegat to StrategyDelegate passed in as parameter
     _action = pAction;
 }
Пример #9
0
 public void InjectPlayerDeathSequence(StrategyDelegate pDeath)
 {
     InitiatePlayerDeath = pDeath;
 }
Пример #10
0
 /// <summary>
 /// CONSTRUCTOR for InputManager
 /// </summary>
 public InputManager(StrategyDelegate pPauseG)
 {
     _pauseUnpause = pPauseG;
 }