Ejemplo n.º 1
0
        private void runSolver(QapSolver solver, QapData data, QapSolutionBenchmark benchmark, QapSolution optimalSolution, String outputFileName)
        {
            //LocalOptimumValidator validator = new LocalOptimumValidator();
            List <ulong[]> list = new List <ulong[]>();

            for (int i = 0; i < RepetitionsNo; i++)
            {
                var lastSolution = solver.GetSolution();

                //Console.WriteLine(validator.CheckLocalOptimum(lastSolution, data, false));
                var firstSolution     = solver.FirstSolution;
                var lastSolutionScore = benchmark.RateSolution(lastSolution, data);
                //Console.WriteLine("last : "+lastSolutionScore);
                var firstSolutionScore = benchmark.RateSolution(firstSolution, data);

                list.Add(new ulong[] { Convert.ToUInt64(optimalSolution.Score), firstSolutionScore, lastSolutionScore });
            }

            using (StreamWriter file = File.AppendText(outputFileName))
            {
                foreach (ulong[] line in list)
                {
                    file.WriteLine(line[0].ToString() + ',' + line[1].ToString() + ',' + line[2].ToString() + ';');
                }
            }
        }
Ejemplo n.º 2
0
        private void runSolver(QapSolver solver, QapData data, QapSolutionBenchmark benchmark, QapSolution optimalSolution, String outputFileName)
        {
            List <long> solutionsScore    = new List <long>();
            ulong       bestSolutionScore = 0;
            //LocalOptimumValidator validator = new LocalOptimumValidator();
            List <ulong[]> list = new List <ulong[]>();

            for (int i = 0; i < RepetitionsNo; i++)
            {
                var lastSolution      = solver.GetSolution();
                var lastSolutionScore = benchmark.RateSolution(lastSolution, data);
                if ((bestSolutionScore == 0) || (bestSolutionScore > lastSolutionScore))
                {
                    bestSolutionScore = lastSolutionScore;
                }
                solutionsScore.Add(((long)lastSolutionScore));

                list.Add(new ulong[] { Convert.ToUInt64(optimalSolution.Score), lastSolutionScore, (ulong)solutionsScore.Average(), bestSolutionScore });
            }

            using (StreamWriter file = File.AppendText(outputFileName))
            {
                foreach (ulong[] line in list)
                {
                    file.WriteLine(line[0].ToString() + ',' + line[1].ToString() + ',' + line[2].ToString() + ',' + line[3].ToString() + ';');
                }
            }
        }
Ejemplo n.º 3
0
        private void RunSolver(QapSolver solver, QapData data, QapSolutionBenchmark benchmark, QapSolution optimalSolution, String outputFileName)
        {
            ulong           bestSolutionScore          = 0;
            int             repetitionsWithoutProgress = 0;
            List <double[]> list = new List <double[]>();
            Stopwatch       sw   = new Stopwatch();

            for (int i = 0; i < Repetitions; i++)
            {
                while (true)
                {
                    sw.Start();
                    var lastSolution = solver.GetSolution();
                    sw.Stop();
                    var lastSolutionScore = benchmark.RateSolution(lastSolution, data);
                    if ((bestSolutionScore == 0) || (bestSolutionScore > lastSolutionScore))
                    {
                        bestSolutionScore          = lastSolutionScore;
                        repetitionsWithoutProgress = 0;
                    }
                    else
                    {
                        repetitionsWithoutProgress++;
                    }
                    var efficiency = (double)(ulong)optimalSolution.Score / bestSolutionScore;
                    var time       = sw.Elapsed.TotalMilliseconds;
                    list.Add(new double[] { efficiency, time });

                    if (repetitionsWithoutProgress > MaxRepetitionsWithoutImprove)
                    {
                        break;
                    }
                    if (efficiency > 0.99999999999999999999)
                    {
                        break;
                    }
                }
            }
            using (StreamWriter file = File.AppendText(outputFileName))
            {
                foreach (double[] line in list)
                {
                    file.WriteLine(line[0].ToString() + ';' + line[1].ToString() + ';');
                }
            }
        }