diff --git a/contribution/trunk/combinatorial/routing/tsp/src/city_swap.cpp b/contribution/trunk/combinatorial/routing/tsp/src/city_swap.cpp index 8dcd6b7c6..e47a4e31b 100644 --- a/contribution/trunk/combinatorial/routing/tsp/src/city_swap.cpp +++ b/contribution/trunk/combinatorial/routing/tsp/src/city_swap.cpp @@ -1,9 +1,9 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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 * abiding by the rules of distribution of free software. You can use, @@ -38,12 +38,13 @@ #include "city_swap.h" -bool CitySwap :: operator () (Route & __route) { - +bool CitySwap :: operator () (Route & __route) +{ + std :: swap (__route [rng.random (__route.size ())], - __route [rng.random (__route.size ())]) ; - + __route [rng.random (__route.size ())]) ; + __route.invalidate () ; - + return true ; } diff --git a/contribution/trunk/combinatorial/routing/tsp/src/city_swap.h b/contribution/trunk/combinatorial/routing/tsp/src/city_swap.h index 828f94d38..eda897f0f 100644 --- a/contribution/trunk/combinatorial/routing/tsp/src/city_swap.h +++ b/contribution/trunk/combinatorial/routing/tsp/src/city_swap.h @@ -1,9 +1,9 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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 * abiding by the rules of distribution of free software. You can use, @@ -43,12 +43,13 @@ /** Its swaps two vertices randomly choosen */ -class CitySwap : public eoMonOp { - -public : - - bool operator () (Route & __route) ; - -} ; +class CitySwap : public eoMonOp + { + + public : + + bool operator () (Route & __route) ; + + } ; #endif diff --git a/contribution/trunk/combinatorial/routing/tsp/src/edge_xover.cpp b/contribution/trunk/combinatorial/routing/tsp/src/edge_xover.cpp index ff1e7426f..a8b6a8532 100644 --- a/contribution/trunk/combinatorial/routing/tsp/src/edge_xover.cpp +++ b/contribution/trunk/combinatorial/routing/tsp/src/edge_xover.cpp @@ -1,9 +1,9 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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 * abiding by the rules of distribution of free software. You can use, @@ -43,104 +43,122 @@ #define MAXINT 1000000 -void EdgeXover :: build_map (const Route & __par1, const Route & __par2) { - - unsigned len = __par1.size () ; - +void +EdgeXover :: build_map (const Route & __par1, const Route & __par2) +{ + + unsigned int len = __par1.size () ; + /* Initialization */ _map.clear () ; _map.resize (len) ; - - for (unsigned i = 0 ; i < len ; i ++) { - _map [__par1 [i]].insert (__par1 [(i + 1) % len]) ; - _map [__par2 [i]].insert (__par2 [(i + 1) % len]) ; - _map [__par1 [i]].insert (__par1 [(i - 1 + len) % len]) ; - _map [__par2 [i]].insert (__par2 [(i - 1 + len) % len]) ; - } - + + for (unsigned int i = 0 ; i < len ; i ++) + { + _map [__par1 [i]].insert (__par1 [(i + 1) % len]) ; + _map [__par2 [i]].insert (__par2 [(i + 1) % len]) ; + _map [__par1 [i]].insert (__par1 [(i - 1 + len) % len]) ; + _map [__par2 [i]].insert (__par2 [(i - 1 + len) % len]) ; + } + visited.clear () ; visited.resize (len, false) ; } -void EdgeXover :: remove_entry (unsigned __vertex, std :: vector > & __map) { - - std :: set & neigh = __map [__vertex] ; +void +EdgeXover :: remove_entry (unsigned int __vertex, std :: vector > & __map) + { - for (std :: set :: iterator it = neigh.begin () ; - it != neigh.end () ; - it ++) - __map [* it].erase (__vertex) ; - -} + std :: set & neigh = __map [__vertex] ; -void EdgeXover :: add_vertex (unsigned __vertex, Route & __child) { - + for (std :: set :: iterator it = neigh.begin () ; it != neigh.end () ; it ++) + { + __map [* it].erase (__vertex) ; + } + + } + +void +EdgeXover :: add_vertex (unsigned int __vertex, Route & __child) +{ visited [__vertex] = true ; - __child.push_back (__vertex) ; - remove_entry (__vertex, _map) ; /* Removing entries */ + __child.push_back (__vertex) ; + 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) ; - - unsigned len = __par1.size () ; - + + unsigned int len = __par1.size () ; + /* Go ! */ __child.clear () ; - - unsigned cur_vertex = rng.random (len) ; - + + unsigned int cur_vertex = rng.random (len) ; + add_vertex (cur_vertex, __child) ; - for (unsigned i = 1 ; i < len ; i ++) { - - unsigned len_min_entry = MAXINT ; - - std :: set & neigh = _map [cur_vertex] ; - - for (std :: set :: iterator it = neigh.begin () ; - it != neigh.end () ; - it ++) { - unsigned l = _map [* it].size () ; - if (len_min_entry > l) - len_min_entry = l ; - } - - std :: vector cand ; /* Candidates */ - - for (std :: set :: 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 ()) { - - /* Oh no ! Implicit mutation */ - for (unsigned j = 0 ; j < len ; j ++) - if (! visited [j]) - cand.push_back (j) ; - } + for (unsigned int i = 1 ; i < len ; i ++) + { - cur_vertex = cand [rng.random (cand.size ())] ; - - add_vertex (cur_vertex, __child) ; - } + unsigned int len_min_entry = MAXINT ; + + std :: set & neigh = _map [cur_vertex] ; + + for (std :: set :: iterator it = neigh.begin () ; it != neigh.end () ; it ++) + { + unsigned int l = _map [* it].size () ; + if (len_min_entry > l) + { + len_min_entry = l ; + } + } + + std :: vector cand ; /* Candidates */ + + for (std :: set :: 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 */ + for (unsigned int j = 0 ; j < len ; j ++) + { + if (! visited [j]) + { + cand.push_back (j) ; + } + } + } + + cur_vertex = cand [rng.random (cand.size ())] ; + + add_vertex (cur_vertex, __child) ; + } } -bool EdgeXover :: operator () (Route & __route1, Route & __route2) { - +bool +EdgeXover :: operator () (Route & __route1, Route & __route2) +{ + // Init. copy Route par [2] ; par [0] = __route1 ; par [1] = __route2 ; - + cross (par [0], par [1], __route1) ; cross (par [1], par [0], __route2) ; - + assert (valid (__route1)) ; assert (valid (__route2)) ; diff --git a/contribution/trunk/combinatorial/routing/tsp/src/edge_xover.h b/contribution/trunk/combinatorial/routing/tsp/src/edge_xover.h index a719c053e..3e97d6d48 100644 --- a/contribution/trunk/combinatorial/routing/tsp/src/edge_xover.h +++ b/contribution/trunk/combinatorial/routing/tsp/src/edge_xover.h @@ -1,9 +1,9 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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 * abiding by the rules of distribution of free software. You can use, @@ -45,27 +45,28 @@ #include "route.h" /** Edge Crossover */ -class EdgeXover : public eoQuadOp { - -public : - - bool operator () (Route & __route1, Route & __route2) ; +class EdgeXover : public eoQuadOp + { -private : - - void cross (const Route & __par1, const Route & __par2, Route & __child) ; /* Binary */ + public : - void remove_entry (unsigned __vertex, std :: vector > & __map) ; - /* Updating the map of entries */ + bool operator () (Route & __route1, Route & __route2) ; - void build_map (const Route & __par1, const Route & __par2) ; + private : - void add_vertex (unsigned __vertex, Route & __child) ; + void cross (const Route & __par1, const Route & __par2, Route & __child) ; /* Binary */ - std :: vector > _map ; /* The handled map */ + void remove_entry (unsigned int __vertex, std :: vector > & __map) ; + /* Updating the map of entries */ - std :: vector visited ; /* Vertices that are already visited */ + void build_map (const Route & __par1, const Route & __par2) ; -} ; + void add_vertex (unsigned int __vertex, Route & __child) ; + + std :: vector > _map ; /* The handled map */ + + std :: vector visited ; /* Vertices that are already visited */ + + } ; #endif diff --git a/contribution/trunk/combinatorial/routing/tsp/src/graph.h b/contribution/trunk/combinatorial/routing/tsp/src/graph.h index 97a487c59..bea04b225 100644 --- a/contribution/trunk/combinatorial/routing/tsp/src/graph.h +++ b/contribution/trunk/combinatorial/routing/tsp/src/graph.h @@ -1,9 +1,9 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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 * abiding by the rules of distribution of free software. You can use, @@ -40,16 +40,16 @@ #include #include -namespace Graph { - +namespace Graph + { void load (const char * __file_name) ; /* Loading cities (expressed by their coordinates) - from the given file name */ - - float distance (unsigned __from, unsigned __to) ; + from the given file name */ - unsigned size () ; // How many cities ? + float distance (unsigned int __from, unsigned int __to) ; + + unsigned int size () ; // How many cities ? } #endif diff --git a/contribution/trunk/combinatorial/routing/tsp/src/mix.h b/contribution/trunk/combinatorial/routing/tsp/src/mix.h index 9d3cdfa83..fc570a939 100644 --- a/contribution/trunk/combinatorial/routing/tsp/src/mix.h +++ b/contribution/trunk/combinatorial/routing/tsp/src/mix.h @@ -1,9 +1,9 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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 * abiding by the rules of distribution of free software. You can use, @@ -39,10 +39,12 @@ #include -template void mix (std :: vector & __vect) { - - for (unsigned i = 0 ; i < __vect.size () ; i ++) - std :: swap (__vect [i], __vect [rng.random (__vect.size ())]) ; +template void mix (std :: vector & __vect) +{ + for (unsigned int i = 0 ; i < __vect.size () ; i ++) + { + std :: swap (__vect [i], __vect [rng.random (__vect.size ())]) ; + } } #endif diff --git a/contribution/trunk/combinatorial/routing/tsp/src/order_xover.cpp b/contribution/trunk/combinatorial/routing/tsp/src/order_xover.cpp index 726c426c6..9e2c1f408 100644 --- a/contribution/trunk/combinatorial/routing/tsp/src/order_xover.cpp +++ b/contribution/trunk/combinatorial/routing/tsp/src/order_xover.cpp @@ -1,9 +1,9 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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 * abiding by the rules of distribution of free software. You can use, @@ -35,66 +35,80 @@ */ #include +#include #include #include "order_xover.h" #include "route_valid.h" -void OrderXover :: cross (const Route & __par1, const Route & __par2, Route & __child) { - - - unsigned cut = rng.random (__par1.size ()) ; - +void OrderXover :: cross (const Route & __par1, const Route & __par2, Route & __child) +{ + + unsigned int cut = rng.random (__par1.size ()) ; + /* To store vertices that have already been crossed */ - bool v [__par1.size ()] ; - for (unsigned i = 0 ; i < __par1.size () ; i ++) - v [i] = false ; + std::vector v; + v.resize(__par1.size()); + + for (unsigned int i = 0 ; i < __par1.size () ; i ++) + { + v [i] = false ; + } /* Copy of the left partial - route of the first parent */ - for (unsigned i = 0 ; i < cut ; i ++) { - __child [i] = __par1 [i] ; - v [__par1 [i]] = true ; - } - + route of the first parent */ + for (unsigned int i = 0 ; i < cut ; i ++) + { + __child [i] = __par1 [i] ; + v [__par1 [i]] = true ; + } + /* Searching the vertex of the second path, that ended the previous first one */ - unsigned from = 0 ; - for (unsigned i = 0 ; i < __par2.size () ; i ++) - if (__par2 [i] == __child [cut - 1]) { - from = i ; - break ; + unsigned int from = 0 ; + for (unsigned int i = 0 ; i < __par2.size () ; i ++) + { + if (__par2 [i] == __child [cut - 1]) + { + from = i ; + break ; + } } - + /* Selecting a direction Left or Right */ char direct = rng.flip () ? 1 : -1 ; - + /* Copy of the left vertices from the second parent path */ - unsigned l = cut ; - - for (unsigned i = 0 ; i < __par2.size () ; i ++) { - unsigned bidule /* :-) */ = (direct * i + from + __par2.size ()) % __par2.size () ; - if (! v [__par2 [bidule]]) { - __child [l ++] = __par2 [bidule] ; - v [__par2 [bidule]] = true ; - } - } -} + unsigned int l = cut ; + + for (unsigned int i = 0 ; i < __par2.size () ; i ++) + { + unsigned int bidule /* :-) */ = (direct * i + from + __par2.size ()) % __par2.size () ; + if (! v [__par2 [bidule]]) + { + __child [l ++] = __par2 [bidule] ; + v [__par2 [bidule]] = true ; + } + } + + v.clear(); +} + +bool OrderXover :: operator () (Route & __route1, Route & __route2) +{ -bool OrderXover :: operator () (Route & __route1, Route & __route2) { - // Init. copy Route par [2] ; par [0] = __route1 ; par [1] = __route2 ; - + cross (par [0], par [1], __route1) ; cross (par [1], par [0], __route2) ; - + assert (valid (__route1)) ; assert (valid (__route2)) ; diff --git a/contribution/trunk/combinatorial/routing/tsp/src/order_xover.h b/contribution/trunk/combinatorial/routing/tsp/src/order_xover.h index 0be9b1442..924eb4dfd 100644 --- a/contribution/trunk/combinatorial/routing/tsp/src/order_xover.h +++ b/contribution/trunk/combinatorial/routing/tsp/src/order_xover.h @@ -1,9 +1,9 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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 * abiding by the rules of distribution of free software. You can use, @@ -42,15 +42,16 @@ #include "route.h" /** Order Crossover */ -class OrderXover : public eoQuadOp { - -public : - - bool operator () (Route & __route1, Route & __route2) ; +class OrderXover : public eoQuadOp + { -private : - - void cross (const Route & __par1, const Route & __par2, Route & __child) ; -} ; + public : + + bool operator () (Route & __route1, Route & __route2) ; + + private : + + void cross (const Route & __par1, const Route & __par2, Route & __child) ; + } ; #endif diff --git a/contribution/trunk/combinatorial/routing/tsp/src/part_route_eval.h b/contribution/trunk/combinatorial/routing/tsp/src/part_route_eval.h index 73f815c38..a92fad2ce 100644 --- a/contribution/trunk/combinatorial/routing/tsp/src/part_route_eval.h +++ b/contribution/trunk/combinatorial/routing/tsp/src/part_route_eval.h @@ -1,9 +1,9 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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 * abiding by the rules of distribution of free software. You can use, @@ -42,20 +42,21 @@ #include "route.h" /** Route Evaluator */ -class PartRouteEval : public eoEvalFunc { - -public : +class PartRouteEval : public eoEvalFunc + { - /** Constructor */ - PartRouteEval (float __from, float __to) ; - - void operator () (Route & __route) ; - -private : + public : - float from, to ; + /** Constructor */ + PartRouteEval (float __from, float __to) ; -} ; + void operator () (Route & __route) ; + + private : + + float from, to ; + + } ; #endif diff --git a/contribution/trunk/combinatorial/routing/tsp/src/partial_mapped_xover.cpp b/contribution/trunk/combinatorial/routing/tsp/src/partial_mapped_xover.cpp index 460d04c29..ab92d2a3b 100644 --- a/contribution/trunk/combinatorial/routing/tsp/src/partial_mapped_xover.cpp +++ b/contribution/trunk/combinatorial/routing/tsp/src/partial_mapped_xover.cpp @@ -1,9 +1,9 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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 * abiding by the rules of distribution of free software. You can use, @@ -36,53 +36,77 @@ #include +#include + #include #include "partial_mapped_xover.h" #include "route_valid.h" #include "mix.h" -void PartialMappedXover :: repair (Route & __route, unsigned __cut1, unsigned __cut2) { - - unsigned v [__route.size ()] ; // Number of times a cities are visited ... - - for (unsigned i = 0 ; i < __route.size () ; i ++) - v [i] = 0 ; - - for (unsigned i = 0 ; i < __route.size () ; i ++) - v [__route [i]] ++ ; - - std :: vector vert ; +void PartialMappedXover :: repair (Route & __route, unsigned __cut1, unsigned __cut2) +{ + + std::vector v; // Number of times a cities are visited ... + + v.resize(__route.size ()); + + for (unsigned int i = 0 ; i < __route.size () ; i ++) + { + v [i] = 0 ; + } + + for (unsigned int i = 0 ; i < __route.size () ; i ++) + { + v [__route [i]] ++ ; + } + + std :: vector vert ; + + for (unsigned int i = 0 ; i < __route.size () ; i ++) + { + if (! v [i]) + { + vert.push_back (i) ; + } + } - for (unsigned i = 0 ; i < __route.size () ; i ++) - if (! v [i]) - vert.push_back (i) ; - mix (vert) ; - for (unsigned i = 0 ; i < __route.size () ; i ++) - if (i < __cut1 || i >= __cut2) - if (v [__route [i]] > 1) { - __route [i] = vert.back () ; - vert.pop_back () ; - } + for (unsigned int i = 0 ; i < __route.size () ; i ++) + { + if (i < __cut1 || i >= __cut2) + { + if (v [__route [i]] > 1) + { + __route [i] = vert.back () ; + vert.pop_back () ; + } + } + } + + v.clear(); } -bool PartialMappedXover :: operator () (Route & __route1, Route & __route2) { - - unsigned cut1 = rng.random (__route1.size ()), cut2 = rng.random (__route2.size ()) ; - +bool PartialMappedXover :: operator () (Route & __route1, Route & __route2) +{ + unsigned int cut1 = rng.random (__route1.size ()), cut2 = rng.random (__route2.size ()) ; + if (cut2 < cut1) - std :: swap (cut1, cut2) ; - + { + std :: swap (cut1, cut2) ; + } + // Between the cuts - for (unsigned i = cut1 ; i < cut2 ; i ++) - std :: swap (__route1 [i], __route2 [i]) ; - + for (unsigned int i = cut1 ; i < cut2 ; i ++) + { + std :: swap (__route1 [i], __route2 [i]) ; + } + // Outside the cuts repair (__route1, cut1, cut2) ; repair (__route2, cut1, cut2) ; - + // Debug assert (valid (__route1)) ; assert (valid (__route2)) ; diff --git a/contribution/trunk/combinatorial/routing/tsp/src/partial_mapped_xover.h b/contribution/trunk/combinatorial/routing/tsp/src/partial_mapped_xover.h index 19ca644ef..65c6474de 100644 --- a/contribution/trunk/combinatorial/routing/tsp/src/partial_mapped_xover.h +++ b/contribution/trunk/combinatorial/routing/tsp/src/partial_mapped_xover.h @@ -1,9 +1,9 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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 * abiding by the rules of distribution of free software. You can use, @@ -42,15 +42,16 @@ #include "route.h" /** Partial Mapped Crossover */ -class PartialMappedXover : public eoQuadOp { - -public : - - bool operator () (Route & __route1, Route & __route2) ; +class PartialMappedXover : public eoQuadOp + { -private : - - void repair (Route & __route, unsigned __cut1, unsigned __cut2) ; -} ; + public : + + bool operator () (Route & __route1, Route & __route2) ; + + private : + + void repair (Route & __route, unsigned __cut1, unsigned __cut2) ; + } ; #endif diff --git a/contribution/trunk/combinatorial/routing/tsp/src/route_eval.h b/contribution/trunk/combinatorial/routing/tsp/src/route_eval.h index 67ba75f7e..474075cf0 100644 --- a/contribution/trunk/combinatorial/routing/tsp/src/route_eval.h +++ b/contribution/trunk/combinatorial/routing/tsp/src/route_eval.h @@ -1,9 +1,9 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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 * abiding by the rules of distribution of free software. You can use, @@ -42,13 +42,14 @@ #include "route.h" /** Route Evaluator */ -class RouteEval : public eoEvalFunc { - -public : - - void operator () (Route & __route) ; - -} ; +class RouteEval : public eoEvalFunc + { + + public : + + void operator () (Route & __route) ; + + } ; #endif diff --git a/contribution/trunk/combinatorial/routing/tsp/src/route_init.cpp b/contribution/trunk/combinatorial/routing/tsp/src/route_init.cpp index e126ba0ca..09a2c40cb 100644 --- a/contribution/trunk/combinatorial/routing/tsp/src/route_init.cpp +++ b/contribution/trunk/combinatorial/routing/tsp/src/route_init.cpp @@ -1,9 +1,9 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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 * abiding by the rules of distribution of free software. You can use, @@ -39,21 +39,25 @@ #include "route_init.h" #include "graph.h" -void RouteInit :: operator () (Route & __route) { +void RouteInit :: operator () (Route & __route) +{ // Init. __route.clear () ; - for (unsigned i = 0 ; i < Graph :: size () ; i ++) - __route.push_back (i) ; - + for (unsigned int i = 0 ; i < Graph :: size () ; i ++) + { + __route.push_back (i) ; + } + // Swap. cities - for (unsigned i = 0 ; i < Graph :: size () ; i ++) { - //unsigned j = rng.random (Graph :: size ()) ; - - unsigned j = (unsigned) (Graph :: size () * (rand () / (RAND_MAX + 1.0))) ; - unsigned city = __route [i] ; - __route [i] = __route [j] ; - __route [j] = city ; - } + for (unsigned int i = 0 ; i < Graph :: size () ; i ++) + { + //unsigned int j = rng.random (Graph :: size ()) ; + + unsigned int j = (unsigned int) (Graph :: size () * (rand () / (RAND_MAX + 1.0))) ; + unsigned int city = __route [i] ; + __route [i] = __route [j] ; + __route [j] = city ; + } } diff --git a/contribution/trunk/combinatorial/routing/tsp/src/route_init.h b/contribution/trunk/combinatorial/routing/tsp/src/route_init.h index b1e61ea4e..466345c1b 100644 --- a/contribution/trunk/combinatorial/routing/tsp/src/route_init.h +++ b/contribution/trunk/combinatorial/routing/tsp/src/route_init.h @@ -1,9 +1,9 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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 * abiding by the rules of distribution of free software. You can use, @@ -41,12 +41,13 @@ #include "route.h" -class RouteInit : public eoInit { - -public : - - void operator () (Route & __route) ; - -} ; +class RouteInit : public eoInit + { + + public : + + void operator () (Route & __route) ; + + } ; #endif diff --git a/contribution/trunk/combinatorial/routing/tsp/src/route_valid.cpp b/contribution/trunk/combinatorial/routing/tsp/src/route_valid.cpp index 43566d7cf..844cebf82 100644 --- a/contribution/trunk/combinatorial/routing/tsp/src/route_valid.cpp +++ b/contribution/trunk/combinatorial/routing/tsp/src/route_valid.cpp @@ -1,9 +1,9 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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 * abiding by the rules of distribution of free software. You can use, @@ -36,19 +36,33 @@ #include "route_valid.h" -bool valid (Route & __route) { - - unsigned t [__route.size ()] ; - - for (unsigned i = 0 ; i < __route.size () ; i ++) - t [i] = 0 ; - - for (unsigned i = 0 ; i < __route.size () ; i ++) - t [__route [i]] ++ ; - - for (unsigned i = 0 ; i < __route.size () ; i ++) - if (t [i] != 1) - return false ; - +#include + +bool valid (Route & __route) +{ + + std::vector t; + t.resize(__route.size()); + + for (unsigned int i = 0 ; i < __route.size () ; i ++) + { + t [i] = 0 ; + } + + for (unsigned int i = 0 ; i < __route.size () ; i ++) + { + t [__route [i]] ++ ; + } + + for (unsigned int i = 0 ; i < __route.size () ; i ++) + { + if (t [i] != 1) + { + t.clear(); + return false ; + } + } + + t.clear(); return true ; // OK. } diff --git a/contribution/trunk/combinatorial/routing/tsp/src/route_valid.h b/contribution/trunk/combinatorial/routing/tsp/src/route_valid.h index fe8b780d2..607728e8b 100644 --- a/contribution/trunk/combinatorial/routing/tsp/src/route_valid.h +++ b/contribution/trunk/combinatorial/routing/tsp/src/route_valid.h @@ -1,9 +1,9 @@ -/* +/* * * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-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 * abiding by the rules of distribution of free software. You can use,