org.coinor.opents
Class MultiThreadedTabuSearch

java.lang.Object
  extended byorg.coinor.opents.TabuSearchBase
      extended byorg.coinor.opents.SingleThreadedTabuSearch
          extended byorg.coinor.opents.MultiThreadedTabuSearch
All Implemented Interfaces:
java.io.Serializable, TabuSearch

public class MultiThreadedTabuSearch
extends SingleThreadedTabuSearch

This version of the TabuSearch can create multiple threads to take advantage of multiple processors. If more than one thread is requested, then the neighborhood will be split up evenly after the getAllMoves() method is called on your MoveManager.

This is the recommended TabuSearch for nearly all well-threaded applications because it does not block on the startSolving() method. When done solving a given set of iterations, the thread will die, freeing up your computer's resources. If you add iterations with setIterationsToGo() and call startSolving() again, the thread(s) will restart.

This code is licensed for public use under the Common Public License version 0.5.
The Common Public License, developed by IBM and modeled after their industry-friendly IBM Public License, differs from other common open source licenses in several important ways:

Copyright © 2001 Robert Harder

Since:
1.0
See Also:
Serialized Form

Nested Class Summary
protected static class MultiThreadedTabuSearch.NeighborhoodHelper
           
 
Field Summary
 
Fields inherited from class org.coinor.opents.SingleThreadedTabuSearch
aspirationCriteria, bestSolution, chooseFirstImprovingMove, currentSolution, err, fireImprovingMoveMade, fireNewBestSolution, fireNewCurrentSolution, fireNoChangeInValueMoveMade, fireUnimprovingMoveMade, iterationsToGo, keepSolving, maximizing, moveManager, objectiveFunction, solving, tabuList
 
Constructor Summary
MultiThreadedTabuSearch()
          Constructs a MultiThreadedTabuSearch with no tabu objects set.
MultiThreadedTabuSearch(Solution initialSolution, MoveManager moveManager, ObjectiveFunction objectiveFunction, TabuList tabuList, AspirationCriteria aspirationCriteria, boolean maximizing)
          Constructs a MultiThreadedTabuSearch with all tabu objects set.
 
Method Summary
protected  java.lang.Object[] getBestMove(Solution soln, Move[] moves, ObjectiveFunction objectiveFunction, TabuList tabuList, AspirationCriteria aspirationCriteria, boolean maximizing, boolean chooseFirstImprovingMove)
          Gets the best move--one that should be used for this iteration.
 int getThreadPriority()
          Returns the thread priority setting for the threads used by the tabu search.
 int getThreads()
          Returns the number of threads to use when evaluating the tabu search neighborhood.
 void setThreadPriority(int threadPriority)
          Set the thread priority to use for all threads.
 void setThreads(int threads)
          Set the number of threads to use when evaluating the tabu search neighborhood.
 void startSolving()
          Starts the tabu search solving in another thread and immediately returns control to the calling thread.
 void stopSolving()
          Stops the tabu search and preserves the number of iterations remaining.
 void waitToFinish()
          Blocks until the tabu search reaches zero iterations to go.
 
Methods inherited from class org.coinor.opents.SingleThreadedTabuSearch
fireQueuedEvents, firstIsBetterThanSecond, getAspirationCriteria, getBestMove, getBestSolution, getCurrentSolution, getIterationsToGo, getMoveManager, getObjectiveFunction, getTabuList, internalSetBestSolution, internalSetCurrentSolution, isChooseFirstImprovingMove, isFireImprovingMoveMade, isFireNewBestSolution, isFireNewCurrentSolution, isFireNoChangeInValueMoveMade, isFireUnimprovingMoveMade, isFirstBetterThanSecond, isKeepSolving, isMaximizing, isSolving, isTabu, performOneIteration, setAspirationCriteria, setBestSolution, setChooseFirstImprovingMove, setCurrentSolution, setFireImprovingMoveMade, setFireNewBestSolution, setFireNewCurrentSolution, setFireNoChangeInValueMoveMade, setFireUnimprovingMoveMade, setIterationsToGo, setKeepSolving, setMaximizing, setMoveManager, setObjectiveFunction, setSolving, setTabuList
 
