/// <summary>
        /// Creates a tree of fully instantiated nodes with given depth. Nodes at the leaf level will be default-value-nodes.
        /// </summary>
        /// <param name="cl"></param>
        /// <param name="profile"></param>
        /// <param name="depth"></param>
        /// <returns></returns>
        public static Node createRandomTree(NodeClass cl, NodeTypeRelativizedFrequencyProfile profile, int depth, NodeType?parrentType = null, NodeCreationConstrains contrains = null)
        {
            if (depth == 0)
            {
                return(createDefaultNode(cl, contrains));
            }
            Node root = createRandomNode(cl, parrentType, profile, contrains);

            foreach (var slot in root.successors.getSlots())
            {
                slot.setNodeConnectedToSlot(createRandomTree(slot.argumentClass, profile, depth - 1, root?.type, contrains));
            }
            return(root);
        }
Example #2
0
        /// <summary>
        /// Main function for testing the search.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //NodeTypeFrequencyProfile p = NodeTypeFrequencyProfile.createProfile(new List<SolutionProgram> { getProgram0(), getProgram1(), getProgram2() }, true);
            NodeTypeRelativizedFrequencyProfile p = NodeTypeRelativizedFrequencyProfile.createProfile(new List <SolutionProgram> {
                getProgram0(), getProgram1(), getProgram2()
            });

            //TrainingSamplesGenerator g = new SimpleCopySamplesGenerator();
            TrainingSamplesGenerator g = new MaximumOfTwo_SamplesGenerator();
            //TrainingSamplesGenerator g = new AlwaysOne_SamplesGenerator();

            //RandomMutationSearch s = new RandomMutationSearch(generator: g, mutationsInEachStep: 5, profile: p);
            SearchAlgorithm s = new FullEnumerationSearch(generator: g);

            var res = s.search(TimeSpan.FromMinutes(10));

            new GraphVisualizer().visualizeDialog(ProgramTreeDrawer.createGraph(res));
        }
Example #3
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);
        }
        public static NodeTypeRelativizedFrequencyProfile createProfile(List <SolutionProgram> programs)
        {
            int minPrograms = 100;
            int repeat      = programs.Count < minPrograms ? minPrograms - programs.Count : 1;
            NodeTypeRelativizedFrequencyProfile result = new NodeTypeRelativizedFrequencyProfile();

            result.simpleProfile = createProfile(programs, atLeastOneOfEach: true);

            foreach (var program in programs)
            {
                foreach (var node in program.getAllNodes())
                {
                    if (!result.relativizedProfiles.ContainsKey(node.type))
                    {
                        NodeTypeFrequencyProfile p = NodeTypeFrequencyProfile.createProfile(enumarateAllNodesThatAreSuccessorsOfType(node.type, programs, repeat), atLeastOneOfEach: true);
                        result.relativizedProfiles.Add(node.type, p);
                    }
                }
            }
            return(result);
        }
        /// <summary>
        /// Creates a new fully initialized node whose type is selected randomly based on distribution in given NodeTypeFrequencyProfile object. Node that require value to be set (like numeric constants) will receive a random number between 0 and 10 as their value.
        /// If the node requires successors to be specified, such successors will be created and default-value-node will be used.
        /// </summary>
        /// <param name="cl"></param>
        /// <param name="profile"></param>
        /// <returns></returns>
        public static Node createRandomNode(NodeClass cl, NodeType?parrentType, NodeTypeRelativizedFrequencyProfile profile, NodeCreationConstrains constrains = null)
        {
            NodeType t = profile.getRandomNodeType(cl, parrentType, constrains);

            return(createRandomNode(t, constrains));
        }