/*
 *  Open BEAGLE
 *  Copyright (C) 2001-2004 by Christian Gagne and Marc Parizeau
 *
 *  This library 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 2.1 of the License, or (at your option) any later version.
 *
 *  This library 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 library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  Contact:
 *  Laboratoire de Vision et Systemes Numeriques
 *  Departement de genie electrique et de genie informatique
 *  Universite Laval, Quebec, Canada, G1V 4J7
 *  http://vision.gel.ulaval.ca
 *
 */

/*!
 *  \file   beagle/GP/FitnessKoza.hpp
 *  \brief  Definition of the class GP/FitnessKoza.
 *  \author Christian Gagne
 *  \author Marc Parizeau
 *  $Revision: 1.2 $
 *  $Date: 2004/01/15 21:08:56 $
 */

/*!
 *  \defgroup GPFit GP Fitness
 *  \ingroup GPF
 *  \brief Genetic programming specific fitness measure and related elements, part of the GP
 *  framework.
 */

#ifndef Beagle_GP_FitnessKoza_hpp
#define Beagle_GP_FitnessKoza_hpp

#include "beagle/config.hpp"
#include "beagle/macros.hpp"
#include "beagle/Object.hpp"
#include "beagle/AllocatorT.hpp"
#include "beagle/PointerT.hpp"
#include "beagle/ContainerT.hpp"
#include "beagle/Stats.hpp"
#include "beagle/FitnessSimple.hpp"

namespace Beagle {
namespace GP {

/*!
 *  \class FitnessKoza beagle/GP/FitnessKoza.hpp "beagle/GP/FitnessKoza.hpp"
 *  \brief Koza's fitness class.
 *  \ingroup GPF
 *  \ingroup GPFit
 *  \par Note:
 *    Fitness measure express by Koza in Genetic Programming I. Only Normalized fitness
 *    is used in the natural selection process, others fitness are only indications.
 */
class FitnessKoza : public FitnessSimple {

public:

  //! GP::FitnessKoza allocator type.
  typedef AllocatorT<FitnessKoza,FitnessSimple::Alloc>
          Alloc;
  //! GP::FitnessKoza handle type.
  typedef PointerT<FitnessKoza,FitnessSimple::Handle>
          Handle;
  //! GP::FitnessKoza bag type.
  typedef ContainerT<FitnessKoza,FitnessSimple::Bag>
          Bag;

           FitnessKoza();
  explicit FitnessKoza(float inNormalizedFitness,
                       float inAdjustedFitness,
                       float inStandardizedFitness,
                       float inRawFitness,
                       unsigned int inHits);
  virtual ~FitnessKoza() { }


  virtual void calculateStats(Beagle::Deme& ioDeme, Beagle::Context& ioContext) const;
  virtual void read(XMLNode::Handle& inNode);
  virtual void setFitness(float inNormalizedFitness,
                          float inAdjustedFitness,
                          float inStandardizedFitness,
                          float inRawFitness,
                          unsigned int inHits);
  virtual void write(XMLStreamer& ioStreamer) const;
  
  /*!
   *  \brief Return normalized fitness value.
   *  \return Normalized fitness value.
   */
  inline float getNormalizedFitness() const
  {
    return mFitness;
  }

  /*!
   *  \brief Return adjusted fitness value.
   *  \return Adjusted fitness value.
   */
  inline float getAdjustedFitness() const
  {
    return mAdjustedFitness;
  }

  /*!
   *  \brief Return standardized fitness value.
   *  \return Standardized fitness value.
   */
  inline float getStandardizedFitness() const
  {
    return mStandardizedFitness;
  }

  /*!
   *  \brief Return raw fitness value.
   *  \return Raw fitness value.
   */
  inline float getRawFitness() const
  {
    return mRawFitness;
  }

  /*!
   *  \brief Return hits measure value.
   *  \return Hits measure value.
   */
  inline unsigned int getHits() const
  {
    return mHits;
  }

private:
  float        mAdjustedFitness;      //!< Adjusted fitness measure.
  float        mStandardizedFitness;  //!< Standardized fitness measure.
  float        mRawFitness;           //!< Standardized fitness measure.
  unsigned int mHits;                 //!< Number of hits.

};

}
}

#endif // Beagle_GP_FitnessKoza_hpp

