lio.search
Class LiOSearch

java.lang.Object
  extended by lio.search.LiOSearch
All Implemented Interfaces:
java.lang.Runnable, LiOResource
Direct Known Subclasses:
CHC, EDA, GRASP, GreedyConstruction, ILS, MRHillClimbing, PBIL, PSO, SA, StdGeneticAlgorithm

public abstract class LiOSearch
extends java.lang.Object
implements LiOResource, java.lang.Runnable

This class implements the common features of every search method and contains all necessary elements to perform search.


Field Summary
protected  javax.swing.event.EventListenerList listenerList
          Holds all EventListeners
(package private) static java.lang.String outputFile
          If not null, writes data on the specified file
protected  SearchOutput searchOutput
          Object that contains and computes statistics of the search.
(package private) static boolean showResults
          Determines whether to show or not results by standard output
protected  StopCondition stopCondition
          Determines the stopping condition of the search.
protected  boolean stopFlag
          Shows whether the execution must be halted
 
Constructor Summary
LiOSearch()
           
 
Method Summary
 void addLiOEventListener(LiOEventListener listener)
          This method allows objects to register for FinishEvent
protected  boolean build()
          Builds the search by getting the resources from default configuration or from a file configuration if present.
protected  void cleanExecution()
          This method should be invoked as the last action in the algorithm execution.
static boolean execute(LiOSearch algorithm, java.lang.String[] options)
          This method performs all operations needed to launch an algorithm.
protected  void fireFinishEvent(FinishEvent evt)
          This protected method is used to fire FinishEvent
 SearchOutput getSearchOutput()
           
 StopCondition getStopCondition()
           
 boolean initialize()
          Performs all actions needed in order to prepare an algorithm to be executed
 boolean initialize(boolean changeTask, boolean changeAlg)
          Performs all actions needed in order to prepare an algorithm to be executed
 void loadSearchOutput(java.lang.String className)
           
 void loadStatistics(java.lang.String className)
           
 void loadStopCondition(java.lang.String className)
           
 void removeLiOEventListener(LiOEventListener listener)
          This method allows objects to unregister for FinishEvent
 void setOptions(java.lang.String[] options)
          Sets up parameters of search from command line.
 void setSearchOutput(SearchOutput searchOutput)
           
 void setStopCondition(StopCondition stopCondition)
           
 void setTask(java.lang.String pTask)
          Creates a new instance of a LiOTask class to solve it whit this algorithm
 void showOptions()
          Shows generic options for search
protected  boolean stopCondition()
          This method tells whether the algorithm's execution is due to end.
 void stopSearching()
          Sets stopFlag to true in order to stop the execution.
 void updateTaskDependentResources(LiOResource res)
           
abstract  boolean worksWith(LiOTask kindOfTask)
          Allows knowing if the specified algorithm is able to process the task.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface lio.core.LiOResource
getDefinition
 
Methods inherited from interface java.lang.Runnable
run
 

Field Detail

searchOutput

protected SearchOutput searchOutput
Object that contains and computes statistics of the search.


stopCondition

protected StopCondition stopCondition
Determines the stopping condition of the search.


stopFlag

protected boolean stopFlag
Shows whether the execution must be halted


listenerList

protected javax.swing.event.EventListenerList listenerList
Holds all EventListeners


showResults

static boolean showResults
Determines whether to show or not results by standard output


outputFile

static java.lang.String outputFile
If not null, writes data on the specified file

Constructor Detail

LiOSearch

public LiOSearch()
Method Detail

addLiOEventListener

public void addLiOEventListener(LiOEventListener listener)
This method allows objects to register for FinishEvent


removeLiOEventListener

public void removeLiOEventListener(LiOEventListener listener)
This method allows objects to unregister for FinishEvent


fireFinishEvent

protected void fireFinishEvent(FinishEvent evt)
This protected method is used to fire FinishEvent


stopSearching

public void stopSearching()
Sets stopFlag to true in order to stop the execution.


stopCondition

protected boolean stopCondition()
This method tells whether the algorithm's execution is due to end.
Every algorithm can override this method to do all action related with this issue.

Returns:
true if search progress must be halted.

cleanExecution

protected void cleanExecution()
This method should be invoked as the last action in the algorithm execution.
Every subclass can override this method, but must call LiOSearch implementation in order to fire events to registered object


showOptions

public void showOptions()
Shows generic options for search


setOptions

public void setOptions(java.lang.String[] options)
                throws java.lang.Exception
Sets up parameters of search from command line.

Parameters:
options - Search options.
Throws:
java.lang.Exception

setTask

public void setTask(java.lang.String pTask)
Creates a new instance of a LiOTask class to solve it whit this algorithm

Parameters:
pTask - Full qualified class or path to a class file representing task to solve

initialize

public boolean initialize()
Performs all actions needed in order to prepare an algorithm to be executed

Returns:
true if no error raised, false otherwise

initialize

public boolean initialize(boolean changeTask,
                          boolean changeAlg)
Performs all actions needed in order to prepare an algorithm to be executed

Parameters:
changeTask - tells whether task object must be reloaded
changeAlg - tells whether search object must be reconstructed
Returns:
true if no error raised, false otherwise

build

protected boolean build()
Builds the search by getting the resources from default configuration or from a file configuration if present.
Each subclass can implement this method in a proper way to manage its own parameters and resources

Returns:
true if build process succeed

updateTaskDependentResources

public void updateTaskDependentResources(LiOResource res)

loadSearchOutput

public void loadSearchOutput(java.lang.String className)

loadStopCondition

public void loadStopCondition(java.lang.String className)

loadStatistics

public void loadStatistics(java.lang.String className)

worksWith

public abstract boolean worksWith(LiOTask kindOfTask)
Allows knowing if the specified algorithm is able to process the task.

Returns:
true if the search algorithm can deal with this kind of task and the corresponding data-type

execute

public static boolean execute(LiOSearch algorithm,
                              java.lang.String[] options)
This method performs all operations needed to launch an algorithm. After prepare the algorithm try to run it asynchronously, so this method can return before algorithm end its execution.
This method is useful for command line.

Parameters:
algorithm - Algorithm to execute
options - Command line options
Returns:
true if algorithm has been launched without problems.

getSearchOutput

public SearchOutput getSearchOutput()
Returns:
Returns the searchOutput.

setSearchOutput

public void setSearchOutput(SearchOutput searchOutput)
Parameters:
searchOutput - The searchOutput to set.

getStopCondition

public StopCondition getStopCondition()
Returns:
Returns the stopCondition.

setStopCondition

public void setStopCondition(StopCondition stopCondition)
Parameters:
stopCondition - The stopCondition to set.