示例#1
0
        private static void WriteBest(BeesAlgorithm algorithm, string[] production_names)
        {
            Console.Write("Best pop:\t");
            var rez   = algorithm.GetTheBestBee();
            var names = ConvertNames(rez.Item1, production_names);

            for (int i = 0; i < names.Count; i++)
            {
                Console.Write(names[i] + '\t');
            }
            Console.WriteLine('\n' + rez.Item2.ToString());
        }
示例#2
0
        private static void LaunchBees()
        {
            int production_size = default;

            string[] production_names = default;
            float[]  ecologies        = default;
            int[]    costs            = default;
            int[]    profits          = default;
            int      a = default;

            Console.WriteLine("Choose input data:\n" +
                              "1 - from console;\n" +
                              "2 - from file;\n");
            int choose = int.Parse(Console.ReadLine());

            if (choose == 1)
            {
                ReadStartInfoFromConsole(ref production_size, ref production_names, ref ecologies, ref costs, ref profits, ref a);
            }
            else if (choose == 2)
            {
                ReadStartInfoFromFile(ref production_size, ref production_names, ref ecologies, ref costs, ref profits, ref a);
            }

            Console.Write("Enter scouts count: ");
            int scout_count = Convert.ToInt32(Console.ReadLine());

            BeesAlgorithm algorithm = new BeesAlgorithm(production_size, ecologies.ToList(), costs.ToList(), profits.ToList(), a);
            int           i_not     = 0;
            int           i         = 0;

            string[] rez_names = default;
            float    rez_cf    = default;
            Dictionary <float, List <string> > best = new Dictionary <float, List <string> >();

            best.Add(0, null);
            while (i_not < 30)
            {
                i++;
                algorithm.RunScouts();

                algorithm.GetTheBestScouts(3);

                algorithm.RunForagingBees();

                algorithm.LocalUpdate();
                WriteBest(algorithm, production_names);
                var rez = algorithm.GetTheBestBee();
                rez_names = ConvertNames(rez.Item1, production_names).ToArray();
                rez_cf    = rez.Item2;

                WriteIterationBestResultToFile(i, rez_cf);

                if (rez.Item2 <= best.Keys.Max())
                {
                    i_not++;
                }
                else
                {
                    i_not = 0;
                }

                if (!best.ContainsKey(rez_cf))
                {
                    best.Add(rez_cf, rez_names.ToList());
                }
            }
            var item = best.First(x => x.Key == best.Keys.Max());

            WriteResultToFile(item.Value.ToArray(), item.Key);
        }
        public void Run()
        {
            if (A == null)
            {
                MessageBox.Show("Załaduj najpierw dane");
                return;
            }
            IAlgorithm algorithm  = null;
            string     name       = "Algorytm";
            int        iterations = 0;

            //wybieranie algorytmu
            switch (SelectedTab)
            {
            case 0:
                algorithm  = new AntColony(_antColony.Ants, _antColony.MaxAssigns, _antColony.Alpha, _antColony.Beta, _antColony.Rho, _antColony.q, _antColony.Q0, _antColony.T0, _antColony.Q);
                name       = "AlgorytmMrówkowy";
                iterations = _antColony.MaxAssigns;

                break;

            case 1:
                algorithm = new BeesAlgorithm()
                {
                    M    = BeeAlgorithm.M,
                    Imax = BeeAlgorithm.Imax,
                    E    = beeAlgorithm.E,
                    Ngh  = beeAlgorithm.Ngh,
                    Nsp  = beeAlgorithm.Nsp,
                    Nb   = beeAlgorithm.Nb,
                    Nep  = beeAlgorithm.Nep
                };
                name       = "AlgorytmPszczeli";
                iterations = BeeAlgorithm.Imax;
                break;

            case 2:
                algorithm = new FireflyAlgorithm()
                {
                    M     = FireflyAlgorithm.M,
                    Imax  = FireflyAlgorithm.Imax,
                    Gamma = FireflyAlgorithm.Gamma,
                    Alfa  = FireflyAlgorithm.Alfa
                };
                name       = "AlgorytmŚwietlikowy";
                iterations = FireflyAlgorithm.Imax;
                break;

            case 3:
                algorithm  = new BeeAlgorithm(this.beeAlgorithmSBC.TotalNumberBees, this.beeAlgorithmSBC.NumberScout, this.beeAlgorithmSBC.MaxNumberVisits, this.beeAlgorithmSBC.MaxNumberCycles, this.beeAlgorithmSBC.ProbPersuasion, this.beeAlgorithmSBC.ProbMistake);
                name       = "AlgorytmPszczeliBSC";
                iterations = FireflyAlgorithm.Imax;
                break;
            }

            if (algorithm == null)
            {
                MessageBox.Show("Nie załadowano algorytmu.");
                return;
            }

            //ładowanie algorytmu
            algorithm.SetTestData((int[, ])A.Clone(), (int[, ])B.Clone(), size);
            var sth = new Chart(algorithm, iterations, name, this.iterationGap, filename);

            sth.Show();
        }