net.usa.rharder.tabusearch22
Class TSEngine

java.lang.Object
  |
  +--net.usa.rharder.tabusearch22.TSEngine

public class TSEngine
extends java.lang.Object

The TSEngine is the main source of control for the programmer. The extended and instantiated tabu objects are passed to the engine, and the engine fires off relevant events to interested listeners. These events make it easy to extend the tabu search to include popular techniques such as intensification, diversification, and strategic oscillation.

Since:
1.0

Field Summary
protected static boolean DEBUGGING
          When set to true, information will be printed to System.out and System.err at various points in the code.
 
Constructor Summary
TSEngine(TSSolution initialSolution, TSTabuList tabuList, TSFunction objectiveFunction, TSFunction penaltyFunction, TSMoveManager moveManager)
          This most basic constructor assumes a maximization problem and uses just one thread for searching.
TSEngine(TSSolution initialSolution, TSTabuList tabuList, TSFunction objectiveFunction, TSFunction penaltyFunction, TSMoveManager moveManager, boolean maximizing)
          This constructor lets you specify if you are maximizing or minimizing.
TSEngine(TSSolution initialSolution, TSTabuList tabuList, TSFunction objectiveFunction, TSFunction penaltyFunction, TSMoveManager moveManager, boolean maximizing, int numberOfThreads)
          This constructor lets you specify if you are maximizing or minimizing.
 
Method Summary
 void addEngineFinishedListener(TSEngineFinishedListener listener)
          Registers listener to receive tabu events when the engine finishes.
 void addEngineStartedListener(TSEngineStartedListener listener)
          Registers listener to receive tabu events when the engine starts.
 void addNewBestSolutionListener(TSNewBestSolutionListener listener)
          Registers listener to receive tabu events when a new best solution is found.
 void addNewCurrentSolutionListener(TSNewCurrentSolutionListener listener)
          Registers listener to receive tabu events when a new current solution is found.
 void addUnimprovingMoveListener(TSUnimprovingMoveListener listener)
          Registers listener to receive tabu events when an unimproving move is made.
protected  void fireEngineFinished()
          This quick method is called when the engine finishes.
protected  void fireEngineStarted()
          This quick method is called when the engine starts.
protected  void fireNewBestSolution()
          This quick method is called when a new best solution is found.
protected  void fireNewCurrentSolution()
          This quick method is called when a new current solution is found.
protected  void fireUnimprovingMoveMade()
          This quick method is called when an unimproving move is made.
 TSSolution getBestSolution()
          Returns the best solution found so far.
 int getCurrentIteration()
          Returns the current iteration of the engine.
 TSSolution getCurrentSolution()
          Returns the current solution.
 int getIterationOfBestSolution()
          Returns the iteration number when the best solution was found.
 int getIterationsToGo()
          Returns the iterations left in the engine.
 long getLastSolveMillis()
          Returns the number of milliseconds it took to solve the last set of iterations.
 TSMoveManager getMoveManager()
          Returns the move manager being used by the engine.
 TSMove[] getMovesUsedOnLastIteration()
          Returns the moves that were used on the last iteration.
 TSFunction getObjectiveFunction()
          Returns the objective function being used by the engine.
 TSFunction getPenaltyFunction()
          Returns the penalty function being used by the engine.
 TSTabuList getTabuList()
          Returns the tabu list that is being used by the engine.
 void removeEngineFinishedListener(TSEngineFinishedListener listener)
          Removes listener from list of objects to notify when the engine finished its appointed iterations.
 void removeEngineStartedListener(TSEngineStartedListener listener)
          Removes listener from list of objects to notify when the engine starts its appointed iterations.
 void removeNewBestSolutionListener(TSNewBestSolutionListener listener)
          Removes listener from list of objects to notify when a new best solution is found.
 void removeNewCurrentSolutionListener(TSNewCurrentSolutionListener listener)
          Removes listener from list of objects to notify when a new current solution is found.
 void removeUnimprovingMoveListener(TSUnimprovingMoveListener listener)
          Removes listener from list of objects to notify when an unimproving move is made.
 void setBestSolutionToCopyOf(TSSolution solution)
          Sets the best solution to a copy of the passed solution.
 void setCurrentSolutionToCopyOf(TSSolution solution)
          Sets the current solution to a copy of the passed solution.
 void startSolving(int additionalIterations)
          Starts the engine solving for the given number of iterations.
 void stopSolving()
          Stop the engine after the current iteration.
 void trySettingBestSolutionToCopyOf(TSSolution solution)
          Sets the best solution to a copy of the passed solution but only if the new solution is better than the existing best solution.
 void waitToFinish()
          Returns control when the engine has stopped.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUGGING

protected static final boolean DEBUGGING
When set to true, information will be printed to System.out and System.err at various points in the code.
Constructor Detail

TSEngine

public TSEngine(TSSolution initialSolution,
                TSTabuList tabuList,
                TSFunction objectiveFunction,
                TSFunction penaltyFunction,
                TSMoveManager moveManager)
