コード例 #1
0
        public static void printResult(string s, string note, bool header)
        {
            string output = "Parameters Invidual:\n";

            output = output + "POPULATION_SIZE: " + Algorithm.POPULATION_SIZE + "\n";
            output = output + "GENERATION_COUNT: " + Algorithm.GENERATION_COUNT + "\n";
            output = output + "P_CROSSOVER: " + Algorithm.P_CROSSOVER + "\n";
            output = output + "P_MUTATION: " + Algorithm.P_MUTATION + "\n";
            output = output + "LENGTH: " + Algorithm.LENGTH + "\n";
            output = output + "CROSSIN_POINT: " + Algorithm.CROSSIN_POINT + "\n";
            output = output + "GOAL_DISTANCE: " + Algorithm.GOAL_DISTANCE + "\n";
            output = output + "DISTANCE_COST: " + Algorithm.DISTANCE_COST + "\n";
            output = output + "CAR_COST: " + Algorithm.CAR_COST + "\n";

            output = output + "\nParameters SuperInvidual:\n";
            output = output + "ORDER_CAPACITY: " + SuperInvidual.ORDER_CAPACITY + "\n";
            output = output + "CAR_COST: " + SuperInvidual.CAR_COST + "\n";
            output = output + "KM_COST: " + SuperInvidual.KM_COST + "\n";
            output = output + "OVERLOAD_PENALTY: " + SuperInvidual.OVERLOAD_PENALTY + "\n";
            output = output + "CROSSIN_POINT: " + InputOutput.getActiveOrdersCount() / 2 + "\n";
            output = output + "\n\n";

            DateTime thisDay = DateTime.Now;

            output = output + thisDay.ToString("yyyy-MM-dd HH:mm:ss") + "\n\n";

            if (header == true)
            {
                output = output + s;
            }
            else
            {
                output = s;
            }

            string address = Controller.pathOutput;
            string name    = note + "-" + thisDay.ToString("yyyy-MM-dd_HH-mm-ss");

            string printTo = (address + name) + ".txt";

            System.IO.TextWriter writeFile = new StreamWriter(printTo);

            writeFile.Write(output);
            writeFile.Flush();
            writeFile.Close();
            writeFile = null;
        }
コード例 #2
0
        /// <summary>
        /// Vygeneruji náhodné objednávky
        /// </summary>
        public void generateRandomOrders()
        {
            List <string> remainingCities = InputOutput.getUniqueColumnsValuesActiveOrders(1);

            var    rnd       = new Random();
            int    a         = rnd.Next(0, remainingCities.Count);
            string city      = remainingCities[a];
            int    cityCount = remainingCities.Count - 1;

            string newOrder   = remainingCities[a];
            string newOrderId = Cities.getId(remainingCities[a]);

            remainingCities.RemoveAt(a);
            int newOrderValue = Convert.ToInt32(Controller.activeOrdersTable.Rows[a]["Count"].ToString());

            for (int i = 0; i < cityCount; i++)
            {
                a = rnd.Next(0, remainingCities.Count);
                if (newOrderValue + Convert.ToInt32(Controller.activeOrdersTable.Rows[a]["Count"].ToString()) < ORDER_CAPACITY)
                {
                    newOrder   = newOrder + "-" + remainingCities[a];
                    newOrderId = newOrderId + "-" + Cities.getId(remainingCities[a]);
                    remainingCities.RemoveAt(a);
                    newOrderValue = newOrderValue + Convert.ToInt32(Controller.activeOrdersTable.Rows[a]["Count"].ToString());
                }
                else
                {
                    newOrder   = newOrder + ":" + newOrderValue;
                    newOrderId = newOrderId + ":" + newOrderValue;
                    this.ordersList.Add(newOrder);
                    this.ordersListIds.Add(newOrderId);
                    newOrder   = remainingCities[a];
                    newOrderId = Cities.getId(remainingCities[a]);
                    remainingCities.RemoveAt(a);
                    newOrderValue = Convert.ToInt32(Controller.activeOrdersTable.Rows[a]["Count"].ToString());
                }
            }

            if (newOrder.Length > 0)
            {
                newOrder   = newOrder + ":" + newOrderValue;
                newOrderId = newOrderId + ":" + newOrderValue;
                this.ordersList.Add(newOrder);
                this.ordersListIds.Add(newOrderId);
            }
        }
