Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
        private static void RunForAllRunners(IList <Instance> instances, IList <ISolver> solvers)
        {
            foreach (var solver in solvers)
            {
                Console.WriteLine(solver.GetType().Name);
                Console.WriteLine(new string('-', 48));

                var runner = new CompareRunner(instances, new DynamicByWeightSolver(), solver);
                runner.Run();
            }
        }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        private static void RunSimulatedAnnealingForConfiguration(IInstanceProvider instanceProvider,
                                                                  double initTemperature, double frozenTemperature, double coolingCoeficient, int equilibriumCoeficient)
        {
            Console.WriteLine($"Init temperature:       {initTemperature}");
            Console.WriteLine($"Cooling coeficient:     {coolingCoeficient}");
            Console.WriteLine($"Equilibrium coeficient: {equilibriumCoeficient}");

            var exactSolver = new DynamicByPriceSolver();
            var simulatedAnnealingSolver = new SimulatedAnnealingSolver(initTemperature, frozenTemperature, coolingCoeficient, equilibriumCoeficient);

            var runner = new CompareRunner(instanceProvider, exactSolver, simulatedAnnealingSolver);

            runner.Run();
            Console.WriteLine();
        }
Ejemplo n.º 5
0
        private static void RunHomework2Compare(int size)
        {
            Console.WriteLine($"Size {size}:");

            var path             = string.Format(Path, size);
            var instanceProvider = new TextReaderInstanceProvider(new StreamReader(path));
            ////var solver1 = new DynamicByPriceSolver();
            var solver1 = new DynamicByWeightSolver();
            ////var solver2 = new FptasSolver(0.1);
            ////var solver2 = new FptasSolver(0.2);
            var solver2 = new FptasSolver(0.5);

            var runner = new CompareRunner(instanceProvider, solver1, solver2);

            runner.Run();
        }