Class GraspBuilder<M extends Move<S,I>,S extends Solution<S,I>,I extends Instance>

java.lang.Object
es.urjc.etsii.grafo.create.grasp.GraspBuilder<M,S,I>
Type Parameters:
M - Move class
S - Solution class
I - Instance class

public class GraspBuilder<M extends Move<S,I>,S extends Solution<S,I>,I extends Instance> extends Object
Creates GRASP constructive instances using with different configurations, allowing to easily configure them and reuse the configurations.
  • Constructor Details

    • GraspBuilder

      public GraspBuilder()
  • Method Details

    • withStrategyGreedyRandom

      public GraspBuilder<M,S,I> withStrategyGreedyRandom()
      Use greedy random strategy, or in other words, pick a subset of elements whose greedy function value is near the best value and then pick a random element from this subset.
      Returns:
      same builder with its config changed
    • withStrategyRandomGreedy

      public GraspBuilder<M,S,I> withStrategyRandomGreedy()
      Use random greedy strategy, or in other words, pick a subset of elements randomly, and then pick the best element from this subset.
      Returns:
      same builder with its config changed
    • withObjective

      public GraspBuilder<M,S,I> withObjective(Objective<M,S,I> objective)
      Determines both which greedy function is used to evaluate moves, and if the greedy function should be minimized or maximized.
      Parameters:
      objective - objective function to use
      Returns:
      same builder with its config changed
    • withAlphaValue

      public GraspBuilder<M,S,I> withAlphaValue(double alpha)
      Configure alpha value to a fixed value. The alpha value is used to determine the randomness / greediness of the method.
      Parameters:
      alpha - fixed alpha value to use, must be in range [0, 1]. A value of 0 means completely greedy, while a value of one means completely random.
      Returns:
      same builder with its config changed
    • withAlphaRandom

      public GraspBuilder<M,S,I> withAlphaRandom()
      Use a random alpha value in each constructive iteration.
      Returns:
      same builder with its config changed
    • withAlphaInRange

      public GraspBuilder<M,S,I> withAlphaInRange(double alphaMin, double alphaMax)
      Pick a random alpha value in range [min, max].
      Parameters:
      alphaMin - minimum value, inclusive
      alphaMax - maximum value, inclusive
      Returns:
      same builder with its config changed
    • withAlphaProvider

      public GraspBuilder<M,S,I> withAlphaProvider(AlphaProvider provider, String explained)
      Configure any custom strategy for configuring alpha values. The function provided as a first argument will be called once per constructive iteration.
      Parameters:
      provider - function that generates an alpha value for each grasp iteration. Using a lambda expression is recommended.
      explained - String that explains how the alpha provider is generating the values. Examples: FIXED{a=0.25}, RANGE{min=0.1, max=0.3}
      Returns:
      same builder with its config changed
    • withListManager

      public GraspBuilder<M,S,I> withListManager(GRASPListManager<? extends M,S,I> graspListManager)
      Configure the GRASP list manager, responsible for generating the initial candidate list and updating it after each move iteration.
      Parameters:
      graspListManager - GRASP list manager instance
      Returns:
      same builder with its config changed
    • build

      public GRASPConstructive<M,S,I> build()
      Build the GRASP constructive with the config specified previously. Before building the constructive method, a set of checks are executed in order to verify that al parameters are assigned and have valid values.
      Returns:
      an instance of a GRASP constructive
      Throws:
      IllegalArgumentException - if any config value is not valid or there are missing values