private DimensionSet <BinaryRepresentation> GetNeighbour(DimensionSet <BinaryRepresentation> subject)
        {
            var randomDimension = new Random().Next(0, subject.Count() - 1);

            var alteredRepresentation = new StringBuilder(subject.ElementAt(randomDimension).AsString());
            var randomBit             = new Random().Next(0, alteredRepresentation.Length);

            alteredRepresentation[randomBit] = alteredRepresentation[randomBit] == '0' ? '1' : '0';

            var neighbour = subject.ToList();

            neighbour[randomDimension] = BinaryRepresentation.Create(alteredRepresentation.ToString());

            return(new DimensionSet <BinaryRepresentation>(neighbour));
        }
예제 #2
0
        private static IEnumerable <DimensionSet <BinaryRepresentation> > GetNeighbourhood(DimensionSet <BinaryRepresentation> subject)
        {
            return(subject.SelectMany((bitRepresentation, index) =>
            {
                var allAlterations = GetAlteredRepresentations(bitRepresentation);

                var neighbourhood = new List <DimensionSet <BinaryRepresentation> >();
                foreach (var alteration in allAlterations)
                {
                    var neighbour = subject.ToList();
                    neighbour[index] = alteration;

                    neighbourhood.Add(new DimensionSet <BinaryRepresentation>(neighbour));
                }
                return neighbourhood;
            }).ToList());
        }