Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            EALoop ea = new EALoop();

            Console.WriteLine("STARTING");
            SocialNetwork socialNetwork = new SocialNetwork();
            DataCollector data          = new DataCollector();
            List <Agent>  population    = new List <Agent>();
            Dialogue      dialogue      = new Dialogue();
            int           generations   = 1;

            for (int i = 0; i < populationSize; i++)
            {
                population.Add(new Agent(ea.AgentIdCounter));
                ea.AgentIdCounter++;
            }
            List <Agent> speakerPool = new List <Agent>();

            foreach (Agent a in population)
            {
                if (socialNetwork.getAgentsConnections(a) != null)
                {
                    speakerPool.Add(a);
                }
            }
            Console.WriteLine("Speaker pool: " + speakerPool.Count);
            ea.dialogueThreads(socialNetwork, speakerPool, population);

            ea.fitnessOfPopulation(population, socialNetwork);
            population = ea.survivalSelection(population, socialNetwork);
            data.addDiscreteGraph(population, socialNetwork, generations);
            data.addFitnessData(population);
            data.setDialogues(population);
            ea.addFitnessDegreeData(population, socialNetwork, data);
            data.setUniqueWords(population);

            ea.updateAges(population);


            while (generations < Totalgenerations)
            {
                generations++;
                Console.WriteLine("\nGeneration number: " + generations);
                //Console.WriteLine("Nodes in the socialnetwork: " + socialNetwork.socialNetwork.Count);

                //--   MAKE CHILDREN   --//
                //Console.WriteLine("Size of population before children is made: " + population.Count);
                population.AddRange(ea.makeChildren(population, socialNetwork));
                //Console.WriteLine("Size of population after children was made: " + population.Count);

                //--    PERFORM DIALOGUES   --//
                //Console.WriteLine("socialnetwork count  "+socialNetwork.socialNetwork.Count);
                speakerPool = new List <Agent>();
                for (int q = 0; q < population.Count; q++)
                {
                    //Console.WriteLine("index: " + q);
                    if (population[q] == null)
                    {
                        population.RemoveAt(q);
                    }
                    else if (socialNetwork.getAgentsConnections(population[q]) != null && socialNetwork.getAgentsConnections(population[q]).Count > 0)
                    {
                        speakerPool.Add(population[q]);
                    }
                }
                Console.WriteLine("Speaker pool: " + speakerPool.Count);
                ea.dialogueThreads(socialNetwork, speakerPool, population);

                //ea.succcessfullDialogues = 0;
                //Console.WriteLine("Dialogues performed");

                //--    CALCULATE FITNESS   --//
                ea.fitnessOfPopulation(population, socialNetwork);


                //--    SURVIVAL SELECTION   --//
                population = ea.survivalSelection(population, socialNetwork);

                //--   DATA GATHERING   --//
                data.setDialogues(population);
                data.setUniqueWords(population);
                data.addFitnessData(population);
                if (generations % 5 == 0)
                {
                    data.addDiscreteGraph(population, socialNetwork, generations);
                }
                ea.addFitnessDegreeData(population, socialNetwork, data);

                ea.updateAges(population);

                //Console.WriteLine("Size of population after survival selection: " + population.Count);
            }
            Console.WriteLine("fitness data: " + data.getFitnessdata().Count + "\ndialogue data: " + data.getDialogues().Count + "\nUnique words data: " + data.getUniqueWords().Count);
            data.writeToFiles();
            data.addDiscreteGraph(population, socialNetwork, generations);
            Console.Write("Press any button to end");
        }
Ejemplo n.º 2
0
        private void addFitnessDegreeData(List <Agent> population, SocialNetwork socialNetwork, DataCollector d)
        {
            double C = 0.5;
            double allConnections     = 0;
            double AvgWeight          = 0;
            double learnRateSum       = 0;
            double totalVocLen        = 0;
            double speakToParentsGene = 0;
            double extrovertProb      = 0;

            foreach (Agent a in population)
            {
                double agentsAvgWeight   = 0;
                double agentsConnections = 0;
                speakToParentsGene += a.getGenome().getNormalisedGenome()[5] * speakToParentsConstant;
                List <double> genome = a.getGenome().getValuesGenome();
                extrovertProb += ((genome[3] + (100 - genome[6]) / 200) * C) / 100;
                totalVocLen   += a.getVocabulary().getVocabulary().Count;
                List <double> normGenome = a.getGenome().getNormalisedGenome();
                learnRateSum += (normGenome[0] + normGenome[8] + normGenome[9] - normGenome[4] - normGenome[1] - normGenome[7]);
                if (socialNetwork.getAgentsConnections(a) != null && socialNetwork.getAgentsConnections(a).Count > 0)
                {
                    foreach (var i in socialNetwork.getAgentsConnections(a))
                    {
                        if (i.Value > 0.0)
                        {
                            agentsConnections++;
                            agentsAvgWeight += i.Value;
                        }
                    }
                    if (agentsConnections > 0)
                    {
                        AvgWeight      += (agentsAvgWeight / agentsConnections);
                        allConnections += agentsConnections;
                    }
                }
            }
            Console.WriteLine("Speak to parents prob: " + (speakToParentsGene / population.Count));
            Console.WriteLine("Extrovert probability: " + (extrovertProb / population.Count));
            Console.WriteLine("average vocabulary length: " + (totalVocLen / population.Count));
            Console.WriteLine("Fittest agent: " + population[0].getFitness());
            Console.WriteLine("Average connections: " + (allConnections / population.Count));
            Console.WriteLine("Agents average weight: " + (AvgWeight / population.Count));
            Console.WriteLine("Average learn rate: " + (learnRateSum / population.Count) + "\n\n");
            d.addExtrovertData((extrovertProb / population.Count));
            d.addSpeakToParentsGenome((speakToParentsGene / population.Count));
            d.addAvgVocLen((totalVocLen / population.Count));
            d.addFittest(population[0].getFitness());
            d.setDegree(allConnections / population.Count);
            d.addLearnRate((learnRateSum / population.Count));
        }