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

java.lang.Object
es.urjc.etsii.grafo.algorithms.Algorithm<S,I>
Type Parameters:
S - Solution class
I - Instance class
Direct Known Subclasses:
EmptyAlgorithm, IteratedGreedy, MultiStartAlgorithm, ScatterSearch, SimpleAlgorithm, TestAlgorithm, VNS

public abstract class Algorithm<S extends Solution<S,I>,I extends Instance> extends Object
Base algorithm class, all algorithms should extend this class or any of its subclasses.
  • Constructor Details

    • Algorithm

      protected Algorithm(String algorithmName)
      Initialize common algorithm fields
      Parameters:
      algorithmName - algorithm name. See setName(String)
  • Method Details

    • getName

      public String getName()
      Algorithm name, uniquely identifies the algorithm inside an experiment
      Returns:
      algorithm name
    • setName

      public void setName(String algorithmName)
      Sets the algorithm name. This method can be called after the algorithm has been built, for example if we want to customize the name generated by the autoconfig module. This method CANNOT be called after the algorithm has started executing, as it would break the experiment results. The algorithm name is used to uniquely identify the algorithm inside an experiment.
      Parameters:
      algorithmName - must uniquely identify the algorithm inside an experiment
    • algorithm

      public abstract S algorithm(I instance)
      Runs the algorithm
      Parameters:
      instance - Instance to solve
      Returns:
      Built solution
    • newSolution

      public S newSolution(I instance)
      Create a new solution for the given instance. Solution is empty by default.
      Parameters:
      instance - Instance
      Returns:
      Empty solution, by default created calling the constructor Solution(Instance i)
    • getBuilder

      protected SolutionBuilder<S,I> getBuilder()
      Get solution builder
      Returns:
      solution builder
    • 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);
           }
       
      Parameters:
      builder - solution builder
    • toString

      public String toString()
      Overrides:
      toString in class Object