예제 #1
0
        static void Main(string[] args)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            Console.WriteLine("ABC Started...");
            // Storages
            StoragesData storagesData = new StoragesData(9);

            // Hive
            Hive hive = new Hive(totalNumberBees, numberInactive, numberActive, numberScout, maxNumberVisits, maxNumberCycles, storagesData, storageId, foodType, foodValue);

            hive.Solve();
            Console.WriteLine("ABC Ended...");
            Console.WriteLine("-----------------------------------------------------------");
            Console.WriteLine("ABC Solution :");
            hive.printSolution();
            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("Time elapsed: " + elapsedMs);
            string s = Console.ReadLine();
        }
예제 #2
0
        public Hive(int totalNumberBees, int numberInactive,
                    int numberActive, int numberScout, int maxNumberVisits,
                    int maxNumberCycles, StoragesData storagesData, int storageId, int foodType, int foodValue)
        {
            random = new Random(0);

            this.totalNumberBees = totalNumberBees;
            this.numberInactive  = numberInactive;
            this.numberActive    = numberActive;
            this.numberScout     = numberScout;
            this.maxNumberVisits = maxNumberVisits;
            this.maxNumberCycles = maxNumberCycles;
            this.storageId       = storageId;
            this.foodType        = foodType;
            this.foodValue       = foodValue;

            this.storagesData = storagesData;

            this.bees             = new Bee[totalNumberBees];
            this.bestMemoryMatrix = GenerateRandomMemoryMatrix();
            //Console.WriteLine(getStorageById(bestMemoryMatrix[bestMemoryMatrix.Count - 1]).getResources());
            foreach (Tuple <Resource, int> r in getStorageById(bestMemoryMatrix[bestMemoryMatrix.Count - 1]).getResources())
            {
                //Console.WriteLine(r.Item1);
                if (r.Item1.getType() == foodType)
                {
                    this.bestResourceCost = r.Item2;
                }
            }
            this.bestMeasureOfQuality = MeasureOfQuality(this.bestMemoryMatrix) + this.bestResourceCost;

            this.indexesOfInactiveBees = new List <int>();
            foreach (int i in this.bestMemoryMatrix)
            {
                Console.Write(i);
            }
            Console.WriteLine();
            Console.WriteLine(this.bestMeasureOfQuality);
            Console.WriteLine("After .......................");
            for (int i = 0; i < totalNumberBees; ++i)
            {
                int currStatus;
                if (i < numberInactive)
                {
                    currStatus = 0; // inactive
                    indexesOfInactiveBees.Add(i);
                }
                else if (i < numberInactive + numberScout)
                {
                    currStatus = 2; // scout
                }
                else
                {
                    currStatus = 1; // active
                }
                List <int> randomMemoryMatrix = GenerateRandomMemoryMatrix();
                int        randomResourceCost = 0;
                foreach (Tuple <Resource, int> r in getStorageById(randomMemoryMatrix[randomMemoryMatrix.Count - 1]).getResources())
                {
                    if (r.Item1.getType() == foodType)
                    {
                        randomResourceCost = r.Item2;
                    }
                }
                double mq             = MeasureOfQuality(randomMemoryMatrix) + randomResourceCost;
                int    numberOfVisits = 0;

                bees[i] = new Bee(currStatus, randomMemoryMatrix, mq, numberOfVisits);

                if (bees[i].measureOfQuality < bestMeasureOfQuality)
                {
                    this.bestMemoryMatrix     = bees[i].memoryMatrix;
                    this.bestMeasureOfQuality = bees[i].measureOfQuality;
                }
            }
            foreach (int i in this.bestMemoryMatrix)
            {
                Console.Write(i);
            }
            Console.WriteLine();
            Console.WriteLine(this.bestMeasureOfQuality);
        }