Exemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        //btn1に生成ボタンをGameObjectとして登録
        btn1 = GameObject.Find("生成ボタン");

        //生成ボタンのコンポーネントであるgenerationスクリプトを登録
        script = btn1.GetComponent <generation>();

        //これは自分のボタンをbtn2として登録
        btn2 = GetComponent <Button>();
    }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //Getting command line parameters
            if (args.Length > 0) {
                Program.chanceOfMutation  = Double.Parse(args[0]);
                Program.chanceOfCrossover = Double.Parse(args[1]);
                Program.totalGenerations = int.Parse(args[2]);
                reportname = "mute=" + Program.chanceOfMutation + "-cross=" + Program.chanceOfCrossover + "-runs=" + Program.totalGenerations + ".html";
            }

            //A friendly welcoming message
            Console.WriteLine("Welcome to the Cemetery Distance Calculator.  Reading the data");

            //Step 1: Reading in the data
            readData();

            //Step 2: Generate the first generation
            Console.WriteLine("Generating the most responsible parents in the world");
            List<genome> startgen = new List<genome>();
            for (int i = 0; i < generationSize; i++) {

                genome g = new genome(maxCrossoverSize);
                g.randomize();
                startgen.Add(g);

                Console.WriteLine("Travel Miles: " + g.travelDist + " | Penalty: " + g.penalty);
            }

            // ---- Start Loop ---- //

            // 3: Figure out children
            List<genome> nextGeneration = startgen;
            for (int i = 0; i < totalGenerations; i++) {

                List<genome> parents = nextGeneration;
                List<genome> children = new List<genome>();

                foreach (genome g in parents) {
                    genome childToAdd = g.getChild(chanceOfCrossover, chanceOfMutation);
                    children.Add(childToAdd);
                }

                nextGeneration = new List<genome>();
                nextGeneration = elitismTest(parents, children);

                //Keeping track of each generation for reporting purposes
                generation gen = new generation(nextGeneration);
                genealogy.Add(gen);

                if (i % 100 == 0)
                {
                    Console.WriteLine(" Generation " + i + " | Average Fitness:" + gen.avgFitness());
                    Console.WriteLine("                  Best Fitness:" + gen.bestFitness());
                }
            }
            // ---- End Loop ------ //

            //Step 4: Generate Reports
            //Generating the maps
            Console.WriteLine("Writing maps...");
            mapReport(nextGeneration);
            Console.WriteLine("Writing progress report...");
            progressReport(genealogy);

            System.Diagnostics.Process.Start(Program.reportname);
        }