com.mrami.libre.annealing
Class Annealer

java.lang.Object
  extended bycom.mrami.libre.annealing.Annealer

public class Annealer
extends java.lang.Object

Runs a simulated annealing session over an Annealable object.

Simulated annealing is designed to work like annealing in the real world: the more slowly you lower the temperature of a liquid as it freezes, the more likely the resulting solid will have larger crystals (which in turn means a lower total energy configuration).

With simulated annealing, we are basically doing the same thing. Lowering the "temperature" slowly lowers the probability that we have a "high-energy" configuration. The fact that high-energy configurations can exist means that we are more likely not to get shoehorned into a local minimum.

For reference, check any material on simulated annealing. My thanks to "Numerical Recipes in C" for the basic algorithm here.

Version:
$Id: Annealer.java,v 1.2 2005/02/17 17:15:28 mrami Exp $
Author:
mrami

Constructor Summary
Annealer(double startTemp, int itersPerTemp, int tempSteps, double stepPercent)
          Set up the annealer.
 
Method Summary
 Annealable anneal(Annealable start, java.io.PrintWriter outStream)
          Anneal an annealable.
 int getItersPerTemp()
           
 double getStartTemp()
           
 double getStepPercent()
           
 int getTempSteps()
           
protected  boolean metropolis(double temp, double delta)
          The metropolis algorithm.
 void setItersPerTemp(int itersPerTemp)
           
 void setStartTemp(double startTemp)
           
 void setStepPercent(double stepPercent)
           
 void setTempSteps(int tempSteps)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Annealer

public Annealer(double startTemp,
                int itersPerTemp,
                int tempSteps,
                double stepPercent)
Set up the annealer.

Parameters:
startTemp - start temperature
itersPerTemp - iterations before lowering the temperature
tempSteps - number of times to lower the temperature
stepPercent - percentage to decrease the temp per lowering (i.e., newTemp = oldTemp * stepPercent)
Method Detail

getItersPerTemp

public int getItersPerTemp()
Returns:
Returns the itersPerTemp.

setItersPerTemp

public void setItersPerTemp(int itersPerTemp)
Parameters:
itersPerTemp - The itersPerTemp to set.

getStartTemp

public double getStartTemp()
Returns:
Returns the startTemp.

setStartTemp

public void setStartTemp(double startTemp)
Parameters:
startTemp - The startTemp to set.

getStepPercent

public double getStepPercent()
Returns:
Returns the stepPercent.

setStepPercent

public void setStepPercent(double stepPercent)
Parameters:
stepPercent - The stepPercent to set.

getTempSteps

public int getTempSteps()
Returns:
Returns the tempSteps.

setTempSteps

public void setTempSteps(int tempSteps)
Parameters:
tempSteps - The tempSteps to set.

anneal

public Annealable anneal(Annealable start,
                         java.io.PrintWriter outStream)
Anneal an annealable. The annealer works by changing the object, recording the cost of the change, and then possibly accepting the change. During the process, the start parameter will be modified.

Parameters:
start - the start configuration (WILL BE MODIFIED)
outStream - output stream to send log messages to (or null)
Returns:
the annealed confiuration (will be == start)

metropolis

protected boolean metropolis(double temp,
                             double delta)
The metropolis algorithm. Determines whether a configuration will be accepted.

Parameters:
temp - the current temperature
delta - the cost difference between old configuration and new configuration
Returns:
whether or not to accept the new configuration