Class HybridConstructiveHeuristic<T extends Copyable<T>>

  • Type Parameters:
    T - The type of Partial object for which this HybridConstructiveHeuristic guides construction, which is assumed to be an object that is a sequence of integers (e.g., vector of integers, permutation, or some other indexable type that stores integers).
    All Implemented Interfaces:
    ConstructiveHeuristic<T>

    public final class HybridConstructiveHeuristic<T extends Copyable<T>>
    extends Object
    implements ConstructiveHeuristic<T>

    A HybridConstructiveHeuristic maintains a list of ConstructiveHeuristic objects for a problem, for use in a multiheuristic stochastic sampling search, where each full iteration of the stochastic sampler uses a single heuristic for all decisions, but where a different heuristic is chosen for each iteration.

    The HybridConstructiveHeuristic supports the following heuristic selection strategies:

    • Choose a heuristic uniformly at random at the start of the iteration.
    • Use a round robin strategy that uses the heuristics in order as determined by the order they were passed to the constructor, cycling around to the start of the list when necessary.
    • Choose a heuristic using a weighted random decision, where each heuristic has an associated weight. For example, if the weight of heuristic 1 is 2 and the weight of heuristic 2 is 3, then on average you can expect 2 out of every 5 iterations to use heuristic 1, and 3 out of every 5 iterations to use heuristic 2.

    See the documentation of the various constructors to make your choice of which of these strategies to use.

    • Constructor Detail

      • HybridConstructiveHeuristic

        public HybridConstructiveHeuristic​(List<? extends ConstructiveHeuristic<T>> heuristics)
        Constructs the HybridConstructiveHeuristic, where the heuristic is chosen uniformly at random at the start of each iteration of the stochastic sampler (i.e., each time createIncrementalEvaluation() is called).
        Parameters:
        heuristics - A list of ConstructiveHeuristic, all of which must be configured to solve the same problem instance. The list of heuristics must be non-empty.
        Throws:
        IllegalArgumentException - if not all of the heuristics are configured for the same problem instance.
        IllegalArgumentException - if heuristics.size() equals 0.
      • HybridConstructiveHeuristic

        public HybridConstructiveHeuristic​(List<? extends ConstructiveHeuristic<T>> heuristics,
                                           boolean roundRobin)
        Constructs the HybridConstructiveHeuristic, where the heuristic is either chosen uniformly at random at the start of each iteration of the stochastic sampler (i.e., each time createIncrementalEvaluation() is called), or using the round robin strategy.
        Parameters:
        heuristics - A list of ConstructiveHeuristic, all of which must be configured to solve the same problem instance. The list of heuristics must be non-empty.
        roundRobin - If true, then each time createIncrementalEvaluation() is called, the HybridConstructiveHeuristic cycles to the next heuristic systematically. Otherwise, if false, it chooses uniformly at random.
        Throws:
        IllegalArgumentException - if not all of the heuristics are configured for the same problem instance.
        IllegalArgumentException - if heuristics.size() equals 0.
      • HybridConstructiveHeuristic

        public HybridConstructiveHeuristic​(List<? extends ConstructiveHeuristic<T>> heuristics,
                                           int[] weights)
        Constructs the HybridConstructiveHeuristic, where the heuristic is chosen using a weighted random decision at the start of each iteration of the stochastic sampler (i.e., each time createIncrementalEvaluation() is called). If this constructor is used, it will choose a heuristic using a weighted random decision, where each heuristic has an associated weight. For example, if the weight of heuristic 1 is 2 and the weight of heuristic 2 is 3, then on average you can expect 2 out of every 5 iterations to use heuristic 1, and 3 out of every 5 iterations to use heuristic 2.
        Parameters:
        heuristics - A list of ConstructiveHeuristics, all of which must be configured to solve the same problem instance. The list of heuristics must be non-empty.
        weights - An array of weights, which must be the same length as heuristics. Each weight corresponds to the heuristic in the same position in the sequence. All weights must be positive.
        Throws:
        IllegalArgumentException - if not all of the heuristics are configured for the same problem instance.
        IllegalArgumentException - if heuristics.size() equals 0.
        IllegalArgumentException - if heuristics.size() is not equal to weights.length.
        IllegalArgumentException - if there exists an i, such that weights[i] < 1.
    • Method Detail

      • h

        public double h​(Partial<T> p,
                        int element,
                        IncrementalEvaluation<T> incEval)
        Description copied from interface: ConstructiveHeuristic
        Heuristically evaluates the possible addition of an element to the end of a Partial. Higher evaluations imply that the element is a better choice for the next element to add. For example, if you evaluate two elements, x and y, with h, and h returns a higher value for y than for x, then this means that y is believed to be the better choice according to the heuristic. Implementations of this interface must ensure that h always returns a positive result. This is because stochastic sampling algorithms such as HBSS and VBSS assume that the constructive heuristic returns only positive values.
        Specified by:
        h in interface ConstructiveHeuristic<T extends Copyable<T>>
        Parameters:
        p - The current state of the Partial
        element - The element under consideration for adding to the Partial
        incEval - An IncrementalEvaluation of p. This method assumes that incEval is of the same runtime type as the object returned by ConstructiveHeuristic.createIncrementalEvaluation().
        Returns:
        The heuristic evaluation of the hypothetical addition of element to the end of p. The higher the evaluation, the more important the heuristic believes that element should be added next. The intention is to compare the value returned with the heuristic evaluations of other elements. Individual results in isolation are not necessarily meaningful.
      • createPartial

        public Partial<T> createPartial​(int n)
        Description copied from interface: ConstructiveHeuristic
        Creates an empty Partial solution, which will be incrementally transformed into a complete solution of a specified length.
        Specified by:
        createPartial in interface ConstructiveHeuristic<T extends Copyable<T>>
        Parameters:
        n - the desired length of the final complete solution.
        Returns:
        an empty Partial solution
      • completeLength

        public int completeLength()
        Description copied from interface: ConstructiveHeuristic
        Gets the required length of complete solutions to the problem instance for which this constructive heuristic is configured.
        Specified by:
        completeLength in interface ConstructiveHeuristic<T extends Copyable<T>>
        Returns:
        length of solutions to the problem instance for which this heuristic is configured
      • getProblem

        public Problem<T> getProblem()
        Description copied from interface: ConstructiveHeuristic
        Gets a reference to the instance of the optimization problem that is the subject of this heuristic.
        Specified by:
        getProblem in interface ConstructiveHeuristic<T extends Copyable<T>>
        Returns:
        the instance of the optimization problem that is the subject of this heuristic.