jmetal.core
Class Solution

java.lang.Object
  extended by jmetal.core.Solution
All Implemented Interfaces:
java.io.Serializable

public class Solution
extends java.lang.Object
implements java.io.Serializable

Class representing a solution for a problem.

See Also:
Serialized Form

Constructor Summary
Solution()
          Constructor.
Solution(int numberOfObjectives)
          Constructor
Solution(Problem problem)
          Constructor.
Solution(Problem problem, Variable[] variables)
          Constructor
Solution(Solution solution)
          Copy constructor.
 
Method Summary
 double getAggregativeValue()
          Returns the aggregative value of the solution
 double getCrowdingDistance()
          Gets the crowding distance of the solution into a SolutionSet.
 Variable[] getDecisionVariables()
          Returns the decision variables of the solution.
 double getDistanceToSolutionSet()
          Gets the distance from the solution to a SolutionSet.
 double getFitness()
          Gets the fitness of the solution.
 int getLocation()
          Gets the location of this solution in a SolutionSet.
static Solution getNewSolution(Problem problem)
           
 int getNumberOfBits()
          Returns the number of bits of the chromosome in case of using a binary representation
 int getNumberOfObjectives()
          Returns the number of objectives.
 int getNumberOfViolatedConstraint()
          Gets the number of constraint violated by the solution.
 double getObjective(int i)
          Returns the value of the i-th objective.
 double getOverallConstraintViolation()
          Gets the overall constraint violated by the solution.
 Problem getProblem()
           
 int getRank()
          Gets the rank of the solution.
 SolutionType getType()
          Gets the type of the encodings.variable
 boolean isMarked()
          Indicates if the solution is marked.
 void marked()
          Establishes the solution as marked.
 int numberOfVariables()
          Returns the number of decision variables of the solution.
 void setCrowdingDistance(double distance)
          Sets the crowding distance of a solution in a SolutionSet.
 void setDecisionVariables(Variable[] variables)
          Sets the decision variables for the solution.
 void setDistanceToSolutionSet(double distance)
          Sets the distance between this solution and a SolutionSet.
 void setFitness(double fitness)
          Sets the fitness of a solution.
 void setKDistance(double distance)
          Sets the distance between the solution and its k-nearest neighbor in a SolutionSet.
 void setLocation(int location)
          Sets the location of the solution into a solutionSet.
 void setNumberOfViolatedConstraint(int value)
          Sets the number of constraints violated by the solution.
 void setObjective(int i, double value)
          Sets the value of the i-th objective.
 void setOverallConstraintViolation(double value)
          Sets the overall constraints violated by the solution.
 void setRank(int value)
          Sets the rank of a solution.
 void setType(SolutionType type)
          Sets the type of the encodings.variable.
 java.lang.String toString()
          Returns a string representing the solution.
 void unMarked()
          Established the solution as unmarked.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Solution

public Solution()
Constructor.


Solution

public Solution(int numberOfObjectives)
Constructor

Parameters:
numberOfObjectives - Number of objectives of the solution This constructor is used mainly to read objective values from a file to variables of a SolutionSet to apply quality indicators

Solution

public Solution(Problem problem)
         throws java.lang.ClassNotFoundException
Constructor.

Parameters:
problem - The problem to solve
Throws:
java.lang.ClassNotFoundException

Solution

public Solution(Problem problem,
                Variable[] variables)
Constructor

Parameters:
problem - The problem to solve

Solution

public Solution(Solution solution)
Copy constructor.

Parameters:
solution - Solution to copy.
Method Detail

getNewSolution

public static Solution getNewSolution(Problem problem)
                               throws java.lang.ClassNotFoundException
Throws:
java.lang.ClassNotFoundException

setDistanceToSolutionSet

public void setDistanceToSolutionSet(double distance)
Sets the distance between this solution and a SolutionSet. The value is stored in distanceToSolutionSet_.

Parameters:
distance - The distance to a solutionSet.

getDistanceToSolutionSet

public double getDistanceToSolutionSet()
Gets the distance from the solution to a SolutionSet. REQUIRE : this method has to be invoked after calling setDistanceToPopulation.

Returns:
the distance to a specific solutionSet.

setKDistance

public void setKDistance(double distance)
Sets the distance between the solution and its k-nearest neighbor in a SolutionSet. The value is stored in kDistance_.

