public class Solution
extends java.lang.Object
implements java.io.Serializable
(key, value)
pairs; they are instance-specific and are not carried over in
the copy constructor.
Solutions should only be constructed in Problem.newSolution()
or
cloned from an existing solution with copy()
. This ensures the
solutions and configured correctly for the given optimization problem.
Modifier | Constructor and Description |
---|---|
|
Solution(double[] objectives)
Constructs a solution with no variables and the specified objectives.
|
|
Solution(int numberOfVariables,
int numberOfObjectives)
Constructs a solution with the specified number of variables and
objectives with no constraints.
|
|
Solution(int numberOfVariables,
int numberOfObjectives,
int numberOfConstraints)
Constructs a solution with the specified number of variables, objectives
and constraints.
|
protected |
Solution(Solution solution)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addAttributes(java.util.Map<java.lang.String,java.lang.Object> attributes)
Adds all attributes to this solution in the specified
Map . |
void |
clearAttributes()
Removes all keys and values from this solution's attributes.
|
Solution |
copy()
Returns an independent copy of this solution.
|
Solution |
deepCopy()
Similar to
copy() except all attributes are also copied. |
double |
distanceTo(Solution otherSolution)
Computes the Euclidean distance between two solutions in objective space.
|
java.lang.Object |
getAttribute(java.lang.String key)
Returns the value of the attribute that is associated with the specified
key, or
null if no value has been associated with the key. |
java.util.Map<java.lang.String,java.io.Serializable> |
getAttributes()
Returns the
Map containing this solution's attributes. |
double |
getConstraint(int index)
Returns the constraint at the specified index.
|
double[] |
getConstraints()
Returns an array containing the constraints of this solution.
|
int |
getNumberOfConstraints()
Returns the number of constraints defined by this solution.
|
int |
getNumberOfObjectives()
Returns the number of objectives defined by this solution.
|
int |
getNumberOfVariables()
Returns the number of variables defined by this solution.
|
double |
getObjective(int index)
Returns the objective at the specified index.
|
double[] |
getObjectives()
Returns an array containing the objectives of this solution.
|
Variable |
getVariable(int index)
Returns the variable at the specified index.
|
boolean |
hasAttribute(java.lang.String key)
Returns
true if the specified key exists in this solution's
attributes; false otherwise. |
java.lang.Object |
removeAttribute(java.lang.String key)
Removes the specified key and its associated value from this solution.
|
java.lang.Object |
setAttribute(java.lang.String key,
java.io.Serializable value)
Associates the specified value with the specified key.
|
void |
setConstraint(int index,
double constraint)
Sets the constraint at the specified index.
|
void |
setConstraints(double[] constraints)
Sets all constraints of this solution.
|
void |
setObjective(int index,
double objective)
Sets the objective at the specified index.
|
void |
setObjectives(double[] objectives)
Sets all objectives of this solution.
|
void |
setVariable(int index,
Variable variable)
Sets the variable at the specified index.
|
boolean |
violatesConstraints()
Returns
true if any of the constraints are violated;
false otherwise. |
public Solution(int numberOfVariables, int numberOfObjectives)
numberOfVariables
- the number of variables defined by this solutionnumberOfObjectives
- the number of objectives defined by this
solutionpublic Solution(int numberOfVariables, int numberOfObjectives, int numberOfConstraints)
numberOfVariables
- the number of variables defined by this solutionnumberOfObjectives
- the number of objectives defined by this
solutionnumberOfConstraints
- the number of constraints defined by this
solutionpublic Solution(double[] objectives)
objectives
- the objectives to be stored in this solutionprotected Solution(Solution solution)
solution
- the solution being copiedpublic Solution copy()
x.copy()
is completely independent from x
. This means
any method invoked on x.copy()
in no way alters the state of
x
and vice versa. It is typically the case that
x.copy().getClass() == x.getClass()
and
x.copy().equals(x)
Note that a solution's attributes are not copied, as the attributes are generally specific to each instance.
public Solution deepCopy()
copy()
except all attributes are also copied. As a
result, this method tends to be significantly slower than copy()
if many large objects are stored as attributes.public int getNumberOfObjectives()
public int getNumberOfVariables()
public int getNumberOfConstraints()
public double getObjective(int index)
index
- index of the objective to returnjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0) || (index >= getNumberOfObjectives())
public Variable getVariable(int index)
index
- index of the variable to returnjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0) || (index >= getNumberOfVariables())
public void setObjective(int index, double objective)
index
- index of the objective to setobjective
- the new value of the objective being setjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0) || (index >= getNumberOfObjectives())
public void setObjectives(double[] objectives)
objectives
- the new objectives for this solutionjava.lang.IllegalArgumentException
- if objectives.length !=
getNumberOfObjectives()
public double[] getObjectives()
public void setVariable(int index, Variable variable)
index
- index of the variable being setvariable
- the new value of the variable being setjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0) || (index >= getNumberOfVariables())
public boolean violatesConstraints()
true
if any of the constraints are violated;
false
otherwise.true
if any of the constraints are violated;
false
otherwisepublic double getConstraint(int index)
index
- index of the variable to be returnedjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0) || (index >= getNumberOfConstraints())
public void setConstraints(double[] constraints)
constraints
- the new constraints for this solutionjava.lang.IllegalArgumentException
- if constraints.length !=
getNumberOfConstraints()
public double[] getConstraints()
public void setConstraint(int index, double constraint)
index
- the index of the constraint being setconstraint
- the new value of the constraint being setjava.lang.IndexOutOfBoundsException
- if the index is out of range
(index < 0) || (index >= getNumberOfConstraints())
public java.lang.Object getAttribute(java.lang.String key)
null
if no value has been associated with the key.key
- the key whose associated value is to be returnednull
if
no value has been associated with the keypublic java.lang.Object setAttribute(java.lang.String key, java.io.Serializable value)
null
if no prior value has been
associated with the key.key
- the key with which the specified value is to be associatedvalue
- the value to be associated with the specified keynull
if no
prior value has been associated with the keypublic java.lang.Object removeAttribute(java.lang.String key)
null
if no
prior value has been associated with the key.key
- the key to be removednull
if no
prior value has been associated with the keypublic boolean hasAttribute(java.lang.String key)
true
if the specified key exists in this solution's
attributes; false
otherwise.key
- the key whose presence is being testedtrue
if the specified key exists in this solution's
attributes; false
otherwisepublic java.util.Map<java.lang.String,java.io.Serializable> getAttributes()
Map
containing this solution's attributes.Map
containing this solution's attributespublic void addAttributes(java.util.Map<java.lang.String,java.lang.Object> attributes)
Map
.attributes
- the Map
containing the attributes to be added
to this solutionpublic void clearAttributes()
public double distanceTo(Solution otherSolution)
s1.distanceTo(s2) == s2.distanceTo(s1)
.otherSolution
- the other solutionjava.lang.IllegalArgumentException
- if the solutions have differing numbers
of objectivesCopyright 2009-2024 David Hadka and other contributors. All rights reserved.
Licensed under the GNU Lesser General Public License.
Return to the MOEA Framework homepage.