From 56484a8cdd3c4532cc83ed4545d247065537275b Mon Sep 17 00:00:00 2001 From: verel Date: Mon, 12 Nov 2012 15:25:58 +0100 Subject: [PATCH] change a maximum limit to the neighborhood exploration --- mo/src/neighborhood/moRndWithReplNeighborhood.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/mo/src/neighborhood/moRndWithReplNeighborhood.h b/mo/src/neighborhood/moRndWithReplNeighborhood.h index 126e56af5..89537bf09 100644 --- a/mo/src/neighborhood/moRndWithReplNeighborhood.h +++ b/mo/src/neighborhood/moRndWithReplNeighborhood.h @@ -57,8 +57,11 @@ public: /** * Constructor * @param _neighborhoodSize the size of the neighborhood + * @param _maxNeighbors the maximum number of visited neighbors (0 = infinite number) */ - moRndWithReplNeighborhood(unsigned int _neighborhoodSize): moIndexNeighborhood(_neighborhoodSize) {} + moRndWithReplNeighborhood(unsigned int _neighborhoodSize, unsigned int _maxNeighbors = 0): moIndexNeighborhood(_neighborhoodSize), maxNeighbors(_maxNeighbors) + { + } /** * Test if it exist a neighbor @@ -75,6 +78,7 @@ public: * @param _neighbor the first neighbor */ virtual void init(EOT & _solution, Neighbor & _neighbor) { + nNeighbors = 1; _neighbor.index(_solution, rng.random(neighborhoodSize)); } @@ -84,6 +88,7 @@ public: * @param _neighbor the next neighbor */ virtual void next(EOT & _solution, Neighbor & _neighbor) { + nNeighbors++; _neighbor.index(_solution, rng.random(neighborhoodSize)); } @@ -93,7 +98,10 @@ public: * @return true if there is again a neighbor to explore */ virtual bool cont(EOT & _solution) { + if (maxNeighbors == 0) return neighborhoodSize > 0; + else + return (neighborhoodSize > 0) && (nNeighbors < maxNeighbors); } /** @@ -104,6 +112,13 @@ public: return "moRndWithReplNeighborhood"; } +private: + // maximum number of visited neighbors + unsigned int maxNeighbors; + + // number of visited neighbors + unsigned int nNeighbors; + }; #endif