Package org.ddolib.examples.gruler
Class GRState
java.lang.Object
org.ddolib.examples.gruler.GRState
Represents a state in the Golomb Ruler (GR) problem.
A state is defined by:
- The set of marks already placed on the ruler (
marks). - The set of pairwise distances between existing marks (
distances). - The position of the last placed mark (
lastMark).
This class is used by search-based algorithms such as DDO (Decision Diagram Optimization), A*, or Anytime Column Search to represent a partial configuration of the Golomb ruler.
Example:
BitSet marks = new BitSet();
marks.set(0);
marks.set(3);
BitSet distances = new BitSet();
distances.set(3);
GRState state = new GRState(marks, distances, 3);
System.out.println(state);
// Output: ([0, 3] , [3] , 3)
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncopy()Creates and returns a deep copy of this state.booleanCompares this state to another for equality.Returns the set of pairwise distances already covered.intReturns the position of the last placed mark.getMarks()Returns the set of marks already placed.intReturns the number of marks currently placed.inthashCode()Computes the hash code for this state based on marks, distances, and the last mark.toString()Returns a human-readable string representation of this state.
-
Constructor Details
-
GRState
Constructs a newGRStatefrom given sets of marks and distances.Defensive copies of the bitsets are made to ensure immutability of the internal state.
- Parameters:
marks- the set of marks already placed.distances- the set of pairwise distances already covered.lastMark- the position of the last placed mark.
-
-
Method Details
-
getMarks
Returns the set of marks already placed.- Returns:
- a
BitSetrepresenting the placed marks.
-
getDistances
Returns the set of pairwise distances already covered.- Returns:
- a
BitSetrepresenting existing distances.
-
getNumberOfMarks
public int getNumberOfMarks()Returns the number of marks currently placed.- Returns:
- the number of marks in this state.
-
getLastMark
public int getLastMark()Returns the position of the last placed mark.- Returns:
- the position (integer value) of the last mark.
-
copy
Creates and returns a deep copy of this state.- Returns:
- a new
GRStateidentical to the current one.
-
hashCode
public int hashCode()Computes the hash code for this state based on marks, distances, and the last mark. -
equals
Compares this state to another for equality. Two states are equal if they have identical marks, identical distances, and the same last mark position. -
toString
Returns a human-readable string representation of this state.The output includes the list of marks, distances, and the last mark position.
-