Package adams.opt.genetic
Class AbstractGeneticAlgorithm.GeneticAlgorithmJob<T extends AbstractGeneticAlgorithm>
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.multiprocess.AbstractJob
-
- adams.opt.genetic.AbstractGeneticAlgorithm.GeneticAlgorithmJob<T>
-
- All Implemented Interfaces:
CleanUpHandler
,LoggingLevelHandler
,LoggingSupporter
,SizeOfHandler
,Stoppable
,StoppableWithFeedback
,Job
,JobWithOwner<T>
,Serializable
- Direct Known Subclasses:
AbstractClassifierBasedGeneticAlgorithm.ClassifierBasedGeneticAlgorithmJob
- Enclosing class:
- AbstractGeneticAlgorithm
public abstract static class AbstractGeneticAlgorithm.GeneticAlgorithmJob<T extends AbstractGeneticAlgorithm> extends AbstractJob implements JobWithOwner<T>
A job class specific to genetic algorithms.- Author:
- dale
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected int
m_Chromosome
the chromosome index.protected Double
m_Fitness
the current fitness.protected T
m_Genetic
the algorithm object this job belongs to.protected int[]
m_Weights
the weights of the chromosomes (0 = turned off, 1 = turned on).-
Fields inherited from class adams.multiprocess.AbstractJob
m_Complete, m_ExecutionError, m_JobCompleteListener, m_JobInfo, m_ProgressInfo, m_Stopped
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description GeneticAlgorithmJob(T g, int chromosome, int[] w)
Initializes the job.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
calcNewFitness()
Calculates the new fitness.void
cleanUp()
Cleans up data structures, frees up memory.int
getChromosome()
Returns the chromosome index.Double
getFitness()
Returns the fitness.T
getOwner()
Returns the algorithm this job belongs to.int[]
getWeights()
Returns the current weights of the attributes.protected String
postProcessCheck()
Checks whether all post-conditions have been met.protected String
preProcessCheck()
Checks whether all pre-conditions have been met.protected void
process()
Does the actual execution of the job.String
toString()
Returns a string representation of the job.String
weightsToString()
Turns the weights into a string representation.static String
weightsToString(int[] weights)
Turns the weights into a string representation.-
Methods inherited from class adams.multiprocess.AbstractJob
execute, getAdditionalErrorInformation, getExecutionError, getJobCompleteListener, getJobInfo, getProgressInfo, hasExecutionError, isComplete, isStopped, jobCompleted, setJobCompleteListener, setJobInfo, setProgressInfo, stopExecution
-
Methods inherited from class adams.core.logging.CustomLoggingLevelObject
setLoggingLevel
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.multiprocess.Job
execute, getExecutionError, getJobCompleteListener, getJobInfo, hasExecutionError, isComplete, jobCompleted, setJobCompleteListener
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
Methods inherited from interface adams.core.logging.LoggingSupporter
getLogger, isLoggingEnabled
-
Methods inherited from interface adams.core.Stoppable
stopExecution
-
Methods inherited from interface adams.core.StoppableWithFeedback
isStopped
-
-
-
-
Field Detail
-
m_Weights
protected int[] m_Weights
the weights of the chromosomes (0 = turned off, 1 = turned on).
-
m_Genetic
protected T extends AbstractGeneticAlgorithm m_Genetic
the algorithm object this job belongs to.
-
m_Fitness
protected Double m_Fitness
the current fitness.
-
m_Chromosome
protected int m_Chromosome
the chromosome index.
-
-
Constructor Detail
-
GeneticAlgorithmJob
public GeneticAlgorithmJob(T g, int chromosome, int[] w)
Initializes the job.- Parameters:
g
- the algorithm object this job belongs tochromosome
- the chromsome indexw
- the initial weights
-
-
Method Detail
-
getOwner
public T getOwner()
Returns the algorithm this job belongs to.- Specified by:
getOwner
in interfaceJobWithOwner<T extends AbstractGeneticAlgorithm>
- Returns:
- the owner
-
getWeights
public int[] getWeights()
Returns the current weights of the attributes.- Returns:
- the weights
-
getChromosome
public int getChromosome()
Returns the chromosome index.- Returns:
- the index
-
getFitness
public Double getFitness()
Returns the fitness.- Returns:
- the fitness
-
weightsToString
public String weightsToString()
Turns the weights into a string representation.- Returns:
- the weights as string
-
weightsToString
public static String weightsToString(int[] weights)
Turns the weights into a string representation.- Parameters:
weights
- the weights to turn into string- Returns:
- the weights as string
-
calcNewFitness
public abstract void calcNewFitness()
Calculates the new fitness.
-
preProcessCheck
protected String preProcessCheck()
Checks whether all pre-conditions have been met.- Specified by:
preProcessCheck
in classAbstractJob
- Returns:
- null if everything is OK, otherwise an error message
-
process
protected void process() throws Exception
Does the actual execution of the job.- Specified by:
process
in classAbstractJob
- Throws:
Exception
- if fails to execute job
-
postProcessCheck
protected String postProcessCheck()
Checks whether all post-conditions have been met.- Specified by:
postProcessCheck
in classAbstractJob
- Returns:
- always null
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory. Sets the weights and the genetic algorithm to null.- Specified by:
cleanUp
in interfaceCleanUpHandler
- Specified by:
cleanUp
in interfaceJob
- Overrides:
cleanUp
in classAbstractJob
-
toString
public String toString()
Returns a string representation of the job.- Specified by:
toString
in classAbstractJob
- Returns:
- a string representation
-
-