This most basic constructor assumes a maximization problem and uses just one thread for searching.
Parameters:
initialSolution - The initial solution
tabuList - The tabu list
objectiveFunction - The objective function. Note that the objective function and the penalty function are really very much the same. They are divided up for easier programming and for possible future enhancements.
penaltyFunction - The penalty function.
moveManager - The Move Manager.
Since:
2.0
See Also:
TSSolution, TSTabuList, TSFunction, TSMoveManager

TSEngine

public TSEngine(TSSolution initialSolution,
                TSTabuList tabuList,
                TSFunction objectiveFunction,
                TSFunction penaltyFunction,
                TSMoveManager moveManager,
                boolean maximizing)
This constructor lets you specify if you are maximizing or minimizing.
Parameters:
initialSolution - The initial solution
tabuList - The tabu list
objectiveFunction - The objective function. Note that the objective function and the penalty function are really very much the same. They are divided up for easier programming and for possible future enhancements.
penaltyFunction - The penalty function.
moveManager - The Move Manager.
maximizing - true if maximizing, false if minimizing
Since:
2.0
See Also:
TSSolution, TSTabuList, TSFunction, TSMoveManager

TSEngine

public TSEngine(TSSolution initialSolution,
                TSTabuList tabuList,
                TSFunction objectiveFunction,
                TSFunction penaltyFunction,
                TSMoveManager moveManager,
                boolean maximizing,
                int numberOfThreads)
This constructor lets you specify if you are maximizing or minimizing. It also lets you specify the number of threads to use during the search. If you are running on a multi-processor computer and have a capable OS such as Solaris, NT, or MacOS X, with jdk1.2.x or better, you will see speed gains by setting the number of threads to use equal to or greater than the number of processors on the machine. If more than one thread is specified, the moves at each iteration are divided up among the threads and evaluated separately. On most computers the speed gain may be only 10% since memory access is commonly still handled in a one-at-a-time manner by most platforms.
Parameters:
initialSolution - The initial solution
tabuList - The tabu list
objectiveFunction - The objective function. Note that the objective function and the penalty function are really very much the same. They are divided up for easier programming and for possible future enhancements.
penaltyFunction - The penalty function.
moveManager - The Move Manager.
maximizing - true if maximizing, false if minimizing
numberOfThreads - number of threads to use when searching
Since:
2.0
See Also:
TSSolution, TSTabuList, TSFunction, TSMoveManager
Method Detail

startSolving

public final void startSolving(int additionalIterations)
Starts the engine solving for the given number of iterations. If the engine is already solving, the passed number of iterations is added to the iterations remaining. If the engine has stopped, it will start up again and fire an event to registered TSEngineStartedListeners.
Parameters:
additionalIterations - Additional iterations to solve.
Since:
1.0
See Also:
TSEngineStartedListener

stopSolving

public final void stopSolving()
Stop the engine after the current iteration. Control is not returned until the engine has stopped and events have been fired to registered TSEngineFinishedListeners.
Since:
2.0
See Also:
TSEngineFinishedListener

waitToFinish

public final void waitToFinish()
Returns control when the engine has stopped. A more sophisticated way to handle waiting for the engine is to use a TSEngineFinishedListener.
See Also:
TSEngineFinishedListener

setCurrentSolutionToCopyOf

public final void setCurrentSolutionToCopyOf(TSSolution solution)
Sets the current solution to a copy of the passed solution. This is useful when implementing various intensification and diversification techniques.
Parameters:
solution - The new solution
Since:
2.1
See Also:
TSSolution

setBestSolutionToCopyOf

public final void setBestSolutionToCopyOf(TSSolution solution)
Sets the best solution to a copy of the passed solution. This is useful when there is more than one TSEngine working on the solution space.
Parameters:
solution - The new best solution
Since:
2.1
See Also:
TSSolution

trySettingBestSolutionToCopyOf

public final void trySettingBestSolutionToCopyOf(TSSolution solution)
Sets the best solution to a copy of the passed solution but only if the new solution is better than the existing best solution. This is useful when there is more than one TSEngine working on the solution space.
Parameters:
solution - The new best solution
Since:
2.1
See Also:
TSSolution

getLastSolveMillis

public final long getLastSolveMillis()
Returns the number of milliseconds it took to solve the last set of iterations. If iterations are added with the startSolving method, the time returned will reflect the time needed to solve the total number of iterations.
Returns:
Number of milliseconds for last solve
Since:
1.0

getBestSolution

public final TSSolution getBestSolution()
Returns the best solution found so far.
Returns:
The best solution found so far.
Since:
1.0
See Also:
TSSolution

getIterationOfBestSolution

public final int getIterationOfBestSolution()
Returns the iteration number when the best solution was found.
Returns:
iteration when best solution was found
Since:
2.1
See Also:
TSSolution

getCurrentIteration

public final int getCurrentIteration()
Returns the current iteration of the engine.
Returns:
current iteration
Since:
2.1

getIterationsToGo

public final int getIterationsToGo()
Returns the iterations left in the engine.
Returns:
iterations to go
Since:
2.1

getCurrentSolution

public final TSSolution getCurrentSolution()
Returns the current solution.
Returns:
the current solution.
Since:
1.0
See Also:
TSSolution

