예제 #1
0
        private void repartirOrdenes()
        {
            try
            {
                GeneticAlgorithm a = new GeneticAlgorithm(agents, requestedServices);
                agente.hablar("Espera mientras resuelvo el problema");
                a.CreateInitialPopulation();
                a.CalculateFitnessGenes();
                for (int i = 0; i < a.GenerationsNumber; i++)
                {
                    a.CreateNextGeneration();
                    a.CalculateFitnessGenes();
                }


                Console.WriteLine(a.BestGenByGeneration());

                formResultado = new Form2();
                formResultado.Show();
                formResultado.cargarGen(a);
                agente.hablar("Así se debe repartir las órdenes");
            }
            catch (Exception ex)
            {
                agente.hablar("Debe cargar los agentes y órdenes primero");
            }
        }
예제 #2
0
        internal void cargarGen(GeneticAlgorithm a)
        {
            Gen gen = a.BestGenByGeneration();
            Dictionary <string, List <string> > dictionary = a.GetDictionary(gen);

            foreach (Agent r in gen.AgentList.AsEnumerable())
            {
                string nl = Environment.NewLine;
                string RS = "";
                foreach (string str in dictionary[r.ID].AsEnumerable())
                {
                    RequestedService rs;
                    Service          s;
                    rs = (from t in a.RequestedServiceList
                          where t.ID == str
                          select t).FirstOrDefault();
                    s = (from ss in XMLData.GetInstance().XMLServices
                         where ss.Code == rs.ServiceCode select ss).FirstOrDefault();

                    RS += "Order ID: " + rs.ID + ", Customer: " + rs.CustomerName +
                          ", Service: " + rs.ServiceCode + ", Time: " + s.Time + ", Commission: " + s.Commission + nl;
                }



                dgSalida.Rows.Add(r.ID, r.Name, r.EarnedCommission, r.WorkTime, RS);
                dgSalida.Rows[dgSalida.Rows.Count - 1].Height = dictionary[r.ID].Count * 30;
                Console.WriteLine(r);
            }
        }