Exemple #1
0
        public override bool Equals(object obj)
        {
            var other = obj as SolutionParameters;

            if (other != null)
            {
                return(other.Width == Width &&
                       other.Height == Height &&
                       SourcePositions.SequenceEqual(other.SourcePositions) &&
                       SinkPositions.SequenceEqual(other.SinkPositions) &&
                       BuildingPositions.SequenceEqual(other.BuildingPositions) &&
                       Connections.SequenceEqual(other.Connections));
            }
            return(base.Equals(obj));
        }
Exemple #2
0
        private void ModifyEdges(double temperature)
        {
            var maxOffset = 2 * (Width + Height) - 4;

            foreach (var sink in SinkPositions.Keys)
            {
                var newPos = IndexToBound(BoundToIndex(SinkPositions[sink]) + (int)((2 * _random.NextDouble() - 1) * maxOffset * temperature));
                SinkPositions = SinkPositions.SetItem(sink, newPos);
            }

            foreach (var source in SourcePositions.Keys)
            {
                var newPos = IndexToBound(BoundToIndex(SourcePositions[source]) + (int)((2 * _random.NextDouble() - 1) * maxOffset * temperature));
                SourcePositions = SourcePositions.SetItem(source, newPos);
            }
        }
Exemple #3
0
        private void ModifySize(double temperature)
        {
            if (_random.NextDouble() > 0.5)
            {
                Width  += _random.Next(-1, 2);
                Height += _random.Next(-1, 2);

                if (Width < 5)
                {
                    Width = 5;
                }
                if (Height < 5)
                {
                    Height = 5;
                }
            }
            else
            {
                var xoff = _random.Next(-1, 2);
                var yoff = _random.Next(-1, 2);

                Width  += xoff;
                Height += yoff;

                if (Width < 5)
                {
                    Width = 5;
                }
                if (Height < 5)
                {
                    Height = 5;
                }

                var offset = new Vector2(xoff, yoff);
                var bounds = new Vector2(Width, Height);

                SourcePositions   = SourcePositions.SetItems(SourcePositions.Select((kvp) => new KeyValuePair <SourceStep, Vector2>(kvp.Key, VectorExtensions.Clamp(kvp.Value + offset, bounds))));
                SinkPositions     = SinkPositions.SetItems(SinkPositions.Select((kvp) => new KeyValuePair <SinkStep, Vector2>(kvp.Key, VectorExtensions.Clamp(kvp.Value + offset, bounds))));
                BuildingPositions = BuildingPositions.SetItems(BuildingPositions.Select((kvp) => new KeyValuePair <ProductionStep, Tuple <Vector2, BuildingRotation> >(kvp.Key, new Tuple <Vector2, BuildingRotation>(kvp.Value.Item1 + offset, kvp.Value.Item2))));
            }
        }