예제 #1
0
        private static void RunHomework4()
        {
            var path             = string.Format(Path, 40);
            var instanceProvider = new TextReaderInstanceProvider(() => new StreamReader(path));

            var exactSolver     = new DynamicByPriceSolver();
            var heuristicSolver = new HeuristicSolver();

            Console.WriteLine("Solving by heuristic");
            Console.WriteLine("===================================================");
            IRunner runner = new CompareRunner(instanceProvider, exactSolver, heuristicSolver);

            runner.Run();
            Console.WriteLine();

            Console.WriteLine("Solving by simulated annealing");
            Console.WriteLine("===================================================");
            Console.WriteLine();

            const int    baseInitTemperature   = 100;
            const int    baseFrozenTemperature = 1;
            const double baseCoolingCoef       = 0.9;
            const int    baseEquilibriumCoef   = 2;

            {
                Console.WriteLine("By temperature");
                Console.WriteLine("---------------------------------------------------");
                var temperatures = new[] { 50, 100, 200, 500 };
                foreach (var temperature in temperatures)
                {
                    RunSimulatedAnnealingForConfiguration(instanceProvider, temperature, baseFrozenTemperature, baseCoolingCoef, baseEquilibriumCoef);
                }
            }

            {
                Console.WriteLine("By cooling coeficient");
                Console.WriteLine("---------------------------------------------------");
                var coolingCoefs = new[] { 0.8, 0.85, 0.9, 0.95 };
                foreach (var coolingCoef in coolingCoefs)
                {
                    RunSimulatedAnnealingForConfiguration(instanceProvider, baseInitTemperature, baseFrozenTemperature, coolingCoef, baseEquilibriumCoef);
                }
            }

            {
                Console.WriteLine("By equilibrium coeficient");
                Console.WriteLine("---------------------------------------------------");
                var equilibriumCoefs = new[] { 1, 2, 3, 5 };
                foreach (var equilibriumCoef in equilibriumCoefs)
                {
                    RunSimulatedAnnealingForConfiguration(instanceProvider, baseInitTemperature, baseFrozenTemperature, baseCoolingCoef, equilibriumCoef);
                }
            }

            Console.ReadLine();
        }
예제 #2
0
        private static void RunHomework1(int size)
        {
            Console.WriteLine($"Size {size}:");

            var path              = string.Format(Path, size);
            var instanceProvider  = new TextReaderInstanceProvider(new StreamReader(path));
            var brutteForceSolver = new BrutteForceSolver();
            var heuristicSolver   = new HeuristicSolver();

            var runner = new CompareRunner(instanceProvider, brutteForceSolver, heuristicSolver);

            runner.Run();
        }