Esempio n. 1
0
        public Link StrengthenLink(Entity entity, List <Pattern> currentPatterns, LinkSeverity severity = LinkSeverity.Weak)
        {
            var strongestPattern = currentPatterns.OrderByDescending(item => item.Length).FirstOrDefault();

            if (strongestPattern == null)
            {
                return(CreateLink(entity, severity));
            }

            var randomGenerator = new Random(DateTime.Now.Millisecond);
            var linkSize        = GetLinkSize(randomGenerator, severity, LinkApplyType.Strengthen);
            var startIndex      = strongestPattern.EndIndex + linkSize <= Settings.SequenceLength - 1 ? strongestPattern.EndIndex + 1 : strongestPattern.StartIndex - linkSize;

            if (startIndex >= 0 && startIndex < Settings.SequenceLength - linkSize - 1)
            {
                for (var i = startIndex; i < startIndex + linkSize; i++)
                {
                    Sequence.Set(i, entity.Sequence.Get(i));
                }
            }

            return(new Link {
                Left = this,
                Right = entity,
                Pattern = SequenceProcessor.CalculateSimillarPatterns(this.Sequence, entity.Sequence, Settings.MinimumPatternLength)
            });
        }
Esempio n. 2
0
        public Link CreateLink(Entity to, LinkSeverity severity = LinkSeverity.Weak)
        {
            if (!Name.Equals(to.Name, StringComparison.InvariantCultureIgnoreCase))
            {
                var randomGenerator = new Random(DateTime.Now.Millisecond);
                var linkSize        = GetLinkSize(randomGenerator, severity);
                var startIndex      = randomGenerator.Next(Settings.SequenceLength - linkSize - 1);

                for (var i = startIndex; i < startIndex + linkSize; i++)
                {
                    Sequence.Set(i, to.Sequence.Get(i));
                }
            }

            return(new Link {
                Left = this,
                Right = to,
                Pattern = SequenceProcessor.CalculateSimillarPatterns(this.Sequence, to.Sequence, Settings.MinimumPatternLength)
            });
        }