示例#1
0
        public static List <Taxon> ForelAlgo(List <FObject> objects, int count)
        {
            double         mx      = double.MinValue;
            double         mn      = double.MaxValue;
            List <FObject> tmpobj1 = ListCopyXX(objects);

            // tmpobj = ListCopyXX(objects);
            foreach (FObject obj in tmpobj1)
            {
                double mxx = getFmax(obj);
                double mnx = getFmin(obj);
                if (mxx > mx)
                {
                    mx = getFmax(obj);
                }
                if (mnx < mn)
                {
                    mn = getFmin(obj);
                }
            }
            foreach (FObject obj in tmpobj1)
            {
                int i = 0;

                /*foreach (double tp in obj.options)
                 * {
                 *  obj.options[i] =
                 *  i++;
                 * }*/
                for (int ll = 0; ll < obj.options.Count; ++ll)
                {
                    obj.options[ll] = (obj.options[ll] - mn) / (mx - mn);
                }
            }
            List <FObject> tmpobj;
            List <Taxon>   tlist = new List <Taxon>();
            int            k     = 0;
            double         R     = 0;
            int            size  = (tmpobj1[0].options.Count);

            R = Math.Sqrt(size) / 2;
            Random rnd = new Random();



            int p = 0;

            while (k < count)
            {
                tmpobj = ListCopy(tmpobj1);
                //k = 0;
                R = R - ((p + 1) * R / 10);
                k = 0;
                tlist.Clear();
                while (tmpobj.Count != 0)
                {
                    List <FObject> tax = new List <FObject>();


                    int     c  = rnd.Next(0, tmpobj.Count);
                    FObject tm = tmpobj.ElementAt(c);

                    do
                    {
                        foreach (FObject ob in tmpobj)
                        {
                            double en = EuclideNorm(ob, tm);
                            if (en <= R)
                            {
                                tax.Add(ob);
                            }
                        }
                        FObject ms = getMassCenter(tax, tm.options.Count);
                        if (tm.isEqual(ms))
                        {
                            break;
                        }
                        else
                        {
                            tm = ms;
                            tax.Clear();
                        }
                    } while (true);

                    Taxon tx = new Taxon();
                    tx.obj_list    = tax;
                    tx.mass_center = tm;
                    tlist.Add(tx);
                    DeleteObjects(tax, tmpobj);
                    k++;
                }
                p += 1;
            }
            return(tlist);
        }