コード例 #3
0
ファイル: SuperInvidual.cs プロジェクト: LukasMisek/Bakalarka
        /// <summary>
        /// Vytvorim cestu nahodne s ohledem na maximalni kapacitu
        /// </summary>
        public SuperInvidual()
        {
            routes = new int[InputOutput.getActiveOrdersCount()];

            List <string> remainingCities = InputOutput.getUniqueColumnsValuesActiveOrders(1);

            // Vybiram nahodne mesto
            var rnd = new Random();
            // Ukazuji na aktualni mesto
            int a = rnd.Next(0, remainingCities.Count);
            // Aktualni ridic
            int driver = 1;

            // aktualni hodnota nakladu
            int routeValue = 0;

            for (int i = 0; i < remainingCities.Count; i++)
            {
                while (remainingCities[a] == "X")
                {
                    a = rnd.Next(0, remainingCities.Count);
                }

                if (routeValue + Convert.ToInt32(Controller.activeOrdersTable.Rows[a]["Count"].ToString()) < ORDER_CAPACITY)
                {
                    routeValue         = routeValue + Convert.ToInt32(Controller.activeOrdersTable.Rows[a]["Count"].ToString());
                    routes[a]          = driver;
                    remainingCities[a] = "X";
                }
                else
                {
                    driver             = driver + 1;
                    routeValue         = Convert.ToInt32(Controller.activeOrdersTable.Rows[a]["Count"].ToString());
                    routes[a]          = driver;
                    remainingCities[a] = "X";
                }
            }

            this.driverCount = driver;

            startAlgorithm();
        }
