FlowShopOpCrossoverQuad.cpp

00001 /*
00002 * <FlowShopOpCrossoverQuad.cpp>
00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
00004 * (C) OPAC Team, LIFL, 2002-2007
00005 *
00006 * Arnaud Liefooghe
00007 *
00008 * This software is governed by the CeCILL license under French law and
00009 * abiding by the rules of distribution of free software.  You can  use,
00010 * modify and/ or redistribute the software under the terms of the CeCILL
00011 * license as circulated by CEA, CNRS and INRIA at the following URL
00012 * "http://www.cecill.info".
00013 *
00014 * As a counterpart to the access to the source code and  rights to copy,
00015 * modify and redistribute granted by the license, users are provided only
00016 * with a limited warranty  and the software's author,  the holder of the
00017 * economic rights,  and the successive licensors  have only  limited liability.
00018 *
00019 * In this respect, the user's attention is drawn to the risks associated
00020 * with loading,  using,  modifying and/or developing or reproducing the
00021 * software by the user in light of its specific status of free software,
00022 * that may mean  that it is complicated to manipulate,  and  that  also
00023 * therefore means  that it is reserved for developers  and  experienced
00024 * professionals having in-depth computer knowledge. Users are therefore
00025 * encouraged to load and test the software's suitability as regards their
00026 * requirements in conditions enabling the security of their systems and/or
00027 * data to be ensured and,  more generally, to use and operate it in the
00028 * same conditions as regards security.
00029 * The fact that you are presently reading this means that you have had
00030 * knowledge of the CeCILL license and that you accept its terms.
00031 *
00032 * ParadisEO WebSite : http://paradiseo.gforge.inria.fr
00033 * Contact: paradiseo-help@lists.gforge.inria.fr
00034 *
00035 */
00036 //-----------------------------------------------------------------------------
00037 
00038 #include <FlowShopOpCrossoverQuad.h>
00039 
00040 
00041 std::string FlowShopOpCrossoverQuad::className() const
00042   {
00043     return "FlowShopOpCrossoverQuad";
00044   }
00045 
00046 
00047 bool FlowShopOpCrossoverQuad::operator()(FlowShop & _flowshop1, FlowShop & _flowshop2)
00048 {
00049   bool oneAtLeastIsModified;
00050   // computation of the 2 random points
00051   unsigned int point1, point2;
00052   do
00053     {
00054       point1 =  rng.random(std::min(_flowshop1.size(), _flowshop2.size()));
00055       point2 =  rng.random(std::min(_flowshop1.size(), _flowshop2.size()));
00056     }
00057   while (fabs((double) point1-point2) <= 2);
00058   // computation of the offspring
00059   FlowShop offspring1 = generateOffspring(_flowshop1, _flowshop2, point1, point2);
00060   FlowShop offspring2 = generateOffspring(_flowshop2, _flowshop1, point1, point2);
00061   // does at least one genotype has been modified ?
00062   if ((_flowshop1 != offspring1) || (_flowshop2 != offspring2))
00063     {
00064       // update
00065       _flowshop1.value(offspring1);
00066       _flowshop2.value(offspring2);
00067       // at least one genotype has been modified
00068       oneAtLeastIsModified = true;
00069     }
00070   else
00071     {
00072       // no genotype has been modified
00073       oneAtLeastIsModified = false;
00074     }
00075   // return 'true' if at least one genotype has been modified
00076   return oneAtLeastIsModified;
00077 }
00078 
00079 
00080 FlowShop FlowShopOpCrossoverQuad::generateOffspring(const FlowShop & _parent1, const FlowShop & _parent2, unsigned int _point1, unsigned int _point2)
00081 {
00082   FlowShop result = _parent1;
00083   std::vector<bool> taken_values(result.size(), false);
00084   if (_point1 > _point2)
00085     std::swap(_point1, _point2);
00086   /* first parent */
00087   for (unsigned int i=0 ; i<=_point1 ; i++)
00088     {
00089       // result[i] == _parent1[i]
00090       taken_values[_parent1[i]] = true;
00091     }
00092   for (unsigned int i=_point2 ; i<result.size() ; i++)
00093     {
00094       // result[i] == _parent1[i]
00095       taken_values[_parent1[i]] = true;
00096     }
00097   /* second parent */
00098   unsigned int i = _point1+1;
00099   unsigned int j = 0;
00100   while (i<_point2 && j<_parent2.size())
00101     {
00102       if (! taken_values[_parent2[j]])
00103         {
00104           result[i] = _parent2[j];
00105           i++;
00106         }
00107       j++;
00108     }
00109   return result;
00110 }

Generated on Thu Mar 13 15:54:07 2008 for ParadisEO-MOEO-MultiObjectiveEvolvingObjects by  doxygen 1.4.7