change a maximum limit to the neighborhood exploration
This commit is contained in:
parent
9d867cb9fa
commit
56484a8cdd
1 changed files with 16 additions and 1 deletions
|
|
@ -57,8 +57,11 @@ public:
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param _neighborhoodSize the size of the neighborhood
|
* @param _neighborhoodSize the size of the neighborhood
|
||||||
|
* @param _maxNeighbors the maximum number of visited neighbors (0 = infinite number)
|
||||||
*/
|
*/
|
||||||
moRndWithReplNeighborhood(unsigned int _neighborhoodSize): moIndexNeighborhood<Neighbor>(_neighborhoodSize) {}
|
moRndWithReplNeighborhood(unsigned int _neighborhoodSize, unsigned int _maxNeighbors = 0): moIndexNeighborhood<Neighbor>(_neighborhoodSize), maxNeighbors(_maxNeighbors)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test if it exist a neighbor
|
* Test if it exist a neighbor
|
||||||
|
|
@ -75,6 +78,7 @@ public:
|
||||||
* @param _neighbor the first neighbor
|
* @param _neighbor the first neighbor
|
||||||
*/
|
*/
|
||||||
virtual void init(EOT & _solution, Neighbor & _neighbor) {
|
virtual void init(EOT & _solution, Neighbor & _neighbor) {
|
||||||
|
nNeighbors = 1;
|
||||||
_neighbor.index(_solution, rng.random(neighborhoodSize));
|
_neighbor.index(_solution, rng.random(neighborhoodSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,6 +88,7 @@ public:
|
||||||
* @param _neighbor the next neighbor
|
* @param _neighbor the next neighbor
|
||||||
*/
|
*/
|
||||||
virtual void next(EOT & _solution, Neighbor & _neighbor) {
|
virtual void next(EOT & _solution, Neighbor & _neighbor) {
|
||||||
|
nNeighbors++;
|
||||||
_neighbor.index(_solution, rng.random(neighborhoodSize));
|
_neighbor.index(_solution, rng.random(neighborhoodSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,7 +98,10 @@ public:
|
||||||
* @return true if there is again a neighbor to explore
|
* @return true if there is again a neighbor to explore
|
||||||
*/
|
*/
|
||||||
virtual bool cont(EOT & _solution) {
|
virtual bool cont(EOT & _solution) {
|
||||||
|
if (maxNeighbors == 0)
|
||||||
return neighborhoodSize > 0;
|
return neighborhoodSize > 0;
|
||||||
|
else
|
||||||
|
return (neighborhoodSize > 0) && (nNeighbors < maxNeighbors);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -104,6 +112,13 @@ public:
|
||||||
return "moRndWithReplNeighborhood";
|
return "moRndWithReplNeighborhood";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
// maximum number of visited neighbors
|
||||||
|
unsigned int maxNeighbors;
|
||||||
|
|
||||||
|
// number of visited neighbors
|
||||||
|
unsigned int nNeighbors;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue