diff --git a/trunk/paradiseo-mo/src/neighborhood/moBitFlippingNeighbor.h b/trunk/paradiseo-mo/src/neighborhood/moBitFlippingNeighbor.h index f11bfd30c..373d7eeed 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moBitFlippingNeighbor.h +++ b/trunk/paradiseo-mo/src/neighborhood/moBitFlippingNeighbor.h @@ -51,7 +51,7 @@ public: */ moBitFlippingNeighbor() : - moIndexSwapNeighbor(){ + moIndexSwapNeighbor () { } /** @@ -60,7 +60,7 @@ public: */ moBitFlippingNeighbor(unsigned int _Kflip) : - moIndexSwapNeighbor(_Kflip) { + moIndexSwapNeighbor (_Kflip) { } /** diff --git a/trunk/paradiseo-mo/src/neighborhood/moIndexSwapNeighbor.h b/trunk/paradiseo-mo/src/neighborhood/moIndexSwapNeighbor.h index db4a6d83d..5da79b28f 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moIndexSwapNeighbor.h +++ b/trunk/paradiseo-mo/src/neighborhood/moIndexSwapNeighbor.h @@ -48,10 +48,17 @@ public: */ moIndexSwapNeighbor() : - moIndexNeighbor (), Kswap(0) { + moIndexNeighbor () { + Kswap = 0; indices = new unsigned int[Kswap + 1]; } +/* moIndexSwapNeighbor(unsigned int _Kswap) : + moIndexNeighbor () { + Kswap = _Kswap; + indices = new unsigned int[Kswap + 1]; + }*/ + /** * Default destructor */ @@ -78,8 +85,9 @@ public: moIndexSwapNeighbor(const moIndexSwapNeighbor& _n) : moIndexNeighbor (_n) { this->Kswap = _n.Kswap; - this->indices=new unsigned int[_n.Kswap + 1];; - for (unsigned int i = 0; i <= _n.Kswap; i++) + this->indices = new unsigned int[Kswap + 1]; + ; + for (unsigned int i = 0; i <= Kswap; i++) this->indices[i] = _n.indices[i]; } diff --git a/trunk/paradiseo-mo/src/neighborhood/moKswapNeighbor.h b/trunk/paradiseo-mo/src/neighborhood/moKswapNeighbor.h index 5d4180529..bad75ec24 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moKswapNeighbor.h +++ b/trunk/paradiseo-mo/src/neighborhood/moKswapNeighbor.h @@ -58,8 +58,8 @@ public: * @param _Kswap the number of swap to do */ - moKswapNeighbor(unsigned int _Kswap) : - moIndexSwapNeighbor(_Kswap) { + moKswapNeighbor() : + moIndexSwapNeighbor(Kswap) { } diff --git a/trunk/paradiseo-mo/src/neighborhood/moKswapNeighborhood.h b/trunk/paradiseo-mo/src/neighborhood/moKswapNeighborhood.h index 7f576f39e..7f481a0fd 100644 --- a/trunk/paradiseo-mo/src/neighborhood/moKswapNeighborhood.h +++ b/trunk/paradiseo-mo/src/neighborhood/moKswapNeighborhood.h @@ -50,7 +50,7 @@ static unsigned int factorial(unsigned int i) { * @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; for (int i = _Kswap; i > 0; i--) { @@ -81,8 +81,8 @@ public: * @param _Kswap the number of swap */ - moKswapNeighborhood(unsigned int _size, unsigned int _Kswap) : - moOrderNeighborhood (sizeMapping(_size, _Kswap)) { + moKswapNeighborhood(unsigned int _size,unsigned int _Kswap) : + moOrderNeighborhood (sizeMapping(_size,_Kswap)) { mutex = true; size = _size; @@ -111,7 +111,7 @@ public: //Compute the mapping only for the first init if (mutex) { - setMapping(size, Kswap); + setMapping(); mutex = false; } @@ -149,43 +149,42 @@ public: /** * Set the mapping of K-indexes * @param _size the solution size - * @param _Kswap the number of swap */ - void setMapping(unsigned int _size, unsigned int _Kswap) { + void setMapping() { - if (!_Kswap) { - for (int i = 0; i < _size; i++) + if (!Kswap) { + for (int i = 0; i < size; i++) mapping[i] = i; } else { 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; int id = 0; bool change = false; 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 + _Kswap * neighborhoodSize] - = _indices[_Kswap]++; + mapping[id + Kswap * neighborhoodSize] + = _indices[Kswap]++; id++; } - _indices[_Kswap]--; + _indices[Kswap]--; if (id < neighborhoodSize) { - for (int i = _Kswap - 1; i >= 0; i--) + for (int i = Kswap - 1; i >= 0; i--) if (!change) - change = nextIndices(_indices, _size, _Kswap, i); + change = nextIndices(_indices, i); } change = false; @@ -198,20 +197,18 @@ public: /** * Compute the next combination of mapping 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 */ - 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]++; int i = 1; - while (_indice + i <= _Kswap) { + while (_indice + i <= Kswap) { _indices[_indice + i] = _indices[_indice + i - 1] + 1; i++; @@ -230,7 +227,7 @@ public: _indices[_indice + 1]++; int i = 2; - while (_indice + i <= _Kswap) { + while (_indice + i <= Kswap) { _indices[_indice + i] = _indices[_indice + i - 1] + 1; i++; }