org.drools.planner.core.solver
Class AbstractSolver

java.lang.Object
  extended by org.drools.planner.core.solver.AbstractSolver
All Implemented Interfaces:
Solver
Direct Known Subclasses:
DefaultBruteForceSolver, DefaultLocalSearchSolver

public abstract class AbstractSolver
extends Object
implements Solver

Abstract superclass for Solver.

See Also:
Solver, DefaultLocalSearchSolver

Field Summary
protected  BestSolutionRecaller bestSolutionRecaller
           
protected  org.slf4j.Logger logger
           
protected  Long randomSeed
           
protected  SolverEventSupport solverEventSupport
           
protected  StartingSolutionInitializer startingSolutionInitializer
           
protected  AtomicBoolean terminatedEarly
           
 
Constructor Summary
AbstractSolver()
           
 
Method Summary
 void addEventListener(SolverEventListener eventListener)
           
abstract  AbstractSolverScope getAbstractSolverScope()
           
 Solution getBestSolution()
           
 ScoreDefinition getScoreDefinition()
           
 StartingSolutionInitializer getStartingSolutionInitializer()
           
 long getTimeMillisSpend()
          TODO timeMillisSpend should not continue to increase after the solver has been terminated
 boolean isTerminatedEarly()
          This method is thread-safe.
 void removeEventListener(SolverEventListener eventListener)
           
 void setBestSolutionRecaller(BestSolutionRecaller bestSolutionRecaller)
           
 void setRandomSeed(long randomSeed)
           
 void setRuleBase(org.drools.RuleBase ruleBase)
           
 void setScoreCalculator(ScoreCalculator scoreCalculator)
           
 void setScoreDefinition(ScoreDefinition scoreDefinition)
           
 void setStartingSolution(Solution startingSolution)
           
 void setStartingSolutionInitializer(StartingSolutionInitializer startingSolutionInitializer)
           
 void solve()
          Solves the planning problem.
protected abstract  void solveImplementation()
           
 void solvingStarted(AbstractSolverScope abstractSolverScope)
           
 boolean terminateEarly()
          Notifies the solver that it should stop at its earliest convenience.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final transient org.slf4j.Logger logger

solverEventSupport

protected SolverEventSupport solverEventSupport

terminatedEarly

protected final AtomicBoolean terminatedEarly

randomSeed

protected Long randomSeed

startingSolutionInitializer

protected StartingSolutionInitializer startingSolutionInitializer

bestSolutionRecaller

protected BestSolutionRecaller bestSolutionRecaller
Constructor Detail

AbstractSolver

public AbstractSolver()
Method Detail

setRandomSeed

public void setRandomSeed(long randomSeed)

setRuleBase

public void setRuleBase(org.drools.RuleBase ruleBase)

getScoreDefinition

public ScoreDefinition getScoreDefinition()
Specified by:
getScoreDefinition in interface Solver
Returns:
never null

setScoreDefinition

public void setScoreDefinition(ScoreDefinition scoreDefinition)

setScoreCalculator

public void setScoreCalculator(ScoreCalculator scoreCalculator)

getStartingSolutionInitializer

public StartingSolutionInitializer getStartingSolutionInitializer()

setStartingSolutionInitializer

public void setStartingSolutionInitializer(StartingSolutionInitializer startingSolutionInitializer)

setBestSolutionRecaller

public void setBestSolutionRecaller(BestSolutionRecaller bestSolutionRecaller)

setStartingSolution

public void setStartingSolution(Solution startingSolution)
Specified by:
setStartingSolution in interface Solver
Parameters:
startingSolution - never null

getBestSolution

public Solution getBestSolution()
Specified by:
getBestSolution in interface Solver
Returns:
never null after solving

getTimeMillisSpend

public long getTimeMillisSpend()
Description copied from interface: Solver
TODO timeMillisSpend should not continue to increase after the solver has been terminated

Specified by:
getTimeMillisSpend in interface Solver
Returns:
the amount of millis spend since this solver started

getAbstractSolverScope

public abstract AbstractSolverScope getAbstractSolverScope()

terminateEarly

public boolean terminateEarly()
Description copied from interface: Solver
Notifies the solver that it should stop at its earliest convenience. This method returns immediatly, but it takes an undetermined time for the Solver.solve() to actually return.

This method is thread-safe.

Specified by:
terminateEarly in interface Solver
Returns:
true if successful
See Also:
Solver.isTerminatedEarly(), Future.cancel(boolean)

isTerminatedEarly

public boolean isTerminatedEarly()
Description copied from interface: Solver
This method is thread-safe.

Specified by:
isTerminatedEarly in interface Solver
Returns:
true if terminateEarly has been called since the started.
See Also:
Future.isCancelled()

solve

public final void solve()
Description copied from interface: Solver
Solves the planning problem. It can take minutes, even hours or days before this method returns, depending on the termination configuration. To terminate a Solver early, call Solver.terminateEarly().

Specified by:
solve in interface Solver
See Also:
Solver.terminateEarly()

solveImplementation

protected abstract void solveImplementation()

solvingStarted

public void solvingStarted(AbstractSolverScope abstractSolverScope)

addEventListener

public void addEventListener(SolverEventListener eventListener)
Specified by:
addEventListener in interface Solver
Parameters:
eventListener - never null

removeEventListener

public void removeEventListener(SolverEventListener eventListener)
Specified by:
removeEventListener in interface Solver
Parameters:
eventListener - never null


Copyright © 2001-2011 JBoss Inc.. All Rights Reserved.