Class AbstractConstraint
java.lang.Object
org.moeaframework.core.constraint.AbstractConstraint
- All Implemented Interfaces:
Serializable
,Comparable<Constraint>
,Constraint
,Copyable<Constraint>
,Defined
,Named
- Direct Known Subclasses:
BoundedConstraint
,ThresholdConstraint
Abstract class for implementing constraints. The constraint value is initialized to 0d/0d, which
serves as an indicator the constraint has not been assigned. By convention, implementations should consider this
default value to be feasible.
Constraints can be assigned a name, but if unset will derive its name from its current index by calling
Constraint.getNameOrDefault(Constraint, int)
. Such constraints are also called "anonymous".
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.moeaframework.core.Defined
Defined.ConstructorComparator
-
Field Summary
-
Constructor Summary
ConstructorDescriptionConstructs a new, anonymous constraint.AbstractConstraint
(String name) Constructs a new constraint with the given name. -
Method Summary
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.moeaframework.core.constraint.Constraint
compareTo, getMagnitudeOfViolation, isViolation, withValue
Methods inherited from interface org.moeaframework.core.Defined
getDefinition
-
Field Details
-
name
The constraint name, ornull
if anonymous. -
value
protected double valueThe constraint value.
-
-
Constructor Details
-
AbstractConstraint
public AbstractConstraint()Constructs a new, anonymous constraint. -
AbstractConstraint
Constructs a new constraint with the given name.- Parameters:
name
- the constraint name, ornull
to create an anonymous constraint
-
-
Method Details
-
getName
Description copied from interface:Named
Returns the name of this object. The format for the name depends on the specific implementation, but in general we recommend:- Prefer using alphanumeric characters including
'_'
and'-'
. - Avoid whitespace and other control characters.
null
can be returned, if allowed by the implementation, to indicate the object is anonymous or has no assigned name.
- Prefer using alphanumeric characters including
-
setValue
public void setValue(double value) Description copied from interface:Constraint
Sets the value of this constraint.- Specified by:
setValue
in interfaceConstraint
- Parameters:
value
- the value of this constraint
-
getValue
public double getValue()Description copied from interface:Constraint
Returns the value of this constraint.- Specified by:
getValue
in interfaceConstraint
- Returns:
- the value of this constraint
-
toString
-
hashCode
public int hashCode() -
equals
-