Пример #1
0
        public Hive(BackgroundWorker backgroundWorker,int totalNumberBees, int numberScout, int maxNumberVisits, int maxNumberCycles,
            double probPersuasion, double probMistake, TestData data)
        {
            random = new Random(0);
            this._backgroundWorker = backgroundWorker;
            this.totalNumberBees = totalNumberBees;
            this.numberScout = numberScout;
            this.numberInactive = this.totalNumberBees - this.numberScout;
            this.numberActive = 0;
            this.maxNumberVisits = maxNumberVisits;
            this.maxNumberCycles = maxNumberCycles;
            this.probPersuasion = probPersuasion;
            this.probMistake = probMistake;
            this.data = data;

            this.costs = new int[maxNumberCycles];

            this.bees = new BeeSBC[totalNumberBees];
            this.bestMemoryMatrix = GenerateRandomMemoryMatrix(); // alternative initializations are possible
            this.bestMeasureOfQuality = MeasureOfQuality(this.bestMemoryMatrix);

            this.indexesOfInactiveBees = new int[numberInactive]; // indexes of bees which are currently inactive

            for (int i = 0; i < totalNumberBees; ++i) // initialize each bee, and best solution
            {
                int currStatus; // depends on i. need status before we can initialize Bee
                if (i < numberInactive)
                {
                    currStatus = 0; // inactive
                    indexesOfInactiveBees[i] = i; // curr bee is inactive
                }
                else if (i < numberInactive + numberScout)
                {
                    currStatus = 2; // scout
                }
                else
                {
                    currStatus = 1; // active
                }

                int[] randomMemoryMatrix = GenerateRandomMemoryMatrix();
                int mq = MeasureOfQuality(randomMemoryMatrix);
                int numberOfVisits = 0;

                bees[i] = new BeeSBC(currStatus, randomMemoryMatrix, mq, numberOfVisits); // instantiate current bee

                // does this bee have best solution?
                if (bees[i].measureOfQuality < bestMeasureOfQuality) // curr bee is better (< because smaller is better)
                {
                    Array.Copy(bees[i].memoryMatrix, this.bestMemoryMatrix, bees[i].memoryMatrix.Length);
                    this.bestMeasureOfQuality = bees[i].measureOfQuality;
                }
            } // each bee
        }
Пример #2
0
        public Hive(BackgroundWorker backgroundWorker, int totalNumberBees, int numberScout, int maxNumberVisits, int maxNumberCycles,
                    double probPersuasion, double probMistake, TestData data)
        {
            random = new Random(0);
            this._backgroundWorker = backgroundWorker;
            this.totalNumberBees   = totalNumberBees;
            this.numberScout       = numberScout;
            this.numberInactive    = this.totalNumberBees - this.numberScout;
            this.numberActive      = 0;
            this.maxNumberVisits   = maxNumberVisits;
            this.maxNumberCycles   = maxNumberCycles;
            this.probPersuasion    = probPersuasion;
            this.probMistake       = probMistake;
            this.data = data;

            this.costs = new int[maxNumberCycles];

            this.bees                 = new BeeSBC[totalNumberBees];
            this.bestMemoryMatrix     = GenerateRandomMemoryMatrix(); // alternative initializations are possible
            this.bestMeasureOfQuality = MeasureOfQuality(this.bestMemoryMatrix);

            this.indexesOfInactiveBees = new int[numberInactive]; // indexes of bees which are currently inactive

            for (int i = 0; i < totalNumberBees; ++i)             // initialize each bee, and best solution
            {
                int currStatus;                                   // depends on i. need status before we can initialize Bee
                if (i < numberInactive)
                {
                    currStatus = 0;               // inactive
                    indexesOfInactiveBees[i] = i; // curr bee is inactive
                }
                else if (i < numberInactive + numberScout)
                {
                    currStatus = 2; // scout
                }
                else
                {
                    currStatus = 1; // active
                }

                int[] randomMemoryMatrix = GenerateRandomMemoryMatrix();
                int   mq             = MeasureOfQuality(randomMemoryMatrix);
                int   numberOfVisits = 0;

                bees[i] = new BeeSBC(currStatus, randomMemoryMatrix, mq, numberOfVisits); // instantiate current bee

                // does this bee have best solution?
                if (bees[i].measureOfQuality < bestMeasureOfQuality) // curr bee is better (< because smaller is better)
                {
                    Array.Copy(bees[i].memoryMatrix, this.bestMemoryMatrix, bees[i].memoryMatrix.Length);
                    this.bestMeasureOfQuality = bees[i].measureOfQuality;
                }
            } // each bee
        }     // Hive constructor