Esempio n. 1
0
        public void TestAll(int size, string ops, int expectedCount)
        {
            var       force = new BinaryBruteForcerOld(ops.Split(' '));
            Stopwatch sw    = Stopwatch.StartNew();
            var       all   = force.Enumerate(size);

            Console.WriteLine("new calculated, size = {0}", all.Count());
            //Assert.AreEqual(expectedCount, all.Count());
            Console.WriteLine(sw.Elapsed);

            //            Console.WriteLine("All:");
            //            foreach (var ar in all)
            //                Console.WriteLine(ar.Printable());

            var force2 = new BinaryBruteForcer(ops.Split(' '));
            var all2   = force2.Enumerate(size);

            Console.WriteLine("new optim calculated, size = {0}", all2.Count());

            var setOfAll = new HashSet <string>(all2.Select(t => t.Printable()));
            var diff     = all.Where(t => !setOfAll.Contains(t.Printable()));

            foreach (var ar in diff.Take(50))
            {
                Console.WriteLine(ar.Printable());
            }
        }
Esempio n. 2
0
        public void Test()
        {
            IEnumerable <byte[]> items = new BinaryBruteForcer("xor", "not").Enumerate(13);

            Console.WriteLine(items.Count());
            //			foreach (var item in items)
            //			{
            //				Console.WriteLine(item.Printable());
            //			}
        }
Esempio n. 3
0
        public void BruteForceAllRealProblems(int size)
        {
            var ps = ProblemsReader.CreateDefault().ReadProblems().Where(p => p.Size == size).ToList();

            Console.WriteLine("{0} problems of size {1}", ps.Count, size);
            foreach (var problem in ps)
            {
                Console.Write("{0}: op:{1} ", problem.Id, string.Join(" ", problem.AllOperators));
                var sw    = Stopwatch.StartNew();
                var count = new BinaryBruteForcer(problem.AllOperators).Enumerate(size).Count();
                Console.WriteLine("count: {0}   time: {1}   ", count, sw.Elapsed);
            }
        }
Esempio n. 4
0
 public void TestIncludeBin(int size)
 {
     Console.WriteLine("size = {0}", size);
     foreach (var problem in GetAllSamples().Where(p => p.Size == size))
     {
         Console.WriteLine("problem #{0}", problem.Id);
         var bruter    = new BinaryBruteForcer(problem.AllOperators);
         var solutions = new HashSet <string>(bruter.Enumerate(size - 1).Select(expr => expr.Printable()));
         if (!solutions.Contains(Parser.ParseFunction(problem.SolutionString).Printable()))
         {
             Console.WriteLine("op: {0}, ", string.Join(", ", problem.AllOperators));
             Console.WriteLine(string.Join("\t", solutions));
             Assert.Fail();
         }
     }
 }