Package org.moeaframework.core
Class Constraint
java.lang.Object
org.moeaframework.core.Constraint
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:
- 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. - 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
Modifier and TypeFieldDescriptionstatic final double
Constant used to indicate a constraint is satisfied. -
Method Summary
Modifier and TypeMethodDescriptionstatic 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
).
-
Field Details
-
SATISFIED
public static final double SATISFIEDConstant 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 valuey
- 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 valuey
- the second valueepsilon
- 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 valuey
- 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 valuey
- the second valueepsilon
- 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 valuey
- 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 valuey
- the second valueepsilon
- 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 valuey
- 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 valuey
- the second valueepsilon
- 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 valuey
- 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 valuey
- the second valueepsilon
- 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 valuey
- 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 valuey
- the second valueepsilon
- 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 boundvalue
- the valueupper
- 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 boundvalue
- the valueupper
- the upper boundepsilon
- 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 boundvalue
- the valueupper
- 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 boundvalue
- the valueupper
- the upper boundepsilon
- the precision when considering if two values are equal- Returns:
- the constraint value
-