Exemple #1
0
        public virtual void oneIterate(FS result)
        {
            theScouts.Clear();
            theWorkers.Clear();
            baseLine  = result.ErrorLearnSamples(result.RulesDatabaseSet[0]);
            Best      = result.RulesDatabaseSet[0];
            theScout  = null;
            theWorker = null;
            for (int s = 0; s < countScouts; s++)
            {
                double goodsLine = -1;
                int    ztryes    = 0;
                while ((goodsLine <= 0) && (ztryes < 100))
                {
                    theScout = new Scout(Best, theFuzzySystem);
                    theScout.generateNewRule(typeTerm, rand);
                    goodsLine = theScout.getGoodsImproove(baseLine);
                }
                theScouts.Add(theScout);
            }
            BeeComparer toBeeSort = new BeeComparer();

            theScouts.Sort(toBeeSort);
            KnowlegeBaseRules ScoutBest = theScouts[theScouts.Count - 1].PositionOfBee;
            int ScoutBestNumRule        = theScouts[theScouts.Count - 1].NumOFRule;

            for (int w = 0; w < countWorkers; w++)
            {
                theWorker = new Worker(ScoutBest, theFuzzySystem);
                theWorkers.Add(theWorker);
                theWorkers[theWorkers.Count - 1].WorkerFly(ScoutBestNumRule, rand);
                theWorkers[theWorkers.Count - 1].getGoodsImproove(baseLine);
            }

            theWorkers.Sort(toBeeSort);

            if (theScouts[theScouts.Count - 1].Goods > theWorkers[theWorkers.Count - 1].Goods)
            {
                Best = theScouts[theScouts.Count - 1].PositionOfBee;
            }
            else
            {
                Best = theWorkers[theWorkers.Count - 1].PositionOfBee;
            }
            theFuzzySystem.RulesDatabaseSet[0] = Best;
        }
Exemple #2
0
        public virtual void oneIterate(FS result)
        {
            //    theScouts.Clear();
            //  theWorkers.Clear();
            baseLine = result.ErrorLearnSamples(result.RulesDatabaseSet[0]);
            Best     = result.RulesDatabaseSet[0];

            /*     for (int s = 0; s < countScouts; s++)
             *   {
             *       double goodsLine = -1;
             *       int ztryes = 0;
             *       while ((goodsLine <= 0) && (ztryes < 100))
             *       {
             *           theScout = new Scout(Best, theFuzzySystem);
             *           theScout.generateNewRule(typeTerm, rand);
             *           goodsLine = theScout.getGoodsImproove(baseLine);
             *       ztryes++;
             *       }
             *       theScouts.Add(theScout);
             *   }*/
            Parallel.For(0, countScouts, new ParallelOptions {
                MaxDegreeOfParallelism = countScouts, TaskScheduler = null
            }, s =>
                         //        for (int s = 0; s < countScouts; s++)
            {
                double goodsLine = -1;
                int ztryes       = 0;
                while ((goodsLine <= 0) && (ztryes < 100))
                {
                    theScouts[s] = new Scout(Best, theFuzzySystem);
                    theScouts[s].generateNewRule(typeTerm, rand.Value);
                    goodsLine = theScouts[s].getGoodsImproove(baseLine);
                    ztryes++;
                }
            }
                         );



            BeeComparer toBeeSort = new BeeComparer();

            Array.Sort(theScouts, toBeeSort);
            KnowlegeBaseRules ScoutBest = theScouts[countScouts - 1].PositionOfBee;
            int ScoutBestNumRule        = theScouts[countScouts - 1].NumOFRule;

            /*for (int w = 0; w < countWorkers; w++)
             * {
             *  theWorker = new Worker(ScoutBest, theFuzzySystem);
             *  theWorkers.Add(theWorker);
             *  theWorkers[theWorkers.Count - 1].WorkerFly( ScoutBestNumRule, rand);
             *  theWorkers[countWorkers*3 - 1].getGoodsImproove(baseLine);
             * }*/

            for (int a = 0; a < 3; a++)
            {
                Parallel.For(0, countWorkers, new ParallelOptions {
                    MaxDegreeOfParallelism = countWorkers, TaskScheduler = null
                }, w =>
                             //   for (int w = 0; w < countWorkers; w++)
                {
                    theWorkers[countWorkers * a + w] = new Worker(theScouts[theScouts.Length - 1 - a].PositionOfBee, theFuzzySystem);
                    theWorkers[countWorkers * a + w].WorkerFly(ScoutBestNumRule, rand.Value);
                    theWorkers[countWorkers * a + w].getGoodsImproove(baseLine);
                }
                             );
            }

            Array.Sort(theWorkers, toBeeSort);

            if (theScouts[countScouts - 1].Goods > theWorkers[countWorkers * 3 - 1].Goods)
            {
                Best = theScouts[countScouts - 1].PositionOfBee;
            }
            else
            {
                Best = theWorkers[countWorkers * 3 - 1].PositionOfBee;
            }
            theFuzzySystem.RulesDatabaseSet[0] = Best;
        }