Interface Constraint

All Superinterfaces:
Comparable<Constraint>, Copyable<Constraint>, Defined, Named, Serializable
All Known Implementing Classes:
AbstractConstraint, Between, BoundedConstraint, Equal, GreaterThan, GreaterThanOrEqual, LessThan, LessThanOrEqual, NotEqual, Outside, ThresholdConstraint

public interface Constraint extends Comparable<Constraint>, Copyable<Constraint>, Serializable, Defined, Named
Defines a constraint. While all constraints are assigned a value, the interpretation of that value with respect to feasibility depends on the specific constraint type. Thus, callers should prefer using specific methods provided by this interface than checking the value itself.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.moeaframework.core.Defined

    Defined.ConstructorComparator
  • Method Summary

    Modifier and Type
    Method
    Description
    default int
     
    static Constraint
    Returns a new instance of the default constraint.
    double
    Returns the magnitude of constraint violation as a non-negative number, with 0.0 representing satisfied or feasible constraints.
    static String
    getNameOrDefault(Constraint constraint, int index)
    Returns the name of the constraint, using either the name assigned to the constraint or deriving the name from its index.
    double
    Returns the value of this constraint.
    default boolean
    Returns true if this constraint is violated; false otherwise.
    void
    setValue(double value)
    Sets the value of this constraint.
    default Constraint
    withValue(double value)
    Sets the value of this constraint and returns this instance.

    Methods inherited from interface org.moeaframework.core.Copyable

    copy

    Methods inherited from interface org.moeaframework.core.Defined

    getDefinition

    Methods inherited from interface org.moeaframework.core.Named

    getName
  • Method Details

    • getValue

      double getValue()
      Returns the value of this constraint.
      Returns:
      the value of this constraint
    • setValue

      void setValue(double value)
      Sets the value of this constraint.
      Parameters:
      value - the value of this constraint
    • withValue

      default Constraint withValue(double value)
      Sets the value of this constraint and returns this instance.
      Parameters:
      value - the value of this constraint
      Returns:
      this instance
    • getMagnitudeOfViolation

      double getMagnitudeOfViolation()
      Returns the magnitude of constraint violation as a non-negative number, with 0.0 representing satisfied or feasible constraints. When comparing two constraints, smaller magnitudes are considered better.
      Returns:
      the magnitude of constraint violation
    • isViolation

      default boolean isViolation()
      Returns true if this constraint is violated; false otherwise.
      Returns:
      true if this constraint is violated; false otherwise
    • compareTo

      default int compareTo(Constraint other)
      Specified by:
      compareTo in interface Comparable<Constraint>
    • createDefault

      static Constraint createDefault()
      Returns a new instance of the default constraint. This is the constraint type used if not explicitly configured by the problem or user.
      Returns:
      the default constraint
    • getNameOrDefault

      static String getNameOrDefault(Constraint constraint, int index)
      Returns the name of the constraint, using either the name assigned to the constraint or deriving the name from its index.
      Parameters:
      constraint - the constraint
      index - the index of the constraint
      Returns:
      the name of the constraint