Package ai.libs.jaicore.basic.algorithm
Class AOptimizer<I,O extends org.api4.java.common.attributedobjects.ScoredItem<V>,V extends java.lang.Comparable<V>>
- java.lang.Object
-
- ai.libs.jaicore.basic.algorithm.AAlgorithm<I,O>
-
- ai.libs.jaicore.basic.algorithm.ASolutionCandidateIterator<I,O>
-
- ai.libs.jaicore.basic.algorithm.AOptimizer<I,O,V>
-
- Type Parameters:
I- The type of input instances (problems) to be solved by the algorithm.O- The type of output that is obtained by running the algorithm on the input.V- The type performance values will have to compare different solutions.
- All Implemented Interfaces:
java.lang.Iterable<org.api4.java.algorithm.events.IAlgorithmEvent>,java.util.concurrent.Callable<O>,java.util.Iterator<org.api4.java.algorithm.events.IAlgorithmEvent>,org.api4.java.algorithm.IAlgorithm<I,O>,org.api4.java.algorithm.IOptimizationAlgorithm<I,O,V>,org.api4.java.algorithm.ISolutionCandidateIterator<I,O>,org.api4.java.common.control.ICancelable,org.api4.java.common.control.ILoggingCustomizable
public abstract class AOptimizer<I,O extends org.api4.java.common.attributedobjects.ScoredItem<V>,V extends java.lang.Comparable<V>> extends ASolutionCandidateIterator<I,O> implements org.api4.java.algorithm.IOptimizationAlgorithm<I,O,V>
The AOptimizer represents an algorithm that is meant to optimize for a single best solution. While it may observe multiple candidates for the best solution and report them via events when running, eventually it will return only the single best observed one.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAOptimizer(IOwnerBasedAlgorithmConfig config, I input)C'tor taking a configuration of the algorithm and an input for the algorithm as arguments.AOptimizer(I input)C'tor taking only an input as a parameter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Ocall()VgetBestScoreKnownToExist()OgetBestSeenSolution()java.lang.StringgetLoggerName()OnextSolutionCandidate()org.api4.java.algorithm.events.result.ISolutionCandidateFoundEvent<O>nextSolutionCandidateEvent()protected booleansetBestSeenSolution(O candidate)Sets the best seen solution regardless the currently best solution.voidsetLoggerName(java.lang.String name)voidtellAboutBestScoreKnownToExist(V bestScoreKnownToExist)protected booleanupdateBestSeenSolution(O candidate)Updates the best seen solution if the new solution is better.-
Methods inherited from class ai.libs.jaicore.basic.algorithm.ASolutionCandidateIterator
collectAllSolutions
-
Methods inherited from class ai.libs.jaicore.basic.algorithm.AAlgorithm
activate, announceTimeoutDetected, avoidReinterruptionOnShutdownOnCurrentThread, cancel, checkAndConductTermination, checkTermination, computeTimeoutAware, getActivationTime, getConfig, getId, getInput, getListeners, getNumCPUs, getRemainingTimeToDeadline, getState, getTimeout, getTimeoutPrecautionOffset, hasNext, hasThreadBeenInterruptedDuringShutdown, interruptThreadAsPartOfShutdown, isCanceled, isShutdownInitialized, isStopCriterionSatisfied, isTimeouted, iterator, next, post, registerActiveThread, registerListener, resolveShutdownInterruptOnCurrentThread, setConfig, setDeadline, setMaxNumThreads, setNumCPUs, setState, setTimeout, setTimeout, setTimeoutPrecautionOffset, shutdown, terminate, unregisterActiveThread, unregisterThreadAndShutdown
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Constructor Detail
-
AOptimizer
public AOptimizer(I input)
C'tor taking only an input as a parameter.- Parameters:
input- The input of the algorithm.
-
AOptimizer
protected AOptimizer(IOwnerBasedAlgorithmConfig config, I input)
C'tor taking a configuration of the algorithm and an input for the algorithm as arguments.- Parameters:
config- The parameterization of the algorithm.input- The input to the algorithm (the problem to solve).
-
-
Method Detail
-
updateBestSeenSolution
protected boolean updateBestSeenSolution(O candidate)
Updates the best seen solution if the new solution is better. Returns true iff the best seen solution has been updated.- Parameters:
candidate- A candidate for a new best seen solution. It is only updated iff the candidate performs better than the bestSeenSolution observed so far.- Returns:
- Returns true iff the candidate is the best seen solution.
-
setBestSeenSolution
protected boolean setBestSeenSolution(O candidate)
Sets the best seen solution regardless the currently best solution.- Parameters:
candidate-- Returns:
- true iff the new solution has a higher score than the existing one
-
nextSolutionCandidate
public O nextSolutionCandidate() throws java.lang.InterruptedException, org.api4.java.algorithm.exceptions.AlgorithmExecutionCanceledException, org.api4.java.algorithm.exceptions.AlgorithmTimeoutedException, org.api4.java.algorithm.exceptions.AlgorithmException
- Specified by:
nextSolutionCandidatein interfaceorg.api4.java.algorithm.ISolutionCandidateIterator<I,O extends org.api4.java.common.attributedobjects.ScoredItem<V>>- Overrides:
nextSolutionCandidatein classASolutionCandidateIterator<I,O extends org.api4.java.common.attributedobjects.ScoredItem<V>>- Throws:
java.lang.InterruptedExceptionorg.api4.java.algorithm.exceptions.AlgorithmExecutionCanceledExceptionorg.api4.java.algorithm.exceptions.AlgorithmTimeoutedExceptionorg.api4.java.algorithm.exceptions.AlgorithmException
-
nextSolutionCandidateEvent
public org.api4.java.algorithm.events.result.ISolutionCandidateFoundEvent<O> nextSolutionCandidateEvent() throws java.lang.InterruptedException, org.api4.java.algorithm.exceptions.AlgorithmExecutionCanceledException, org.api4.java.algorithm.exceptions.AlgorithmTimeoutedException, org.api4.java.algorithm.exceptions.AlgorithmException
- Specified by:
nextSolutionCandidateEventin interfaceorg.api4.java.algorithm.ISolutionCandidateIterator<I,O extends org.api4.java.common.attributedobjects.ScoredItem<V>>- Overrides:
nextSolutionCandidateEventin classASolutionCandidateIterator<I,O extends org.api4.java.common.attributedobjects.ScoredItem<V>>- Throws:
java.lang.InterruptedExceptionorg.api4.java.algorithm.exceptions.AlgorithmExecutionCanceledExceptionorg.api4.java.algorithm.exceptions.AlgorithmTimeoutedExceptionorg.api4.java.algorithm.exceptions.AlgorithmException
-
getBestScoreKnownToExist
public V getBestScoreKnownToExist()
-
tellAboutBestScoreKnownToExist
public void tellAboutBestScoreKnownToExist(V bestScoreKnownToExist)
-
getBestSeenSolution
public O getBestSeenSolution()
- Returns:
- The best seen solution, yet.
-
call
public O call() throws java.lang.InterruptedException, org.api4.java.algorithm.exceptions.AlgorithmExecutionCanceledException, org.api4.java.algorithm.exceptions.AlgorithmTimeoutedException, org.api4.java.algorithm.exceptions.AlgorithmException
- Specified by:
callin interfacejava.util.concurrent.Callable<I>- Specified by:
callin interfaceorg.api4.java.algorithm.IAlgorithm<I,O extends org.api4.java.common.attributedobjects.ScoredItem<V>>- Overrides:
callin classASolutionCandidateIterator<I,O extends org.api4.java.common.attributedobjects.ScoredItem<V>>- Throws:
java.lang.InterruptedExceptionorg.api4.java.algorithm.exceptions.AlgorithmExecutionCanceledExceptionorg.api4.java.algorithm.exceptions.AlgorithmTimeoutedExceptionorg.api4.java.algorithm.exceptions.AlgorithmException
-
getLoggerName
public java.lang.String getLoggerName()
- Specified by:
getLoggerNamein interfaceorg.api4.java.common.control.ILoggingCustomizable- Overrides:
getLoggerNamein classAAlgorithm<I,O extends org.api4.java.common.attributedobjects.ScoredItem<V>>
-
setLoggerName
public void setLoggerName(java.lang.String name)
- Specified by:
setLoggerNamein interfaceorg.api4.java.common.control.ILoggingCustomizable- Overrides:
setLoggerNamein classAAlgorithm<I,O extends org.api4.java.common.attributedobjects.ScoredItem<V>>
-
-