Esempio n. 1
0
 public MaxMinAntSystemBL2OptBest42SP(TwoSPInstance instance, int numberAnts,
                                      double rho, double alpha, double beta,
                                      int maxReinit)
     : base(instance.NumberItems,
            TwoSPUtils.Fitness(instance, TwoSPUtils.BLCoordinates(instance, TwoSPUtils.RandomSolution(instance))),
            numberAnts, rho, alpha, beta, maxReinit)
 {
     Instance = instance;
 }
Esempio n. 2
0
        public void Start(string fileInput, string fileOutput, int timeLimit)
        {
            TwoSPInstance instance = new TwoSPInstance(fileInput);

            int[] ordering = TwoSPUtils.DecreasingArea(instance);
            int[,] coordinates = TwoSPUtils.NPSCoordinates(instance, ordering);
            TwoSPSolution solution = new TwoSPSolution(instance, coordinates);

            solution.Write(fileOutput);
        }
        public void Start(string inputFile, string outputFile, int timeLimit)
        {
            TwoSPInstance instance = new TwoSPInstance(inputFile);
            DiscreteSS    ss       = new DiscreteSSBL42SP(instance, poolSize, refSetSize, explorationFactor);

            ss.Run(timeLimit - timePenalty);
            int[,] coordinates = TwoSPUtils.BLCoordinates(instance, ss.BestSolution);
            TwoSPSolution solution = new TwoSPSolution(instance, coordinates);

            solution.Write(outputFile);
        }
        public void Start(string fileInput, string fileOutput, int timeLimit)
        {
            TwoSPInstance instance = new TwoSPInstance(fileInput);

            int[] ordering = TwoSPUtils.DecreasingWidth(instance);
            TwoSPUtils.BLLocalSearch2OptFirst(instance, ordering);
            int[,] coordinates = TwoSPUtils.BLCoordinates(instance, ordering);
            TwoSPSolution solution = new TwoSPSolution(instance, coordinates);

            solution.Write(fileOutput);
        }
Esempio n. 5
0
        public void Start(string inputFile, string outputFile, int timeLimit)
        {
            TwoSPInstance   instance = new TwoSPInstance(inputFile);
            MaxMinAntSystem aco      = new MaxMinAntSystemNPS42SP(instance, numberAnts, rho, alpha, beta, maxReinit);

            // Solving the problem and writing the best solution found.
            aco.Run(timeLimit - timePenalty);
            int[,] coordinates = TwoSPUtils.NPSCoordinates(instance, aco.BestSolution);
            TwoSPSolution solution = new TwoSPSolution(instance, coordinates);

            solution.Write(outputFile);
        }
        public void Start(string fileInput, string fileOutput, int timeLimit)
        {
            TwoSPInstance instance    = new TwoSPInstance(fileInput);
            int           levelLength = (int)Math.Ceiling(levelLengthFactor * (2 * instance.NumberItems));
            DiscreteSA    sa          = new DiscreteSABL42SP(instance, initialSolutions, levelLength, tempReduction);

            sa.Run(timeLimit - timePenalty);
            int[,] coordinates = TwoSPUtils.BLCoordinates(instance, sa.BestSolution);
            TwoSPSolution solution = new TwoSPSolution(instance, coordinates);

            solution.Write(fileOutput);
        }
        public void Write(string file)
        {
            int totalHeight = TwoSPUtils.Fitness(Instance, Coordinates);

            using (StreamWriter writer = File.CreateText(file)) {
                writer.WriteLine(totalHeight);
                writer.WriteLine(Instance.NumberItems);
                for (int i = 0; i < Instance.NumberItems; i++)
                {
                    writer.WriteLine(Coordinates[i, 0] + " " + Coordinates[i, 1]);
                }
            }
        }
        public void Start(string inputFile, string outputFile, int timeLimit)
        {
            TwoSPInstance instance       = new TwoSPInstance(inputFile);
            int           neighborChecks = (int)Math.Ceiling(neighborChecksFactor * (2 * instance.NumberItems));
            int           tabuListLength = (int)Math.Ceiling(tabuListFactor * instance.NumberItems);
            DiscreteTS    ts             = new DiscreteTSNPS42SP(instance, tabuListLength, neighborChecks);

            ts.Run(timeLimit - timePenalty);
            int[,] coordinates = TwoSPUtils.NPSCoordinates(instance, ts.BestSolution);
            TwoSPSolution solution = new TwoSPSolution(instance, coordinates);

            solution.Write(outputFile);
        }
        protected override int[] InitialSolution()
        {
            int[] solution;

            if (generatedSolutions == 0)
            {
                solution = TwoSPUtils.DecreasingArea(Instance);
            }
            else
            {
                solution = TwoSPUtils.RandomSolution(Instance);
            }

            generatedSolutions++;
            return(solution);
        }
Esempio n. 10
0
        public void Start(string inputFile, string outputFile, int timeLimit)
        {
            TwoSPInstance instance = new TwoSPInstance(inputFile);

            int[] lowerBounds = new int[instance.NumberItems];
            int[] upperBounds = new int[instance.NumberItems];
            for (int i = 0; i < instance.NumberItems; i++)
            {
                lowerBounds[i] = 0;
                upperBounds[i] = instance.NumberItems - 1;
            }
            DiscreteILS ils = new DiscreteILSBL2OptBest42SP(instance, restartIterations, perturbations, lowerBounds, upperBounds);

            ils.Run(timeLimit - timePenalty);
            int[,] coordinates = TwoSPUtils.BLCoordinates(instance, ils.BestSolution);
            TwoSPSolution solution = new TwoSPSolution(instance, coordinates);

            solution.Write(outputFile);
        }
