jopt.csp.search
Class WeightedRandomizedNeighborhood

java.lang.Object
  extended byjopt.csp.search.WeightedRandomizedNeighborhood
All Implemented Interfaces:
Neighborhood

public class WeightedRandomizedNeighborhood
extends java.lang.Object
implements Neighborhood

A wrapper to other neighborhoods that returns neighbors from the wrapped neighborhoods in a random, weighted manner. Differs from the RandomizedNeighborhood in that the specified weights influence the frequency of the neighbors returned from the associated neighborhood. For example, if Neighborhood2 and Neighborhood1 are included with weights of 2.0 and 1.0, respectively, the caller is twice as likely to get a neighbor from Neighborhood2 (assuming the neighbors are requested in numeric order) until Neighborhood2 is exhausted.

Author:
James Boerkoel

Constructor Summary
WeightedRandomizedNeighborhood(Neighborhood[] hoods, double[] weights)
          Creates a weighted, random, unified neighborhood based on a collection of other neighborhoods
WeightedRandomizedNeighborhood(Neighborhood[] hoods, double[] weights, long randomSeed)
          Creates a weighted, random, unified neighborhood based on a collection of other neighborhoods with a specific randomizer seed
 
Method Summary
 SolverSolution getNeighbor(int index)
          Returns the neighboring solution at index i
 Neighborhood getSelectedNeighborhood()
          Returns the Neighborhood represented by the latest selected Neighborhood
 int getSelectedNeighborhoodOffset()
          Returns the offset into Neighborhood represented by the latest selected Neighborhood
 void neighborSelected(int i)
          Indicates that a neighbor has been selected from this neighborhood and is about to be used to update the initial solution.
 void setInitialSolution(SolverSolution initial)
          Sets the initial solution to which this neighborhood is related
 int size()
          Returns the number of potential solutions contained in the neighborhood
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WeightedRandomizedNeighborhood

public WeightedRandomizedNeighborhood(Neighborhood[] hoods,
                                      double[] weights)
Creates a weighted, random, unified neighborhood based on a collection of other neighborhoods


WeightedRandomizedNeighborhood

public WeightedRandomizedNeighborhood(Neighborhood[] hoods,
                                      double[] weights,
                                      long randomSeed)
Creates a weighted, random, unified neighborhood based on a collection of other neighborhoods with a specific randomizer seed

Method Detail

setInitialSolution

public void setInitialSolution(SolverSolution initial)
Description copied from interface: Neighborhood
Sets the initial solution to which this neighborhood is related

Specified by:
setInitialSolution in interface Neighborhood

size

public int size()
Description copied from interface: Neighborhood
Returns the number of potential solutions contained in the neighborhood

Specified by:
size in interface Neighborhood

getNeighbor

public SolverSolution getNeighbor(int index)
Description copied from interface: Neighborhood
Returns the neighboring solution at index i

Specified by:
getNeighbor in interface Neighborhood
Parameters:
index - Index of neighbor within neighborhood
Returns:
Solution given by the neighbor or null if some pre-propagation checks show that the neighbor is invalid (and will fail constraint satisfaction).

getSelectedNeighborhood

public Neighborhood getSelectedNeighborhood()
Description copied from interface: Neighborhood
Returns the Neighborhood represented by the latest selected Neighborhood

Specified by:
getSelectedNeighborhood in interface Neighborhood
Returns:
Neighborhood represented by the latest selected Neighborhood null if no such neighbor has been selected

getSelectedNeighborhoodOffset

public int getSelectedNeighborhoodOffset()
Description copied from interface: Neighborhood
Returns the offset into Neighborhood represented by the latest selected Neighborhood

Specified by:
getSelectedNeighborhoodOffset in interface Neighborhood
Returns:
the offset into Neighborhood represented by the latest selected Neighborhood -1 if no such neighbor has been selected

neighborSelected

public void neighborSelected(int i)
Description copied from interface: Neighborhood
Indicates that a neighbor has been selected from this neighborhood and is about to be used to update the initial solution. This is useful if the neighborhood will adjust the order in which neighbors are produced.

Specified by:
neighborSelected in interface Neighborhood