getTabuList

public final TSTabuList getTabuList()
Returns the tabu list that is being used by the engine.
Returns:
the tabu list.
Since:
1.0
See Also:
TSTabuList

getObjectiveFunction

public final TSFunction getObjectiveFunction()
Returns the objective function being used by the engine.
Returns:
the objective function.
Since:
1.0
See Also:
TSFunction

getPenaltyFunction

public final TSFunction getPenaltyFunction()
Returns the penalty function being used by the engine.
Returns:
the penalty function.
Since:
1.0
See Also:
TSFunction

getMoveManager

public final TSMoveManager getMoveManager()
Returns the move manager being used by the engine.
Returns:
the move manager.
Since:
1.0
See Also:
TSMoveManager

getMovesUsedOnLastIteration

public final TSMove[] getMovesUsedOnLastIteration()
Returns the moves that were used on the last iteration.
Returns:
moves used on last iteration
See Also:
TSMove

addNewBestSolutionListener

public final void addNewBestSolutionListener(TSNewBestSolutionListener listener)
Registers listener to receive tabu events when a new best solution is found.
Parameters:
listener - The TSNewBestSolutionListener to register.
Since:
1.1
See Also:
TSNewBestSolutionListener

addNewCurrentSolutionListener

public final void addNewCurrentSolutionListener(TSNewCurrentSolutionListener listener)
Registers listener to receive tabu events when a new current solution is found.
Parameters:
listener - TSNewCurrentSolutionListener to register.
Since:
1.1
See Also:
TSNewCurrentSolutionListener

addUnimprovingMoveListener

public final void addUnimprovingMoveListener(TSUnimprovingMoveListener listener)
Registers listener to receive tabu events when an unimproving move is made.
Parameters:
listener - TSUnimprovingMoveListener to register.
Since:
2.0
See Also:
TSUnimprovingMoveListener

addEngineFinishedListener

public final void addEngineFinishedListener(TSEngineFinishedListener listener)
Registers listener to receive tabu events when the engine finishes.
Parameters:
listener - that listens for the engine to finish
Since:
2.1
See Also:
TSEngineFinishedListener

addEngineStartedListener

public final void addEngineStartedListener(TSEngineStartedListener listener)
Registers listener to receive tabu events when the engine starts.
Parameters:
listener - that listens for the engine to start
Since:
2.1
See Also:
TSEngineStartedListener

removeNewBestSolutionListener

public final void removeNewBestSolutionListener(TSNewBestSolutionListener listener)
Removes listener from list of objects to notify when a new best solution is found.
Parameters:
listener - TSNewBestSolutionListener to remove from notification list.
Since:
1.1
See Also:
TSNewBestSolutionListener

removeNewCurrentSolutionListener

public final void removeNewCurrentSolutionListener(TSNewCurrentSolutionListener listener)
Removes listener from list of objects to notify when a new current solution is found.
Parameters:
listener - TSNewCurrentSolutionListener to remove from notification list.
Since:
1.1
See Also:
TSNewCurrentSolutionListener

removeUnimprovingMoveListener

public final void removeUnimprovingMoveListener(TSUnimprovingMoveListener listener)
Removes listener from list of objects to notify when an unimproving move is made.
Parameters:
listener - TSUnimprovingMoveListener to remove from notification list.
Since:
2.0
See Also:
TSUnimprovingMoveListener

removeEngineFinishedListener

public final void removeEngineFinishedListener(TSEngineFinishedListener listener)
Removes listener from list of objects to notify when the engine finished its appointed iterations.
Parameters:
listener - TSEngineFinishedListener to remove from notification list.
Since:
2.0
See Also:
TSEngineFinishedListener

removeEngineStartedListener

public final void removeEngineStartedListener(TSEngineStartedListener listener)
Removes listener from list of objects to notify when the engine starts its appointed iterations.
Parameters:
listener - TSEngineStartedListener to remove from notification list.
Since:
2.0
See Also:
TSEngineStartedListener

fireNewBestSolution

protected final void fireNewBestSolution()
This quick method is called when a new best solution is found. The TSTabuEvent sent to the listeners is a "lightweight" event, specifying only the source object, this.
See Also:
TSTabuEvent

fireNewCurrentSolution

protected final void fireNewCurrentSolution()
This quick method is called when a new current solution is found. The TSTabuEvent sent to the listeners is a "lightweight" event, specifying only the source object, this.
See Also:
TSTabuEvent

fireUnimprovingMoveMade

protected final void fireUnimprovingMoveMade()
This quick method is called when an unimproving move is made. The TSTabuEvent sent to the listeners is a "lightweight" event, specifying only the source object, this.
See Also:
TSTabuEvent

fireEngineFinished

protected final void fireEngineFinished()
This quick method is called when the engine finishes. The TSTabuEvent sent to the listeners is a "lightweight" event, specifying only the source object, this.
See Also:
TSTabuEvent

fireEngineStarted

protected final void fireEngineStarted()
This quick method is called when the engine starts. The TSTabuEvent sent to the listeners is a "lightweight" event, specifying only the source object, this.
See Also:
TSTabuEvent