public override SolutionProgram search(TimeSpan timeLimit) { watch = Stopwatch.StartNew(); var bestProgram = new SolutionProgram((DirectiveNode)SearchMethodsSupport.createRandomTree(NodeClass.directive, profile, maxDepth)); var bestPerformance = evaluate(batchSize, bestProgram); Console.WriteLine("best program: "); Console.WriteLine(bestProgram.ToString()); Console.WriteLine($"performance: {bestPerformance}"); while (watch.Elapsed < timeLimit) { var program = new SolutionProgram((DirectiveNode)SearchMethodsSupport.createRandomTree(NodeClass.directive, profile, maxDepth)); var performance = evaluate(batchSize, program); if (performance > bestPerformance) { bestPerformance = performance; bestProgram = program; Console.WriteLine("best program: "); Console.WriteLine(bestProgram.ToString()); Console.WriteLine($"performance: {bestPerformance}"); } } return(bestProgram); }
static void Main2(string[] args) { //SolutionProgram p = getProgram0(); //SolutionProgram p = getProgram1(); SolutionProgram p = getProgram2(); Interpret i = new Interpret(); i.numericInputs = new List <int>() { 97 }; Console.WriteLine(p.ToString()); p.execute(i); new GraphVisualizer().visualizeDialog(ProgramTreeDrawer.createGraph(p)); Console.WriteLine("inputs: " + string.Join(" ", i.numericInputs)); Console.WriteLine("outputs: " + string.Join(" ", i.outputs)); }
public override SolutionProgram search(TimeSpan timeLimit) { watch = Stopwatch.StartNew(); SolutionProgram bestProgram = null; double bestPerformance = -1d; int depth = 0; while (true) { depth++; Console.WriteLine($"Depth: {depth}"); //Console.WriteLine(SearchMethodsSupport.enumerateAllTrees(NodeClass.directive, depth).Count()); foreach (var item in SearchMethodsSupport.enumerateAllTrees(NodeClass.directive, depth)) { if (watch.Elapsed > timeLimit) { return(bestProgram); } var program = new SolutionProgram((DirectiveNode)item); var performance = evaluate(batchSize, program); //Console.WriteLine(program.ToString()); //Console.WriteLine($"performance: {performance}"); if (performance > bestPerformance) { bestPerformance = performance; bestProgram = program; Console.WriteLine("best program: "); Console.Write(bestProgram.ToString()); Console.WriteLine($"performance: {bestPerformance} %"); Console.WriteLine(); if (performance >= 100) { Console.WriteLine("solution found"); return(bestProgram); } } } } }
/// <summary> /// To test the Clone() method /// </summary> /// <param name="args"></param> static void Main3(string[] args) { NodeTypeFrequencyProfile p = NodeTypeFrequencyProfile.createProfile(new List <SolutionProgram> { getProgram0(), getProgram1(), getProgram2() }, true); for (int i = 0; i < 50; i++) { Console.WriteLine("New random program:"); SolutionProgram pr = new SolutionProgram((DirectiveNode)SearchMethodsSupport.createRandomTree(NodeClass.directive, p, 10)); Console.WriteLine(pr.ToString()); new GraphVisualizer().visualizeDialog(ProgramTreeDrawer.createGraph(pr)); Console.WriteLine(); Console.WriteLine("CLONE:"); SolutionProgram clon = (SolutionProgram)pr.Clone(); Console.WriteLine(clon.ToString()); new GraphVisualizer().visualizeDialog(ProgramTreeDrawer.createGraph(clon)); Console.WriteLine(); } }