Class MultiStartAlgorithm<S extends Solution<S,I>,I extends Instance>

java.lang.Object
es.urjc.etsii.grafo.algorithms.Algorithm<S,I>
es.urjc.etsii.grafo.algorithms.multistart.MultiStartAlgorithm<S,I>
Type Parameters:
S - Solution class
I - Instance class

public class MultiStartAlgorithm<S extends Solution<S,I>,I extends Instance> extends Algorithm<S,I>
Example multistart algorithm, executes a user-defined algorithm until N iterations are reached, return best found.
  • Field Details

    • algorithm

      protected final Algorithm<S extends Solution<S,I>,I extends Instance> algorithm
      Algorithm
    • maxIterations

      protected final int maxIterations
      Maximum number of iterations
    • minIterations

      protected final int minIterations
      Minimum number of iterations
    • maxIterationsWithoutImproving

      protected final int maxIterationsWithoutImproving
      Maximum number of iteration without improving. When the algorithm has been executed this number of time without finding a new best solution, the multistart procedure ends.
    • objective

      protected final Objective<?,S extends Solution<S,I>,I extends Instance> objective
      Objective to optimize in the multistart algorithm
  • Constructor Details

    • MultiStartAlgorithm

      public MultiStartAlgorithm(@ProvidedParam String algorithmName, Objective<?,S,I> objective, Algorithm<S,I> algorithm, @IntegerParam(min=1,max=1000000) int maxIterations, @IntegerParam(min=1,max=1000000) int minIterations, @IntegerParam(min=1,max=1000000) int maxIterationsWithoutImproving)
      Use the MultiStartAlgorithmBuilder class to generate a MultiStart Algorithm
      Parameters:
      algorithmName - algorithm name
      algorithm - algorithm
      maxIterations - maximum number of iterations
      minIterations - minimum number of iteration the algorithm will be run. Must be less or equatl than the maximum number of iterations.
      maxIterationsWithoutImproving - number of iterations the algorithm should be run without improving before stop
  • Method Details

    • algorithm

      public S algorithm(I instance)
      Runs the algorithm Algorithm: Execute a single construction and then all the local searchs a single time.
      Specified by:
      algorithm in class Algorithm<S extends Solution<S,I>,I extends Instance>
      Parameters:
      instance - Instance to solve
      Returns:
      Built solution
    • toString

      public String toString()
      Overrides:
      toString in class Algorithm<S extends Solution<S,I>,I extends Instance>
    • printStatus

      protected void printStatus(int iteration, S solution)
      Print the current status of the VNS procedure, i.e., the current iteration the best solution.
      Parameters:
      iteration - current iteration of the procedure
      solution - solution
    • setBuilder

      public void setBuilder(SolutionBuilder<S,I> builder)
      Set solution builder, used by the framework. In case an algorithms contains another algorithms, this method should be overridden as follows:
           @Override
           public void setBuilder(SolutionBuilder<S, I> builder) {
               super.setBuilder(builder);
               this.algorithm.setBuilder(builder);
           }
       
      This method propagates the builder so that it can be used by other algorithms.
      Overrides:
      setBuilder in class Algorithm<S extends Solution<S,I>,I extends Instance>
      Parameters:
      builder - solution builder