Пример #1
0
            /// <summary>
            /// Determines whether the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>.
            /// </summary>
            /// <param name="obj">The <see cref="T:System.Object"/> to compare with the current <see cref="T:System.Object"/>.</param>
            /// <returns>
            /// true if the specified <see cref="T:System.Object"/> is equal to the current <see cref="T:System.Object"/>; otherwise, false.
            /// </returns>
            /// <exception cref="T:System.NullReferenceException">
            /// The <paramref name="obj"/> parameter is null.
            /// </exception>
            public override bool Equals(object obj)
            {
                GroupingId other = obj as GroupingId;

                if (other == null)
                {
                    return(false);
                }
                if (_values.Count != other._values.Count)
                {
                    return(false);
                }
                foreach (Dimension d in _values.Keys)
                {
                    ValueFactoryWithOptionalConcreteValue thisValue = _values[d], otherValue;
                    Debug.Assert(thisValue != null);
                    if (!other._values.TryGetValue(d, out otherValue))
                    {
                        return(false);
                    }
                    if (!thisValue.ValueFactory.Equals(otherValue.ValueFactory))
                    {
                        return(false);
                    }
                }
                return(true);
            }
Пример #2
0
        /// <summary>
        /// Explores the input (sub-)space. Each invocation may return a different set.
        /// </summary>
        /// <returns>
        /// A (reasonably-sized) stream of vectors/values from the (sub-)space.
        /// </returns>
        public override IEnumerable <Vector> Explore()
        {
            Dictionary <GroupingId, List <Vector> > groups = new Dictionary <GroupingId, List <Vector> >();

            foreach (Vector v in WrappedStrategies[0].Explore())
            {
                GroupingId    group = new GroupingId(v, _groupingDimensions);
                List <Vector> list;
                if (!groups.TryGetValue(group, out list))
                {
                    list = new List <Vector>();
                    groups.Add(group, list);
                }
                list.Add(v);
            }
            foreach (KeyValuePair <GroupingId, List <Vector> > group in groups)
            {
                foreach (Vector v in group.Value)
                {
                    if (EnsureSameValuesForCategorizedValues)
                    {
                        group.Key.EnsureSameValuesForCategorizedValues(v);
                    }
                    yield return(v);
                }
            }
        }