/// <summary> /// Create a threshold criteria that fires when a certain parameter reaches a certain threshold (once or continuously). /// </summary> /// <param name="parameter">The parameter (identifier) to check.</param> /// <param name="target">The target threshold comparison (smaller / greater / equals).</param> /// <param name="thresholdValue">The threshold value to compare against.</param> /// <param name="fireContinously">Optionally indicate if this criteria should fire once or continuously when the threshold is reached.</param> public ThresholdCriteria(string parameter, ComparisonTarget target, double thresholdValue, bool fireContinously = true) : base(parameter) { if (parameter == null) { throw new ArgumentNullException(nameof(parameter)); } if (!Enum.IsDefined(typeof(ComparisonTarget), target)) { throw new InvalidEnumArgumentException(nameof(target), (int)target, typeof(ComparisonTarget)); } ParameterRegistry["parameter_identifier"] = parameter; ParameterRegistry["target"] = target; ParameterRegistry["threshold_value"] = thresholdValue; ParameterRegistry["fire_continously"] = fireContinously; ParameterRegistry["last_check_met"] = false; ParameterRegistry["threshold_reached"] = false; }
private bool _InternalThresholdReached(double value, double threshold, ComparisonTarget target) { switch (target) { case ComparisonTarget.Equals: return(value == threshold); case ComparisonTarget.GreaterThanEquals: return(value >= threshold); case ComparisonTarget.GreaterThan: return(value > threshold); case ComparisonTarget.SmallerThanEquals: return(value <= threshold); case ComparisonTarget.SmallerThan: return(value < threshold); default: throw new ArgumentOutOfRangeException($"Comparison target is out of range ({target}), use the provided {nameof(ComparisonTarget)} enum."); } }
/// <summary> /// Create a hook that conditionally (threshold criteria) fetches a given value (i.e. registry identifier) at a given <see cref="ITimeStep"/>. /// </summary> /// <param name="valueIdentifier">The value that will be fetched (i.e. registry identifier). E.g. <c>"optimiser.cost_total"</c></param> /// <param name="timestep">The <see cref="ITimeStep"/> the hook will executed on.</param> /// <param name="threshold">The threshold to compare against.</param> /// <param name="target">The threshold criteria comparison target.</param> /// <param name="fireContinously">If the value should be reported every time step the criteria is satisfied (or just once).</param> public AccumulatedValueReporter(string valueIdentifier, ITimeStep timestep, double threshold, ComparisonTarget target, bool fireContinously = true) : this(new[] { valueIdentifier }, timestep) { On(new ThresholdCriteria(GetAccumulatedIdentifier(valueIdentifier), target, threshold, fireContinously)); }