/*
 *  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/GA/CrossoverBlendESVecOp.hpp
 *  \brief  Definition of the class GA::CrossoverBlendESVecOp.
 *  \author Christian Gagne
 *  \author Marc Parizeau
 *  $Revision: 1.1 $
 *  $Date: 2004/04/05 03:51:57 $
 */

#ifndef Beagle_GA_CrossoverBlendESVecOp_hpp
#define Beagle_GA_CrossoverBlendESVecOp_hpp

#include <string>

#include "beagle/config.hpp"
#include "beagle/macros.hpp"
#include "beagle/Object.hpp"
#include "beagle/CrossoverOp.hpp"

namespace Beagle {
namespace GA {

/*!
 *  \class CrossoverBlendESVecOp beagle/GA/CrossoverBlendESVecOp.hpp
 *    "beagle/GA/CrossoverBlendESVecOp.hpp"
 *  \brief ES blend crossover operator class.
 *  \ingroup ESF
 *
 *  ES blend crossover proceed by blending ES values, \f$(v_1,v_2)\f$, and ES strategy 
 *  parameter \f$(p_1,p_2)\f$ using a randomly choosen factor \f$\alpha\in[0,1]\f$. 
 *  The resulting children are equal to \f$c_1=v_1+(\alpha(v_2-v_1))\f$, 
 *  \f$c_2=v_2-(\alpha(v_2-v_1))\f$ for the values, and \f$s_1=p_1+(\alpha(p_2-p_1))\f$, 
 *  \f$s_2=p_2-(\alpha(p_2-p_1))\f$ for the strategy parameter. So it consists
 *  to generate two children that have values that are on the line connecting the two
 *  parents, with an factor determining how near (or far) the children will be from the 
 *  parents. \f$\alpha\f$ factor near 0.0 and 1.0 produces children very similar to the 
 *  parents, while \f$\alpha\f$ factor near 0.5 produces children different the parents 
 *  (children with parameter values on a point in the parameter space located half-way 
 *  the two parents location).
 *
 */
class CrossoverBlendESVecOp : public CrossoverOp {

public:

  //! GA::CrossoverBlendESVecOp allocator type.
  typedef AllocatorT<CrossoverBlendESVecOp,CrossoverOp::Alloc>
          Alloc;
  //! GA::CrossoverBlendESVecOp handle type.
  typedef PointerT<CrossoverBlendESVecOp,CrossoverOp::Handle>
          Handle;
  //! GA::CrossoverBlendESVecOp bag type.
  typedef ContainerT<CrossoverBlendESVecOp,CrossoverOp::Bag>
          Bag;

  explicit CrossoverBlendESVecOp(std::string inMatingPbName="es.cxblend.prob",
                                 std::string inName="GA-CrossoverBlendESVecOp");
  virtual ~CrossoverBlendESVecOp() { }

  virtual void initialize(System& ioSystem);
  virtual bool mate(Individual& ioIndiv1, Context& ioContext1,
                    Individual& ioIndiv2, Context& ioContext2);
                                 
};

}
}


#endif // Beagle_GA_CrossoverBlendESVecOp_hpp