コード例 #4
0
ファイル: Controller.cs プロジェクト: LukasMisek/Bakalarka
        public Controller()
        {
            double fitness = 0;

            Console.ReadLine();
            InputOutput.start();

            /*
             * Console.WriteLine("vylepsuji populaci");
             * population.improve();
             *
             * population.showResultFull();
             * Console.WriteLine("\n\nUkazal jsem vsechny nadjedince prelozene");
             * Console.ReadLine();
             */


            /*
             * Console.WriteLine("\n\nPokousim se vylepsit populaci");
             * population.improve();
             * Console.WriteLine("\n\nVylepšil jsem populaci");
             * Console.ReadLine();
             *
             * population.showResultFull();
             * Console.WriteLine("\n\nUkazal jsem vsechny nadjedince prelozene");
             * Console.ReadLine();
             */



            Console.WriteLine("Pokusim se vylepsit populaci vicekrat");
            Console.ReadLine();

            Console.WriteLine("\n\nUkazal jsem vsechny nadjedince prelozene");
            Console.ReadLine();



            /*
             * population.updateBest();
             * InvidualOrder best = null;
             * best = population.GetBest();
             * Console.WriteLine("Stáhl jsem si nejlepsiho");
             * Console.ReadLine();
             *
             * best.showMe();
             * Console.WriteLine("ukazuji nejlepsiho");
             * Console.ReadLine();
             */

            /*
             * population.translateResult(9);
             * population.showResultTranslated(9);
             * Console.WriteLine("\n\nPřeložil jsem výsledek 9");
             * Console.ReadLine();
             */


            /*
             *
             * InvidualOrder in1 = new InvidualOrder();
             * InvidualOrder in2 = new InvidualOrder();
             * List<string> listek = new List<string>();
             * Console.WriteLine("ORDER 1:\n");
             * in1.showMe();
             * Console.WriteLine("ORDER 2:\n");
             * in2.showMe();
             * Console.WriteLine("KOMBINACE:\n");
             * InvidualOrder n = new InvidualOrder(in1, in2);
             * n.showMe();
             * Console.ReadLine();
             * Console.WriteLine("KOMBINACE ID:\n");
             * n.showMeId();
             * Console.ReadLine();
             *
             */
            /*
             * Console.WriteLine("calculate routes"); // spusteni algoritmu pro ordery
             * n.calculateRoutes();
             *
             * Console.WriteLine("sorted orders"); // vysledek algoritmu
             * n.showSortedOrders();
             * Console.ReadLine();
             *
             * List<Invidual> resultList;
             * Console.WriteLine("SHOW ME");
             * resultList = n.getOrderListSorted();
             * for (int j = 0; j < resultList.Count; j++)
             * {
             *  Console.WriteLine("{0,-25}{1,0}", ("Vzdálenost: " + resultList[j].getDistanceString()), resultList[j].showSequence());
             * }
             * Console.ReadLine();
             *
             * Console.WriteLine("TRANSLATE");
             * n.translateRoutes();
             * resultList = n.getOrderListSorted();
             * for (int j = 0; j < resultList.Count; j++)
             * {
             *  Console.WriteLine("{0,-25}{1,0}", ("Vzdálenost: " + resultList[j].getDistanceString()), resultList[j].showSequence());
             * }
             * Console.ReadLine();
             */
            /*
             *
             * Orders[]orders = new Orders[10];
             *
             * for (int i = 0; i < 10; i++)
             * {
             *  orders[i] = new Orders();
             * }
             *
             *
             * for (int i = 0; i < 10; i++)
             * {
             *  Console.WriteLine("\nORDER ZOBRAZUJI. CISLO:  " + i + "\n");
             *  orders[i].showMe();
             *  orders[i].showMeId();
             * }
             *
             * Console.ReadLine();
             *
             * for (int i = 0; i < orders.Length; i++) orders[i].calculateRoutes();
             *
             * Console.ReadLine();
             *
             *
             *
             * for (int i = 0; i < orders.Length; i++)
             * {
             *  Console.WriteLine("\nORDER ZOBRAZUJI. CISLO:  " + i + "\n");
             *  Console.WriteLine("Nesetříděné objednávky:");
             *  orders[i].showMe();
             *
             *  List<Invidual> resultList;
             *
             *  resultList = orders[i].getOrderListSorted();
             *  Console.WriteLine("Nepřeložené objednávky:");
             *  for (int j = 0; j < resultList.Count; j++)
             *  {
             *      Console.WriteLine("{0,-25}{1,0}", ("Vzdálenost: " + resultList[j].getDistanceString()), resultList[j].showSequence());
             *  }
             *
             *
             *  orders[i].translateRoutes();
             *
             *  resultList = orders[i].getOrderListSorted();
             *  Console.WriteLine("Roztříděné objednávky:");
             *  for (int j = 0; j < resultList.Count; j++)
             *  {
             *      Console.WriteLine("{0,-25}{1,0}", ("Vzdálenost: "+ resultList[j].getDistanceString()), resultList[j].showSequence());
             *  }
             *
             *  orders[i].calculatePrice();
             *
             *  Console.WriteLine("Cena varianty: " + orders[i].getCost());
             *  Console.WriteLine("Pocet aut:" + orders[i].getOrdersCount());
             *
             *
             * }
             * Console.WriteLine("Konec!");
             * Console.ReadLine();
             *
             */
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: LukasMisek/Bakalarka
        static void Main(string[] args)
        {
            // Oddelovac tisicu muze byt nastaven jinak na ruznych strojich. Timto nastavim "anglickou klavesnici"
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");

            InputOutput.start();

            for (int j = 1; j < 51; j++)
            {
                SuperPopulation sp = new SuperPopulation();
                sp.showMe();

                /*
                 * for (int i = 0; i < 1; i++)
                 * {
                 *  Console.WriteLine("pokousim se vylepsit po " + i);
                 *  sp.improve();
                 *  Console.WriteLine("vylepseno po " + i);
                 *  sp.showMe();
                 *  InputOutput.printResult(sp.getMe(), ("Test" + j + "_Record_Vnejsi0Vnitrni20_Gen" + i), true);
                 * }
                 */

                Console.WriteLine("\n\nDokončeno\n\n");

                SuperInvidual result = sp.GetBest();

                InputOutput.printResult(result.getMe(), "Test" + j + "_Result_Vnejsi0Vnitrni20", true);

                result.showMeFull();

                sp = null;
            }

            /*
             *
             * for (int i = 0; i < 20; i++)
             * {
             *  Console.WriteLine("pokousim se vylepsit po " + i);
             *  sp.improve();
             *  Console.WriteLine("vylepseno po " + i);
             *  sp.showMe();
             *  InputOutput.printResult(sp.getMe(), ("Test1_Record_Vnejsi20Vnitrni50_Gen" + i), true);
             * }
             *
             * Console.WriteLine("\n\nDokončeno\n\n");
             *
             * SuperInvidual result = sp.GetBest();
             *
             * InputOutput.printResult(result.getMe(), "Test1_Result_Vnejsi20Vnitrni50", true);
             *
             * result.showMeFull();
             *
             */
            /*
             *
             * SuperInvidual super = new SuperInvidual();
             *
             *
             *
             * super.showMeFull();
             * Console.ReadLine();
             *
             * Console.WriteLine("prelozen: " + super.checkOverload());
             * Console.ReadLine();
             *
             * SuperInvidual super2 = new SuperInvidual();
             *
             * super2.showMeFull();
             * Console.ReadLine();
             *
             * Console.WriteLine("prelozen: " + super2.checkOverload());
             * Console.ReadLine();
             *
             * SuperInvidual superNew = new SuperInvidual(super, super2);
             *
             * superNew.showMeFull();
             * Console.ReadLine();
             */


            /*
             * Console.WriteLine("prelozen: " + superNew.checkOverload());
             * Console.ReadLine();
             *
             * Console.WriteLine("prelozeni ktereho ridice? ");
             * int i = Convert.ToInt32(Console.ReadLine());
             * Console.WriteLine("prelozen: " + superNew.checkOverload(i));
             * Console.ReadLine();
             *
             * Console.WriteLine("veze: " + superNew.getDriverPallets(i));
             * Console.ReadLine();
             *
             * string[] cesta = new string[superNew.getDriverPallets(i)];
             * cesta = superNew.getSequence(i);
             * Functions.showArray(cesta);
             * Console.ReadLine();
             */

            /*
             * Console.WriteLine("poustim algoritmus");
             * superNew.startAlgorithm();
             * superNew.showMeRoutes();
             * Console.ReadLine();
             *
             * int num = superNew.getFitness();
             * Console.WriteLine("fitness: " + num);
             * Console.ReadLine();
             */



            // Controller controller = new Controller();

            /*
             * string[] s = { "ab", "cd", "dd", "aa", "ab" };
             *
             * Console.WriteLine("pred opravou");
             * Functions.showArray(s);
             *
             * string[] a = Functions.removeDuplicityStringArray(s);
             *
             * Console.WriteLine("po oprave");
             * Functions.showArray(a);
             *
             * Console.ReadLine();
             */
            //InputOutput.start();



            /*
             * Algorithm algoritmus;
             * Invidual result;
             *
             * // Pole jedinců, kteří tvoří objednávku (10 variant objednávek)
             * Orders[] vysledek = new Orders[10];
             *
             * // Zde je seznam všech variant objednávky
             * List<string> orderList = new List<string>();
             *
             * // Seznam názvů měst
             * //string cities = "!#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_abcdefghijklmnopqrstuvwxyz{|}~";
             * string cities = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
             *
             * // Vytvořím 10 skupin objednávek - 10 variant, kudy mohou vést cesty
             * for (int i = 0; i < vysledek.Length; i++) vysledek[i] = new Orders(cities);
             *
             * // Vytvořím jeden dlouhý seznam cest ze všech objednávek (Každá objednávka má několik cest)
             * for (int i = 0; i < vysledek.Length; i++) orderList.AddRange(vysledek[i].getOrdersList());
             *
             * // Ukážu všechny Jedince (každou skupinu objednávek)
             * for (int i = 0; i < vysledek.Length; i++)
             * {
             *  Console.WriteLine("Jedinec cislo "+i+":");
             *  vysledek[i].showMatrix();
             * }
             *
             * Console.ReadLine();
             *
             *
             *
             * int topVzdalenost = 12345675;
             * int delka;
             * int index = 0;
             * List<int> vzdalenostiVysledek = new List<int>();
             * List<string> jedinci = new List<string>();
             * List<Invidual> topJedinci = new List<Invidual>();
             *
             * List<Invidual> currentJedinci = new List<Invidual>();
             *
             * int citac = 0;
             *
             * Console.WriteLine("\n\n\nVypocital jsem tyto nejkratsi cesty:");
             * for (int i = 0; i < vysledek.Length; i++)
             * {
             *  jedinci = vysledek[i].getOrdersList();
             *  delka = 0;
             *  Console.WriteLine("Skupina cislo:" + i);
             *  for (int j = 0; j < jedinci.Count; j++)
             *  {
             *      if (jedinci[j].Length > 1)
             *      {
             *          citac++;
             *          algoritmus = new Algorithm(jedinci[j], jedinci[j].Length);
             *          result = algoritmus.start();
             *          delka = delka + result.getDistance();
             *          currentJedinci.Add(result);
             *
             *          Console.WriteLine(citac + " " + result.getSequence() + "\tVzdalenost: " + result.getDistance());
             *      }
             *
             *  }
             *
             *  Console.WriteLine("Celkova delka:" + delka + "\n");
             *  vzdalenostiVysledek.Add(delka);
             *
             *  if (delka < topVzdalenost)
             *  {
             *      topVzdalenost = delka;
             *      topJedinci.Clear();
             *      topJedinci.AddRange(currentJedinci);
             *      index = i;
             *  }
             *  jedinci.Clear();
             *  currentJedinci.Clear();
             * }
             *
             * Console.WriteLine("\n\n\nMyslim ze tohle je top skupina: (" + index + ")");
             * for (int i = 0; i < topJedinci.Count; i++)
             * {
             *  Console.WriteLine(topJedinci[i].getSequence());
             * }
             * Console.WriteLine("Celkova vzdalenost: " + topVzdalenost);
             *
             * Console.WriteLine("\n\n\nVypocet vzdalenosti po jednom: " + topVzdalenost);
             *
             * int counter = 0;
             *
             * for (int i = 0; i < orderList.Count; i++)
             * {
             *  if (orderList[i].Length > 1)
             *  {
             *      algoritmus = new Algorithm(orderList[i], orderList[i].Length);
             *      result = algoritmus.start();
             *      Console.WriteLine(counter + " Nejlepší jedinec: " + result.getSequence() + "\tVzdálenost:" + result.getDistance());
             *      counter++;
             *  }
             *  else
             *  {
             *      Console.WriteLine(counter + " Nejlepší jedinec: " + orderList[i]);
             *      counter++;
             *  }
             *
             * }
             *
             * Console.ReadLine();
             */
        }