public abstract class NeighbourSearch<V extends Variable<V,T>,T extends Value<V,T>> extends Object implements NeighbourSelection<V,T>, SolutionListener<V,T>, LazyNeighbour.LazyNeighbourAcceptanceCriterion<V,T>
SolutionListener
and the variable neighbourhood selection.
Modifier and Type | Field and Description |
---|---|
protected DecimalFormat |
iDF2 |
protected int |
iIter |
protected Logger |
iLog |
protected String |
iPhase |
protected Progress |
iProgress |
protected long |
iT0 |
Constructor and Description |
---|
NeighbourSearch(DataProperties properties) |
Modifier and Type | Method and Description |
---|---|
boolean |
accept(LazyNeighbour<V,T> neighbour,
double value)
Accept lazy neighbour -- calling the acceptance criterion with lazy = true.
|
protected abstract boolean |
accept(Model<V,T> model,
Neighbour<V,T> neighbour,
double value,
boolean lazy)
Acceptance criterion.
|
protected boolean |
accept(Solution<V,T> solution,
Neighbour<V,T> neighbour)
True if the generated move is to be accepted.
|
protected void |
activate(Solution<V,T> solution)
Called just before the neighbourhood search is called for the first time.
|
protected void |
addNeighbourSelection(NeighbourSelection<V,T> ns,
double bonus)
Add neighbour selection
|
void |
bestCleared(Solution<V,T> solution)
Called by the solution when method
Solution.clearBest() is
called. |
void |
bestRestored(Solution<V,T> solution)
Called by the solution when method
Solution.restoreBest() is
called. |
void |
bestSaved(Solution<V,T> solution)
Called by the solution when method
Solution.saveBest() is called. |
protected boolean |
canContinue(Solution<V,T> solution)
Return false if the search is to be stopped.
|
protected void |
deactivate(Solution<V,T> solution)
Called when the search cannot continue, just before a null neighbour is returned
|
Neighbour<V,T> |
generateMove(Solution<V,T> solution)
Generate a random move
|
void |
getInfo(Solution<V,T> solution,
Map<String,String> info)
Called by the solution when it is asked to produce info table, see
Solution.getInfo() . |
void |
getInfo(Solution<V,T> solution,
Map<String,String> info,
Collection<V> variables)
Called by the solution when it is asked to produce info table, see
Solution.getInfo() . |
protected List<? extends NeighbourSelection<V,T>> |
getNeighbours()
Return list of neighbour selections
|
abstract String |
getParameterBaseName()
Parameter base name.
|
protected long |
getTimeMillis()
Running time in milliseconds (since the last call of activate)
|
protected void |
incIteration(Solution<V,T> solution)
Increment iteration counters etc.
|
void |
init(Solver<V,T> solver)
Criterion initialization
|
protected void |
logNeibourStatus()
Log some information about neigbour selections once in a while
|
protected NeighbourSelection<V,T> |
nextNeighbourSelection()
Generate and return next neighbour selection
|
Neighbour<V,T> |
selectNeighbour(Solution<V,T> solution)
select a neighbour of a given solution
|
protected void |
setHCMode(boolean hcMode)
Set HC mode for all the neighbour selections that support the
HillClimberSelection interface. |
void |
solutionUpdated(Solution<V,T> solution)
Called by the solution when it is updated, see
Solution.update(double) . |
protected DecimalFormat iDF2
protected long iT0
protected int iIter
public NeighbourSearch(DataProperties properties)
protected void addNeighbourSelection(NeighbourSelection<V,T> ns, double bonus)
bonus
- execution bonus (more bonus means more executions of this neighbour selection, see NeighbourSelector
)protected void setHCMode(boolean hcMode)
HillClimberSelection
interface.protected List<? extends NeighbourSelection<V,T>> getNeighbours()
public void init(Solver<V,T> solver)
NeighbourSelection
protected NeighbourSelection<V,T> nextNeighbourSelection()
protected void logNeibourStatus()
public Neighbour<V,T> selectNeighbour(Solution<V,T> solution)
NeighbourSelection
selectNeighbour
in interface NeighbourSelection<V extends Variable<V,T>,T extends Value<V,T>>
solution
- given solutionprotected boolean canContinue(Solution<V,T> solution)
protected void incIteration(Solution<V,T> solution)
protected long getTimeMillis()
protected boolean accept(Solution<V,T> solution, Neighbour<V,T> neighbour)
public boolean accept(LazyNeighbour<V,T> neighbour, double value)
protected abstract boolean accept(Model<V,T> model, Neighbour<V,T> neighbour, double value, boolean lazy)
protected void activate(Solution<V,T> solution)
protected void deactivate(Solution<V,T> solution)
public abstract String getParameterBaseName()
public void bestSaved(Solution<V,T> solution)
SolutionListener
Solution.saveBest()
is called.public void solutionUpdated(Solution<V,T> solution)
SolutionListener
Solution.update(double)
.solutionUpdated
in interface SolutionListener<V extends Variable<V,T>,T extends Value<V,T>>
solution
- source solutionpublic void getInfo(Solution<V,T> solution, Map<String,String> info)
SolutionListener
Solution.getInfo()
. A listener can also add some its info into
this table.public void getInfo(Solution<V,T> solution, Map<String,String> info, Collection<V> variables)
SolutionListener
Solution.getInfo()
. A listener can also add some its info into
this table.public void bestCleared(Solution<V,T> solution)
SolutionListener
Solution.clearBest()
is
called.bestCleared
in interface SolutionListener<V extends Variable<V,T>,T extends Value<V,T>>
solution
- source solutionpublic void bestRestored(Solution<V,T> solution)
SolutionListener
Solution.restoreBest()
is
called.bestRestored
in interface SolutionListener<V extends Variable<V,T>,T extends Value<V,T>>
solution
- source solution