Methods inherited from class org.coinor.opents.TabuSearchBase
addTabuSearchListener, fireImprovingMoveMade, fireNewBestSolution, fireNewCurrentSolution, fireNoChangeInValueMoveMade, fireTabuSearchStarted, fireTabuSearchStopped, fireUnimprovingMoveMade, getIterationsCompleted, incrementIterationsCompleted, removeTabuSearchListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiThreadedTabuSearch

public MultiThreadedTabuSearch()
Constructs a MultiThreadedTabuSearch with no tabu objects set.

Since:
1.0

MultiThreadedTabuSearch

public MultiThreadedTabuSearch(Solution initialSolution,
                               MoveManager moveManager,
                               ObjectiveFunction objectiveFunction,
                               TabuList tabuList,
                               AspirationCriteria aspirationCriteria,
                               boolean maximizing)
Constructs a MultiThreadedTabuSearch with all tabu objects set. The initial solution is evaluated with the objective function, becomes the currentSolution and a copy becomes the bestSolution.

Parameters:
initialSolution - The initial currentSolution
moveManager - The move manager
objectiveFunction - The objective function
tabuList - The tabu list
aspirationCriteria - The aspiration criteria or null if none is to be used
maximizing - Whether or not the tabu search should be maximizing the objective function
Since:
1.0
See Also:
Solution, ObjectiveFunction, MoveManager, TabuList, AspirationCriteria
Method Detail

setThreads

public void setThreads(int threads)
Set the number of threads to use when evaluating the tabu search neighborhood. Generally you should set this to the number of processors that your computer has. If threads is negative then there will be no change.

Parameters:
threads - The number of threads to use when evaluating the neighborhood
Since:
1.0

getThreads

public int getThreads()
Returns the number of threads to use when evaluating the tabu search neighborhood.

Returns:
The number of threads to use when evaluating the tabu search neighborhood.
Since:
1.0

setThreadPriority

public void setThreadPriority(int threadPriority)
Set the thread priority to use for all threads. There will always be at least two threads: one for the main tabu search engine and one for the neighborhood-evaluation thread group. If threadPriority is less than java.lang.Thread#MIN_VALUE or greater than java.lang.Thread#MAX_VALUE then the value will actually be set to java.lang.Thread#MIN_VALUE or java.lang.Thread#MAX_VALUE, whichever is closer.

If the tabu search is already running, this will not take effect until the tabu search restarts.

Parameters:
threadPriority -
Since:
1.0

getThreadPriority

public int getThreadPriority()
Returns the thread priority setting for the threads used by the tabu search.

Returns:
The thread priority setting for the threads used by the tabu search.
Since:
1.0

getBestMove

protected java.lang.Object[] getBestMove(Solution soln,
                                         Move[] moves,
                                         ObjectiveFunction objectiveFunction,
                                         TabuList tabuList,
                                         AspirationCriteria aspirationCriteria,
                                         boolean maximizing,
                                         boolean chooseFirstImprovingMove)
Gets the best move--one that should be used for this iteration. The work load is split up among as many threads as the user requests. The default is 1. By setting chooseFirstImprovingMove to true you tell the tabu search to return the first move it encounters that is improving and non-tabu rather than search through all of the moves. This is actually implemented by having each thread return the first improving move it encounters and then choosing the best among these moves.

Overrides:
getBestMove in class SingleThreadedTabuSearch
Since:
1.0

startSolving

public void startSolving()
Starts the tabu search solving in another thread and immediately returns control to the calling thread.

Specified by:
startSolving in interface TabuSearch
Overrides:
startSolving in class SingleThreadedTabuSearch
Since:
1.0c

stopSolving

public void stopSolving()
Stops the tabu search and preserves the number of iterations remaining.

Specified by:
stopSolving in interface TabuSearch
Overrides:
stopSolving in class SingleThreadedTabuSearch
Since:
1.0

waitToFinish

public void waitToFinish()
Blocks until the tabu search reaches zero iterations to go.

Since:
1.0-exp8