/*
 *  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/Individual.hpp
 *  \brief  Definition of the class Individual.
 *  \author Christian Gagne
 *  \author Marc Parizeau
 *  $Revision: 1.3 $
 *  $Date: 2004/01/15 21:08:57 $
 */

#ifndef Beagle_Individual_hpp
#define Beagle_Individual_hpp

#include "beagle/config.hpp"
#include "beagle/macros.hpp"
#include "beagle/Object.hpp"
#include "beagle/Pointer.hpp"
#include "beagle/PointerT.hpp"
#include "beagle/Allocator.hpp"
#include "beagle/AllocatorT.hpp"
#include "beagle/ContainerAllocator.hpp"
#include "beagle/Container.hpp"
#include "beagle/ContainerT.hpp"
#include "beagle/ContainerAllocatorT.hpp"
#include "beagle/Genotype.hpp"
#include "beagle/IndividualAlloc.hpp"
#include "beagle/Fitness.hpp"

namespace Beagle {

/*!
 *  \class Individual beagle/Individual.hpp "beagle/Individual.hpp"
 *  \brief An individual inherits from a container of genotypes and has a fitness member.
 *  \ingroup ECF
 *  \ingroup Pop
 */
class Individual : public Genotype::Bag {

public:

  //! Individual allocator type.
  typedef IndividualAlloc
          Alloc;
  //! Individual handle type.
  typedef PointerT<Individual,Genotype::Bag::Handle>
          Handle;
  //! Individual bag type.
  typedef ContainerT<Individual,Genotype::Bag::Bag>
          Bag;

  explicit Individual(Genotype::Alloc::Handle inGenotypeAlloc=NULL);
  explicit Individual(Genotype::Alloc::Handle inGenotypeAlloc,
                      Fitness::Alloc::Handle inFitnessAlloc,
                      size_type inN=0);
           Individual(const Individual& inRightIndividual);
  virtual ~Individual() { }

  Individual& operator=(const Individual& inRightIndividual);

  virtual void copyData(const Container& inOrigContainer);
  virtual bool isEqual(const Object& inRightObj) const;
  virtual bool isIdentical(const Individual& inRightIndividual) const;
  virtual bool isLess(const Object& inRightObj) const;
  virtual void readWithContext(XMLNode::Handle& inNode, Context& ioContext);
  virtual void write(XMLStreamer& ioStreamer) const;
  
  /*!
   *  \brief Get the fitness value of the individual.
   *  \return Fitness value.
   */
  inline const Fitness::Handle getFitness() const
  {
    return mFitness;
  }

  /*!
   *  \brief Get the fitness value of the individual.
   *  \return Fitness value.
   */
  inline Fitness::Handle getFitness()
  {
    return mFitness;
  }

  /*!
   *  \brief Get the fitness allocator of the individual.
   *  \return Fitness allocator.
   */
  inline const Fitness::Alloc::Handle getFitnessAlloc() const
  {
    return mFitnessAlloc;
  }

  /*!
   *  \brief Get the fitness allocator of the individual.
   *  \return Fitness allocator.
   */
  inline Fitness::Alloc::Handle getFitnessAlloc()
  {
    return mFitnessAlloc;
  }

  /*!
   *  \brief Set the fitness value of the individual.
   *  \param inFitness Set the fitness value.
   */
  inline void setFitness(Fitness::Handle inFitness)
  {
    mFitness = inFitness;
  }

  /*!
   *  \brief Set the fitness allocator of the individual.
   *  \param inFitnessAlloc Fitness allocator.
   */
  inline void setFitnessAlloc(Fitness::Alloc::Handle inFitnessAlloc)
  {
    mFitnessAlloc = inFitnessAlloc;
  }

protected:
  Fitness::Alloc::Handle mFitnessAlloc;  //!< Fitness allocator.
  Fitness::Handle        mFitness;       //!< Fitness value of the current individual.

public:
  virtual void read(XMLNode::Handle& inNode);   // Undefined for Individual!

};

}

#endif // Beagle_Individual_hpp
