//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.

package org.uma.jmetal.solution.impl;

import org.uma.jmetal.problem.DoubleProblem;
import org.uma.jmetal.solution.DoubleSolution;

import java.util.HashMap;

/**
 * Defines an implementation of a double solution
 *
 * @author Antonio J. Nebro <antonio@lcc.uma.es>
 */
public class DefaultDoubleSolution extends AbstractGenericSolution<Double, DoubleProblem>
    implements DoubleSolution {
  /** Constructor */
  public DefaultDoubleSolution(DoubleProblem problem) {
    super(problem) ;
    overallConstraintViolationDegree = 0.0 ;
    numberOfViolatedConstraints = 0 ;

    for (int i = 0 ; i < problem.getNumberOfVariables(); i++) {
      Double value = randomGenerator.nextDouble() * (getUpperBound(i) - getLowerBound(i)) + getLowerBound(i);
      setVariableValue(i, value) ;
    }

    for (int i = 0; i < problem.getNumberOfObjectives(); i++) {
      setObjective(i, 0.0) ;
    }
  }

  /** Copy constructor */
  public DefaultDoubleSolution(DefaultDoubleSolution solution) {
    super(solution.problem) ;

    for (int i = 0; i < problem.getNumberOfVariables(); i++) {
      setVariableValue(i, solution.getVariableValue(i));
    }

    for (int i = 0; i < problem.getNumberOfObjectives(); i++) {
      setObjective(i, solution.getObjective(i)) ;
    }

    overallConstraintViolationDegree = solution.overallConstraintViolationDegree ;
    numberOfViolatedConstraints = solution.numberOfViolatedConstraints ;
    attributes = new HashMap<Object, Object>(solution.attributes) ;
  }

  @Override
  public Double getUpperBound(int index) {
    return problem.getUpperBound(index);
  }

  @Override
  public Double getLowerBound(int index) {
    return problem.getLowerBound(index) ;
  }

  @Override
  public DefaultDoubleSolution copy() {
    return new DefaultDoubleSolution(this);
  }

  @Override
  public String getVariableValueString(int index) {
    return getVariableValue(index).toString() ;
  }
}

@@ -975,16 +975,21 @@
 olution 
+%0A    
 extends 
@@ -1035,16 +1035,16 @@
 roblem%3E%0A
-
     impl
@@ -1067,16 +1067,17 @@
 ution %7B%0A
+%0A
   /** Co
@@ -1162,24 +1162,29 @@
 (problem) ;%0A
+    %0A
     overallC
@@ -1258,323 +1258,78 @@
 0 ;%0A
-%0A
     
-for (int i = 0 ; i %3C problem.getNumberOfVariables(); i++) %7B%0A      Double value = randomGenerator.nextDouble() * (getUpperBound(i) - getLowerBound(i)) + getLowerBound(i);%0A      setVariableValue(i, value) ;%0A    %7D%0A%0A    for (int i = 0; i %3C problem.getNumberOfObjectives(); i++) %7B%0A      setObjective(i, 0.0) ;%0A    %7D
+%0A    initializeDoubleVariables();%0A    initializeObjectiveValues();
 %0A  %7D
@@ -2349,10 +2349,253 @@
 ) ;%0A  %7D%0A
+  %0A  private void initializeDoubleVariables() %7B%0A    for (int i = 0 ; i %3C problem.getNumberOfVariables(); i++) %7B%0A      Double value = randomGenerator.nextDouble(getLowerBound(i), getUpperBound(i)) ;%0A      setVariableValue(i, value) ;%0A    %7D%0A  %7D%0A
 %7D%0A

Introduce initialization methods for variables and objective values