Пример #1
0
        /// <summary>
        /// Посчитать количество верных клозов
        /// </summary>
        private bool EqualsTrueClozes(byte[] valuesOperands)
        {
            tempSumTrueFirstClozes  = 0;
            tempSumTrueSecondClozes = 0;

            for (int i = 0; i < firstClozes.Count; i++)
            {
                firstString = firstClozes[i];
                if (i < secondClozes.Count)
                {
                    secondString = secondClozes[i];
                }

                for (int j = 0; j < valuesOperands.Length; j++)
                {
                    firstString  = firstString.Replace(allOperands[j], char.Parse(valuesOperands[j].ToString()));
                    secondString = secondString.Replace(allOperands[j], char.Parse(valuesOperands[j].ToString()));
                }

                if (ReplaceOrAnd.WorkWithOrAndV2(firstString))
                {
                    tempSumTrueFirstClozes++;
                }
                if (ReplaceOrAnd.WorkWithOrAndV2(secondString))
                {
                    tempSumTrueSecondClozes++;
                }
            }

            return(tempSumTrueFirstClozes + tempSumTrueSecondClozes >= this.sumTrueFirstClozes + this.sumTrueSecondClozes ? true : false);
        }
Пример #2
0
        /// <summary>
        /// Посчитать количество верных клозов
        /// </summary>
        private void CalculateTrueClozes()
        {
            sumTrueFirstClozes  = 0;
            sumTrueSecondClozes = 0;

            for (int i = 0; i < firstClozes.Count; i++)
            {
                string firstString = firstClozes[i];
                for (int j = 0; j < valuesOperands.Length; j++)
                {
                    firstString = firstString.Replace(allOperands[j], char.Parse(valuesOperands[j].ToString()));
                }

                if (ReplaceOrAnd.WorkWithOrAndV2(firstString))
                {
                    sumTrueFirstClozes++;
                }
            }
            for (int i = 0; i < secondClozes.Count; i++)
            {
                string secondString = secondClozes[i];
                for (int j = 0; j < valuesOperands.Length; j++)
                {
                    secondString = secondString.Replace(allOperands[j], char.Parse(valuesOperands[j].ToString()));
                }

                if (ReplaceOrAnd.WorkWithOrAndV2(secondString))
                {
                    sumTrueSecondClozes++;
                }
            }
        }
Пример #3
0
        public List <string> initAlgorithm(string[] local, bool onlyFirstData, string input, int maxtime)
        {
            sw.Reset();
            sw.Start();
            List <string>            resultList = new List <string>();
            Dictionary <string, int> letternum  = new Dictionary <string, int>();

            int count = 0;

            foreach (string t in local)
            {
                if (letternum.ContainsKey(t))
                {
                    continue;
                }
                letternum.Add(t, count);
                count++;
            }
            int numChars = letternum.Count;

            List <char[]> ses = new Combinations().Combine(numChars);

            string local2 = input.Replace(" ", "").Replace("^", ",").Replace("v", ".");

            foreach (char[] se in ses)
            {
                string local3     = local2;
                string tempstring = "";
                foreach (var i in letternum)
                {
                    int    ubicacoin = letternum[i.Key];
                    string resulado  = se[ubicacoin].ToString();
                    local3      = local3.Replace(i.Key, resulado);
                    tempstring += i.Key + "=" + resulado + ", ";
                }

                bool resultad = ReplaceOrAnd.WorkWithOrAndV2(local3);

                if (!resultad)
                {
                    continue;
                }
                resultList.Add(tempstring + ": " + resultad);
                if (onlyFirstData)
                {
                    break;
                }
                if (sw.Elapsed.TotalSeconds >= maxtime)
                {
                    break;
                }
            }
            _numChars = numChars;
            sw.Stop();
            return(resultList);
        }
Пример #4
0
        /// <summary>
        /// Проверить строку клозов на правильность
        /// </summary>
        /// <param name="listOfClozes"></param>
        /// <returns></returns>
        private bool CheckCorrectly(string formule)
        {
            string fornuleTemp = formule;

            for (int i = 0; i < valuesOperands.Length; i++)
            {
                fornuleTemp = fornuleTemp.Replace(allOperands[i].ToString(), valuesOperands[i].ToString());
            }

            return(ReplaceOrAnd.WorkWithOrAndV2(fornuleTemp));
        }
Пример #5
0
        private bool CheckCorrectly(string formule)
        {
            string fornuleTemp = formule;

            for (int i = 0; i < letter1.Count; i++)
            {
                fornuleTemp = fornuleTemp.Replace(letter1[i], letterState[i].ToString());
            }

            return(ReplaceOrAnd.WorkWithOrAndV2(fornuleTemp));
        }
Пример #6
0
        private bool CheckCorrectly(string formule, char[] values)
        {
            string fornuleTemp = formule;

            for (int i = 0; i < values.Length; i++)
            {
                fornuleTemp = fornuleTemp.Replace(letter1[i], values[i].ToString());
            }

            return(ReplaceOrAnd.WorkWithOrAndV2(fornuleTemp));
        }
Пример #7
0
        internal List <string> InitRandom(string input, bool onlyFirstData)
        {
            //_randomAlgorithm.RandomMethod(local2); // решение жадным методом
            Numtrue = 0;
            Sw.Reset();
            Sw.Start();
            string[]                 local      = input.Split(new[] { ' ', '|', '&', '-' }, StringSplitOptions.RemoveEmptyEntries);
            List <string>            resultList = new List <string>();
            Dictionary <string, int> letternum  = new Dictionary <string, int>();
            List <string>            usedComb   = new List <string>();

            int count = 0;

            foreach (string t in local)
            {
                if (letternum.ContainsKey(t))
                {
                    continue;
                }
                letternum.Add(t, count);
                count++;
            }

            NumChars = letternum.Count;
            char[] actualComb = new char[NumChars];
            int    ses        = new Combinations().Combine(NumChars).Count;

            while (usedComb.Count < ses)
            {
                string comb;
                do
                {
                    comb = "";
                    for (int i = 0; i < NumChars; i++)
                    {
                        actualComb[i] = rnd.Next(0, 2) == 0 ? '0' : '1';
                        comb         += actualComb[i].ToString();
                    }
                    if (!usedComb.Contains(comb))
                    {
                        break;
                    }
                    if (Sw.Elapsed.TotalSeconds >= _maxtime)
                    {
                        outTime = true;
                        break;
                    }
                } while (usedComb.Count < ses);

                usedComb.Add(comb);

                string local3     = input.Replace(" ", "").Replace("^", ",").Replace("v", ".");
                string tempstring = "";
                foreach (KeyValuePair <string, int> i in letternum)
                {
                    int    ubicacoin = letternum[i.Key];
                    string resulado  = actualComb[ubicacoin].ToString();
                    local3      = local3.Replace(i.Key, resulado);
                    tempstring += i.Key + "=" + resulado + ", ";
                }

                bool resultad = ReplaceOrAnd.WorkWithOrAndV2(local3);

                if (resultad)
                {
                    if (outTime)
                    {
                        resultList.Add(tempstring + ": " + resultad + "-- outTime");
                    }
                    else
                    {
                        resultList.Add(tempstring + ": " + resultad);
                    }

                    Numtrue++;
                    if (onlyFirstData)
                    {
                        break;
                    }
                }
                //90000
                if (Sw.Elapsed.TotalSeconds >= _maxtime || outTime)
                {
                    outTime = true;
                    break;
                }
            }

            Sw.Stop();

            Numtrue = resultList.Count;
            return(resultList);
        }