Parameters:
distance - The distance to the k-nearest neighbor.

setCrowdingDistance

public void setCrowdingDistance(double distance)
Sets the crowding distance of a solution in a SolutionSet. The value is stored in crowdingDistance_.

Parameters:
distance - The crowding distance of the solution.

getCrowdingDistance

public double getCrowdingDistance()
Gets the crowding distance of the solution into a SolutionSet. Returns the value stored in crowdingDistance_. REQUIRE : this method has to be invoked after calling setCrowdingDistance.

Returns:
the distance crowding distance of the solution.

setFitness

public void setFitness(double fitness)
Sets the fitness of a solution. The value is stored in fitness_.

Parameters:
fitness - The fitness of the solution.

getFitness

public double getFitness()
Gets the fitness of the solution. Returns the value of stored in the encodings.variable fitness_. REQUIRE : This method has to be invoked after calling setFitness().

Returns:
the fitness.

setObjective

public void setObjective(int i,
                         double value)
Sets the value of the i-th objective.

Parameters:
i - The number identifying the objective.
value - The value to be stored.

getObjective

public double getObjective(int i)
Returns the value of the i-th objective.

Parameters:
i - The value of the objective.

getNumberOfObjectives

public int getNumberOfObjectives()
Returns the number of objectives.

Returns:
The number of objectives.

numberOfVariables

public int numberOfVariables()
Returns the number of decision variables of the solution.

Returns:
The number of decision variables.

toString

public java.lang.String toString()
Returns a string representing the solution.

Overrides:
toString in class java.lang.Object
Returns:
The string.

getDecisionVariables

public Variable[] getDecisionVariables()
Returns the decision variables of the solution.

Returns:
the DecisionVariables object representing the decision variables of the solution.

setDecisionVariables

public void setDecisionVariables(Variable[] variables)
Sets the decision variables for the solution.

Parameters:
variables - The DecisionVariables object representing the decision variables of the solution.

getProblem

public Problem getProblem()

isMarked

public boolean isMarked()
Indicates if the solution is marked.

Returns:
true if the method marked has been called and, after that, the method unmarked hasn't been called. False in other case.

marked

public void marked()
Establishes the solution as marked.


unMarked

public void unMarked()
Established the solution as unmarked.


setRank

public void setRank(int value)
Sets the rank of a solution.

Parameters:
value - The rank of the solution.

getRank

public int getRank()
Gets the rank of the solution. REQUIRE : This method has to be invoked after calling setRank().

Returns:
the rank of the solution.

setOverallConstraintViolation

public void setOverallConstraintViolation(double value)
Sets the overall constraints violated by the solution.

Parameters:
value - The overall constraints violated by the solution.

getOverallConstraintViolation

public double getOverallConstraintViolation()
Gets the overall constraint violated by the solution. REQUIRE : This method has to be invoked after calling overallConstraintViolation.

Returns:
the overall constraint violation by the solution.

setNumberOfViolatedConstraint

public void setNumberOfViolatedConstraint(int value)
Sets the number of constraints violated by the solution.

Parameters:
value - The number of constraints violated by the solution.

getNumberOfViolatedConstraint

public int getNumberOfViolatedConstraint()
Gets the number of constraint violated by the solution. REQUIRE : This method has to be invoked after calling setNumberOfViolatedConstraint.

Returns:
the number of constraints violated by the solution.

setLocation

public void setLocation(int location)
Sets the location of the solution into a solutionSet.

Parameters:
location - The location of the solution.

getLocation

public int getLocation()
Gets the location of this solution in a SolutionSet. REQUIRE : This method has to be invoked after calling setLocation.

Returns:
the location of the solution into a solutionSet

setType

public void setType(SolutionType type)
Sets the type of the encodings.variable.

Parameters:
type - The type of the encodings.variable.

getType

public SolutionType getType()
Gets the type of the encodings.variable

Returns:
the type of the encodings.variable

getAggregativeValue

public double getAggregativeValue()
Returns the aggregative value of the solution

Returns:
The aggregative value.

getNumberOfBits

public int getNumberOfBits()
Returns the number of bits of the chromosome in case of using a binary representation

Returns:
The number of bits if the case of binary variables, 0 otherwise This method had a bug which was fixed by Rafael Olaechea