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 intcompareTo(Constraint other) static ConstraintReturns a new instance of the default constraint.doubleReturns the magnitude of constraint violation as a non-negative number, with0.0representing satisfied or feasible constraints.static StringgetNameOrDefault(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.doublegetValue()Returns the value of this constraint.default booleanReturnstrueif this constraint is violated;falseotherwise.voidsetValue(double value) Sets the value of this constraint.default ConstraintwithValue(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.0representing satisfied or feasible constraints. When comparing two constraints, smaller magnitudes are considered better.- Returns:
- the magnitude of constraint violation
-
isViolation
default boolean isViolation()Returnstrueif this constraint is violated;falseotherwise.- Returns:
trueif this constraint is violated;falseotherwise
-
compareTo
- Specified by:
compareToin 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
-