git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@2019 331e1502-861f-0410-8da2-ba01fb791d7f

This commit is contained in:
boufaras 2010-12-06 10:11:27 +00:00
commit 2eb04d2eff
4 changed files with 36 additions and 31 deletions

View file

@ -51,7 +51,7 @@ public:
*/ */
moBitFlippingNeighbor() : moBitFlippingNeighbor() :
moIndexSwapNeighbor<EOT>(){ moIndexSwapNeighbor<EOT> () {
} }
/** /**
@ -60,7 +60,7 @@ public:
*/ */
moBitFlippingNeighbor(unsigned int _Kflip) : moBitFlippingNeighbor(unsigned int _Kflip) :
moIndexSwapNeighbor<EOT>(_Kflip) { moIndexSwapNeighbor<EOT> (_Kflip) {
} }
/** /**

View file

@ -48,10 +48,17 @@ public:
*/ */
moIndexSwapNeighbor() : moIndexSwapNeighbor() :
moIndexNeighbor<EOT> (), Kswap(0) { moIndexNeighbor<EOT> () {
Kswap = 0;
indices = new unsigned int[Kswap + 1]; indices = new unsigned int[Kswap + 1];
} }
/* moIndexSwapNeighbor(unsigned int _Kswap) :
moIndexNeighbor<EOT> () {
Kswap = _Kswap;
indices = new unsigned int[Kswap + 1];
}*/
/** /**
* Default destructor * Default destructor
*/ */
@ -78,8 +85,9 @@ public:
moIndexSwapNeighbor(const moIndexSwapNeighbor& _n) : moIndexSwapNeighbor(const moIndexSwapNeighbor& _n) :
moIndexNeighbor<EOT> (_n) { moIndexNeighbor<EOT> (_n) {
this->Kswap = _n.Kswap; this->Kswap = _n.Kswap;
this->indices=new unsigned int[_n.Kswap + 1];; this->indices = new unsigned int[Kswap + 1];
for (unsigned int i = 0; i <= _n.Kswap; i++) ;
for (unsigned int i = 0; i <= Kswap; i++)
this->indices[i] = _n.indices[i]; this->indices[i] = _n.indices[i];
} }

View file

@ -58,8 +58,8 @@ public:
* @param _Kswap the number of swap to do * @param _Kswap the number of swap to do
*/ */
moKswapNeighbor(unsigned int _Kswap) : moKswapNeighbor() :
moIndexSwapNeighbor<EOT>(_Kswap) { moIndexSwapNeighbor<EOT>(Kswap) {
} }

View file

@ -50,7 +50,7 @@ static unsigned int factorial(unsigned int i) {
* @param _Kswap the number of swap * @param _Kswap the number of swap
*/ */
static unsigned int sizeMapping(unsigned int _size, unsigned int _Kswap) { static unsigned int sizeMapping(unsigned int _size,unsigned int _Kswap) {
int _sizeMapping = _size; int _sizeMapping = _size;
for (int i = _Kswap; i > 0; i--) { for (int i = _Kswap; i > 0; i--) {
@ -81,8 +81,8 @@ public:
* @param _Kswap the number of swap * @param _Kswap the number of swap
*/ */
moKswapNeighborhood(unsigned int _size, unsigned int _Kswap) : moKswapNeighborhood(unsigned int _size,unsigned int _Kswap) :
moOrderNeighborhood<Neighbor> (sizeMapping(_size, _Kswap)) { moOrderNeighborhood<Neighbor> (sizeMapping(_size,_Kswap)) {
mutex = true; mutex = true;
size = _size; size = _size;
@ -111,7 +111,7 @@ public:
//Compute the mapping only for the first init //Compute the mapping only for the first init
if (mutex) { if (mutex) {
setMapping(size, Kswap); setMapping();
mutex = false; mutex = false;
} }
@ -149,43 +149,42 @@ public:
/** /**
* Set the mapping of K-indexes * Set the mapping of K-indexes
* @param _size the solution size * @param _size the solution size
* @param _Kswap the number of swap
*/ */
void setMapping(unsigned int _size, unsigned int _Kswap) { void setMapping() {
if (!_Kswap) { if (!Kswap) {
for (int i = 0; i < _size; i++) for (int i = 0; i < size; i++)
mapping[i] = i; mapping[i] = i;
} else { } else {
unsigned int * _indices; unsigned int * _indices;
_indices = new unsigned int[_Kswap + 1]; _indices = new unsigned int[Kswap + 1];
for (int i = 0; i < _Kswap + 1; i++) for (int i = 0; i < Kswap + 1; i++)
_indices[i] = i; _indices[i] = i;
int id = 0; int id = 0;
bool change = false; bool change = false;
while (id < neighborhoodSize) { while (id < neighborhoodSize) {
while (_indices[_Kswap] < _size) { while (_indices[Kswap] < size) {
for (int k = 0; k < _Kswap; k++) { for (int k = 0; k < Kswap; k++) {
mapping[id + k * neighborhoodSize] = _indices[k]; mapping[id + k * neighborhoodSize] = _indices[k];
} }
mapping[id + _Kswap * neighborhoodSize] mapping[id + Kswap * neighborhoodSize]
= _indices[_Kswap]++; = _indices[Kswap]++;
id++; id++;
} }
_indices[_Kswap]--; _indices[Kswap]--;
if (id < neighborhoodSize) { if (id < neighborhoodSize) {
for (int i = _Kswap - 1; i >= 0; i--) for (int i = Kswap - 1; i >= 0; i--)
if (!change) if (!change)
change = nextIndices(_indices, _size, _Kswap, i); change = nextIndices(_indices, i);
} }
change = false; change = false;
@ -198,20 +197,18 @@ public:
/** /**
* Compute the next combination of mapping indices * Compute the next combination of mapping indices
* @param _indices the current combination of indices * @param _indices the current combination of indices
* @param _size the solution size
* @param _Kswap the number of swap
* @param _indice compute next combination of indices from this index * @param _indice compute next combination of indices from this index
*/ */
bool nextIndices(unsigned int* _indices, int _size, int _Kswap, int _indice) { bool nextIndices(unsigned int* _indices, int _indice) {
if (_indices[_indice + 1] == _size - _Kswap + _indice) { if (_indices[_indice + 1] == size - Kswap + _indice) {
if (_indices[_indice] + 1 < _size - _Kswap + _indice) { if (_indices[_indice] + 1 < size - Kswap + _indice) {
_indices[_indice]++; _indices[_indice]++;
int i = 1; int i = 1;
while (_indice + i <= _Kswap) { while (_indice + i <= Kswap) {
_indices[_indice + i] = _indices[_indice + i - 1] + 1; _indices[_indice + i] = _indices[_indice + i - 1] + 1;
i++; i++;
@ -230,7 +227,7 @@ public:
_indices[_indice + 1]++; _indices[_indice + 1]++;
int i = 2; int i = 2;
while (_indice + i <= _Kswap) { while (_indice + i <= Kswap) {
_indices[_indice + i] = _indices[_indice + i - 1] + 1; _indices[_indice + i] = _indices[_indice + i - 1] + 1;
i++; i++;
} }