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() + ';');
                }
            }
        }
        public DeltaSolutionBenchmark(QapData data, QapSolution solution)
        {
            QapSolutionBenchmark bench = new QapSolutionBenchmark();

            ActualBestSolution = solution;
            Data        = data;
            SwapCounter = 0;
            ActualBestSolution.Score = Convert.ToInt32(bench.RateSolution(solution.Solution.ToArray(), data));
            CalcDeltaTable();
        }
        public bool CheckLocalOptimum(int[] solution, QapData data, bool startZeroIndex)
        {
            int size = data.Distances.Length;
            QapSolutionBenchmark benchmark = new QapSolutionBenchmark();
            var bestFitness = 0.0;

            if (startZeroIndex)
            {
                bestFitness = benchmark.RateSolutionIndexedFromZero(solution, data);
            }
            else
            {
                bestFitness = benchmark.RateSolution(solution, data);
            }
            for (int i = 0; i < size - 1; i++)
            {
                for (int j = i + 1; i < size; i++)
                {
                    var tempSolution = solution;
                    var temp         = tempSolution[i];
                    tempSolution[i] = tempSolution[j];
                    tempSolution[j] = temp;
                    var fitness = 0.0;
                    if (startZeroIndex)
                    {
                        fitness = benchmark.RateSolutionIndexedFromZero(tempSolution, data);
                    }
                    else
                    {
                        fitness = benchmark.RateSolution(tempSolution, data);
                    }
                    if (fitness < bestFitness)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 5
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() + ';');
                }
            }
        }