Class AbstractConstraint

java.lang.Object
org.moeaframework.core.constraint.AbstractConstraint
All Implemented Interfaces:
Serializable, Comparable<Constraint>, Constraint, Copyable<Constraint>, Defined, Named
Direct Known Subclasses:
BoundedConstraint, ThresholdConstraint

public abstract class AbstractConstraint extends Object implements Constraint
Abstract class for implementing constraints. The constraint value is initialized to 0d/0d, which serves as an indicator the constraint has not been assigned. By convention, implementations should consider this default value to be feasible.

Constraints can be assigned a name, but if unset will derive its name from its current index by calling Constraint.getNameOrDefault(Constraint, int). Such constraints are also called "anonymous".

See Also:
  • Field Details

    • name

      protected final String name
      The constraint name, or null if anonymous.
    • value

      protected double value
      The constraint value.
  • Constructor Details

    • AbstractConstraint

      public AbstractConstraint()
      Constructs a new, anonymous constraint.
    • AbstractConstraint

      public AbstractConstraint(String name)
      Constructs a new constraint with the given name.
      Parameters:
      name - the constraint name, or null to create an anonymous constraint
  • Method Details

    • getName

      public String getName()
      Description copied from interface: Named
      Returns the name of this object. The format for the name depends on the specific implementation, but in general we recommend:
      1. Prefer using alphanumeric characters including '_' and '-'.
      2. Avoid whitespace and other control characters.
      3. null can be returned, if allowed by the implementation, to indicate the object is anonymous or has no assigned name.
      Specified by:
      getName in interface Named
      Returns:
      the name
    • setValue

      public void setValue(double value)
      Description copied from interface: Constraint
      Sets the value of this constraint.
      Specified by:
      setValue in interface Constraint
      Parameters:
      value - the value of this constraint
    • getValue

      public double getValue()
      Description copied from interface: Constraint
      Returns the value of this constraint.
      Specified by:
      getValue in interface Constraint
      Returns:
      the value of this constraint
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object