add method index(sol, index) to moIndexNeighbor
This commit is contained in:
parent
948da627ea
commit
72ffb89999
6 changed files with 70 additions and 34 deletions
|
|
@ -86,17 +86,32 @@ public:
|
|||
* Getter
|
||||
* @return index of the IndexNeighbor
|
||||
*/
|
||||
unsigned int index() {
|
||||
inline unsigned int index() const {
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter
|
||||
* Setter :
|
||||
* Only set the index which not depends on the current solution
|
||||
*
|
||||
* @param _key index of the IndexNeighbor
|
||||
*/
|
||||
void index(unsigned int _key) {
|
||||
key = _key;
|
||||
void index(unsigned int _key) {
|
||||
key = _key;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setter
|
||||
* The "parameters" of the neighbor is a function of key and the current solution
|
||||
* for example, for variable length solution
|
||||
*
|
||||
* @param _solution solution from which the neighborhood is visited
|
||||
* @param _key index of the IndexNeighbor
|
||||
*/
|
||||
virtual void index(EOT & _solution, unsigned int _key) {
|
||||
key = _key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param _neighbor a neighbor
|
||||
|
|
|
|||
|
|
@ -49,7 +49,14 @@ public:
|
|||
*/
|
||||
typedef typename Neighbor::EOT EOT;
|
||||
|
||||
using moIndexNeighborhood<Neighbor>::neighborhoodSize;
|
||||
using moIndexNeighborhood<Neighbor>::getNeighborhoodSize;
|
||||
|
||||
/**
|
||||
* Empty constructor
|
||||
*/
|
||||
moOrderNeighborhood() :
|
||||
moIndexNeighborhood<Neighbor>(0), currentIndex(0) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
|
@ -65,7 +72,7 @@ public:
|
|||
* @return true if the neighborhood was not empty
|
||||
*/
|
||||
virtual bool hasNeighbor(EOT& _solution) {
|
||||
return neighborhoodSize > 0;
|
||||
return getNeighborhoodSize() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -75,7 +82,7 @@ public:
|
|||
*/
|
||||
virtual void init(EOT & _solution, Neighbor & _neighbor) {
|
||||
currentIndex = 0;
|
||||
_neighbor.index(currentIndex);
|
||||
_neighbor.index(_solution, currentIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -85,7 +92,7 @@ public:
|
|||
*/
|
||||
virtual void next(EOT & _solution, Neighbor & _neighbor) {
|
||||
currentIndex++;
|
||||
_neighbor.index(currentIndex);
|
||||
_neighbor.index(_solution, currentIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -96,14 +103,14 @@ public:
|
|||
* @return true if there is again a neighbor to explore
|
||||
*/
|
||||
virtual bool cont(EOT & _solution) {
|
||||
return (currentIndex < neighborhoodSize - 1);
|
||||
return (currentIndex < getNeighborhoodSize() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter
|
||||
* @return the position in the Neighborhood
|
||||
*/
|
||||
unsigned int position() {
|
||||
inline unsigned int position() const {
|
||||
return currentIndex;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ public:
|
|||
* @param _neighbor the first neighbor
|
||||
*/
|
||||
virtual void init(EOT & _solution, Neighbor & _neighbor) {
|
||||
_neighbor.index(rng.random(neighborhoodSize));
|
||||
_neighbor.index(_solution, rng.random(neighborhoodSize));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -84,7 +84,7 @@ public:
|
|||
* @param _neighbor the next neighbor
|
||||
*/
|
||||
virtual void next(EOT & _solution, Neighbor & _neighbor) {
|
||||
_neighbor.index(rng.random(neighborhoodSize));
|
||||
_neighbor.index(_solution, rng.random(neighborhoodSize));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ public:
|
|||
unsigned int i, tmp;
|
||||
maxIndex = neighborhoodSize ;
|
||||
i = rng.random(maxIndex);
|
||||
_neighbor.index(indexVector[i]);
|
||||
_neighbor.index(_solution, indexVector[i]);
|
||||
tmp=indexVector[i];
|
||||
indexVector[i]=indexVector[maxIndex-1];
|
||||
indexVector[maxIndex-1]=tmp;
|
||||
|
|
@ -97,7 +97,7 @@ public:
|
|||
virtual void next(EOT & _solution, Neighbor & _neighbor) {
|
||||
unsigned int i, tmp;
|
||||
i = rng.random(maxIndex);
|
||||
_neighbor.index(indexVector[i]);
|
||||
_neighbor.index(_solution, indexVector[i]);
|
||||
tmp=indexVector[i];
|
||||
indexVector[i]=indexVector[maxIndex-1];
|
||||
indexVector[maxIndex-1]=tmp;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue