Class Constraint

java.lang.Object
org.moeaframework.core.Constraint

public class Constraint extends Object
Useful methods for calculating constraints. The returned value represents the degree of constraint violation, where 0.0 indicates the constraint is satisfied and any non-zero value indicates a constraint violation, and can be passed directly into Solution.setConstraint(int, double).

These methods are useful as they:

  1. Take an epsilon value, defaulting to 1.0E-10, used to determine if two numbers are sufficiently close to be considered equal. This helps account for rounding or computational errors introduced by floating-point numbers.
  2. Calculates the magnitude of constraint violation, effectively providing a "gradient" towards the feasible solution. This helps optimization algorithms distinguish solutions with more or less severe violations.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Constant used to indicate a constraint is satisfied.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    between(double lower, double value, double upper)
    Constraint requiring the value to be between a lower and upper bounds (l <= x <= u).
    static double
    between(double lower, double value, double upper, double epsilon)
    Constraint requiring the value to be between a lower and upper bounds (l <= x <= u).
    static double
    equal(double x, double y)
    Equality constraint (x == y).
    static double
    equal(double x, double y, double epsilon)
    Equality constraint (x == y).
    static double
    greaterThan(double x, double y)
    Greater than constraint (x > y).
    static double
    greaterThan(double x, double y, double epsilon)
    Greater than constraint (x > y).
    static double
    greaterThanOrEqual(double x, double y)
    Greater than or equal constraint (x >= y).
    static double
    greaterThanOrEqual(double x, double y, double epsilon)
    Greater than or equal constraint (x >= y).
    static double
    lessThan(double x, double y)
    Less than constraint (x < y).
    static double
    lessThan(double x, double y, double epsilon)
    Less than constraint (x < y).
    static double
    lessThanOrEqual(double x, double y)
    Less than or equal constraint (x <= y).
    static double
    lessThanOrEqual(double x, double y, double epsilon)
    Less than or equal constraint (x <= y).
    static double
    notEqual(double x, double y)
    Not-equals constraint (x != y).
    static double
    notEqual(double x, double y, double epsilon)
    Not-equals constraint (x != y).
    static double
    outside(double lower, double value, double upper)
    Constraint requiring the value to be outside a given range (l < x && x > u).
    static double
    outside(double lower, double value, double upper, double epsilon)
    Constraint requiring the value to be outside a given range (x < l && x > u).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SATISFIED

      public static final double SATISFIED
      Constant used to indicate a constraint is satisfied.
      See Also:
  • Method Details

    • equal

      public static double equal(double x, double y)
      Equality constraint (x == y).
      Parameters:
      x - the first value
      y - the second value
      Returns:
      the constraint value
    • equal

      public static double equal(double x, double y, double epsilon)
      Equality constraint (x == y).
      Parameters:
      x - the first value
      y - the second value
      epsilon - the precision when considering if two values are equal
      Returns:
      the constraint value
    • notEqual

      public static double notEqual(double x, double y)
      Not-equals constraint (x != y).
      Parameters:
      x - the first value
      y - the second value
      Returns:
      the constraint value
    • notEqual

      public static double notEqual(double x, double y, double epsilon)
      Not-equals constraint (x != y).
      Parameters:
      x - the first value
      y - the second value
      epsilon - the precision when considering if two values are equal
      Returns:
      the constraint value
    • lessThanOrEqual

      public static double lessThanOrEqual(double x, double y)
      Less than or equal constraint (x <= y).
      Parameters:
      x - the first value
      y - the second value
      Returns:
      the constraint value
    • lessThanOrEqual

      public static double lessThanOrEqual(double x, double y, double epsilon)
      Less than or equal constraint (x <= y).
      Parameters:
      x - the first value
      y - the second value
      epsilon - the precision when considering if two values are equal
      Returns:
      the constraint value
    • greaterThanOrEqual

      public static double greaterThanOrEqual(double x, double y)
      Greater than or equal constraint (x >= y).
      Parameters:
      x - the first value
      y - the second value
      Returns:
      the constraint value
    • greaterThanOrEqual

      public static double greaterThanOrEqual(double x, double y, double epsilon)
      Greater than or equal constraint (x >= y).
      Parameters:
      x - the first value
      y - the second value
      epsilon - the precision when considering if two values are equal
      Returns:
      the constraint value
    • lessThan

      public static double lessThan(double x, double y)
      Less than constraint (x < y).
      Parameters:
      x - the first value
      y - the second value
      Returns:
      the constraint value
    • lessThan

      public static double lessThan(double x, double y, double epsilon)
      Less than constraint (x < y).
      Parameters:
      x - the first value
      y - the second value
      epsilon - the precision when considering if two values are equal
      Returns:
      the constraint value
    • greaterThan

      public static double greaterThan(double x, double y)
      Greater than constraint (x > y).
      Parameters:
      x - the first value
      y - the second value
      Returns:
      the constraint value
    • greaterThan

      public static double greaterThan(double x, double y, double epsilon)
      Greater than constraint (x > y).
      Parameters:
      x - the first value
      y - the second value
      epsilon - the precision when considering if two values are equal
      Returns:
      the constraint value
    • between

      public static double between(double lower, double value, double upper)
      Constraint requiring the value to be between a lower and upper bounds (l <= x <= u).
      Parameters:
      lower - the lower bound
      value - the value
      upper - the upper bound
      Returns:
      the constraint value
    • between

      public static double between(double lower, double value, double upper, double epsilon)
      Constraint requiring the value to be between a lower and upper bounds (l <= x <= u).
      Parameters:
      lower - the lower bound
      value - the value
      upper - the upper bound
      epsilon - the precision when considering if two values are equal
      Returns:
      the constraint value
    • outside

      public static double outside(double lower, double value, double upper)
      Constraint requiring the value to be outside a given range (l < x && x > u).
      Parameters:
      lower - the lower bound
      value - the value
      upper - the upper bound
      Returns:
      the constraint value
    • outside

      public static double outside(double lower, double value, double upper, double epsilon)
      Constraint requiring the value to be outside a given range (x < l && x > u).
      Parameters:
      lower - the lower bound
      value - the value
      upper - the upper bound
      epsilon - the precision when considering if two values are equal
      Returns:
      the constraint value