/// <summary>Initializes a new instance of the <see cref="BoxTransformationAlgorithm"/> class.
 /// </summary>
 /// <param name="optimizer">The <see cref="MultiDimOptimizer"/> object that serves as factory of the current object and solve optimization problems without constraints.</param>
 /// <param name="boxConstraint">The box constraint.</param>
 internal BoxTransformationAlgorithm(MultiDimOptimizer optimizer, MultiDimRegion.Interval boxConstraint)
 {
     m_Optimizer               = optimizer ?? throw new ArgumentNullException(nameof(optimizer));
     m_BoxConstraint           = boxConstraint ?? throw new ArgumentNullException(nameof(boxConstraint));
     m_TempFunctionArgument    = new double[boxConstraint.Dimension];
     m_InnerOptimizerAlgorithm = optimizer.Create(boxConstraint.Dimension);
 }
Beispiel #2
0
        /// <summary>Initializes a new instance of the <see cref="QuadraticPenaltyAlgorithm"/> class.
        /// </summary>
        /// <param name="optimizer">The <see cref="MultiDimOptimizer"/> object that serves as factory of the current object and solve optimization problems without constraints.</param>
        /// <param name="multiDimRegionCollection">The constraints in its <see cref="MultiDimOptimizer.IConstraint"/> representation.</param>
        /// <param name="relativePenaltyWeight">The relative weight of the penalty function.</param>
        /// <param name="absolutePenaltyWeight">The absolute weight of the penalty function.</param>
        internal QuadraticPenaltyAlgorithm(MultiDimOptimizer optimizer, IEnumerable <MultiDimOptimizer.IConstraint> multiDimRegionCollection, double relativePenaltyWeight = 1e20, double absolutePenaltyWeight = 0.0)
        {
            m_Optimizer       = optimizer ?? throw new ArgumentNullException(nameof(optimizer));
            m_MultiDimRegions = CheckConstraintConsistency(multiDimRegionCollection);
            Dimension         = multiDimRegionCollection.FirstOrDefault().Dimension;

            m_InnerOptimizerAlgorithm = optimizer.Create(Dimension);
            m_RelativePenaltyWeight   = relativePenaltyWeight;
            m_AbsolutePenaltyWeight   = absolutePenaltyWeight;
        }
 /// <summary>Creates a specific <see cref="IMultiDimOptimizerAlgorithm"/> object.
 /// </summary>
 /// <param name="optimizer">The <see cref="MultiDimOptimizer"/> object that supports a optimization problems without constraints.</param>
 /// <param name="multiDimRegionCollection">The constraints in its <see cref="MultiDimOptimizer.IConstraint"/> representation.</param>
 /// <returns>The specific <see cref="IMultiDimOptimizerAlgorithm"/> object.</returns>
 public override IMultiDimOptimizerAlgorithm Create(MultiDimOptimizer optimizer, MultiDimOptimizer.IConstraint[] multiDimRegionCollection)
 {
     return(new QuadraticPenaltyAlgorithm(optimizer, multiDimRegionCollection, RelativePenaltyWeight, AbsolutePenaltyWeight));
 }
Beispiel #4
0
        /// <summary>Converts a collection of <see cref="IMultiDimRegion"/> objects to a specific <see cref="MultiDimOptimizer.IConstraint"/> representation.
        /// </summary>
        /// <param name="multiDimOptimizer">The <see cref="MultiDimOptimizer"/> object.</param>
        /// <param name="constraints">The constraints in its generic <see cref="IMultiDimRegion"/> representation.</param>
        /// <returns>The collection of <see cref="MultiDimOptimizer.IConstraint"/> that contains the algorithm specific representation of the <paramref name="constraints"/>.</returns>
        public static IEnumerable <MultiDimOptimizer.IConstraint> GetConvertedConstraints(this MultiDimOptimizer multiDimOptimizer, IEnumerable <IMultiDimRegion> constraints)
        {
            if (constraints == null)
            {
                throw new ArgumentNullException(nameof(constraints));
            }
            int dimension = -1;

            foreach (var constraint in constraints)
            {
                if (dimension == -1)
                {
                    dimension = constraint.Dimension;
                }
                else if (dimension != constraint.Dimension)
                {
                    throw new ArgumentException(nameof(constraints));
                }
                if (constraint is MultiDimRegion.Interval)
                {
                    yield return(multiDimOptimizer.Constraint.Create((MultiDimRegion.Interval)constraint));
                }
                else if (constraint is MultiDimRegion.LinearInequality)
                {
                    yield return(multiDimOptimizer.Constraint.Create((MultiDimRegion.LinearInequality)constraint));
                }
                else if (constraint is MultiDimRegion.LinearEquality)
                {
                    yield return(multiDimOptimizer.Constraint.Create((MultiDimRegion.LinearEquality)constraint));
                }
                else if (constraint is MultiDimRegion.Polynomial)
                {
                    yield return(multiDimOptimizer.Constraint.Create((MultiDimRegion.Polynomial)constraint));
                }
                else if (constraint is MultiDimRegion.Inequality)
                {
                    yield return(multiDimOptimizer.Constraint.Create((MultiDimRegion.Inequality)constraint));
                }
                else
                {
                    throw new ArgumentException(nameof(constraints));
                }
            }
        }
Beispiel #5
0
 /// <summary>Creates a new <see cref="IMultiDimOptimizerAlgorithm"/> object.
 /// </summary>
 /// <param name="multiDimOptimizer">The <see cref="MultiDimOptimizer"/> object.</param>
 /// <param name="constraints">A collection of contraints for the optimization algorithm.</param>
 /// <returns>A new <see cref="IMultiDimOptimizerAlgorithm"/> object.</returns>
 public static IMultiDimOptimizerAlgorithm Create(this MultiDimOptimizer multiDimOptimizer, params IMultiDimRegion[] constraints)
 {
     return(multiDimOptimizer.Create(GetConvertedConstraints(multiDimOptimizer, constraints).ToArray()));
 }
Beispiel #6
0
 /// <summary>Creates a new <see cref="IMultiDimOptimizerAlgorithm"/> object.
 /// </summary>
 /// <param name="multiDimOptimizer">The <see cref="MultiDimOptimizer"/> object.</param>
 /// <param name="constraints">A collection of contraints for the optimization algorithm.</param>
 /// <returns>A new <see cref="IMultiDimOptimizerAlgorithm"/> object.</returns>
 public static IMultiDimOptimizerAlgorithm Create(this MultiDimOptimizer multiDimOptimizer, IEnumerable <IMultiDimRegion> constraints)
 {
     return(multiDimOptimizer.Create(GetConvertedConstraints(multiDimOptimizer, constraints).ToArray()));
 }