FlowShopOpCrossoverQuad.cpp

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // FlowShopOpCrossoverQuad.cpp
00005 // (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
00006 /*
00007     This library...
00008 
00009     Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
00010  */
00011 //-----------------------------------------------------------------------------
00012 
00013 #include <FlowShopOpCrossoverQuad.h>
00014 
00015 
00016 std::string FlowShopOpCrossoverQuad::className() const
00017 {
00018     return "FlowShopOpCrossoverQuad";
00019 }
00020 
00021 
00022 bool FlowShopOpCrossoverQuad::operator()(FlowShop & _flowshop1, FlowShop & _flowshop2)
00023 {
00024     bool oneAtLeastIsModified;
00025     // computation of the 2 random points
00026     unsigned int point1, point2;
00027     do
00028     {
00029         point1 =  rng.random(std::min(_flowshop1.size(), _flowshop2.size()));
00030         point2 =  rng.random(std::min(_flowshop1.size(), _flowshop2.size()));
00031     } while (fabs((double) point1-point2) <= 2);
00032     // computation of the offspring
00033     FlowShop offspring1 = generateOffspring(_flowshop1, _flowshop2, point1, point2);
00034     FlowShop offspring2 = generateOffspring(_flowshop2, _flowshop1, point1, point2);
00035     // does at least one genotype has been modified ?
00036     if ((_flowshop1 != offspring1) || (_flowshop2 != offspring2))
00037     {
00038         // update
00039         _flowshop1.value(offspring1);
00040         _flowshop2.value(offspring2);
00041         // at least one genotype has been modified
00042         oneAtLeastIsModified = true;
00043     }
00044     else
00045     {
00046         // no genotype has been modified
00047         oneAtLeastIsModified = false;
00048     }
00049     // return 'true' if at least one genotype has been modified
00050     return oneAtLeastIsModified;
00051 }
00052 
00053 
00054 FlowShop FlowShopOpCrossoverQuad::generateOffspring(const FlowShop & _parent1, const FlowShop & _parent2, unsigned int _point1, unsigned int _point2)
00055 {
00056     FlowShop result = _parent1;
00057     std::vector<bool> taken_values(result.size(), false);
00058     if (_point1 > _point2)
00059         std::swap(_point1, _point2);
00060     /* first parent */
00061     for (unsigned int i=0 ; i<=_point1 ; i++)
00062     {
00063         // result[i] == _parent1[i]
00064         taken_values[_parent1[i]] = true;
00065     }
00066     for (unsigned int i=_point2 ; i<result.size() ; i++)
00067     {
00068         // result[i] == _parent1[i]
00069         taken_values[_parent1[i]] = true;
00070     }
00071     /* second parent */
00072     unsigned int i = _point1+1;
00073     unsigned int j = 0;
00074     while (i<_point2 && j<_parent2.size())
00075     {
00076         if (! taken_values[_parent2[j]])
00077         {
00078             result[i] = _parent2[j];
00079             i++;
00080         }
00081         j++;
00082     }
00083     return result;
00084 }

Generated on Mon Oct 8 10:35:51 2007 for ParadisEO-MOEOMovingObjects by  doxygen 1.4.7