Ejemplo n.º 1
0
 /// <summary>Initialises a new instance of the Processing class.</summary>
 /// <param name="worker">The BackgroundWorker in wich Processing is run.</param>
 /// <param name="prgBar">The progress bar indicated executing.</param>
 /// <param name="wordLength">The length of word.</param>
 /// <param name="mismatchCnt">The amount of mismatches.</param>
 /// <param name="isAllPossible">True if all possible words are processed.</param>
 /// <param name="isTurbo">True if Turbo mode is defined.</param>
 /// <param name="isDrawPlot">True if a plot should be drawing; otherwise, false.</param>
 public Processing(BackgroundWorker worker, ProgressBar prgBar, byte wordLength, byte mismatchCnt, bool isAllPossible, bool isTurbo, bool isDrawPlot)
 {
     _worker     = worker;
     _prgBar     = prgBar;
     _isDrawPlot = isDrawPlot;
     Words.Init(wordLength, mismatchCnt, isTurbo);
     Patterns.Init(isAllPossible);
 }
Ejemplo n.º 2
0
        /// <summary>Creates and filled a shrinked or 'crude' instance of Patterns class from the range of the inputArray array
        /// and calculate their averages and standart deviation values.
        /// </summary>
        /// <param name="worker">The BackgroundWorker in wich Processing is run.</param>
        /// <param name="startIndex">The index in the input sequence at which scanning begins.</param>
        /// <param name="length">The length of scanning range.</param>
        /// <param name="shakeCnt">The amount of shakes.</param>
        /// <param name="avrgs">Null in case of Individual mode; the array of single Average otherwise.</param>
        /// <param name="maxFreqNumber">The number of Pattern with max Frequence: used in 'Global' only.</param>
        /// <param name="stepCntOnShake">The number of progress bar steps generated by method within one shake; 0 if without progress bar steps.</param>
        /// <param name="isDrawPlot">True if a plot should be drawing; otherwise, false.</param>
        /// <returns>Sorted by Frequence and shrinked collection in case of isSortByFreq=true; otherwise sorted by Number and unshrinked.</returns>
        public static Patterns GetTreatedPatterns(
            BackgroundWorker worker,
            int startIndex, int length, short shakeCnt,
            ref Average[] avrgs, ref int maxFreqNumber, float stepCntOnShake,
            bool isDrawPlot)
        {
            int strictLength = length - Words.WordLength;

            int[] strictFreqs  = new int[Words.Count];
            int   loopsPerStep = stepCntOnShake > 0 ? (int)(Words.Count / stepCntOnShake) : -1;

            Patterns mainPtns = new Patterns();

            mainPtns.Init(
                worker, Sequence.Original, startIndex,
                strictLength, strictFreqs, loopsPerStep, ref maxFreqNumber, true, isDrawPlot
                );
            if (shakeCnt > 0)           // calculate mean & SD
            {
                int      i;
                int      maxFreqNumberTmp = 0;
                Patterns shakedPtns       = new Patterns();
                // corretcing ProgressBar steps for for shake and scanning
                int shakeSteps = 0;
                //if (loopsPerStep > 3)       shakeSteps = 3;
                //else if (loopsPerStep > 2)  shakeSteps = 2;
                //else if (loopsPerStep > 1)  shakeSteps = 1;
                loopsPerStep -= shakeSteps;

                if (avrgs != null)  //*** Max Average Choice mode set
                {
                    Average.SumCounter sumCounter = new Average.SumCounter();
                    // search patterns with max Frequance for each shake and add this value to the sumCounter
                    for (i = 0; i < shakeCnt; i++)
                    {
                        // we need only max Frequance from the shaked Patterns
                        sumCounter += shakedPtns.Init(worker,
                                                      Sequence.Shake(startIndex, length, worker, shakeSteps),
                                                      0, strictLength, strictFreqs, loopsPerStep, ref maxFreqNumberTmp, false, isDrawPlot
                                                      );
                    }
                    avrgs[0] = new Average(sumCounter); // set total Average on the first place;
                }
                else                                    //*** Individual Average Choice mode set
                {
                    // this case is possible only in Local task, so mainPtns is always sorted and shrinked
                    // create and fill the array of sum counters of frequencies from shaked Patterns;
                    // it is 'sinchronised' with shakedPtns, or the same order as a shakedPtns
                    Average.SumCounter[] SCounters = new Average.SumCounter[Words.Count];
                    maxFreqNumberTmp = -1;      // disable max frequency return
                    for (int j = 0; j < shakeCnt; j++)
                    {
                        shakedPtns.Init(worker,
                                        Sequence.Shake(startIndex, length, worker, shakeSteps),
                                        0, strictLength, strictFreqs, loopsPerStep, ref maxFreqNumberTmp, false, isDrawPlot
                                        );
                        for (i = 0; i < Words.Count; i++)
                        {
                            //if (shakedPtns[i].Freq > 0)
                            //    SCounters[i] += shakedPtns[i].Freq;
                            if (shakedPtns[i] > 0)
                            {
                                SCounters[i] += shakedPtns[i];
                            }
                        }
                    }
                    // set the average of frequency and SD for each Pattern in the initial collection
                    avrgs = new Average[mainPtns.Count];
                    for (i = 0; i < mainPtns.Count; i++)   // each initial pattern with unzero Frequency...
                    {
                        avrgs[i] = new Average(SCounters[i]);
                    }
                }
            }
            return(mainPtns);
        }