Class GRState

java.lang.Object
org.ddolib.examples.gruler.GRState

public class GRState extends Object
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
    Constructor
    Description
    GRState(BitSet marks, BitSet distances, int lastMark)
    Constructs a new GRState from given sets of marks and distances.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates and returns a deep copy of this state.
    boolean
    Compares this state to another for equality.
    Returns the set of pairwise distances already covered.
    int
    Returns the position of the last placed mark.
    Returns the set of marks already placed.
    int
    Returns the number of marks currently placed.
    int
    Computes the hash code for this state based on marks, distances, and the last mark.
    Returns a human-readable string representation of this state.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • GRState

      public GRState(BitSet marks, BitSet distances, int lastMark)
      Constructs a new GRState from 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

      public BitSet getMarks()
      Returns the set of marks already placed.
      Returns:
      a BitSet representing the placed marks.
    • getDistances

      public BitSet getDistances()
      Returns the set of pairwise distances already covered.
      Returns:
      a BitSet representing 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

      public GRState copy()
      Creates and returns a deep copy of this state.
      Returns:
      a new GRState identical to the current one.
    • hashCode

      public int hashCode()
      Computes the hash code for this state based on marks, distances, and the last mark.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code of this state.
    • equals

      public boolean equals(Object obj)
      Compares this state to another for equality. Two states are equal if they have identical marks, identical distances, and the same last mark position.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare to.
      Returns:
      true if the states are identical; false otherwise.
    • toString

      public String toString()
      Returns a human-readable string representation of this state.

      The output includes the list of marks, distances, and the last mark position.

      Overrides:
      toString in class Object
      Returns:
      a string describing this state.