Record Class GRProblem

java.lang.Object
java.lang.Record
org.ddolib.examples.nolayer.gruler.GRProblem
Record Components:
order - the number of marks the ruler must have
All Implemented Interfaces:
Problem<GRState>

public record GRProblem(int order) extends Record implements Problem<GRState>
Nolayer formulation of the Golomb Ruler Problem (GRP): find a set of order marks on a ruler such that no two pairs of marks are the same distance apart, minimizing the length of the ruler.
  • Constructor Summary

    Constructors
    Constructor
    Description
    GRProblem(int order)
    Creates an instance of a GRProblem record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    domain(GRState state)
    Returns the domain of possible labels/actions from a given state.
    final boolean
    Indicates whether some other object is "equal to" this one.
    double
    evaluate(List<Integer> solution)
    Given a solution (a sequence of applied labels), returns its value and checks if the solution respects the problem's constraints.
    final int
    Returns a hash code value for this object.
    boolean
    The transition costs are non-negative: each new mark is placed after the last one.
    Returns the initial state of the problem.
    double
    Returns the initial objective value associated with the initial state.
    boolean
    Checks whether the given state is a target (sink) state.
    int
    Returns the value of the order record component.
    Returns a string representation of this record class.
    transition(GRState state, int label)
    Applies a label/action to a state, computing the next state according to the problem's transition function.
    double
    transitionCost(GRState state, int label)
    Computes the change in objective value resulting from applying a label to a given state.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.ddolib.nolayer.modeling.Problem

    optimalValue
  • Constructor Details

    • GRProblem

      public GRProblem(int order)
      Creates an instance of a GRProblem record class.
      Parameters:
      order - the value for the order record component
  • Method Details

    • initialState

      public GRState initialState()
      Description copied from interface: Problem
      Returns the initial state of the problem.
      Specified by:
      initialState in interface Problem<GRState>
      Returns:
      the state representing the starting point of the optimization
    • initialValue

      public double initialValue()
      Description copied from interface: Problem
      Returns the initial objective value associated with the initial state.
      Specified by:
      initialValue in interface Problem<GRState>
      Returns:
      the starting value of the objective function
    • isTarget

      public boolean isTarget(GRState state)
      Description copied from interface: Problem
      Checks whether the given state is a target (sink) state.
      Specified by:
      isTarget in interface Problem<GRState>
      Parameters:
      state - the current state
      Returns:
      true if the state is a target state, false otherwise
    • domain

      public Iterator<Integer> domain(GRState state)
      Description copied from interface: Problem
      Returns the domain of possible labels/actions from a given state.
      Specified by:
      domain in interface Problem<GRState>
      Parameters:
      state - the current state
      Returns:
      an iterator over all feasible labels for the given state
    • transition

      public GRState transition(GRState state, int label)
      Description copied from interface: Problem
      Applies a label/action to a state, computing the next state according to the problem's transition function.
      Specified by:
      transition in interface Problem<GRState>
      Parameters:
      state - the state from which the transition originates
      label - the label to apply
      Returns:
      the resulting state after applying the label
    • transitionCost

      public double transitionCost(GRState state, int label)
      Description copied from interface: Problem
      Computes the change in objective value resulting from applying a label to a given state.
      Specified by:
      transitionCost in interface Problem<GRState>
      Parameters:
      state - the state from which the transition originates
      label - the label to apply
      Returns:
      the incremental objective cost/value associated with this label
    • evaluate

      public double evaluate(List<Integer> solution) throws InvalidSolutionException
      Description copied from interface: Problem
      Given a solution (a sequence of applied labels), returns its value and checks if the solution respects the problem's constraints.
      Specified by:
      evaluate in interface Problem<GRState>
      Parameters:
      solution - a solution of the problem (sequence of labels)
      Returns:
      the value of the input solution
      Throws:
      InvalidSolutionException - if the solution does not respect problem's constraints
    • hasNonNegativeCosts

      public boolean hasNonNegativeCosts()
      The transition costs are non-negative: each new mark is placed after the last one.
      Specified by:
      hasNonNegativeCosts in interface Problem<GRState>
      Returns:
      true
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • order

      public int order()
      Returns the value of the order record component.
      Returns:
      the value of the order record component