/*
 * Evaluation.h
 *
 *  Created on: Jul 28, 2015
 *      Author: jjpalacios
 */

#ifndef SRC_ECOPERATORS_EVALUATION_H_
#define SRC_ECOPERATORS_EVALUATION_H_

#include "../heading.h"
#include "../ecObjects/Population.h"

namespace clbDEB {


//=============================================================================
//
//	Abstract class Evaluation
//
//=============================================================================
/**
 * This class provides the framework to implement an evaluation function
 *
 * It will be responsible of assigning a fitness value to each individual
 *
 * @author jjpalacios
 *
 */
class Evaluation {
public:
	//=========================================================================
	//		CONSTRUCTORS / INITIALIZERS
	//=========================================================================
public:
	/**
	 * Default constructor
	 */
	explicit Evaluation(ParameterDB *parameters = NULL);

	/**
	 * Loads the needed parameters. No default parameters
	 */
	virtual void setup(ParameterDB *parameters) { }

	/**
	 * Destructor
	 */
	virtual ~Evaluation() { }; 	// Nothing to destroy here



	//=========================================================================
	//		METHODS
	//=========================================================================
public:
	/**
	 * Computed the fitness value for a given individual
	 *
	 * @param svars Shared elements of the algorithm*
	 * @param individual Individual to evaluate
	 * @return the fitness value
	 */
	virtual double evaluate(SharedVars *svars, Individual *individual)=0;

	/**
	 * Evaluates an entire population.
	 *
	 * @param population Population of individuals to evaluate
	 * @param svars Shared elements of the algorithm
	 * @param reEvaluate Force the evaluation of the individual
	 * @return the average fitness value
	 */
	virtual double evaluatePopulation(SharedVars *svars,
			Population *population, bool reEvaluate=false);


	/**
	 * Get the name and setup of the operator
	 *
	 * @return A string of parameter values. The first string is the name of
	 * the operator
	 */
	virtual std::vector<std::string> getName() const=0;

};





//=============================================================================
//
//	Class NaiveEvaluation
//
//=============================================================================
/**
 * This class implements a naive evaluation function that returns the sum
 * of all genes
 *
 * It's made for testing purposes
 *
 * @author jjpalacios
 *
 */
class NaiveEvaluation : public Evaluation {
public:
	//=========================================================================
	//		CONSTRUCTORS / INITIALIZERS
	//=========================================================================
public:
	/**
	 * Default constructor
	 */
	explicit NaiveEvaluation(ParameterDB *parameters = NULL)
		: Evaluation(parameters) { }

	/**
	 * Destructor
	 */
	virtual ~NaiveEvaluation() { }; 	// Nothing to destroy here



	//=========================================================================
	//		METHODS
	//=========================================================================
public:
	/**
	 * Computed the fitness value for a given individual
	 *
	 * @param svars Shared elements of the algorithm*
	 * @param individual Individual to evaluate
	 * @return the fitness value
	 */
	virtual double evaluate(SharedVars *svars, Individual *individual);


	/**
	 * Get the name and setup of the operator
	 *
	 * @return A string of parameter values. The first string is the name of
	 * the operator
	 */
	virtual std::vector<std::string> getName() const {
		std::vector<std::string> setup;
		setup.push_back("Gene Sum");
		return setup;
	}
};


}

#endif /* SRC_ECOPERATORS_EVALUATION_H_ */