Esempio n. 11
0
        public void Start(string fileInput, string fileOutput, int timeLimit)
        {
            TwoSPInstance instance = new TwoSPInstance(fileInput);

            // Setting the parameters of the MA for this instance of the problem.
            int[] lowerBounds = new int[instance.NumberItems];
            int[] upperBounds = new int[instance.NumberItems];
            for (int i = 0; i < instance.NumberItems; i++)
            {
                lowerBounds[i] = 0;
                upperBounds[i] = instance.NumberItems - 1;
            }
            DiscreteMA memetic = new DiscreteMABL42SP(instance, (int)popSize, mutProbability, lowerBounds, upperBounds);

            // Solving the problem and writing the best solution found.
            memetic.Run(timeLimit - (int)timePenalty);
            int[,] coordinates = TwoSPUtils.BLCoordinates(instance, memetic.BestIndividual);
            TwoSPSolution solution = new TwoSPSolution(instance, coordinates);

            solution.Write(fileOutput);
        }
Esempio n. 12
0
        public void Start(string fileInput, string fileOutput, int timeLimit)
        {
            TwoSPInstance instance = new TwoSPInstance(fileInput);

            // Setting the parameters of the PSO for this instance of the problem.
            int[] lowerBounds = new int[instance.NumberItems];
            int[] upperBounds = new int[instance.NumberItems];
            for (int i = 0; i < instance.NumberItems; i++)
            {
                lowerBounds[i] = 0;
                upperBounds[i] = instance.NumberItems - 1;
            }
            DiscretePSO pso = new DiscretePSOBL2OptBest42SP(instance, (int)particlesCount, prevConf, neighConf, lowerBounds, upperBounds);

            // Solving the problem and writing the best solution found.
            pso.Run(timeLimit - (int)timePenalty);
            int[,] coordinates = TwoSPUtils.BLCoordinates(instance, pso.BestPosition);
            TwoSPSolution solution = new TwoSPSolution(instance, coordinates);

            solution.Write(fileOutput);
        }
Esempio n. 13
0
        public void Start(string fileInput, string fileOutput, int timeLimit)
        {
            TwoSPInstance instance = new TwoSPInstance(fileInput);

            // Setting the parameters of the UMDA for this instance of the problem.
            int popSize = (int)Math.Ceiling(popFactor * instance.NumberItems);

            int[] lowerBounds = new int[instance.NumberItems];
            int[] upperBounds = new int[instance.NumberItems];
            for (int i = 0; i < instance.NumberItems; i++)
            {
                lowerBounds[i] = 0;
                upperBounds[i] = instance.NumberItems - 1;
            }
            DiscreteUMDA umda = new DiscreteUMDANPS42SP(instance, popSize, truncFactor, lowerBounds, upperBounds);

            // Solving the problem and writing the best solution found.
            umda.Run(timeLimit - timePenalty);
            int[,] coordinates = TwoSPUtils.NPSCoordinates(instance, umda.BestIndividual);
            TwoSPSolution solution = new TwoSPSolution(instance, coordinates);

            solution.Write(fileOutput);
        }
Esempio n. 14
0
        protected override int[] RandomSolution()
        {
            int[] solution;

            if (generatedSolutions == 0)
            {
                solution = TwoSPUtils.DecreasingArea(Instance);
            }
            else if (generatedSolutions == 1)
            {
                solution = TwoSPUtils.DecreasingWidth(Instance);
            }
            else if (generatedSolutions == 2)
            {
                solution = TwoSPUtils.DecreasingHeight(Instance);
            }
            else
            {
                solution = TwoSPUtils.RandomSolution(Instance);
            }

            generatedSolutions++;
            return(solution);
        }
 protected override void Improve(int[] solution)
 {
     TwoSPUtils.BLLocalSearch2OptFirst(Instance, solution);
 }
Esempio n. 16
0
 protected override void PerturbateSolution(int[] solution, int perturbation)
 {
     TwoSPUtils.PerturbateSolution(solution, perturbation);
 }
Esempio n. 17
0
 protected override void LocalSearch(int[] individual)
 {
     TwoSPUtils.BLLocalSearch2OptBest(Instance, individual);
 }
 protected override int[] GetNeighbor(int[] solution)
 {
     return(TwoSPUtils.GetNeighbor(Instance, solution));
 }
Esempio n. 19
0
 public override void LocalSearch(int[] solution)
 {
     TwoSPUtils.BLLocalSearch2OptBest(Instance, solution);
 }
Esempio n. 20
0
 protected override double Fitness(int[] solution)
 {
     return(TwoSPUtils.Fitness(Instance, TwoSPUtils.BLCoordinates(Instance, solution)));
 }
Esempio n. 21
0
 protected override double Fitness(int[] individual)
 {
     return(TwoSPUtils.Fitness(Instance, TwoSPUtils.NPSCoordinates(Instance, individual)));
 }
Esempio n. 22
0
 protected override void Repair(int[] individual)
 {
     TwoSPUtils.Repair(Instance, individual);
 }
Esempio n. 23
0
 protected override void Repair(int[] solution)
 {
     TwoSPUtils.Repair(Instance, solution);
 }
Esempio n. 24
0
 protected override double Distance(int[] a, int[] b)
 {
     return(TwoSPUtils.Distance(Instance, a, b));
 }
 protected override Tuple <int, int> GetTabu(int[] current, int[] neighbor)
 {
     return(TwoSPUtils.GetTabu(current, neighbor));
 }