Exemplo n.º 1
0
 public RunWindow(Detector detector, IRemoveStrategy removeStrategy, ICharGenerator charGenerator,
                  SaveData saveData, int length, int runsCount)
 {
     this.detector       = detector;
     this.removeStrategy = removeStrategy;
     this.charGenerator  = charGenerator;
     this.saveData       = saveData;
     this.length         = length;
     this.runsCount      = runsCount;
     InitializeComponent();
 }
Exemplo n.º 2
0
        public static StringBuilder Generate([NotNull] Detector detector1, [NotNull] Detector detector2, int length,
                                             [NotNull] IRemoveStrategy removeStrategy,
                                             [NotNull] ICharGenerator generator, [CanBeNull] IGeneratorLogger logger = null)
        {
            var text = detector1.Text;

            text.EnsureCapacity(length);
            while (text.Length < length)
            {
                text.Append(generator.Generate());
                if (logger != null)
                {
                    logger.LogAfterGenerate(text);
                }
                Repetition repetition1, repetition2;
                var        delete1 = 0;
                if (detector1.TryDetect(out repetition1))
                {
                    delete1 = removeStrategy.GetCharsToDelete(text.Length, repetition1);
                    if (logger != null)
                    {
                        logger.LogRepetition(text, repetition1);
                    }
                }
                var delete2 = 0;
                if (detector2.TryDetect(out repetition2))
                {
                    delete2 = removeStrategy.GetCharsToDelete(text.Length, repetition2);
                    if (logger != null)
                    {
                        logger.LogRepetition(text, repetition2);
                    }
                }
                if (delete1 != delete2)
                {
                    throw new Exception("Not matching");
                }
                for (var i = 0; i < delete1; ++i)
                {
                    detector1.Backtrack();
                    detector2.Backtrack();
                    text.Remove(text.Length - 1, 1);
                }
            }
            return(text);
        }
Exemplo n.º 3
0
        private static void Calculate(int runs, Detector detector, int length,
                                      IRemoveStrategy removeStrategy, ICharGenerator generator, IGeneratorLogger logger,
                                      StreamWriter output)
        {
            Console.WriteLine("Conversion for length = {0}", length);
            var conversionCoeffs = new double[runs];
            var times            = new long[runs];

            for (var run = 0; run < runs; ++run)
            {
                detector.Reset();
                var sw = Stopwatch.StartNew();
                RandomWordGenerator.Generate(detector, length, removeStrategy, generator, logger);
                sw.Stop();
                times[run]            = sw.ElapsedMilliseconds;
                conversionCoeffs[run] = RandomWordGenerator.Statistics.CharsGenerated * 1.0 / length;
                Console.WriteLine("\rRun {0} generated in {1} ms", run + 1, sw.ElapsedMilliseconds);
            }
            output.WriteLine("{0} {1} {2} {3}", runs, length, conversionCoeffs.Average(), times.Average());
            output.Flush();
        }
        public static StringBuilder Generate([NotNull] Detector detector, int length, [NotNull] IRemoveStrategy removeStrategy,
                                             [NotNull] ICharGenerator generator, [CanBeNull] IGeneratorLogger logger = null, [CanBeNull] CancellationToken?token = null)
        {
            Statistics.Clear();
            var text = detector.Text;

            text.EnsureCapacity(length);
            var sw = Stopwatch.StartNew();

            while (text.Length < length)
            {
                if (token != null && token.Value.IsCancellationRequested)
                {
                    break;
                }
                text.Append(generator.Generate());
                Statistics.CharsGenerated++;
                if (logger != null)
                {
                    logger.LogAfterGenerate(text);
                }
                Repetition repetition;
                if (detector.TryDetect(out repetition))
                {
                    AddToStats(repetition);
                    var charsToDelete = removeStrategy.GetCharsToDelete(text.Length, repetition);
                    if (logger != null)
                    {
                        logger.LogRepetition(text, repetition);
                    }
                    for (var i = 0; i < charsToDelete; ++i)
                    {
                        detector.Backtrack();
                        text.Remove(text.Length - 1, 1);
                    }
                }
            }
            sw.Stop();
            Statistics.Milliseconds = sw.ElapsedMilliseconds;
            return(text);
        }
Exemplo n.º 5
0
 public NoMoreThanStrategy(IRemoveStrategy baseStrategy, int maxCharactersToRemove)
 {
     BaseStrategy          = baseStrategy;
     MaxCharactersToRemove = maxCharactersToRemove;
 }