00001 /* 00002 * <order_xover.cpp> 00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 00004 * (C) OPAC Team, LIFL, 2002-2007 00005 * 00006 * Sébastien Cahon, Jean-Charles Boisson 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 #include <vector> 00039 00040 #include <utils/eoRNG.h> 00041 00042 #include "order_xover.h" 00043 #include "route_valid.h" 00044 00045 void OrderXover :: cross (const Route & __par1, const Route & __par2, Route & __child) 00046 { 00047 00048 unsigned int cut = rng.random (__par1.size ()) ; 00049 00050 /* To store vertices that have 00051 already been crossed */ 00052 std::vector<bool> v; 00053 v.resize(__par1.size()); 00054 00055 for (unsigned int i = 0 ; i < __par1.size () ; i ++) 00056 { 00057 v [i] = false ; 00058 } 00059 00060 /* Copy of the left partial 00061 route of the first parent */ 00062 for (unsigned int i = 0 ; i < cut ; i ++) 00063 { 00064 __child [i] = __par1 [i] ; 00065 v [__par1 [i]] = true ; 00066 } 00067 00068 /* Searching the vertex of the second path, that ended 00069 the previous first one */ 00070 unsigned int from = 0 ; 00071 for (unsigned int i = 0 ; i < __par2.size () ; i ++) 00072 { 00073 if (__par2 [i] == __child [cut - 1]) 00074 { 00075 from = i ; 00076 break ; 00077 } 00078 } 00079 00080 /* Selecting a direction 00081 Left or Right */ 00082 char direct = rng.flip () ? 1 : -1 ; 00083 00084 /* Copy of the left vertices from 00085 the second parent path */ 00086 unsigned int l = cut ; 00087 00088 for (unsigned int i = 0 ; i < __par2.size () ; i ++) 00089 { 00090 unsigned int bidule /* :-) */ = (direct * i + from + __par2.size ()) % __par2.size () ; 00091 if (! v [__par2 [bidule]]) 00092 { 00093 __child [l ++] = __par2 [bidule] ; 00094 v [__par2 [bidule]] = true ; 00095 } 00096 } 00097 00098 v.clear(); 00099 } 00100 00101 bool OrderXover :: operator () (Route & __route1, Route & __route2) 00102 { 00103 00104 // Init. copy 00105 Route par [2] ; 00106 par [0] = __route1 ; 00107 par [1] = __route2 ; 00108 00109 cross (par [0], par [1], __route1) ; 00110 cross (par [1], par [0], __route2) ; 00111 00112 assert (valid (__route1)) ; 00113 assert (valid (__route2)) ; 00114 00115 __route1.invalidate () ; 00116 __route2.invalidate () ; 00117 00118 return true ; 00119 }
1.4.7