Пример #1
0
        double GetFitness(Chromosome a, char[] key, string s)
        {
            Substitution sub1   = new Substitution();
            FileStream   stream = new FileStream("myDictionary1.txt", FileMode.Open);
            StreamReader reader = new StreamReader(stream);
            string       str    = reader.ReadToEnd();

            stream.Close();
            string firsttext = s;

            str = s + str;
            string[] words      = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            char[]   encText    = sub1.EncodingText(firsttext, key);
            char[]   GotText    = sub1.DecodingText(encText, this.gens);
            string   GotTextStr = new string(GotText);

            string[] words2     = GotTextStr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            int      knownwords = 0;

            for (int x = 0; x < words2.Length; x++)
            {
                for (int y = 0; y < words.Length; y++)
                {
                    if (words2[x] == words[y])
                    {
                        knownwords++;
                        break;
                    }
                }
            }
            double result = 100 * (words2.Length - knownwords) / words2.Length;

            return(result);
        }
Пример #2
0
 public Form1()
 {
     InitializeComponent();
     sub = new Substitution();
     comboBox1.Items.Add("Tournament");
     comboBox1.Items.Add("Roulette Wheel");
 }