예제 #1
0
        private static void PrintConfig(GAResult result)
        {
            for (var i = 0; i < result.Result.Genom.Length; i++)
            {
                Console.Write("[x{0} {1}] ", i + 1, result.Result.Genom[i]);
            }

            Console.WriteLine();
        }
예제 #2
0
        static void Run3SATSolver(string filePath, GeneticOptions options, bool verbose = false)
        {
            var instance = SATInstanceLoader.LoadInstance(filePath);

            var problem = new ThreeSATProblem(instance.Formula);

            var stopwatch = new Stopwatch();

            GAResult result = null;
            double   relErr = 0;
            double   time   = 0;

            for (int i = 0; i < MeasurementCount; i++)
            {
                stopwatch.Reset();
                stopwatch.Start();

                result = GeneticAlgorithm.Solve(problem, options, verbose);

                stopwatch.Stop();

                time  += stopwatch.Elapsed.TotalMilliseconds;
                relErr = CalculateRelativeError(instance.OptimalWeight, result.Result.Fitness);
            }

            if (verbose)
            {
                Console.WriteLine();
                PrintConfig(result);
            }

            var relativeErr = CalculateRelativeError(instance.OptimalWeight, result.Result.Fitness) * 100;

            if (verbose)
            {
                Console.WriteLine("Optimal result is '{0}' and approx. '{1}'. Relative error is '{2}%'.", instance.OptimalWeight, result.Result.Fitness, relativeErr);
            }

            if (verbose)
            {
                Console.WriteLine();
            }

            time /= MeasurementCount;
            Console.WriteLine(FormatCsvResult(instance.InstanceId, time, relErr));
        }