Esempio n. 1
0
        private int GetRCB(BinaryString item1, BinaryString item2, int threshold)
        {
            BinaryString result = new BinaryString(new bool[item1.Value.Length]);

            for (int i = 0; i < item1.Value.Length; i++)
            {
                result.Value[i] = (item1.Value[i] == item2.Value[i]);
            }
            int count = 0;
            int max   = 0;

            for (int i = 1; i < result.Value.Length; i++)
            {
                if (result.Value[i])
                {
                    count++;
                }
                else
                {
                    if (count > max)
                    {
                        max = count;
                    }
                    count = 0;
                }
            }
            if (max >= threshold)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
        public void Computing(List <BinaryString> detectorSet, BinaryString sample, int limitCount)
        {
            int threadCount = detectorSet.Count / limitCount;

            if (detectorSet.Count % limitCount != 0)
            {
                threadCount++;
            }
            List <Thread> threads = new List <Thread>();
            List <ComputingAff_DisThreadUnit> units = new List <ComputingAff_DisThreadUnit>();

            for (int i = 0; i < threadCount; i++)
            {
                BinaryString[] tempX = new BinaryString[(i == (threadCount - 1)) ? detectorSet.Count - i * limitCount : limitCount];
                detectorSet.CopyTo(i * limitCount, tempX, 0, tempX.Length);
                ComputingAff_DisThreadUnit cleanUnit = new ComputingAff_DisThreadUnit();
                units.Add(cleanUnit);
                threads.Add(new Thread(delegate() { cleanUnit.Computing(tempX, sample); }));
            }
            for (int i = 0; i < threads.Count; i++)
            {
                threads[i].IsBackground = true;
                threads[i].Start();
            }
            for (int i = 0; i < threads.Count; i++)
            {
                threads[i].Join();
            }
            for (int i = 0; i < units.Count; i++)
            {
                this.result.AddRange(units[i].Result);
            }
        }
 public void Computing(BinaryString[] detectorSet, BinaryString sample)
 {
     for (int i = 0; i < detectorSet.Length; i++)
     {
         Detector_Aff temp = new Detector_Aff()
         {
             Detector = detectorSet[i], Sample = sample, Distance = MatchingMachine.GetHammingDis(detectorSet[i], sample)
         };
         result.Add(temp);
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Compare 2 binary strings are equal or not.
 /// </summary>
 /// <param name="item1">1st binary string</param>
 /// <param name="item2">2nd binary string</param>
 /// <returns>Return TRUE if 2 binary strings are equal, return FALSE if not</returns>
 public static bool Compare2BinaryString(BinaryString item1, BinaryString item2)
 {
     for (int i = 0; i < item1.Value.Length; i++)
     {
         if (!(item1.Value[i] == item2.Value[i]))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 5
0
 /// <summary>
 /// Check 2 binary strings equal or not
 /// </summary>
 /// <param name="obj">The para that the binary string compare to</param>
 /// <returns></returns>
 public override bool Equals(object obj)
 {
     if (obj == null || !(obj is BinaryString))
     {
         return(false);
     }
     else
     {
         return(BinaryString.Compare2BinaryString(this, (BinaryString)obj));
     }
 }
Esempio n. 6
0
        public static int GetHammingAff(BinaryString item1, BinaryString item2)
        {
            int count  = 0;
            int length = item1.Value.Length;

            for (int i = 0; i < length; i++)
            {
                if (item1.Value[i] == item2.Value[i])
                {
                    count++;
                }
            }
            return(count);
        }
Esempio n. 7
0
        public void GlobalCleanXBasedOnY(List <BinaryString> X, HashSet <BinaryString> Y, int matchingThreshold, int threadCount)
        {
            //int threadCount = X.Count / limitCount;
            //if (X.Count % limitCount != 0) threadCount++;
            //int threadCount = 5;

            int limitCount = 0;

            if (X.Count >= 20)
            {
                limitCount = X.Count / threadCount;
                if (X.Count % threadCount != 0)
                {
                    threadCount++;
                }
            }
            else
            {
                threadCount = 1;
                limitCount  = X.Count;
            }
            List <Thread>          threads = new List <Thread>();
            List <CleanThreadUnit> units   = new List <CleanThreadUnit>();

            for (int i = 0; i < threadCount; i++)
            {
                BinaryString[] tempX = new BinaryString[(i == (threadCount - 1)) ? X.Count - i * limitCount : limitCount];
                X.CopyTo(i * limitCount, tempX, 0, tempX.Length);
                CleanThreadUnit cleanUnit = new CleanThreadUnit();
                units.Add(cleanUnit);
                threads.Add(new Thread(delegate() { cleanUnit.CleanXBasedOnY(tempX, Y, matchingThreshold); }));
            }
            for (int i = 0; i < threads.Count; i++)
            {
                threads[i].IsBackground = true;
                threads[i].Start();
            }
            for (int i = 0; i < threads.Count; i++)
            {
                threads[i].Join();
            }
            for (int i = 0; i < units.Count; i++)
            {
                cleanedSet.UnionWith(units[i].CleanedSet);
            }
        }
Esempio n. 8
0
        public BinaryString GenerateADetector(BinaryString pattern, int m)
        {
            Random rd     = new Random();
            int    length = pattern.Value.Length;

            bool[] newValue = new bool[pattern.Value.Length];
            pattern.Value.CopyTo(newValue, 0);
            List <int> choices = new List <int>();

            for (int i = 0; i < length; i++)
            {
                choices.Add(i);
            }
            for (int i = 0; i < m; i++)
            {
                int temp  = rd.Next(0, choices.Count);
                int index = choices[temp];
                choices.RemoveAt(temp);
                newValue[index] = rd.Next(0, 2) == 1;
            }
            return(new BinaryString(newValue));
        }
Esempio n. 9
0
 private HashSet <BinaryString> GetRelevantDetectors(BinaryString currGene, HashSet <BinaryString> detectors)
 {
     return(detectors);
 }
Esempio n. 10
0
 private double GetHA(BinaryString item1, BinaryString item2)
 {
     return(MatchingMachine.GetHammingDis(item1, item2));
 }
Esempio n. 11
0
 private int GetRCBA(BinaryString currGene, BinaryString detector, int r)
 {
     return(GetRCB(currGene, detector, r));
 }
Esempio n. 12
0
        public static bool HammingDisWithThreshold(BinaryString item1, BinaryString item2, int threshold)
        {
            int dis = GetHammingDis(item1, item2);

            return(dis <= threshold);
        }
Esempio n. 13
0
 public static int GetHammingDis(BinaryString item1, BinaryString item2)
 {
     return(item1.Value.Length - GetHammingAff(item1, item2));
 }