Tsp source code update has been also made for contribution

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@938 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jboisson 2008-02-13 14:56:53 +00:00
commit df20d8acc5
16 changed files with 362 additions and 278 deletions

View file

@ -3,7 +3,7 @@
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
* *
* Sébastien Cahon, Thomas Legrand * Sébastien Cahon, Jean-Charles Boisson
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -38,7 +38,8 @@
#include "city_swap.h" #include "city_swap.h"
bool CitySwap :: operator () (Route & __route) { bool CitySwap :: operator () (Route & __route)
{
std :: swap (__route [rng.random (__route.size ())], std :: swap (__route [rng.random (__route.size ())],
__route [rng.random (__route.size ())]) ; __route [rng.random (__route.size ())]) ;

View file

@ -3,7 +3,7 @@
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
* *
* Sébastien Cahon, Thomas Legrand * Sébastien Cahon, Jean-Charles Boisson
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -43,12 +43,13 @@
/** Its swaps two vertices /** Its swaps two vertices
randomly choosen */ randomly choosen */
class CitySwap : public eoMonOp <Route> { class CitySwap : public eoMonOp <Route>
{
public : public :
bool operator () (Route & __route) ; bool operator () (Route & __route) ;
} ; } ;
#endif #endif

View file

@ -3,7 +3,7 @@
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
* *
* Sébastien Cahon, Thomas Legrand * Sébastien Cahon, Jean-Charles Boisson
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -43,15 +43,18 @@
#define MAXINT 1000000 #define MAXINT 1000000
void EdgeXover :: build_map (const Route & __par1, const Route & __par2) { void
EdgeXover :: build_map (const Route & __par1, const Route & __par2)
{
unsigned len = __par1.size () ; unsigned int len = __par1.size () ;
/* Initialization */ /* Initialization */
_map.clear () ; _map.clear () ;
_map.resize (len) ; _map.resize (len) ;
for (unsigned i = 0 ; i < len ; i ++) { for (unsigned int i = 0 ; i < len ; i ++)
{
_map [__par1 [i]].insert (__par1 [(i + 1) % len]) ; _map [__par1 [i]].insert (__par1 [(i + 1) % len]) ;
_map [__par2 [i]].insert (__par2 [(i + 1) % len]) ; _map [__par2 [i]].insert (__par2 [(i + 1) % len]) ;
_map [__par1 [i]].insert (__par1 [(i - 1 + len) % len]) ; _map [__par1 [i]].insert (__par1 [(i - 1 + len) % len]) ;
@ -62,68 +65,81 @@ void EdgeXover :: build_map (const Route & __par1, const Route & __par2) {
visited.resize (len, false) ; visited.resize (len, false) ;
} }
void EdgeXover :: remove_entry (unsigned __vertex, std :: vector <std :: set <unsigned> > & __map) { void
EdgeXover :: remove_entry (unsigned int __vertex, std :: vector <std :: set <unsigned int> > & __map)
{
std :: set <unsigned> & neigh = __map [__vertex] ; std :: set <unsigned int> & neigh = __map [__vertex] ;
for (std :: set <unsigned> :: iterator it = neigh.begin () ; for (std :: set <unsigned int> :: iterator it = neigh.begin () ; it != neigh.end () ; it ++)
it != neigh.end () ; {
it ++)
__map [* it].erase (__vertex) ; __map [* it].erase (__vertex) ;
}
} }
void EdgeXover :: add_vertex (unsigned __vertex, Route & __child) {
void
EdgeXover :: add_vertex (unsigned int __vertex, Route & __child)
{
visited [__vertex] = true ; visited [__vertex] = true ;
__child.push_back (__vertex) ; __child.push_back (__vertex) ;
remove_entry (__vertex, _map) ; /* Removing entries */ remove_entry (__vertex, _map) ; /* Removing entries */
} }
void EdgeXover :: cross (const Route & __par1, const Route & __par2, Route & __child) { void
EdgeXover :: cross (const Route & __par1, const Route & __par2, Route & __child)
{
build_map (__par1, __par2) ; build_map (__par1, __par2) ;
unsigned len = __par1.size () ; unsigned int len = __par1.size () ;
/* Go ! */ /* Go ! */
__child.clear () ; __child.clear () ;
unsigned cur_vertex = rng.random (len) ; unsigned int cur_vertex = rng.random (len) ;
add_vertex (cur_vertex, __child) ; add_vertex (cur_vertex, __child) ;
for (unsigned i = 1 ; i < len ; i ++) { for (unsigned int i = 1 ; i < len ; i ++)
{
unsigned len_min_entry = MAXINT ; unsigned int len_min_entry = MAXINT ;
std :: set <unsigned> & neigh = _map [cur_vertex] ; std :: set <unsigned int> & neigh = _map [cur_vertex] ;
for (std :: set <unsigned> :: iterator it = neigh.begin () ; for (std :: set <unsigned int> :: iterator it = neigh.begin () ; it != neigh.end () ; it ++)
it != neigh.end () ; {
it ++) { unsigned int l = _map [* it].size () ;
unsigned l = _map [* it].size () ;
if (len_min_entry > l) if (len_min_entry > l)
{
len_min_entry = l ; len_min_entry = l ;
} }
std :: vector <unsigned> cand ; /* Candidates */
for (std :: set <unsigned> :: iterator it = neigh.begin () ;
it != neigh.end () ;
it ++) {
unsigned l = _map [* it].size () ;
if (len_min_entry == l)
cand.push_back (* it) ;
} }
if (! cand.size ()) { std :: vector <unsigned int> cand ; /* Candidates */
for (std :: set <unsigned> :: iterator it = neigh.begin () ; it != neigh.end () ; it ++)
{
unsigned int l = _map [* it].size () ;
if (len_min_entry == l)
{
cand.push_back (* it) ;
}
}
if (! cand.size ())
{
/* Oh no ! Implicit mutation */ /* Oh no ! Implicit mutation */
for (unsigned j = 0 ; j < len ; j ++) for (unsigned int j = 0 ; j < len ; j ++)
{
if (! visited [j]) if (! visited [j])
{
cand.push_back (j) ; cand.push_back (j) ;
} }
}
}
cur_vertex = cand [rng.random (cand.size ())] ; cur_vertex = cand [rng.random (cand.size ())] ;
@ -131,7 +147,9 @@ void EdgeXover :: cross (const Route & __par1, const Route & __par2, Route & __c
} }
} }
bool EdgeXover :: operator () (Route & __route1, Route & __route2) { bool
EdgeXover :: operator () (Route & __route1, Route & __route2)
{
// Init. copy // Init. copy
Route par [2] ; Route par [2] ;

View file

@ -3,7 +3,7 @@
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
* *
* Sébastien Cahon, Thomas Legrand * Sébastien Cahon, Jean-Charles Boisson
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -45,27 +45,28 @@
#include "route.h" #include "route.h"
/** Edge Crossover */ /** Edge Crossover */
class EdgeXover : public eoQuadOp <Route> { class EdgeXover : public eoQuadOp <Route>
{
public : public :
bool operator () (Route & __route1, Route & __route2) ; bool operator () (Route & __route1, Route & __route2) ;
private : private :
void cross (const Route & __par1, const Route & __par2, Route & __child) ; /* Binary */ void cross (const Route & __par1, const Route & __par2, Route & __child) ; /* Binary */
void remove_entry (unsigned __vertex, std :: vector <std :: set <unsigned> > & __map) ; void remove_entry (unsigned int __vertex, std :: vector <std :: set <unsigned> > & __map) ;
/* Updating the map of entries */ /* Updating the map of entries */
void build_map (const Route & __par1, const Route & __par2) ; void build_map (const Route & __par1, const Route & __par2) ;
void add_vertex (unsigned __vertex, Route & __child) ; void add_vertex (unsigned int __vertex, Route & __child) ;
std :: vector <std :: set <unsigned> > _map ; /* The handled map */ std :: vector <std :: set <unsigned int> > _map ; /* The handled map */
std :: vector <bool> visited ; /* Vertices that are already visited */ std :: vector <bool> visited ; /* Vertices that are already visited */
} ; } ;
#endif #endif

View file

@ -3,7 +3,7 @@
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
* *
* Sébastien Cahon, Thomas Legrand * Sébastien Cahon, Jean-Charles Boisson
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -40,16 +40,16 @@
#include <vector> #include <vector>
#include <utility> #include <utility>
namespace Graph { namespace Graph
{
void load (const char * __file_name) ; void load (const char * __file_name) ;
/* Loading cities /* Loading cities
(expressed by their coordinates) (expressed by their coordinates)
from the given file name */ from the given file name */
float distance (unsigned __from, unsigned __to) ; float distance (unsigned int __from, unsigned int __to) ;
unsigned size () ; // How many cities ? unsigned int size () ; // How many cities ?
} }
#endif #endif

View file

@ -3,7 +3,7 @@
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
* *
* Sébastien Cahon, Thomas Legrand * Sébastien Cahon, Jean-Charles Boisson
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -39,10 +39,12 @@
#include <utils/eoRNG.h> #include <utils/eoRNG.h>
template <class T> void mix (std :: vector <T> & __vect) { template <class T> void mix (std :: vector <T> & __vect)
{
for (unsigned i = 0 ; i < __vect.size () ; i ++) for (unsigned int i = 0 ; i < __vect.size () ; i ++)
{
std :: swap (__vect [i], __vect [rng.random (__vect.size ())]) ; std :: swap (__vect [i], __vect [rng.random (__vect.size ())]) ;
}
} }
#endif #endif

View file

@ -3,7 +3,7 @@
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
* *
* Sébastien Cahon, Thomas Legrand * Sébastien Cahon, Jean-Charles Boisson
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -35,38 +35,47 @@
*/ */
#include <assert.h> #include <assert.h>
#include <vector>
#include <utils/eoRNG.h> #include <utils/eoRNG.h>
#include "order_xover.h" #include "order_xover.h"
#include "route_valid.h" #include "route_valid.h"
void OrderXover :: cross (const Route & __par1, const Route & __par2, Route & __child) { void OrderXover :: cross (const Route & __par1, const Route & __par2, Route & __child)
{
unsigned int cut = rng.random (__par1.size ()) ;
unsigned cut = rng.random (__par1.size ()) ;
/* To store vertices that have /* To store vertices that have
already been crossed */ already been crossed */
bool v [__par1.size ()] ; std::vector<bool> v;
for (unsigned i = 0 ; i < __par1.size () ; i ++) v.resize(__par1.size());
for (unsigned int i = 0 ; i < __par1.size () ; i ++)
{
v [i] = false ; v [i] = false ;
}
/* Copy of the left partial /* Copy of the left partial
route of the first parent */ route of the first parent */
for (unsigned i = 0 ; i < cut ; i ++) { for (unsigned int i = 0 ; i < cut ; i ++)
{
__child [i] = __par1 [i] ; __child [i] = __par1 [i] ;
v [__par1 [i]] = true ; v [__par1 [i]] = true ;
} }
/* Searching the vertex of the second path, that ended /* Searching the vertex of the second path, that ended
the previous first one */ the previous first one */
unsigned from = 0 ; unsigned int from = 0 ;
for (unsigned i = 0 ; i < __par2.size () ; i ++) for (unsigned int i = 0 ; i < __par2.size () ; i ++)
if (__par2 [i] == __child [cut - 1]) { {
if (__par2 [i] == __child [cut - 1])
{
from = i ; from = i ;
break ; break ;
} }
}
/* Selecting a direction /* Selecting a direction
Left or Right */ Left or Right */
@ -74,18 +83,23 @@ void OrderXover :: cross (const Route & __par1, const Route & __par2, Route & __
/* Copy of the left vertices from /* Copy of the left vertices from
the second parent path */ the second parent path */
unsigned l = cut ; unsigned int l = cut ;
for (unsigned i = 0 ; i < __par2.size () ; i ++) { for (unsigned int i = 0 ; i < __par2.size () ; i ++)
unsigned bidule /* :-) */ = (direct * i + from + __par2.size ()) % __par2.size () ; {
if (! v [__par2 [bidule]]) { unsigned int bidule /* :-) */ = (direct * i + from + __par2.size ()) % __par2.size () ;
if (! v [__par2 [bidule]])
{
__child [l ++] = __par2 [bidule] ; __child [l ++] = __par2 [bidule] ;
v [__par2 [bidule]] = true ; v [__par2 [bidule]] = true ;
} }
} }
v.clear();
} }
bool OrderXover :: operator () (Route & __route1, Route & __route2) { bool OrderXover :: operator () (Route & __route1, Route & __route2)
{
// Init. copy // Init. copy
Route par [2] ; Route par [2] ;

View file

@ -3,7 +3,7 @@
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
* *
* Sébastien Cahon, Thomas Legrand * Sébastien Cahon, Jean-Charles Boisson
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -42,15 +42,16 @@
#include "route.h" #include "route.h"
/** Order Crossover */ /** Order Crossover */
class OrderXover : public eoQuadOp <Route> { class OrderXover : public eoQuadOp <Route>
{
public : public :
bool operator () (Route & __route1, Route & __route2) ; bool operator () (Route & __route1, Route & __route2) ;
private : private :
void cross (const Route & __par1, const Route & __par2, Route & __child) ; void cross (const Route & __par1, const Route & __par2, Route & __child) ;
} ; } ;
#endif #endif

View file

@ -3,7 +3,7 @@
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
* *
* Sébastien Cahon, Thomas Legrand * Sébastien Cahon, Jean-Charles Boisson
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -42,20 +42,21 @@
#include "route.h" #include "route.h"
/** Route Evaluator */ /** Route Evaluator */
class PartRouteEval : public eoEvalFunc <Route> { class PartRouteEval : public eoEvalFunc <Route>
{
public : public :
/** Constructor */ /** Constructor */
PartRouteEval (float __from, float __to) ; PartRouteEval (float __from, float __to) ;
void operator () (Route & __route) ; void operator () (Route & __route) ;
private : private :
float from, to ; float from, to ;
} ; } ;
#endif #endif

View file

@ -3,7 +3,7 @@
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
* *
* Sébastien Cahon, Thomas Legrand * Sébastien Cahon, Jean-Charles Boisson
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -36,48 +36,72 @@
#include <assert.h> #include <assert.h>
#include <vector>
#include <utils/eoRNG.h> #include <utils/eoRNG.h>
#include "partial_mapped_xover.h" #include "partial_mapped_xover.h"
#include "route_valid.h" #include "route_valid.h"
#include "mix.h" #include "mix.h"
void PartialMappedXover :: repair (Route & __route, unsigned __cut1, unsigned __cut2) { void PartialMappedXover :: repair (Route & __route, unsigned __cut1, unsigned __cut2)
{
unsigned v [__route.size ()] ; // Number of times a cities are visited ... std::vector<unsigned int> v; // Number of times a cities are visited ...
for (unsigned i = 0 ; i < __route.size () ; i ++) v.resize(__route.size ());
for (unsigned int i = 0 ; i < __route.size () ; i ++)
{
v [i] = 0 ; v [i] = 0 ;
}
for (unsigned i = 0 ; i < __route.size () ; i ++) for (unsigned int i = 0 ; i < __route.size () ; i ++)
{
v [__route [i]] ++ ; v [__route [i]] ++ ;
}
std :: vector <unsigned> vert ; std :: vector <unsigned int> vert ;
for (unsigned i = 0 ; i < __route.size () ; i ++) for (unsigned int i = 0 ; i < __route.size () ; i ++)
{
if (! v [i]) if (! v [i])
{
vert.push_back (i) ; vert.push_back (i) ;
}
}
mix (vert) ; mix (vert) ;
for (unsigned i = 0 ; i < __route.size () ; i ++) for (unsigned int i = 0 ; i < __route.size () ; i ++)
{
if (i < __cut1 || i >= __cut2) if (i < __cut1 || i >= __cut2)
if (v [__route [i]] > 1) { {
if (v [__route [i]] > 1)
{
__route [i] = vert.back () ; __route [i] = vert.back () ;
vert.pop_back () ; vert.pop_back () ;
} }
}
}
v.clear();
} }
bool PartialMappedXover :: operator () (Route & __route1, Route & __route2) { bool PartialMappedXover :: operator () (Route & __route1, Route & __route2)
{
unsigned cut1 = rng.random (__route1.size ()), cut2 = rng.random (__route2.size ()) ; unsigned int cut1 = rng.random (__route1.size ()), cut2 = rng.random (__route2.size ()) ;
if (cut2 < cut1) if (cut2 < cut1)
{
std :: swap (cut1, cut2) ; std :: swap (cut1, cut2) ;
}
// Between the cuts // Between the cuts
for (unsigned i = cut1 ; i < cut2 ; i ++) for (unsigned int i = cut1 ; i < cut2 ; i ++)
{
std :: swap (__route1 [i], __route2 [i]) ; std :: swap (__route1 [i], __route2 [i]) ;
}
// Outside the cuts // Outside the cuts
repair (__route1, cut1, cut2) ; repair (__route1, cut1, cut2) ;

View file

@ -3,7 +3,7 @@
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
* *
* Sébastien Cahon, Thomas Legrand * Sébastien Cahon, Jean-Charles Boisson
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -42,15 +42,16 @@
#include "route.h" #include "route.h"
/** Partial Mapped Crossover */ /** Partial Mapped Crossover */
class PartialMappedXover : public eoQuadOp <Route> { class PartialMappedXover : public eoQuadOp <Route>
{
public : public :
bool operator () (Route & __route1, Route & __route2) ; bool operator () (Route & __route1, Route & __route2) ;
private : private :
void repair (Route & __route, unsigned __cut1, unsigned __cut2) ; void repair (Route & __route, unsigned __cut1, unsigned __cut2) ;
} ; } ;
#endif #endif

View file

@ -3,7 +3,7 @@
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
* *
* Sébastien Cahon, Thomas Legrand * Sébastien Cahon, Jean-Charles Boisson
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -42,13 +42,14 @@
#include "route.h" #include "route.h"
/** Route Evaluator */ /** Route Evaluator */
class RouteEval : public eoEvalFunc <Route> { class RouteEval : public eoEvalFunc <Route>
{
public : public :
void operator () (Route & __route) ; void operator () (Route & __route) ;
} ; } ;
#endif #endif

View file

@ -3,7 +3,7 @@
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
* *
* Sébastien Cahon, Thomas Legrand * Sébastien Cahon, Jean-Charles Boisson
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -39,20 +39,24 @@
#include "route_init.h" #include "route_init.h"
#include "graph.h" #include "graph.h"
void RouteInit :: operator () (Route & __route) { void RouteInit :: operator () (Route & __route)
{
// Init. // Init.
__route.clear () ; __route.clear () ;
for (unsigned i = 0 ; i < Graph :: size () ; i ++) for (unsigned int i = 0 ; i < Graph :: size () ; i ++)
{
__route.push_back (i) ; __route.push_back (i) ;
}
// Swap. cities // Swap. cities
for (unsigned i = 0 ; i < Graph :: size () ; i ++) { for (unsigned int i = 0 ; i < Graph :: size () ; i ++)
//unsigned j = rng.random (Graph :: size ()) ; {
//unsigned int j = rng.random (Graph :: size ()) ;
unsigned j = (unsigned) (Graph :: size () * (rand () / (RAND_MAX + 1.0))) ; unsigned int j = (unsigned int) (Graph :: size () * (rand () / (RAND_MAX + 1.0))) ;
unsigned city = __route [i] ; unsigned int city = __route [i] ;
__route [i] = __route [j] ; __route [i] = __route [j] ;
__route [j] = city ; __route [j] = city ;
} }

View file

@ -3,7 +3,7 @@
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
* *
* Sébastien Cahon, Thomas Legrand * Sébastien Cahon, Jean-Charles Boisson
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -41,12 +41,13 @@
#include "route.h" #include "route.h"
class RouteInit : public eoInit <Route> { class RouteInit : public eoInit <Route>
{
public : public :
void operator () (Route & __route) ; void operator () (Route & __route) ;
} ; } ;
#endif #endif

View file

@ -3,7 +3,7 @@
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
* *
* Sébastien Cahon, Thomas Legrand * Sébastien Cahon, Jean-Charles Boisson
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,
@ -36,19 +36,33 @@
#include "route_valid.h" #include "route_valid.h"
bool valid (Route & __route) { #include <vector>
unsigned t [__route.size ()] ; bool valid (Route & __route)
{
for (unsigned i = 0 ; i < __route.size () ; i ++) std::vector<unsigned int> t;
t.resize(__route.size());
for (unsigned int i = 0 ; i < __route.size () ; i ++)
{
t [i] = 0 ; t [i] = 0 ;
}
for (unsigned i = 0 ; i < __route.size () ; i ++) for (unsigned int i = 0 ; i < __route.size () ; i ++)
{
t [__route [i]] ++ ; t [__route [i]] ++ ;
}
for (unsigned i = 0 ; i < __route.size () ; i ++) for (unsigned int i = 0 ; i < __route.size () ; i ++)
{
if (t [i] != 1) if (t [i] != 1)
{
t.clear();
return false ; return false ;
}
}
t.clear();
return true ; // OK. return true ; // OK.
} }

View file

@ -3,7 +3,7 @@
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
* (C) OPAC Team, LIFL, 2002-2007 * (C) OPAC Team, LIFL, 2002-2007
* *
* Sébastien Cahon, Thomas Legrand * Sébastien Cahon, Jean-Charles Boisson
* *
* This software is governed by the CeCILL license under French law and * This software is governed by the CeCILL license under French law and
* abiding by the rules of distribution of free software. You can use, * abiding by the rules of distribution of free software. You can use,