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 TypeMethodDescriptiondefault int
compareTo
(Constraint other) static Constraint
Returns a new instance of the default constraint.double
Returns the magnitude of constraint violation as a non-negative number, with0.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
getValue()
Returns the value of this constraint.default boolean
Returnstrue
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.Defined
getDefinition
-
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
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, with0.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()Returnstrue
if this constraint is violated;false
otherwise.- Returns:
true
if this constraint is violated;false
otherwise
-
compareTo
- Specified by:
compareTo
in interfaceComparable<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
Returns the name of the constraint, using either the name assigned to the constraint or deriving the name from its index.- Parameters:
constraint
- the constraintindex
- the index of the constraint- Returns:
- the name of the constraint
-