public override SolutionProgram search(TimeSpan timeLimit)
        {
            watch.Start();

            SolutionProgram current = new SolutionProgram((DirectiveNode)SearchMethodsSupport.createRandomTree(NodeClass.directive, profile, 3));
            int             steps   = 0;

            while (watch.Elapsed < timeLimit)
            {
                steps++;
                mutatedPrograms.Clear();
                for (int i = 0; i < mutationsInStep; i++)
                {
                    SolutionProgram mutated = (SolutionProgram)current.Clone();
                    mutator.modify(mutated);
                    mutatedPrograms.Add(new EvaluatedEntity <SolutionProgram>(mutated, 0));
                }
                mutatedPrograms.Add(new EvaluatedEntity <SolutionProgram>(new SolutionProgram((DirectiveNode)SearchMethodsSupport.createRandomTree(NodeClass.directive, profile, 3)), 0));
                addEvaluation(batchSize, mutatedPrograms);
                var selected = selector.select(mutatedPrograms);
                if (selected.value >= 99)                       //more than 99% accuracy reached -> ending the search.
                {
                    printMSG(selected.value.ToString());
                    return(selected.item);
                }

                printMSG("Steps: " + steps);
                printMSG("Best evaluation: " + mutatedPrograms.Max(p => p.value));
                printMSG("Best program: " + mutatedPrograms.Where(p => p.value >= mutatedPrograms.Max(q => q.value)).First().item.ToString());
            }
            watch.Stop();
            return(mutatedPrograms.Where(p => p.value >= mutatedPrograms.Max(q => q.value)).First().item);
        }
Exemple #2
0
        /// <summary>
        /// To test the primality testing program and Erratic sequence program
        /// </summary>
        /// <param name="args"></param>
        static void Main4(string[] args)
        {
            runEvaluation(new PrimalityTestingSamplesGenerator(), getProgram2(), 10000, quiet: true);
            new GraphVisualizer().visualizeDialog(ProgramTreeDrawer.createGraph(getProgram2()));

            //applies a random mutation to the program and evaluates it. Repeates 10-times.
            NodeTypeRelativizedFrequencyProfile prof = NodeTypeRelativizedFrequencyProfile.createProfile(new List <SolutionProgram> {
                getProgram0(), getProgram1(), getProgram2()
            });
            PointMutation m = new PointMutation(prof, 1);

            for (int i = 0; i < 10; i++)
            {
                var p = getProgram2();
                m.modify(p);
                new GraphVisualizer().visualizeDialog(ProgramTreeDrawer.createGraph(p));
                runEvaluation(new PrimalityTestingSamplesGenerator(), p, 10000, quiet: true);
            }
            //runEvaluation(new ErraticSequenceLengthSamplesGenerator(), getProgram1(), 10000);
        }