|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.coinor.opents.TabuSearchBase org.coinor.opents.SingleThreadedTabuSearch
This version of the TabuSearch
does not create any new threads, making it
ideal for embedding in Enterprise JavaBeans. The startSolving()
method
blocks until the given number of iterations have been completed.
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
Field Summary | |
protected AspirationCriteria |
aspirationCriteria
Aspiration criteria. |
protected Solution |
bestSolution
Best solution. |
protected boolean |
chooseFirstImprovingMove
Choose first improving neighbor instead of best neighbor overall. |
protected Solution |
currentSolution
Current solution. |
protected static java.io.PrintStream |
err
Print errors to this stream. |
protected boolean |
fireImprovingMoveMade
Fire improving solution event at the end of the iteration. |
protected boolean |
fireNewBestSolution
Fire new best solution event at the end of the iteration. |
protected boolean |
fireNewCurrentSolution
Fire new current solution event at the end of the iteration. |
protected boolean |
fireNoChangeInValueMoveMade
Fire no change in value solution event at the end of the iteration. |
protected boolean |
fireUnimprovingMoveMade
Fire unimproving solution event at the end of the iteration. |
protected int |
iterationsToGo
Iterations to go. |
protected boolean |
keepSolving
Whether or not the tabu search should keep solving if it gets a chance to quit. |
protected boolean |
maximizing
Maximizing: true. |
protected MoveManager |
moveManager
Move manager. |
protected ObjectiveFunction |
objectiveFunction
Objective function. |
protected boolean |
solving
Whether or not the the tabu search is solving. |
protected TabuList |
tabuList
Tabu list. |
Constructor Summary | |
SingleThreadedTabuSearch()
Constructs a SingleThreadedTabuSearch with no tabu objects set. |
|
SingleThreadedTabuSearch(Solution initialSolution,
MoveManager moveManager,
ObjectiveFunction objectiveFunction,
TabuList tabuList,
AspirationCriteria aspirationCriteria,
boolean maximizing)
Constructs a SingleThreadedTabuSearch with all tabu objects set. |
Method Summary | |
protected void |
fireQueuedEvents()
Fires events that are queued for firing at the end of an iteration. |
static boolean |
firstIsBetterThanSecond(double[] first,
double[] second,
boolean maximizing)
Deprecated. |
AspirationCriteria |
getAspirationCriteria()
Returns the aspiration criteria. |
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. |
protected static java.lang.Object[] |
getBestMove(Solution soln,
Move[] moves,
ObjectiveFunction objectiveFunction,
TabuList tabuList,
AspirationCriteria aspirationCriteria,
boolean maximizing,
boolean chooseFirstImprovingMove,
TabuSearch This)
The static method that actually does the work. |
Solution |
getBestSolution()
Returns the best solution found by the tabu search. |
Solution |
getCurrentSolution()
Returns the current solution being used by the tabu search. |
int |
getIterationsToGo()
Returns the number of iterations left for the tabu search to execute. |
MoveManager |
getMoveManager()
Returns the move manager being used by the tabu search. |
ObjectiveFunction |
getObjectiveFunction()
Returns the objective function being used by the tabu search. |
TabuList |
getTabuList()
Returns the tabu list being used by the tabu search. |
protected void |
internalSetBestSolution(Solution solution)
Set the best solution and prepare to fire an event. |
protected void |
internalSetCurrentSolution(Solution solution)
Set the current solution and prepare to fire an event. |
boolean |
isChooseFirstImprovingMove()
Returns whether or not the tabu search engine will choose the first improving move it encounters at each iteration (true) or the best move (false). |
protected boolean |
isFireImprovingMoveMade()
Returns whether or not the tabu search plans to fire an improving move made TabuSearchEvent
at the end of the iteration. |
protected boolean |
isFireNewBestSolution()
Returns whether or not the tabu search plans to fire a new best solution TabuSearchEvent
at the end of the iteration. |
protected boolean |
isFireNewCurrentSolution()
Returns whether or not the tabu search plans to fire a new current solution TabuSearchEvent
at the end of the iteration. |
protected boolean |
isFireNoChangeInValueMoveMade()
Returns whether or not the tabu search plans to fire a no change in value move made TabuSearchEvent
at the end of the iteration. |
protected boolean |
isFireUnimprovingMoveMade()
Returns whether or not the tabu search plans to fire an unimproving move made TabuSearchEvent
at the end of the iteration. |
static boolean |
isFirstBetterThanSecond(double[] first,
double[] second,
boolean maximizing)
This single method is called many times to compare solutions. |
protected boolean |
isKeepSolving()
Returns whether or not the tabu search should keep solving the next chance it gets to quit, like at the start of a new iteration. |
boolean |
isMaximizing()
Returns whether or not the tabu search should be maximizing the objective function. |
boolean |
isSolving()
Returns whether or not the tabu search is currently solving. |
protected static boolean |
isTabu(Solution soln,
Move move,
double[] val,
TabuList tabuList,
AspirationCriteria aspirationCriteria,
TabuSearch This)
Determine if the move is tabu and consider whether or not it satisfies the aspiration criteria. |
protected void |
performOneIteration()
This large method goes through one iteration. |
void |
setAspirationCriteria(AspirationCriteria aspirationCriteria)
Sets the aspiration criteria, effective at the start of the next iteration. |
void |
setBestSolution(Solution solution)
Sets the best solution, effective at the start of the next iteration, and fires an event to registered TabuSearchListener s. |
void |
setChooseFirstImprovingMove(boolean choose)
Setting this to true will cause the search to go faster by not necessarily evaluating all of the moves in a neighborhood for each iteration. |
void |
setCurrentSolution(Solution solution)
Sets the current solution, effective at the start of the next iteration, and fires an event to registered TabuSearchListener s. |
protected void |
setFireImprovingMoveMade(boolean b)
Internally set whether or not an improving move made TabuSearchEvent should be fired at the end of the iteration. |
protected void |
setFireNewBestSolution(boolean b)
Internally set whether or not a new best solution TabuSearchEvent should be fired at the end of the iteration. |
protected void |
setFireNewCurrentSolution(boolean b)
Internally set whether or not a new current solution TabuSearchEvent should be fired at the end of the iteration. |
protected void |
setFireNoChangeInValueMoveMade(boolean b)
Internally set whether or not a no change in value move made TabuSearchEvent should be fired at the end of the iteration. |
protected void |
setFireUnimprovingMoveMade(boolean b)
Internally set whether or not an unimproving move made TabuSearchEvent should be fired at the end of the iteration. |
void |
setIterationsToGo(int iterations)
Sets the number of iterations that the tabu search has left to go. |
protected void |
setKeepSolving(boolean keepSolving)
Tells the tabu search internally whether or not to keep solving the next chance it gets to quit, like at the start of a new iteration. |
void |
setMaximizing(boolean maximizing)
Sets whether the tabu search should be maximizing or minimizing the objective function. |
void |
setMoveManager(MoveManager moveManager)
Sets the move manager, effective at the start of the next iteration. |
void |
setObjectiveFunction(ObjectiveFunction function)
Sets the objective function, effective at the start of the next iteration, and re-evaluates the current and best solution values. |
protected void |
setSolving(boolean solving)
Sets the status of either solving or not solving. |
void |
setTabuList(TabuList tabuList)
Sets the tabu list, effective at the start of the next iteration. |
void |
startSolving()
Starts the tabu search solving in the current thread, blocking until the iterationsToGo property is zero. |
void |
stopSolving()
Stops the tabu search and preserves the number of iterations remaining. |
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 |
Field Detail |
protected ObjectiveFunction objectiveFunction
protected MoveManager moveManager
protected TabuList tabuList
protected AspirationCriteria aspirationCriteria
protected Solution currentSolution
protected Solution bestSolution
protected int iterationsToGo
protected boolean maximizing
protected boolean solving
protected boolean keepSolving
protected boolean fireNewCurrentSolution
protected boolean fireNewBestSolution
protected boolean fireUnimprovingMoveMade
protected boolean fireImprovingMoveMade
protected boolean fireNoChangeInValueMoveMade
protected boolean chooseFirstImprovingMove
protected static java.io.PrintStream err
Constructor Detail |
public SingleThreadedTabuSearch()
public SingleThreadedTabuSearch(Solution initialSolution, MoveManager moveManager, ObjectiveFunction objectiveFunction, TabuList tabuList, AspirationCriteria aspirationCriteria, boolean maximizing)
initialSolution
- The initial currentSolutionmoveManager
- The move managerobjectiveFunction
- The objective functiontabuList
- The tabu listaspirationCriteria
- The aspiration criteria or null if none is to be usedmaximizing
- Whether or not the tabu search should be maximizing the objective functionSolution
,
ObjectiveFunction
,
MoveManager
,
TabuList
,
AspirationCriteria
Method Detail |
protected void performOneIteration() throws NoMovesGeneratedException, NoCurrentSolutionException
NoMovesGeneratedException
NoCurrentSolutionException
getBestMove(org.coinor.opents.Solution, org.coinor.opents.Move[], org.coinor.opents.ObjectiveFunction, org.coinor.opents.TabuList, org.coinor.opents.AspirationCriteria, boolean, boolean)
,
isFirstBetterThanSecond(double[], double[], boolean)
,
fireQueuedEvents()
protected java.lang.Object[] getBestMove(Solution soln, Move[] moves, ObjectiveFunction objectiveFunction, TabuList tabuList, AspirationCriteria aspirationCriteria, boolean maximizing, boolean chooseFirstImprovingMove)
protected static java.lang.Object[] getBestMove(Solution soln, Move[] moves, ObjectiveFunction objectiveFunction, TabuList tabuList, AspirationCriteria aspirationCriteria, boolean maximizing, boolean chooseFirstImprovingMove, TabuSearch This)
protected static boolean isTabu(Solution soln, Move move, double[] val, TabuList tabuList, AspirationCriteria aspirationCriteria, TabuSearch This)
public static boolean firstIsBetterThanSecond(double[] first, double[] second, boolean maximizing)
isFirstBetterThanSecond(double[], double[], boolean)
to be named more consistently. This method still works. It simply
calls the newly-named version.
first
- The first array of doublessecond
- The second array of doublesmaximizing
- Whether or not the tabu search should be maximizing
public static boolean isFirstBetterThanSecond(double[] first, double[] second, boolean maximizing)
first
- The first array of doublessecond
- The second array of doublesmaximizing
- Whether or not the tabu search should be maximizing
protected void fireQueuedEvents()
protected void internalSetCurrentSolution(Solution solution)
solution
- The new current solutionprotected void internalSetBestSolution(Solution solution)
solution
- The new best solutionprotected void setSolving(boolean solving)
solving
- Whether or not the tabu search should be marked as solving or not.protected void setKeepSolving(boolean keepSolving)
keepSolving
- Whether or not to keep solvingprotected boolean isKeepSolving()
protected void setFireNewCurrentSolution(boolean b)
TabuSearchEvent
should be fired at the end of the iteration.
b
- Whether or not to fire a new current solution event.protected void setFireNewBestSolution(boolean b)
TabuSearchEvent
should be fired at the end of the iteration.
b
- Whether or not to fire a new best solution event.protected void setFireUnimprovingMoveMade(boolean b)
TabuSearchEvent
should be fired at the end of the iteration.
b
- Whether or not to fire an unimproving move made event.protected void setFireImprovingMoveMade(boolean b)
TabuSearchEvent
should be fired at the end of the iteration.
b
- Whether or not to fire an improving move made event.protected void setFireNoChangeInValueMoveMade(boolean b)
TabuSearchEvent
should be fired at the end of the iteration.
b
- Whether or not to fire a no change in value move made event.protected boolean isFireNewCurrentSolution()
TabuSearchEvent
at the end of the iteration.
protected boolean isFireNewBestSolution()
TabuSearchEvent
at the end of the iteration.
protected boolean isFireUnimprovingMoveMade()
TabuSearchEvent
at the end of the iteration.
protected boolean isFireImprovingMoveMade()
TabuSearchEvent
at the end of the iteration.
protected boolean isFireNoChangeInValueMoveMade()
TabuSearchEvent
at the end of the iteration.
public void startSolving()
TabuSearch.setIterationsToGo(int)
,
TabuSearch.getIterationsToGo()
public void stopSolving()
TabuSearch.setIterationsToGo(int)
,
TabuSearch.getIterationsToGo()
public boolean isSolving()
public void setObjectiveFunction(ObjectiveFunction function)
function
- The new objective function.ObjectiveFunction
public void setMoveManager(MoveManager moveManager)
moveManager
- The new move manager.MoveManager
public void setTabuList(TabuList tabuList)
tabuList
- The new tabu list.TabuList
public void setAspirationCriteria(AspirationCriteria aspirationCriteria)
aspirationCriteria
- The new aspiration criteriaAspirationCriteria
public void setBestSolution(Solution solution)
TabuSearchListener
s.
solution
- The new best solution.Solution
public void setCurrentSolution(Solution solution)
TabuSearchListener
s.
solution
- The new current solution.Solution
public void setIterationsToGo(int iterations)
startSolving()
is called.
iterations
- The number of iterations left for the tabu earch to execute.startSolving()
public void setMaximizing(boolean maximizing)
maximizing
- Whether or not the tabu search should be maximizing the objective function.public void setChooseFirstImprovingMove(boolean choose)
choose
- Whether or not the first improving move will be chosenpublic ObjectiveFunction getObjectiveFunction()
ObjectiveFunction
public MoveManager getMoveManager()
MoveManager
public TabuList getTabuList()
TabuList
public AspirationCriteria getAspirationCriteria()
AspirationCriteria
public Solution getBestSolution()
Solution
public Solution getCurrentSolution()
Solution
public int getIterationsToGo()
public boolean isMaximizing()
public boolean isChooseFirstImprovingMove()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |