Exemple #1
0
        private IDataSet <string[]> getRandomSet()
        {
            IDataSet <string[]> temp = Factory.getObject <IDataSet <string[]> >();

            temp.AddItem(getRandomData());

            IDataItem <string[]> di = Factory.getObject <IDataItem <string[]> >();

            di.setValue(new string[3]);

            di.getValue()[0] = r.Next(1, 4).ToString();

            temp.AddItem(di);

            temp.AddItem(getRandomData());

            if (temp.GetItem(0).getValue() != temp.GetItem(2).getValue())
            {
                return(temp);
            }
            else
            {
                return(getRandomSet());
            }
        }
Exemple #2
0
        private double GetMatches(IDataSet <string[]> di)
        {
            IList <int> matches = Factory.getObject <IList <int> >();

            for (int i = 0; i < fileData.Length; i++)
            {
                int    col = int.Parse(di.GetItem(0).getValue()[0]);
                string val = di.GetItem(0).getValue()[1];

                if (fileData[i].GetItem(col).getValue() == val)
                {
                    matches.Add(i);
                }
            }

            for (int i = 0; i < matches.Count; i++)
            {
                int    col = int.Parse(di.GetItem(2).getValue()[0]);
                string val = di.GetItem(2).getValue()[1];

                if (fileData[matches[i]].GetItem(col).getValue() != val)
                {
                    matches.RemoveAt(i);
                }
            }

            return(((double)matches.Count / (double)fileData.Length) * 100);
        }
Exemple #3
0
        public override IDataSet <string[]> mutate(IDataSet <string[]> child)
        {
            int n = r.Next(0, 3);

            if (n == 1)
            {
                child.GetItem(1).getValue()[0] = r.Next(1, 4).ToString();
            }
            else
            {
                IDataItem <string[]> di = getRandomData();

                if (di.getValue()[0] == child.GetItem(n).getValue()[0])
                {
                    child = mutate(child);
                }
                else
                {
                    child.GetItem(n).setValue(di.getValue());
                }
            }

            return(child);
        }
        public IDataSet <T> CreateChild(IDataSet <T> p1, IDataSet <T> p2)
        {
            if (p1.Length() != p2.Length())
            {
                throw new Exception("parent sizes don't match");
            }

            IDataSet <T> child = new myDataSet <T>(p1.Length());

            for (int i = 0; i < p1.Length(); i++)
            {
                if (i % 2 == 0)
                {
                    child.SetValue(p1.GetItem(i).getValue(), i);
                }
                else
                {
                    child.SetValue(p2.GetItem(i).getValue(), i);
                }
            }

            return(child);
        }