public class DurationFunctionExplorer extends Object
Duration
and the dependent variable is double, looking for one or more threshold crossings
or local extrema. Interesting findings while exploring the function are reported
via events. A supplied callback is used to determine how the function is sampled.Constructor and Description |
---|
DurationFunctionExplorer()
Initializes a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addFunctionSampled(EventHandler<DurationFunctionSampledEventArgs> value)
Adds a handler for an event that is raised each time a function is sampled.
|
void |
addLocalExtremumFound(EventHandler<DurationExtremumFoundEventArgs> value)
Raised when a precise local minimum or maximum has been found.
|
void |
addLocalExtremumIndicated(EventHandler<DurationExtremumIndicatedEventArgs> value)
Adds a handler for an event that is raised when three points are found that indicate the existence of a local extremum (minimum or maximum).
|
void |
addThresholdCrossingFound(EventHandler<DurationThresholdCrossingFoundEventArgs> value)
Adds a handler for an event that is raised when a precise threshold crossing has been found.
|
void |
addThresholdCrossingIndicated(EventHandler<DurationThresholdCrossingIndicatedEventArgs> value)
Adds a handler for an event that is raised when two points are found that indicate a threshold was crossed.
|
void |
explore(Duration start,
Duration stop)
Explores the function, raising events for each finding.
|
void |
explore(Duration start,
Duration stop,
ITrackCalculationProgress tracker)
Explores the function, raising events for each finding.
|
Duration |
getCrossingDurationTolerance()
Gets the tolerance with which to converge on duration when finding
a precise crossing of a threshold.
|
Duration |
getCurrentDuration()
Gets the current duration, which is the duration of the most recent sample.
|
boolean |
getCurrentDurationIsValid()
Gets a value indicating whether
CurrentDuration (get ) is valid. |
HierarchicalLogger |
getDebuggingLogger()
Gets a logger to which debugging information will be written.
|
boolean |
getExploreExtremaToFindCrossings()
Gets a value indicating whether extrema should be explored if exploring those extrema
could lead to additional threshold crossings being identified.
|
double |
getExtremaCrossingUncertaintyFactor()
Gets a value determining how finely to explore an extremum with the potential to cross a threshold.
|
Duration |
getExtremumDurationTolerance()
Gets the tolerance with which to converge on duration when
precisely finding a local extremum.
|
boolean |
getFindAllCrossingsPrecisely()
Gets a value indicating whether all crossings should be
found precisely.
|
boolean |
getFindAllExtremaPrecisely()
Gets a value indicating whether all extrema should be
found precisely.
|
DurationFunctionCollection |
getFunctions()
Gets the collection of functions to be explored.
|
Duration |
getPreviousDuration()
Gets the duration of the previous sample.
|
boolean |
getPreviousDurationIsValid()
Gets a value indicating whether
PreviousDuration (get ) is valid. |
Duration |
getPreviousPreviousDuration()
Gets the duration of the previous, previous sample.
|
boolean |
getPreviousPreviousDurationIsValid()
Gets a value indicating whether
PreviousPreviousDuration (get ) is valid. |
boolean |
getReportExtremaAtEndpoints()
Gets a value indicating whether extrema should be reported at the start and stop times
given to
DurationFunctionExplorer.explore(Duration,Duration) when the function is not flat
at those endpoints. |
DurationSampleSuggestionCallback |
getSampleSuggestionCallback()
Gets the callback to use to determine the times at which to sample the
Functions (get )
when the DurationFunctionExplorer.explore(Duration,Duration) method is called. |
void |
removeFunctionSampled(EventHandler<DurationFunctionSampledEventArgs> value)
Removes a handler for an event that is raised each time a function is sampled.
|
void |
removeLocalExtremumFound(EventHandler<DurationExtremumFoundEventArgs> value)
Raised when a precise local minimum or maximum has been found.
|
void |
removeLocalExtremumIndicated(EventHandler<DurationExtremumIndicatedEventArgs> value)
Removes a handler for an event that is raised when three points are found that indicate the existence of a local extremum (minimum or maximum).
|
void |
removeThresholdCrossingFound(EventHandler<DurationThresholdCrossingFoundEventArgs> value)
Removes a handler for an event that is raised when a precise threshold crossing has been found.
|
void |
removeThresholdCrossingIndicated(EventHandler<DurationThresholdCrossingIndicatedEventArgs> value)
Removes a handler for an event that is raised when two points are found that indicate a threshold was crossed.
|
void |
reset()
Resets exploration.
|
void |
setCrossingDurationTolerance(Duration value)
Sets the tolerance with which to converge on duration when finding
a precise crossing of a threshold.
|
void |
setDebuggingLogger(HierarchicalLogger value)
Sets a logger to which debugging information will be written.
|
void |
setExploreExtremaToFindCrossings(boolean value)
Sets a value indicating whether extrema should be explored if exploring those extrema
could lead to additional threshold crossings being identified.
|
void |
setExtremaCrossingUncertaintyFactor(double value)
Sets a value determining how finely to explore an extremum with the potential to cross a threshold.
|
void |
setExtremumDurationTolerance(Duration value)
Sets the tolerance with which to converge on duration when
precisely finding a local extremum.
|
void |
setFindAllCrossingsPrecisely(boolean value)
Sets a value indicating whether all crossings should be
found precisely.
|
void |
setFindAllExtremaPrecisely(boolean value)
Sets a value indicating whether all extrema should be
found precisely.
|
void |
setReportExtremaAtEndpoints(boolean value)
Sets a value indicating whether extrema should be reported at the start and stop times
given to
DurationFunctionExplorer.explore(Duration,Duration) when the function is not flat
at those endpoints. |
void |
setSampleSuggestionCallback(DurationSampleSuggestionCallback value)
Sets the callback to use to determine the times at which to sample the
Functions (get )
when the DurationFunctionExplorer.explore(Duration,Duration) method is called. |
void |
step(Duration next)
Explores the function through one step, raising events for any findings over the step.
|
Iterable<DurationFunctionFinding> |
stepInteractively(Duration next)
Steps exploration to a specified duration.
|
public DurationFunctionExplorer()
public final void addThresholdCrossingIndicated(EventHandler<DurationThresholdCrossingIndicatedEventArgs> value)
value
- The handler.public final void removeThresholdCrossingIndicated(EventHandler<DurationThresholdCrossingIndicatedEventArgs> value)
value
- The handler.public final void addLocalExtremumIndicated(EventHandler<DurationExtremumIndicatedEventArgs> value)
value
- The handler.public final void removeLocalExtremumIndicated(EventHandler<DurationExtremumIndicatedEventArgs> value)
value
- The handler.public final void addThresholdCrossingFound(EventHandler<DurationThresholdCrossingFoundEventArgs> value)
FindAllCrossingsPrecisely
(get
/ set
) is true
or
DurationFunctionThresholdCrossingIndicated.findPreciseCrossing()
is called during the handling of the ThresholdCrossingIndicated
(add
/ remove
) event.value
- The handler.public final void removeThresholdCrossingFound(EventHandler<DurationThresholdCrossingFoundEventArgs> value)
FindAllCrossingsPrecisely
(get
/ set
) is true
or
DurationFunctionThresholdCrossingIndicated.findPreciseCrossing()
is called during the handling of the ThresholdCrossingIndicated
(add
/ remove
) event.value
- The handler.public final void addLocalExtremumFound(EventHandler<DurationExtremumFoundEventArgs> value)
Raised when a precise local minimum or maximum has been found. This event will only be raised if the local extremum is found precisely. Local extrema are found precisely if:
FindAllExtremaPrecisely
(get
/ set
) is true
.
DurationFunctionExtremumIndicated.findPreciseExtremum()
is called during the handling of the LocalExtremumIndicated
(add
/ remove
) event.
ExploreExtremaToFindCrossings
(get
/ set
) is true
and the extrema could have lead to additional threshold crossings being indicated.
ReportExtremaAtEndpoints
(get
/ set
) is true
and the function is not
flat at the endpoints.
public final void removeLocalExtremumFound(EventHandler<DurationExtremumFoundEventArgs> value)
Raised when a precise local minimum or maximum has been found. This event will only be raised if the local extremum is found precisely. Local extrema are found precisely if:
FindAllExtremaPrecisely
(get
/ set
) is true
.
DurationFunctionExtremumIndicated.findPreciseExtremum()
is called during the handling of the LocalExtremumIndicated
(add
/ remove
) event.
ExploreExtremaToFindCrossings
(get
/ set
) is true
and the extrema could have lead to additional threshold crossings being indicated.
ReportExtremaAtEndpoints
(get
/ set
) is true
and the function is not
flat at the endpoints.
public final void addFunctionSampled(EventHandler<DurationFunctionSampledEventArgs> value)
value
- The handler.public final void removeFunctionSampled(EventHandler<DurationFunctionSampledEventArgs> value)
value
- The handler.@Nonnull public final DurationFunctionCollection getFunctions()
public final DurationSampleSuggestionCallback getSampleSuggestionCallback()
Functions
(get
)
when the DurationFunctionExplorer.explore(Duration,Duration)
method is called.public final void setSampleSuggestionCallback(DurationSampleSuggestionCallback value)
Functions
(get
)
when the DurationFunctionExplorer.explore(Duration,Duration)
method is called.public final boolean getFindAllCrossingsPrecisely()
false
,
precise crossings will only be found if
DurationFunctionThresholdCrossingIndicated.findPreciseCrossing()
is called during the ThresholdCrossingIndicated
(add
/ remove
) event. By default, this property
has the value false
.public final void setFindAllCrossingsPrecisely(boolean value)
false
,
precise crossings will only be found if
DurationFunctionThresholdCrossingIndicated.findPreciseCrossing()
is called during the ThresholdCrossingIndicated
(add
/ remove
) event. By default, this property
has the value false
.public final boolean getFindAllExtremaPrecisely()
false
,
precise extrema will only be found if
DurationFunctionExtremumIndicated.findPreciseExtremum()
is called during the ThresholdCrossingIndicated
(add
/ remove
) event, or if
ExploreExtremaToFindCrossings
(get
/ set
) is true
and the indicated extrema
might cross the threshold. By default, this property has the value false
.public final void setFindAllExtremaPrecisely(boolean value)
false
,
precise extrema will only be found if
DurationFunctionExtremumIndicated.findPreciseExtremum()
is called during the ThresholdCrossingIndicated
(add
/ remove
) event, or if
ExploreExtremaToFindCrossings
(get
/ set
) is true
and the indicated extrema
might cross the threshold. By default, this property has the value false
.public final boolean getExploreExtremaToFindCrossings()
true
, that extremum is
explored until it is found precisely, or it is determined based on ExtremaCrossingUncertaintyFactor
(get
/ set
)
that the extremum is unlikely to cross any threshold values. Such an extrema is explored even if
FindAllExtremaPrecisely
(get
/ set
) is false
.
By default, this property has the value true
.public final void setExploreExtremaToFindCrossings(boolean value)
true
, that extremum is
explored until it is found precisely, or it is determined based on ExtremaCrossingUncertaintyFactor
(get
/ set
)
that the extremum is unlikely to cross any threshold values. Such an extrema is explored even if
FindAllExtremaPrecisely
(get
/ set
) is false
.
By default, this property has the value true
.public final double getExtremaCrossingUncertaintyFactor()
Error
(get
) to determine the tolerance to compare against the difference between the current
guess of the extrema and the closest applicable threshold value. This property is only used if FindAllExtremaPrecisely
(get
/ set
)
is set to false
and ExploreExtremaToFindCrossings
(get
/ set
) is set to true
.
By default, this property has the value Double.POSITIVE_INFINITY
which effectively causes a complete search of all extrema.
If you do not desire to completely search all extrema with the potential to cross a threshold, set this to a value greater than 1.0.public final void setExtremaCrossingUncertaintyFactor(double value)
Error
(get
) to determine the tolerance to compare against the difference between the current
guess of the extrema and the closest applicable threshold value. This property is only used if FindAllExtremaPrecisely
(get
/ set
)
is set to false
and ExploreExtremaToFindCrossings
(get
/ set
) is set to true
.
By default, this property has the value Double.POSITIVE_INFINITY
which effectively causes a complete search of all extrema.
If you do not desire to completely search all extrema with the potential to cross a threshold, set this to a value greater than 1.0.public final boolean getReportExtremaAtEndpoints()
DurationFunctionExplorer.explore(Duration,Duration)
when the function is not flat
at those endpoints. By default, this property has the value true
.public final void setReportExtremaAtEndpoints(boolean value)
DurationFunctionExplorer.explore(Duration,Duration)
when the function is not flat
at those endpoints. By default, this property has the value true
.@Nonnull public final Duration getExtremumDurationTolerance()
public final void setExtremumDurationTolerance(@Nonnull Duration value)
@Nonnull public final Duration getCrossingDurationTolerance()
public final void setCrossingDurationTolerance(@Nonnull Duration value)
@Nonnull public final Duration getCurrentDuration()
IllegalStateException
- The current duration is not available because the explorer has not yet been stepped for
the first time.public final boolean getCurrentDurationIsValid()
@Nonnull public final Duration getPreviousDuration()
IllegalStateException
- The previous duration is not available because the explorer has not yet been stepped for
the second time.public final boolean getPreviousDurationIsValid()
@Nonnull public final Duration getPreviousPreviousDuration()
IllegalStateException
- The previous previous duration is not available because the explorer has not yet been stepped for
the third time.public final boolean getPreviousPreviousDurationIsValid()
public final HierarchicalLogger getDebuggingLogger()
public final void setDebuggingLogger(HierarchicalLogger value)
public final void explore(@Nonnull Duration start, @Nonnull Duration stop)
start
- The duration at which to start exploring the function.stop
- The duration at which to stop exploring the function.PropertyInvalidException
- Thrown when Functions
(get
) is empty or SampleSuggestionCallback
(get
/ set
) is null
.IllegalStateException
- Thrown when SampleSuggestionCallback
(get
/ set
) suggests a zero-length step.public final void explore(@Nonnull Duration start, @Nonnull Duration stop, @Nullable ITrackCalculationProgress tracker)
start
- The duration at which to start exploring the function.stop
- The duration at which to stop exploring the function.tracker
- The object to which progress is reported and that is able to cancel this operation before it is complete, or null
.PropertyInvalidException
- Thrown when Functions
(get
) is empty or SampleSuggestionCallback
(get
/ set
) is null
.IllegalStateException
- Thrown when SampleSuggestionCallback
(get
/ set
) suggests a zero-length step.public final void step(@Nonnull Duration next)
next
- The duration of the next step.@Nonnull public final Iterable<DurationFunctionFinding> stepInteractively(@Nonnull Duration next)
DurationFunctionFindings
.
Events are not raised for the findings.next
- The duration to which to step.public final void reset()