New style for MO
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@787 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
47298125ec
commit
7161febf9c
80 changed files with 2014 additions and 2038 deletions
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <city_swap.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -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 ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <city_swap.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -43,12 +43,13 @@
|
|||
|
||||
/** Its swaps two vertices
|
||||
randomly choosen */
|
||||
class CitySwap : public eoMonOp <Route> {
|
||||
|
||||
public :
|
||||
|
||||
bool operator () (Route & __route) ;
|
||||
|
||||
} ;
|
||||
class CitySwap : public eoMonOp <Route>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
bool operator () (Route & __route) ;
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <edge_xover.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -44,119 +44,121 @@
|
|||
#define MAXINT 1000000
|
||||
|
||||
void
|
||||
EdgeXover :: build_map (const Route & __par1, const Route & __par2)
|
||||
EdgeXover :: build_map (const Route & __par1, const Route & __par2)
|
||||
{
|
||||
|
||||
|
||||
unsigned int len = __par1.size () ;
|
||||
|
||||
|
||||
/* Initialization */
|
||||
_map.clear () ;
|
||||
_map.resize (len) ;
|
||||
|
||||
for (unsigned int i = 0 ; i < len ; i ++)
|
||||
|
||||
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 int __vertex, std :: vector <std :: set <unsigned int> > & __map)
|
||||
{
|
||||
|
||||
std :: set <unsigned int> & neigh = __map [__vertex] ;
|
||||
EdgeXover :: remove_entry (unsigned int __vertex, std :: vector <std :: set <unsigned int> > & __map)
|
||||
{
|
||||
|
||||
for (std :: set <unsigned int> :: iterator it = neigh.begin () ; it != neigh.end () ; it ++)
|
||||
{
|
||||
__map [* it].erase (__vertex) ;
|
||||
}
|
||||
|
||||
}
|
||||
std :: set <unsigned int> & neigh = __map [__vertex] ;
|
||||
|
||||
for (std :: set <unsigned int> :: iterator it = neigh.begin () ; it != neigh.end () ; it ++)
|
||||
{
|
||||
__map [* it].erase (__vertex) ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
EdgeXover :: add_vertex (unsigned int __vertex, Route & __child)
|
||||
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) {
|
||||
|
||||
EdgeXover :: cross (const Route & __par1, const Route & __par2, Route & __child)
|
||||
{
|
||||
|
||||
build_map (__par1, __par2) ;
|
||||
|
||||
|
||||
unsigned int len = __par1.size () ;
|
||||
|
||||
|
||||
/* Go ! */
|
||||
__child.clear () ;
|
||||
|
||||
|
||||
unsigned int cur_vertex = rng.random (len) ;
|
||||
|
||||
|
||||
add_vertex (cur_vertex, __child) ;
|
||||
|
||||
for (unsigned int i = 1 ; i < len ; i ++) {
|
||||
|
||||
unsigned int len_min_entry = MAXINT ;
|
||||
|
||||
std :: set <unsigned int> & neigh = _map [cur_vertex] ;
|
||||
|
||||
for (std :: set <unsigned int> :: 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 <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 */
|
||||
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) ;
|
||||
}
|
||||
for (unsigned int i = 1 ; i < len ; i ++)
|
||||
{
|
||||
|
||||
unsigned int len_min_entry = MAXINT ;
|
||||
|
||||
std :: set <unsigned int> & neigh = _map [cur_vertex] ;
|
||||
|
||||
for (std :: set <unsigned int> :: 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 <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 */
|
||||
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)
|
||||
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)) ;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <edge_xover.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -45,28 +45,28 @@
|
|||
#include "route.h"
|
||||
|
||||
/** Edge Crossover */
|
||||
class EdgeXover : public eoQuadOp <Route>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
bool operator () (Route & __route1, Route & __route2) ;
|
||||
class EdgeXover : public eoQuadOp <Route>
|
||||
{
|
||||
|
||||
private :
|
||||
|
||||
void cross (const Route & __par1, const Route & __par2, Route & __child) ; /* Binary */
|
||||
public :
|
||||
|
||||
void remove_entry (unsigned int __vertex, std :: vector <std :: set <unsigned> > & __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 int __vertex, Route & __child) ;
|
||||
void cross (const Route & __par1, const Route & __par2, Route & __child) ; /* Binary */
|
||||
|
||||
std :: vector <std :: set <unsigned int> > _map ; /* The handled map */
|
||||
void remove_entry (unsigned int __vertex, std :: vector <std :: set <unsigned> > & __map) ;
|
||||
/* Updating the map of entries */
|
||||
|
||||
std :: vector <bool> 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 <std :: set <unsigned int> > _map ; /* The handled map */
|
||||
|
||||
std :: vector <bool> visited ; /* Vertices that are already visited */
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <graph.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -40,73 +40,74 @@
|
|||
|
||||
#include "graph.h"
|
||||
|
||||
namespace Graph {
|
||||
namespace Graph
|
||||
{
|
||||
|
||||
static std :: vector <std :: pair <double, double> > vectCoord ; // Coordinates
|
||||
|
||||
|
||||
static std :: vector <std :: vector <unsigned int> > dist ; // Distances Mat.
|
||||
|
||||
unsigned size ()
|
||||
unsigned size ()
|
||||
{
|
||||
return dist.size () ;
|
||||
}
|
||||
|
||||
void computeDistances ()
|
||||
void computeDistances ()
|
||||
{
|
||||
|
||||
|
||||
// Dim.
|
||||
unsigned int numCities = vectCoord.size () ;
|
||||
dist.resize (numCities) ;
|
||||
for (unsigned int i = 0 ; i < dist.size () ; i ++)
|
||||
{
|
||||
dist [i].resize (numCities) ;
|
||||
dist [i].resize (numCities) ;
|
||||
}
|
||||
|
||||
|
||||
// Computations.
|
||||
for (unsigned int i = 0 ; i < dist.size () ; i ++)
|
||||
{
|
||||
for (unsigned int j = i + 1 ; j < dist.size () ; j ++)
|
||||
{
|
||||
double distX = (double)(vectCoord [i].first - vectCoord [j].first) ;
|
||||
double distY = (double)(vectCoord [i].second - vectCoord [j].second) ;
|
||||
dist [i] [j] = dist [j] [i] = (unsigned) (sqrt ((float) (distX * distX + distY * distY)) + 0.5) ;
|
||||
}
|
||||
for (unsigned int j = i + 1 ; j < dist.size () ; j ++)
|
||||
{
|
||||
double distX = (double)(vectCoord [i].first - vectCoord [j].first) ;
|
||||
double distY = (double)(vectCoord [i].second - vectCoord [j].second) ;
|
||||
dist [i] [j] = dist [j] [i] = (unsigned) (sqrt ((float) (distX * distX + distY * distY)) + 0.5) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void load (const char * __fileName)
|
||||
void load (const char * __fileName)
|
||||
{
|
||||
|
||||
|
||||
std :: ifstream f (__fileName) ;
|
||||
|
||||
|
||||
std :: cout << ">> Loading [" << __fileName << "]" << std :: endl ;
|
||||
|
||||
if (f)
|
||||
|
||||
if (f)
|
||||
{
|
||||
unsigned int num_vert ;
|
||||
|
||||
f >> num_vert ;
|
||||
vectCoord.resize (num_vert) ;
|
||||
|
||||
for (unsigned int i = 0 ; i < num_vert ; i ++)
|
||||
{
|
||||
f >> vectCoord [i].first >> vectCoord [i].second ;
|
||||
}
|
||||
|
||||
f.close () ;
|
||||
|
||||
computeDistances () ;
|
||||
unsigned int num_vert ;
|
||||
|
||||
f >> num_vert ;
|
||||
vectCoord.resize (num_vert) ;
|
||||
|
||||
for (unsigned int i = 0 ; i < num_vert ; i ++)
|
||||
{
|
||||
f >> vectCoord [i].first >> vectCoord [i].second ;
|
||||
}
|
||||
|
||||
f.close () ;
|
||||
|
||||
computeDistances () ;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
|
||||
std :: cout << __fileName << " doesn't exist !!!" << std :: endl ;
|
||||
// Bye !!!
|
||||
exit (1) ;
|
||||
|
||||
std :: cout << __fileName << " doesn't exist !!!" << std :: endl ;
|
||||
// Bye !!!
|
||||
exit (1) ;
|
||||
}
|
||||
}
|
||||
|
||||
float distance (unsigned int __from, unsigned int __to)
|
||||
|
||||
float distance (unsigned int __from, unsigned int __to)
|
||||
{
|
||||
return (float)(dist [__from] [__to]) ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <graph.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -40,13 +40,13 @@
|
|||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
namespace Graph
|
||||
{
|
||||
namespace Graph
|
||||
{
|
||||
void load (const char * __file_name) ;
|
||||
/* Loading cities
|
||||
(expressed by their coordinates)
|
||||
from the given file name */
|
||||
|
||||
from the given file name */
|
||||
|
||||
float distance (unsigned int __from, unsigned int __to) ;
|
||||
|
||||
unsigned int size () ; // How many cities ?
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <mix.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -39,9 +39,9 @@
|
|||
|
||||
#include <utils/eoRNG.h>
|
||||
|
||||
template <class T> void mix (std :: vector <T> & __vect)
|
||||
template <class T> void mix (std :: vector <T> & __vect)
|
||||
{
|
||||
for (unsigned int i = 0 ; i < __vect.size () ; i ++)
|
||||
for (unsigned int i = 0 ; i < __vect.size () ; i ++)
|
||||
{
|
||||
std :: swap (__vect [i], __vect [rng.random (__vect.size ())]) ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <order_xover.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -42,73 +42,73 @@
|
|||
#include "order_xover.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 ()) ;
|
||||
|
||||
|
||||
/* To store vertices that have
|
||||
already been crossed */
|
||||
std::vector<bool> 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 int i = 0 ; i < cut ; i ++)
|
||||
route of the first parent */
|
||||
for (unsigned int i = 0 ; i < cut ; i ++)
|
||||
{
|
||||
__child [i] = __par1 [i] ;
|
||||
__child [i] = __par1 [i] ;
|
||||
v [__par1 [i]] = true ;
|
||||
}
|
||||
|
||||
|
||||
/* Searching the vertex of the second path, that ended
|
||||
the previous first one */
|
||||
unsigned int from = 0 ;
|
||||
for (unsigned int i = 0 ; i < __par2.size () ; i ++)
|
||||
{
|
||||
if (__par2 [i] == __child [cut - 1])
|
||||
{
|
||||
from = i ;
|
||||
break ;
|
||||
}
|
||||
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 int l = cut ;
|
||||
|
||||
for (unsigned int i = 0 ; i < __par2.size () ; i ++)
|
||||
|
||||
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 ;
|
||||
}
|
||||
if (! v [__par2 [bidule]])
|
||||
{
|
||||
__child [l ++] = __par2 [bidule] ;
|
||||
v [__par2 [bidule]] = true ;
|
||||
}
|
||||
}
|
||||
|
||||
v.clear();
|
||||
}
|
||||
|
||||
bool OrderXover :: operator () (Route & __route1, Route & __route2)
|
||||
v.clear();
|
||||
}
|
||||
|
||||
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)) ;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <order_xover.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -42,16 +42,16 @@
|
|||
#include "route.h"
|
||||
|
||||
/** Order Crossover */
|
||||
class OrderXover : public eoQuadOp <Route>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
bool operator () (Route & __route1, Route & __route2) ;
|
||||
|
||||
private :
|
||||
|
||||
void cross (const Route & __par1, const Route & __par2, Route & __child) ;
|
||||
} ;
|
||||
class OrderXover : public eoQuadOp <Route>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
bool operator () (Route & __route1, Route & __route2) ;
|
||||
|
||||
private :
|
||||
|
||||
void cross (const Route & __par1, const Route & __par2, Route & __child) ;
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <part_route_eval.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -37,16 +37,17 @@
|
|||
#include "part_route_eval.h"
|
||||
#include "graph.h"
|
||||
|
||||
PartRouteEval :: PartRouteEval (float __from, float __to) : from (__from), to (__to) {}
|
||||
PartRouteEval :: PartRouteEval (float __from, float __to) : from (__from), to (__to)
|
||||
{}
|
||||
|
||||
void PartRouteEval :: operator () (Route & __route)
|
||||
void PartRouteEval :: operator () (Route & __route)
|
||||
{
|
||||
float len = 0 ;
|
||||
|
||||
|
||||
for (unsigned int i = (unsigned int) (__route.size () * from) ; i < (unsigned int ) (__route.size () * to) ; i ++)
|
||||
{
|
||||
len -= Graph :: distance (__route [i], __route [(i + 1) % Graph :: size ()]) ;
|
||||
}
|
||||
|
||||
|
||||
__route.fitness (len) ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <part_route_eval.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -42,21 +42,21 @@
|
|||
#include "route.h"
|
||||
|
||||
/** Route Evaluator */
|
||||
class PartRouteEval : public eoEvalFunc <Route>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
/** Constructor */
|
||||
PartRouteEval (float __from, float __to) ;
|
||||
|
||||
void operator () (Route & __route) ;
|
||||
|
||||
private :
|
||||
class PartRouteEval : public eoEvalFunc <Route>
|
||||
{
|
||||
|
||||
float from, to ;
|
||||
|
||||
} ;
|
||||
public :
|
||||
|
||||
/** Constructor */
|
||||
PartRouteEval (float __from, float __to) ;
|
||||
|
||||
void operator () (Route & __route) ;
|
||||
|
||||
private :
|
||||
|
||||
float from, to ;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <part_two_opt_init.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -38,7 +38,7 @@
|
|||
|
||||
#include "part_two_opt_init.h"
|
||||
|
||||
void PartTwoOptInit :: operator () (TwoOpt & __move, const Route & __route)
|
||||
void PartTwoOptInit :: operator () (TwoOpt & __move, const Route & __route)
|
||||
{
|
||||
__move.first = rng.random (__route.size () - 6) ;
|
||||
__move.second = __move.first + 2 ;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <part_two_opt_init.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -42,13 +42,13 @@
|
|||
#include "two_opt.h"
|
||||
|
||||
/** It sets the first couple of edges */
|
||||
class PartTwoOptInit : public moMoveInit <TwoOpt>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
void operator () (TwoOpt & __move, const Route & __route) ;
|
||||
|
||||
} ;
|
||||
class PartTwoOptInit : public moMoveInit <TwoOpt>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
void operator () (TwoOpt & __move, const Route & __route) ;
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <part_two_opt_next.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -37,21 +37,21 @@
|
|||
#include "part_two_opt_next.h"
|
||||
#include "graph.h"
|
||||
|
||||
bool TwoOptNext :: operator () (TwoOpt & __move, const Route & __route)
|
||||
bool TwoOptNext :: operator () (TwoOpt & __move, const Route & __route)
|
||||
{
|
||||
if (__move.first == Graph :: size () - 4 && __move.second == __move.first + 2)
|
||||
{
|
||||
return false ;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
__move.second ++ ;
|
||||
if (__move.second == Graph :: size () - 1)
|
||||
{
|
||||
__move.first ++ ;
|
||||
__move.second = __move.first + 2 ;
|
||||
}
|
||||
|
||||
if (__move.second == Graph :: size () - 1)
|
||||
{
|
||||
__move.first ++ ;
|
||||
__move.second = __move.first + 2 ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <part_two_opt_next.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,13 +41,13 @@
|
|||
#include "two_opt.h"
|
||||
|
||||
/** It updates a couple of edges */
|
||||
class PartTwoOptNext : public moNextMove <TwoOpt>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
bool operator () (TwoOpt & __move, const Route & __route) ;
|
||||
|
||||
} ;
|
||||
class PartTwoOptNext : public moNextMove <TwoOpt>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
bool operator () (TwoOpt & __move, const Route & __route) ;
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <partial_mapped_xover.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -44,69 +44,69 @@
|
|||
#include "route_valid.h"
|
||||
#include "mix.h"
|
||||
|
||||
void PartialMappedXover :: repair (Route & __route, unsigned __cut1, unsigned __cut2)
|
||||
void PartialMappedXover :: repair (Route & __route, unsigned __cut1, unsigned __cut2)
|
||||
{
|
||||
|
||||
|
||||
std::vector<unsigned int> v; // Number of times a cities are visited ...
|
||||
|
||||
v.resize(__route.size ());
|
||||
|
||||
|
||||
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 <unsigned int> vert ;
|
||||
|
||||
for (unsigned int i = 0 ; i < __route.size () ; i ++)
|
||||
{
|
||||
if (! v [i])
|
||||
{
|
||||
vert.push_back (i) ;
|
||||
}
|
||||
{
|
||||
vert.push_back (i) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mix (vert) ;
|
||||
|
||||
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 () ;
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
if (v [__route [i]] > 1)
|
||||
{
|
||||
__route [i] = vert.back () ;
|
||||
vert.pop_back () ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
v.clear();
|
||||
}
|
||||
|
||||
bool PartialMappedXover :: operator () (Route & __route1, Route & __route2)
|
||||
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) ;
|
||||
}
|
||||
|
||||
|
||||
// Between the cuts
|
||||
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)) ;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <partial_mapped_xover.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -42,15 +42,16 @@
|
|||
#include "route.h"
|
||||
|
||||
/** Partial Mapped Crossover */
|
||||
class PartialMappedXover : public eoQuadOp <Route> {
|
||||
|
||||
public :
|
||||
|
||||
bool operator () (Route & __route1, Route & __route2) ;
|
||||
class PartialMappedXover : public eoQuadOp <Route>
|
||||
{
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <route.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <route_eval.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -37,15 +37,15 @@
|
|||
#include "route_eval.h"
|
||||
#include "graph.h"
|
||||
|
||||
void RouteEval :: operator () (Route & __route)
|
||||
void RouteEval :: operator () (Route & __route)
|
||||
{
|
||||
|
||||
|
||||
float len = 0 ;
|
||||
|
||||
|
||||
for (unsigned int i = 0 ; i < Graph :: size () ; i ++)
|
||||
{
|
||||
len -= Graph :: distance (__route [i], __route [(i + 1) % Graph :: size ()]) ;
|
||||
len -= Graph :: distance (__route [i], __route [(i + 1) % Graph :: size ()]) ;
|
||||
}
|
||||
|
||||
|
||||
__route.fitness (len) ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <route_eval.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -42,14 +42,14 @@
|
|||
#include "route.h"
|
||||
|
||||
/** Route Evaluator */
|
||||
class RouteEval : public eoEvalFunc <Route>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
void operator () (Route & __route) ;
|
||||
|
||||
} ;
|
||||
class RouteEval : public eoEvalFunc <Route>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
void operator () (Route & __route) ;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <route_init.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -39,25 +39,25 @@
|
|||
#include "route_init.h"
|
||||
#include "graph.h"
|
||||
|
||||
void RouteInit :: operator () (Route & __route)
|
||||
void RouteInit :: operator () (Route & __route)
|
||||
{
|
||||
|
||||
|
||||
// Init.
|
||||
__route.clear () ;
|
||||
for (unsigned int i = 0 ; i < Graph :: size () ; i ++)
|
||||
{
|
||||
__route.push_back (i) ;
|
||||
}
|
||||
|
||||
|
||||
// Swap. cities
|
||||
|
||||
for (unsigned int i = 0 ; i < Graph :: size () ; i ++)
|
||||
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 ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <route_init.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,13 +41,13 @@
|
|||
|
||||
#include "route.h"
|
||||
|
||||
class RouteInit : public eoInit <Route>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
void operator () (Route & __route) ;
|
||||
|
||||
} ;
|
||||
class RouteInit : public eoInit <Route>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
void operator () (Route & __route) ;
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <route_valid.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -38,31 +38,31 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
bool valid (Route & __route)
|
||||
bool valid (Route & __route)
|
||||
{
|
||||
|
||||
|
||||
std::vector<unsigned int> 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 false ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
t.clear();
|
||||
return true ; // OK.
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <route_valid.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <tsp.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -36,24 +36,24 @@
|
|||
|
||||
#include "two_opt.h"
|
||||
|
||||
TwoOpt TwoOpt :: operator ! () const
|
||||
{
|
||||
TwoOpt move = * this ;
|
||||
std :: swap (move.first, move.second) ;
|
||||
|
||||
return move ;
|
||||
}
|
||||
TwoOpt TwoOpt :: operator ! () const
|
||||
{
|
||||
TwoOpt move = * this ;
|
||||
std :: swap (move.first, move.second) ;
|
||||
|
||||
void TwoOpt :: operator () (Route & __route)
|
||||
return move ;
|
||||
}
|
||||
|
||||
void TwoOpt :: operator () (Route & __route)
|
||||
{
|
||||
|
||||
|
||||
std :: vector <unsigned int> seq_cities ;
|
||||
|
||||
|
||||
for (unsigned int i = second ; i > first ; i --)
|
||||
{
|
||||
seq_cities.push_back (__route [i]) ;
|
||||
}
|
||||
|
||||
|
||||
unsigned int j = 0 ;
|
||||
for (unsigned int i = first + 1 ; i < second + 1 ; i ++)
|
||||
{
|
||||
|
|
@ -61,12 +61,12 @@ void TwoOpt :: operator () (Route & __route)
|
|||
}
|
||||
}
|
||||
|
||||
void TwoOpt :: readFrom (std :: istream & __is)
|
||||
void TwoOpt :: readFrom (std :: istream & __is)
|
||||
{
|
||||
__is >> first >> second ;
|
||||
}
|
||||
|
||||
void TwoOpt :: printOn (std :: ostream & __os) const
|
||||
{
|
||||
__os << first << ' ' << second ;
|
||||
}
|
||||
void TwoOpt :: printOn (std :: ostream & __os) const
|
||||
{
|
||||
__os << first << ' ' << second ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -44,18 +44,18 @@
|
|||
|
||||
#include "route.h"
|
||||
|
||||
class TwoOpt : public moMove <Route>, public std :: pair <unsigned, unsigned>, public eoPersistent
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
TwoOpt operator ! () const ;
|
||||
|
||||
void operator () (Route & __route) ;
|
||||
|
||||
void readFrom (std :: istream & __is) ;
|
||||
|
||||
void printOn (std :: ostream & __os) const ;
|
||||
} ;
|
||||
class TwoOpt : public moMove <Route>, public std :: pair <unsigned, unsigned>, public eoPersistent
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
TwoOpt operator ! () const ;
|
||||
|
||||
void operator () (Route & __route) ;
|
||||
|
||||
void readFrom (std :: istream & __is) ;
|
||||
|
||||
void printOn (std :: ostream & __os) const ;
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt_incr_eval.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -37,17 +37,17 @@
|
|||
#include "two_opt_incr_eval.h"
|
||||
#include "graph.h"
|
||||
|
||||
float TwoOptIncrEval :: operator () (const TwoOpt & __move, const Route & __route)
|
||||
float TwoOptIncrEval :: operator () (const TwoOpt & __move, const Route & __route)
|
||||
{
|
||||
// From
|
||||
unsigned int v1 = __route [__move.first], v1_next = __route [__move.first + 1] ;
|
||||
|
||||
|
||||
// To
|
||||
unsigned int v2 = __route [__move.second], v2_next = __route [__move.second + 1] ;
|
||||
|
||||
|
||||
return __route.fitness ()
|
||||
- Graph :: distance (v1, v2)
|
||||
- Graph :: distance (v1_next, v2_next)
|
||||
+ Graph :: distance (v1, v1_next)
|
||||
+ Graph :: distance (v2, v2_next) ;
|
||||
- Graph :: distance (v1, v2)
|
||||
- Graph :: distance (v1_next, v2_next)
|
||||
+ Graph :: distance (v1, v1_next)
|
||||
+ Graph :: distance (v2, v2_next) ;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt_incr_eval.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -40,13 +40,13 @@
|
|||
#include <moMoveIncrEval.h>
|
||||
#include "two_opt.h"
|
||||
|
||||
class TwoOptIncrEval : public moMoveIncrEval <TwoOpt>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
float operator () (const TwoOpt & __move, const Route & __route) ;
|
||||
class TwoOptIncrEval : public moMoveIncrEval <TwoOpt>
|
||||
{
|
||||
|
||||
} ;
|
||||
public :
|
||||
|
||||
float operator () (const TwoOpt & __move, const Route & __route) ;
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt_init.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -36,7 +36,7 @@
|
|||
|
||||
#include "two_opt_init.h"
|
||||
|
||||
void TwoOptInit :: operator () (TwoOpt & __move, const Route & __route)
|
||||
void TwoOptInit :: operator () (TwoOpt & __move, const Route & __route)
|
||||
{
|
||||
__move.first = 0 ;
|
||||
__move.second = 2 ;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt_init.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -42,13 +42,13 @@
|
|||
#include "two_opt.h"
|
||||
|
||||
/** It sets the first couple of edges */
|
||||
class TwoOptInit : public moMoveInit <TwoOpt>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
void operator () (TwoOpt & __move, const Route & __route) ;
|
||||
|
||||
} ;
|
||||
class TwoOptInit : public moMoveInit <TwoOpt>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
void operator () (TwoOpt & __move, const Route & __route) ;
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt_next.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -37,21 +37,21 @@
|
|||
#include "two_opt_next.h"
|
||||
#include "graph.h"
|
||||
|
||||
bool TwoOptNext :: operator () (TwoOpt & __move, const Route & __route)
|
||||
bool TwoOptNext :: operator () (TwoOpt & __move, const Route & __route)
|
||||
{
|
||||
if (__move.first == Graph :: size () - 4 && __move.second == __move.first + 2)
|
||||
{
|
||||
return false ;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
__move.second ++ ;
|
||||
if (__move.second == Graph :: size () - 1)
|
||||
{
|
||||
__move.first ++ ;
|
||||
__move.second = __move.first + 2 ;
|
||||
}
|
||||
|
||||
if (__move.second == Graph :: size () - 1)
|
||||
{
|
||||
__move.first ++ ;
|
||||
__move.second = __move.first + 2 ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt_next.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,13 +41,13 @@
|
|||
#include "two_opt.h"
|
||||
|
||||
/** It updates a couple of edges */
|
||||
class TwoOptNext : public moNextMove <TwoOpt>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
bool operator () (TwoOpt & __move, const Route & __route) ;
|
||||
|
||||
} ;
|
||||
class TwoOptNext : public moNextMove <TwoOpt>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
bool operator () (TwoOpt & __move, const Route & __route) ;
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt_rand.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -38,7 +38,7 @@
|
|||
#include "graph.h"
|
||||
#include <utils/eoRNG.h>
|
||||
|
||||
void TwoOptRand :: operator () (TwoOpt & __move)
|
||||
void TwoOptRand :: operator () (TwoOpt & __move)
|
||||
{
|
||||
__move.first = rng.random (Graph :: size () - 3) ;
|
||||
__move.second = __move.first + 2 + rng.random (Graph :: size () - __move.first - 3) ;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt_rand.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -41,13 +41,13 @@
|
|||
|
||||
#include "two_opt.h"
|
||||
|
||||
class TwoOptRand : public moRandMove <TwoOpt>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
void operator () (TwoOpt & __move) ;
|
||||
|
||||
} ;
|
||||
class TwoOptRand : public moRandMove <TwoOpt>
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
void operator () (TwoOpt & __move) ;
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt_tabu_list.cpp>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -39,45 +39,45 @@
|
|||
|
||||
#define TABU_LENGTH 10
|
||||
|
||||
void TwoOptTabuList :: init ()
|
||||
void TwoOptTabuList :: init ()
|
||||
{
|
||||
// Size (eventually)
|
||||
tabu_span.resize (Graph :: size ()) ;
|
||||
for (unsigned int i = 0 ; i < tabu_span.size () ; i ++)
|
||||
{
|
||||
tabu_span [i].resize (Graph :: size ()) ;
|
||||
tabu_span [i].resize (Graph :: size ()) ;
|
||||
}
|
||||
|
||||
// Clear
|
||||
for (unsigned int i = 0 ; i < tabu_span.size () ; i ++)
|
||||
{
|
||||
for (unsigned int j = 0 ; j < tabu_span [i].size () ; j ++)
|
||||
{
|
||||
tabu_span [i] [j] = 0 ;
|
||||
}
|
||||
{
|
||||
tabu_span [i] [j] = 0 ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool TwoOptTabuList :: operator () (const TwoOpt & __move, const Route & __sol)
|
||||
bool TwoOptTabuList :: operator () (const TwoOpt & __move, const Route & __sol)
|
||||
{
|
||||
return tabu_span [__move.first] [__move.second] > 0 ;
|
||||
}
|
||||
|
||||
void TwoOptTabuList :: add (const TwoOpt & __move, const Route & __sol)
|
||||
{
|
||||
tabu_span [__move.first] [__move.second] = tabu_span [__move.second] [__move.first] = TABU_LENGTH ;
|
||||
}
|
||||
void TwoOptTabuList :: add (const TwoOpt & __move, const Route & __sol)
|
||||
{
|
||||
tabu_span [__move.first] [__move.second] = tabu_span [__move.second] [__move.first] = TABU_LENGTH ;
|
||||
}
|
||||
|
||||
void TwoOptTabuList :: update ()
|
||||
void TwoOptTabuList :: update ()
|
||||
{
|
||||
for (unsigned int i = 0 ; i < tabu_span.size () ; i ++)
|
||||
{
|
||||
for (unsigned int j = 0 ; j < tabu_span [i].size () ; j ++)
|
||||
{
|
||||
if (tabu_span [i] [j] > 0)
|
||||
{
|
||||
tabu_span [i] [j] -- ;
|
||||
}
|
||||
}
|
||||
{
|
||||
if (tabu_span [i] [j] > 0)
|
||||
{
|
||||
tabu_span [i] [j] -- ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* <two_opt_tabu_list.h>
|
||||
* Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
|
||||
* (C) OPAC Team, LIFL, 2002-2007
|
||||
|
|
@ -42,22 +42,22 @@
|
|||
#include "route.h"
|
||||
|
||||
/** The table of tabu movements, i.e. forbidden edges */
|
||||
class TwoOptTabuList : public moTabuList <TwoOpt>
|
||||
{
|
||||
public :
|
||||
|
||||
bool operator () (const TwoOpt & __move, const Route & __sol) ;
|
||||
|
||||
void add (const TwoOpt & __move, const Route & __sol) ;
|
||||
|
||||
void update () ;
|
||||
|
||||
void init () ;
|
||||
|
||||
private :
|
||||
|
||||
std :: vector <std :: vector <unsigned> > tabu_span ;
|
||||
|
||||
} ;
|
||||
class TwoOptTabuList : public moTabuList <TwoOpt>
|
||||
{
|
||||
public :
|
||||
|
||||
bool operator () (const TwoOpt & __move, const Route & __sol) ;
|
||||
|
||||
void add (const TwoOpt & __move, const Route & __sol) ;
|
||||
|
||||
void update () ;
|
||||
|
||||
void init () ;
|
||||
|
||||
private :
|
||||
|
||||
std :: vector <std :: vector <unsigned> > tabu_span ;
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue