Environment for
DeveLoping
KDD-Applications
Supported by Index-Structures

de.lmu.ifi.dbs.elki.algorithm
Class AbstractAlgorithm<O extends DatabaseObject>

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.logging.AbstractLoggable
      extended by de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizable
          extended by de.lmu.ifi.dbs.elki.algorithm.AbstractAlgorithm<O>
Type Parameters:
O - the type of DatabaseObjects handled by this Algorithm
All Implemented Interfaces:
Algorithm<O>, Loggable, Parameterizable
Direct Known Subclasses:
AbstractBiclustering, APRIORI, CASH, CLIQUE, COPAA, DiSH, DistanceBasedAlgorithm, EM, ERiC, ProjectedClustering, ProjectedDBSCAN, SNNClustering

public abstract class AbstractAlgorithm<O extends DatabaseObject>
extends AbstractParameterizable
implements Algorithm<O>

AbstractAlgorithm sets the values for flags verbose and time.

This class serves also as a model of implementing an algorithm within this framework. Any Algorithm that makes use of these flags may extend this class. Beware to make correct use of parameter settings via optionHandler as commented with constructor and methods.

Author:
Arthur Zimek

Field Summary
private  boolean time
          Holds the value of TIME_FLAG.
private  Flag TIME_FLAG
          Flag to request output of performance time.
private  boolean verbose
          Holds the value of VERBOSE_FLAG.
private  Flag VERBOSE_FLAG
          Flag to allow verbose messages while performing the algorithm.
 
Fields inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizable
optionHandler
 
Fields inherited from class de.lmu.ifi.dbs.elki.logging.AbstractLoggable
debug
 
Constructor Summary
protected AbstractAlgorithm()
          Adds the flags VERBOSE_FLAG and TIME_FLAG to the option handler.
 
Method Summary
 String description()
          Returns a description of the class and the required parameters.
 boolean isTime()
          Returns whether the performance time of the algorithm should be assessed.
 boolean isVerbose()
          Returns whether verbose messages should be printed while executing the algorithm.
 void run(Database<O> database)
          Calls the runInTime()-method of extending classes.
protected abstract  void runInTime(Database<O> database)
          The run method encapsulated in measure of runtime.
 String[] setParameters(String[] args)
          Grabs all specified options from the option handler and sets the values for the flags VERBOSE_FLAG and TIME_FLAG.
 void setTime(boolean time)
          Sets whether whether the time should be assessed while executing the algorithm.
 void setVerbose(boolean verbose)
          Sets whether verbose messages should be printed while executing the algorithm.
 
Methods inherited from class de.lmu.ifi.dbs.elki.utilities.optionhandling.AbstractParameterizable
addOption, checkGlobalParameterConstraints, deleteOption, description, description, getAttributeSettings, getParameters, getParameterValue, getPossibleOptions, inlineDescription, isSet, setParameters
 
Methods inherited from class de.lmu.ifi.dbs.elki.logging.AbstractLoggable
debugFine, debugFiner, debugFinest, exception, message, progress, progress, progress, verbose, verbose, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.lmu.ifi.dbs.elki.algorithm.Algorithm
getDescription, getResult
 
Methods inherited from interface de.lmu.ifi.dbs.elki.utilities.optionhandling.Parameterizable
checkGlobalParameterConstraints, getAttributeSettings, getParameters, getPossibleOptions, inlineDescription
 

Field Detail

VERBOSE_FLAG

private final Flag VERBOSE_FLAG
Flag to allow verbose messages while performing the algorithm.

Key: -verbose


verbose

private boolean verbose
Holds the value of VERBOSE_FLAG.


TIME_FLAG

private final Flag TIME_FLAG
Flag to request output of performance time.

Key: -time


time

private boolean time
Holds the value of TIME_FLAG.

Constructor Detail

AbstractAlgorithm

protected AbstractAlgorithm()
Adds the flags VERBOSE_FLAG and TIME_FLAG to the option handler. Any extending class should call this constructor, then add further parameters. Subclasses can add further parameters using AbstractParameterizable.addOption(de.lmu.ifi.dbs.elki.utilities.optionhandling.Option)

Method Detail

description

public String description()
Description copied from interface: Parameterizable
Returns a description of the class and the required parameters.

This description should be suitable for a usage description as for a standalone application.

Specified by:
description in interface Parameterizable
Overrides:
description in class AbstractParameterizable
Returns:
String a description of the class and the required parameters
See Also:
Parameterizable.description()

setParameters

public String[] setParameters(String[] args)
                       throws ParameterException
Grabs all specified options from the option handler and sets the values for the flags VERBOSE_FLAG and TIME_FLAG. Any extending class should call this method first and return the returned array without further changes, but after setting further required parameters. An example for overwritting this method taking advantage from the previously (in superclasses) defined options would be:

 {
   String[] remainingParameters = super.setParameters(args);
   // set parameters for your class
   // for example like this:
   if(isSet(MY_PARAM_VALUE_PARAM))
   {
      myParamValue = getParameterValue(MY_PARAM_VALUE_PARAM);
   }
   .
   .
   .
   return remainingParameters;
   // or in case of attributes requesting parameters themselves
   // return parameterizableAttribbute.setParameters(remainingParameters);
 }
 

Specified by:
setParameters in interface Parameterizable
Overrides:
setParameters in class AbstractParameterizable
Parameters:
args - parameters to set the attributes accordingly to
Returns:
String[] an array containing the unused parameters
Throws:
ParameterException - in case of wrong parameter-setting
See Also:
Parameterizable.setParameters(String[])

isTime

public boolean isTime()
Returns whether the performance time of the algorithm should be assessed.

Returns:
true, if output of performance time is requested, false otherwise

isVerbose

public boolean isVerbose()
Returns whether verbose messages should be printed while executing the algorithm.

Returns:
true, if verbose messages should be printed while executing the algorithm, false otherwise

setVerbose

public void setVerbose(boolean verbose)
Description copied from interface: Algorithm
Sets whether verbose messages should be printed while executing the algorithm.

Specified by:
setVerbose in interface Algorithm<O extends DatabaseObject>
Parameters:
verbose - the flag to allow verbose messages while performing the algorithm
See Also:
Algorithm.setVerbose(boolean)

setTime

public void setTime(boolean time)
Description copied from interface: Algorithm
Sets whether whether the time should be assessed while executing the algorithm.

Specified by:
setTime in interface Algorithm<O extends DatabaseObject>
Parameters:
time - the flag to request output of performance time
See Also:
Algorithm.setTime(boolean)

run

public final void run(Database<O> database)
               throws IllegalStateException
Calls the runInTime()-method of extending classes. Measures and prints the runtime and, in case of an index based database, the I/O costs of this method.

Specified by:
run in interface Algorithm<O extends DatabaseObject>
Parameters:
database - the database to run the algorithm on
Throws:
IllegalStateException - if the algorithm has not been initialized properly (e.g. the setParameters(String[]) method has been failed to be called).
See Also:
Algorithm.run(de.lmu.ifi.dbs.elki.database.Database)

runInTime

protected abstract void runInTime(Database<O> database)
                           throws IllegalStateException
The run method encapsulated in measure of runtime. An extending class needs not to take care of runtime itself.

Parameters:
database - the database to run the algorithm on
Throws:
IllegalStateException - if the algorithm has not been initialized properly (e.g. the setParameters(String[]) method has been failed to be called).

Release 0.1 (2008-07-10_1838)