- Main Page
- Namespaces
- Classes
- Files

- Search for |

# order_xover.cpp

    00001 /*
    00002 * <order_xover.cpp>
    00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
    00004 * (C) OPAC Team, LIFL, 2002-2007
    00005 *
    00006 * Sebastien Cahon, Alexandru-Adrian Tantar
    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 #include <assert.h>
    00038
    00039 #include <utils/eoRNG.h>
    00040
    00041 #include "order_xover.h"
    00042
    00043 void OrderXover :: cross (const Route & __par1, const Route & __par2, Route & __child) {
    00044
    00045   unsigned cut2 = 1 + rng.random (numNodes) ;
    00046   unsigned cut1 = rng.random (cut2);
    00047   unsigned l = 0;
    00048
    00049   /* To store vertices that have already been crossed */
    00050   std :: vector <bool> v (numNodes, false);
    00051
    00052   /* Copy of the left partial route of the first parent */
    00053   for (unsigned i = cut1 ; i < cut2 ; i ++) {
    00054     __child [l ++] = __par1 [i] ;
    00055     v [__par1 [i]] = true ;
    00056   }
    00057
    00058   /* Searching the vertex of the second path, that ended the previous first one */
    00059   unsigned from = 0 ;
    00060   for (unsigned i = 0; i < numNodes; i ++)
    00061     if (__par2 [i] == __child [cut2 - 1]) {
    00062       from = i ;
    00063       break ;
    00064     }
    00065
    00066   /* Selecting a direction (Left or Right) */
    00067   char direct = rng.flip () ? 1 : -1 ;
    00068
    00069   for (unsigned i = 0; i < numNodes + 1; i ++) {
    00070     unsigned bidule = (direct * i + from + numNodes) % numNodes;
    00071     if (! v [__par2 [bidule]]) {
    00072       __child [l ++] = __par2 [bidule] ;
    00073       v [__par2 [bidule]] = true ;
    00074     }
    00075   }
    00076 }
    00077
    00078 bool OrderXover :: operator () (Route & __route1, Route & __route2) {
    00079
    00080   // Init. copy
    00081   Route par [2] ;
    00082   par [0] = __route1 ;
    00083   par [1] = __route2 ;
    00084
    00085   cross (par [0], par [1], __route1) ;
    00086   cross (par [1], par [0], __route2) ;
    00087
    00088   __route1.invalidate () ;
    00089   __route2.invalidate () ;
    00090
    00091   return true ;
    00092 }