Package xal.extension.solver.algorithm
Class SearchAlgorithm
java.lang.Object
xal.extension.solver.algorithm.SearchAlgorithm
- All Implemented Interfaces:
AlgorithmScheduleListener
,SolutionJudgeListener
- Direct Known Subclasses:
DirectedStep
,InitialAlgorithm
,RandomSearch
,RandomShrinkSearch
,SimplexSearchAlgorithm
public abstract class SearchAlgorithm
extends Object
implements AlgorithmScheduleListener, SolutionJudgeListener
Abstract super class for an optimization search algorithm.
- Author:
- ky6
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Comparator<SearchAlgorithm>
comparator for sorting based on efficiencyprotected Problem
the problem to solve -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a search algorithm listener.void
algorithmRunExecuted
(AlgorithmSchedule schedule, SearchAlgorithm algorithm, ScoreBoard scoreBoard) Handle an event where a new algorithm run stack has completed.void
algorithmRunWillExecute
(AlgorithmSchedule schedule, SearchAlgorithm algorithm, ScoreBoard scoreBoard) Handle an event where a new algorithm run stack will start.evaluateTrialPoint
(TrialPoint trialPoint) Evaluate the given trial point.final void
executeRun
(AlgorithmSchedule schedule, ScoreBoard scoreboard) Execute an algorithm run (typically many evaluations up to those proposed)void
foundNewOptimalSolution
(SolutionJudge source, List<Trial> solutions, Trial solution) Send a message that a new optimal solution has been found.final double
Get this algorithm's efficiency for improving satisfaction.int
get the amount of evaluations left to run for this algorithmabstract String
getLabel()
Get the label for this search algorithm.int
Get the maximum number of evaluations per run.int
Get the minimum number of evaluations per run.abstract void
performRun
(AlgorithmSchedule algorithmSchedule) Calculate the next few trial points.void
Remove a search algorithm listener.void
reset()
Reset this algorithm.void
setProblem
(Problem problem) Assign a new problem.void
setProposedEvaluations
(int proposedEvaluations) Sets that proposed minimum evaluations for an algorithmvoid
trialScored
(AlgorithmSchedule schedule, Trial trial) Handle a message that a trial has been scored.void
trialVetoed
(AlgorithmSchedule schedule, Trial trial) Handle a message that a trial has been vetoed.
-
Field Details
-
EFFICIENCY_COMPARATOR
comparator for sorting based on efficiency -
problem
the problem to solve
-
-
Constructor Details
-
SearchAlgorithm
protected SearchAlgorithm()Empty constructor.
-
-
Method Details
-
setProblem
Assign a new problem. -
reset
public void reset()Reset this algorithm. -
executeRun
Execute an algorithm run (typically many evaluations up to those proposed)- Parameters:
schedule
- the schedule requesting the algorithm executionscoreboard
- the scoreboard of solver status
-
evaluateTrialPoint
Evaluate the given trial point.- Parameters:
trialPoint
- the trial point to evaluate- Returns:
- the scored trial
-
getLabel
Get the label for this search algorithm.- Returns:
- The label for this algorithm
-
performRun
Calculate the next few trial points. -
getEvaluationsLeft
public int getEvaluationsLeft()get the amount of evaluations left to run for this algorithm -
getMinEvaluationsPerRun
public int getMinEvaluationsPerRun()Get the minimum number of evaluations per run. Subclasses may want to override this method.- Returns:
- the minimum number of evaluation per run.
-
getMaxEvaluationsPerRun
public int getMaxEvaluationsPerRun()Get the maximum number of evaluations per run. Subclasses may want to override this method.- Returns:
- the maximum number of evaluation per run.
-
setProposedEvaluations
public void setProposedEvaluations(int proposedEvaluations) Sets that proposed minimum evaluations for an algorithm -
getEfficiency
public final double getEfficiency()Get this algorithm's efficiency for improving satisfaction.- Returns:
- the efficiency
-
addSearchAlgorithmListener
Add a search algorithm listener.- Parameters:
listener
- The listener to add.
-
removeSearchAlgorithmListener
Remove a search algorithm listener.- Parameters:
listener
- The listener to remove.
-
trialScored
Handle a message that a trial has been scored.- Specified by:
trialScored
in interfaceAlgorithmScheduleListener
- Parameters:
schedule
- Description of the Parametertrial
- Description of the Parameter
-
trialVetoed
Handle a message that a trial has been vetoed.- Specified by:
trialVetoed
in interfaceAlgorithmScheduleListener
- Parameters:
schedule
- Description of the Parametertrial
- Description of the Parameter
-
algorithmRunWillExecute
public void algorithmRunWillExecute(AlgorithmSchedule schedule, SearchAlgorithm algorithm, ScoreBoard scoreBoard) Handle an event where a new algorithm run stack will start.- Specified by:
algorithmRunWillExecute
in interfaceAlgorithmScheduleListener
- Parameters:
schedule
- the schedule posting the eventalgorithm
- the algorithm which will executescoreBoard
- the scoreboard
-
algorithmRunExecuted
public void algorithmRunExecuted(AlgorithmSchedule schedule, SearchAlgorithm algorithm, ScoreBoard scoreBoard) Handle an event where a new algorithm run stack has completed.- Specified by:
algorithmRunExecuted
in interfaceAlgorithmScheduleListener
- Parameters:
schedule
- the schedule posting the eventalgorithm
- the algorithm that has executedscoreBoard
- the scoreboard
-
foundNewOptimalSolution
Send a message that a new optimal solution has been found.- Specified by:
foundNewOptimalSolution
in interfaceSolutionJudgeListener
- Parameters:
source
- The source of the new optimal solution.solutions
- The list of solutions.solution
- The new optimal solution.
-