Package org.insa.graphs.algorithm
Class AbstractAlgorithm<Observer>
- java.lang.Object
-
- org.insa.graphs.algorithm.AbstractAlgorithm<Observer>
-
- Type Parameters:
Observer
- Observer type for the algorithm.
- Direct Known Subclasses:
CarPoolingAlgorithm
,PackageSwitchAlgorithm
,ShortestPathAlgorithm
,WeaklyConnectedComponentsAlgorithm
public abstract class AbstractAlgorithm<Observer> extends java.lang.Object
Base class for algorithm classes.
-
-
Field Summary
Fields Modifier and Type Field Description protected AbstractInputData
data
protected java.util.ArrayList<Observer>
observers
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractAlgorithm(AbstractInputData data)
Create a new algorithm with an empty list of observers.protected
AbstractAlgorithm(AbstractInputData data, java.util.ArrayList<Observer> observers)
Create a new algorithm with the given list of observers.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addObserver(Observer observer)
Add an observer to this algorithm.protected abstract AbstractSolution
doRun()
Abstract method that should be implemented by child class.AbstractInputData
getInputData()
java.util.ArrayList<Observer>
getObservers()
AbstractSolution
run()
Run the algorithm and return the solution.
-
-
-
Field Detail
-
data
protected final AbstractInputData data
-
observers
protected final java.util.ArrayList<Observer> observers
-
-
Constructor Detail
-
AbstractAlgorithm
protected AbstractAlgorithm(AbstractInputData data)
Create a new algorithm with an empty list of observers.- Parameters:
data
- Input data for the algorithm.
-
AbstractAlgorithm
protected AbstractAlgorithm(AbstractInputData data, java.util.ArrayList<Observer> observers)
Create a new algorithm with the given list of observers.- Parameters:
data
- Input data for the algorithm.observers
- Initial list of observers for the algorithm.
-
-
Method Detail
-
addObserver
public void addObserver(Observer observer)
Add an observer to this algorithm.- Parameters:
observer
- Observer to add to this algorithm.
-
getObservers
public java.util.ArrayList<Observer> getObservers()
- Returns:
- The list of observers for this algorithm.
-
getInputData
public AbstractInputData getInputData()
- Returns:
- Input for this algorithm.
-
run
public AbstractSolution run()
Run the algorithm and return the solution. This methods internally time the call to doRun() and update the result of the call with the computed solving time.- Returns:
- The solution found by the algorithm (may not be a feasible solution).
-
doRun
protected abstract AbstractSolution doRun()
Abstract method that should be implemented by child class.- Returns:
- The solution found, must not be null (use an infeasible or unknown status if necessary).
-
-