- java.lang.Object
-
- org.logicng.handlers.ComputationHandler
-
- org.logicng.handlers.TimeoutHandler
-
- org.logicng.handlers.TimeoutOptimizationHandler
-
- All Implemented Interfaces:
Handler,OptimizationHandler
public class TimeoutOptimizationHandler extends TimeoutHandler implements OptimizationHandler
An optimization handler which cancels the computation process after a given timeout.- Since:
- 2.1.0
- Version:
- 2.1.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.logicng.handlers.TimeoutHandler
TimeoutHandler.TimerType
-
-
Field Summary
-
Fields inherited from class org.logicng.handlers.TimeoutHandler
designatedEnd, timeout, type
-
Fields inherited from class org.logicng.handlers.ComputationHandler
aborted
-
-
Constructor Summary
Constructors Constructor Description TimeoutOptimizationHandler(long timeout)Constructs a new timeout handler with a given timeout and uses the timeout typeTimeoutHandler.TimerType.SINGLE_TIMEOUT.TimeoutOptimizationHandler(long timeout, TimeoutHandler.TimerType type)Constructs a new timeout handler with a given timeout and a timeout type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaborted()Returns whether the computation was aborted by the handler.booleanfoundBetterBound(Supplier<Assignment> lastModelProvider)This method is called when the solver found a better bound for the optimization.AssignmentgetIntermediateResult()Returns the latest intermediate result of the optimization ornullif no such result was yet computed.SATHandlersatHandler()Returns a SAT handler which can be used to cancel internal SAT calls of the model enumeration process.voidstarted()This method is called when the computation starts.-
Methods inherited from class org.logicng.handlers.TimeoutHandler
timeLimitExceeded
-
-
-
-
Constructor Detail
-
TimeoutOptimizationHandler
public TimeoutOptimizationHandler(long timeout, TimeoutHandler.TimerType type)Constructs a new timeout handler with a given timeout and a timeout type. The interpretation of the timeout depends on the timeout type:TimeoutHandler.TimerType.SINGLE_TIMEOUT: The timeout is started whenHandler.started()is called. Further calls toHandler.started()have no effect on the timeout. Thus, the timeout can only be started once.TimeoutHandler.TimerType.RESTARTING_TIMEOUT: The timeout is restarted whenHandler.started()is called.TimeoutHandler.TimerType.FIXED_END: Timeout which is interpreted as fixed point in time (in milliseconds) at which the computation should be aborted. The methodHandler.started()must still be called, but does not have an effect on the timeout.
- Parameters:
timeout- the timeout in milliseconds, its meaning is defined by the timeout typetype- the type of the timer, must not benull
-
TimeoutOptimizationHandler
public TimeoutOptimizationHandler(long timeout)
Constructs a new timeout handler with a given timeout and uses the timeout typeTimeoutHandler.TimerType.SINGLE_TIMEOUT. Thus, the timeout is started whenHandler.started()is called and further calls toHandler.started()have no effect on the timeout.- Parameters:
timeout- the timeout in milliseconds
-
-
Method Detail
-
satHandler
public SATHandler satHandler()
Returns a SAT handler which can be used to cancel internal SAT calls of the model enumeration process. Note that this handler will only be available after the first call tostarted().- Specified by:
satHandlerin interfaceOptimizationHandler- Returns:
- the SAT handler
-
aborted
public boolean aborted()
Description copied from interface:HandlerReturns whether the computation was aborted by the handler.- Specified by:
abortedin interfaceHandler- Specified by:
abortedin interfaceOptimizationHandler- Overrides:
abortedin classComputationHandler- Returns:
trueif the computation was aborted by the handler, otherwisefalse
-
started
public void started()
Description copied from interface:HandlerThis method is called when the computation starts.- Specified by:
startedin interfaceHandler- Overrides:
startedin classTimeoutHandler
-
foundBetterBound
public boolean foundBetterBound(Supplier<Assignment> lastModelProvider)
Description copied from interface:OptimizationHandlerThis method is called when the solver found a better bound for the optimization.- Specified by:
foundBetterBoundin interfaceOptimizationHandler- Parameters:
lastModelProvider- a provider for the current result, can be used to examine the current result or to use this result if the optimization should be aborted- Returns:
trueif the optimization process should be continued, otherwisefalse
-
getIntermediateResult
public Assignment getIntermediateResult()
Returns the latest intermediate result of the optimization ornullif no such result was yet computed.- Returns:
- the latest intermediate result
-
-