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

java.lang.Object
es.urjc.etsii.grafo.algorithms.vns.VNSBuilder<S,I>

public class VNSBuilder<S extends Solution<S,I>,I extends Instance> extends Object
  • Field Details

    • objective

      protected Objective<?,S extends Solution<S,I>,I extends Instance> objective
      Objective to optimize Defaults to the default objective declared in the current Context
  • Constructor Details

    • VNSBuilder

      public VNSBuilder()
  • Method Details

    • withConstructive

      public VNSBuilder<S,I> withConstructive(Constructive<S,I> constructive)
      Creates a new VNSBuilder instance.
      Parameters:
      constructive - Constructive procedure to use when generating initial solutions.
      Returns:
      This builder instance for method chaining
    • withImprover

      public VNSBuilder<S,I> withImprover(Improver<S,I> improver)
      Configures the improvement procedure
      Parameters:
      improver - Improvement procedure to use when improving the solution.
      Returns:
      This builder instance for method chaining
    • withShake

      public VNSBuilder<S,I> withShake(Shake<S,I> shake)
      Configures the shake procedure.
      Parameters:
      shake - Shake procedure to use when perturbing the solution.
      Returns:
      This builder instance for method chaining
    • withDefaultObjective

      public VNSBuilder<S,I> withDefaultObjective()
      Optimize default objective function, which is the main objective declared in the current Context. Note that calling this method is optional, if the objective is not set it will default to the main objective.
      Returns:
      This builder instance for method chaining
    • withObjective

      public VNSBuilder<S,I> withObjective(Objective<?,S,I> objective)
      Configures the objective function to optimize.
      Parameters:
      objective - Objective function to optimize.
      Returns:
      This builder instance for method chaining
    • withNeighChange

      public VNSBuilder<S,I> withNeighChange(VNSNeighChange<S,I> neighChange)
      Configures the neighborhood change strategy. Provide a custom implementation of VNSNeighChange to define how the k value should change. And when the VNS should stop.
      Parameters:
      neighChange - Custom neighborhood change strategy. This should implement the VNSNeighChange interface, or be a lambada function that takes a solution and an integer k, and returns an integer k value (the updated k value). Example: withNeighChange((solution, k) -> k+1); // note that in this example k will keep increasing forever if the solution does not improve
      Returns:
      This builder instance for method chaining
    • withNeighChange

      public VNSBuilder<S,I> withNeighChange(int maxK)
      Configures the neighborhood change strategy with a maximum K value. Increment defaults to 1.
      Parameters:
      maxK - Maximum K value for the neighborhood change. When k reaches this value, the VNS will stop.
      Returns:
      This builder instance for method chaining
    • withNeighChange

      public VNSBuilder<S,I> withNeighChange(int maxK, int increment)
      Configures the neighborhood change strategy with a maximum K value and a one-by-one increment.
      Parameters:
      maxK - Maximum K value for the neighborhood change. When k reaches this value, the VNS will stop.
      increment - Increment to apply to K when the solution does not improve
      Returns:
      This builder instance for method chaining
    • build

      public VNS<S,I> build()
      Builds the VNS algorithm with the configured parameters. Uses a random name for the algorithm.
      Returns:
      A new instance of VNS
    • build

      public VNS<S,I> build(String name)
      Builds the VNS algorithm with the configured parameters.
      Returns:
      A new instance of VNS