/// <summary>Creates a specific <see cref="IOneDimRegion"/> object that represents the intersection of two intervals. /// </summary> /// <param name="interval1">The first interval; ignored if <c>null</c>.</param> /// <param name="interval2">The second interval; ignored if <c>null</c>.</param> /// <returns>The specific <see cref="IOneDimRegion"/> that represents the intersection of <paramref name="interval1"/> and <paramref name="interval2"/>.</returns> public static IOneDimRegion Create(IOneDimRegion interval1, IOneDimRegion interval2) { if ((interval1 == null) || (interval1 is RealAxis)) { return((interval2 == null) ? RealAxis : interval2); } if ((interval2 == null) || (interval2 is RealAxis)) { return((interval1 == null) ? RealAxis : interval1); } double a = DoMath.Max(interval1.Infimum, interval2.Infimum); double b = DoMath.Min(interval1.Supremum, interval2.Supremum); return(Create(a, b)); }
/// <summary>Initializes a new instance of the <see cref="OneDimOptimizerConstraint" /> class. /// </summary> /// <param name="constraintDescriptor">The constraint descriptor in its <see cref="OneDimOptimizerConstraintFactory"/> representation that serves as factory for the current object.</param> /// <param name="constraint">The constraint of the optimizer in its <see cref="IOneDimRegion"/> representation.</param> internal OneDimOptimizerConstraint(OneDimOptimizerConstraintFactory constraintDescriptor, IOneDimRegion constraint) { Factory = constraintDescriptor; IntervalRepresentation = constraint; }
/// <summary>Initializes a new instance of the <see cref="OneDimRootFinderConstraint" /> class. /// </summary> /// <param name="constraintFactory">The constraint descriptor in its <see cref="OneDimRootFinderConstraintFactory"/> representation that serves as factory for the current object.</param> /// <param name="constraint">The constraint of the optimizer in its <see cref="IOneDimRegion"/> representation.</param> internal OneDimRootFinderConstraint(OneDimRootFinderConstraintFactory constraintFactory, IOneDimRegion constraint) { Factory = constraintFactory; IntervalRepresentation = constraint; }
/// <summary>Creates a new <see cref="OneDimOptimizer.IConstraint"/> object. /// </summary> /// <param name="constraintDescriptor">The specific <see cref="OneDimOptimizer.IConstraintFactory"/> object.</param> /// <param name="interval">The specific constraint in its <see cref="IOneDimRegion"/> representation, i.e. the argument of the objective function are constrainted to lie in the specified interval.</param> /// <returns>A specific <see cref="OneDimOptimizer.IConstraint"/> object with respect to the specified optimization algorithm.</returns> /// <exception cref="InvalidOperationException">Thrown, if the optimization algorithm does not support this kind of constraints.</exception> /// <exception cref="ArgumentException">Thrown, if <paramref name="interval"/> can not be cast to one of the following one-dimensional interval representation: /// <see cref="RealAxis"/>, <see cref="Interval.Bounded"/>, <see cref="Interval.LeftBounded"/>, <see cref="Interval.RightBounded"/>.</exception> public static OneDimOptimizer.IConstraint Create(this OneDimOptimizer.IConstraintFactory constraintDescriptor, IOneDimRegion interval) { if (interval == null) { return(constraintDescriptor.Create(Interval.RealAxis)); } if (interval is RealAxis) { return(constraintDescriptor.Create((RealAxis)interval)); } else if (interval is Interval.Bounded) { return(constraintDescriptor.Create((Interval.Bounded)interval)); } else if (interval is Interval.LeftBounded) { return(constraintDescriptor.Create((Interval.LeftBounded)interval)); } else if (interval is Interval.RightBounded) { return(constraintDescriptor.Create((Interval.RightBounded)interval)); } throw new ArgumentException("Do not support the specific 1-dimensional interval constraint.", nameof(interval)); }
/// <summary>Creates a new <see cref="IOneDimOptimizerAlgorithm"/> object. /// </summary> /// <param name="oneDimOptimizer">The <see cref="OneDimOptimizer"/> object.</param> /// <param name="interval">The constraint in its <see cref="IOneDimRegion"/> representation.</param> /// <returns>A new <see cref="IOneDimOptimizerAlgorithm"/> object.</returns> public static IOneDimOptimizerAlgorithm Create(this OneDimOptimizer oneDimOptimizer, IOneDimRegion interval) { if (interval == null) { return(oneDimOptimizer.Create(oneDimOptimizer.Constraint.Create(Interval.RealAxis))); } var constraint = oneDimOptimizer.Constraint.Create(interval); return(oneDimOptimizer.Create(constraint)); }