public void BrainStorm1() { var factory = new RandomExpressionBuilder(); IObjectCreator objectCreator = new MockTestObjectCreator(() => { return 2; }); factory.CreationConditions = new ExpressionCreationConditions(maxDepth: 2); factory.ExpressionCreator.NewObjectCreator = objectCreator; // Act var expression = factory.NewExpression(ExpressionType.Add); ////RandomExpressionBuilder builder = new RandomExpressionBuilder(); ////builder.CreationConditions = new ExpressionCreationConditions(maxDepth: 3); ////Expression e = builder.NewExpression(); LambdaExpression func = Expression.Lambda<Action>(expression); DynamicProgram program = new DynamicProgram(func); string filename = Path.ChangeExtension(Path.GetRandomFileName(), "dll"); program.Export(filename); }
static void Dps() { //dynamic var dynamic = new DynamicProgram(); //Fib(dynamic); //int[] input = new int[] { 10, 9, 2, 5, 3, 7, 101, 18, 20, 29, 60, 11 }; ////max length 7 either [2, 5, 7, 18, 20, 29, 60] or [2, 3, 7, 18, 20, 29, 60] ////{ 10, 9, 2, 5, 3, 7, 101, 18 }; //max length 4 int[] input = new int[] { 10, 9, 2, 5, 3, 7, 101, 18, 1 }; Console.WriteLine("longest increase number: " + dynamic.LengthOfLIS(input)); //Console.WriteLine("longest increase number (binary search): " + dynamic.LengthOfLISBinarySearch(input)); //longest common substring //"cgefaaaaaabvbbbbbbp", "hqwaaafavbpbbbbbbb" -> 6 bbbbbb //"cgefaaaaaabvp", "hqwaaafavbpb" -> 3 aaa //Console.WriteLine("Longest common subsrting: " + dynamic.LCSubstring("cbad", "efhbac")); //longest common sequence //Console.WriteLine("Longest common sequence: " + dynamic.LCSubsequence("abcdaf", "abcf")); }
static void Fib(DynamicProgram dynamic) { //1, 1, 2, 3, 5, 8, 13, 21 int totalcall = 0; Console.WriteLine("recur n=5: " + dynamic.FibonacciRecur(5, ref totalcall)); //5 Console.WriteLine("Recursion Total calls: " + totalcall); totalcall = 0; Console.WriteLine("dynamic n=5: " + dynamic.FibonacciDynamic(5, ref totalcall)); Console.WriteLine("Dynamic Total calls: " + totalcall); totalcall = 0; Console.WriteLine("dynamic bottomToUp n=5: " + dynamic.FibnoaccBottomToUp(5, ref totalcall)); Console.WriteLine("Dynamic bottomToUp Total calls: " + totalcall); totalcall = 0; Console.WriteLine("recur n=6: " + dynamic.FibonacciRecur(20, ref totalcall)); //6765 Console.WriteLine("Recursion Total calls: " + totalcall); totalcall = 0; Console.WriteLine("dynamic n=8: " + dynamic.FibonacciDynamic(20, ref totalcall)); Console.WriteLine("Dynamic Total calls: " + totalcall); totalcall = 0; Console.WriteLine("dynamic bottomToUp n=20: " + dynamic.FibnoaccBottomToUp(20, ref totalcall)); Console.WriteLine("Dynamic bottomToUp Total calls: " + totalcall); /* * recur n=5: 5 * Recursion Total calls: 9 * dynamic n=5: 5 * Dynamic Total calls: 5 * recur n=6: 6765 * dynamic bottomToUp n=5: 5 * Dynamic bottomToUp Total calls: 1 * Recursion Total calls: 13529 * dynamic n=8: 6765 * Dynamic Total calls: 20 * dynamic bottomToUp n=5: 5 * Dynamic bottomToUp Total calls: 1 */ }