- Main Page
- Classes
- Files

- Search for |

# FlowShopOpMutationShift.cpp

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // FlowShopOpMutationShift.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 <FlowShopOpMutationShift.h>
    00014
    00015
    00016 std::string FlowShopOpMutationShift::className() const
    00017 {
    00018     return "FlowShopOpMutationShift";
    00019 }
    00020
    00021
    00022 bool FlowShopOpMutationShift::operator()(FlowShop & _flowshop)
    00023 {
    00024     bool isModified;
    00025     int direction;
    00026     unsigned int tmp;
    00027     FlowShop result = _flowshop;
    00028     // computation of the 2 random points
    00029     unsigned int point1, point2;
    00030     do
    00031     {
    00032         point1 = rng.random(result.size());
    00033         point2 = rng.random(result.size());
    00034     } while (point1 == point2);
    00035     // direction
    00036     if (point1 < point2)
    00037         direction = 1;
    00038     else
    00039         direction = -1;
    00040     // mutation
    00041     tmp = result[point1];
    00042     for (unsigned int i=point1 ; i!=point2 ; i+=direction)
    00043         result[i] = result[i+direction];
    00044     result[point2] = tmp;
    00045     // update (if necessary)
    00046     if (result != _flowshop)
    00047     {
    00048         // update
    00049         _flowshop.value(result);
    00050         // the genotype has been modified
    00051         isModified = true;
    00052     }
    00053     else
    00054     {
    00055         // the genotype has not been modified
    00056         isModified = false;
    00057     }
    00058     // return 'true' if the genotype has been modified
    00059     return isModified;
    00060 }