コード例 #1
0
 /// <summary>
 /// Adds the specified object to the problem definition as is similiarly done
 /// for abstractOptMethod.
 /// </summary>
 /// <param name="function">The function.</param>
 /// <exception cref="Exception">Function, " + function + ", not of known type (needs "
 ///                                      + "to inherit from inequality, equality, or objectiveFunction.</exception>
 public void Add(object function)
 {
     if (function is IInequality)
     {
         g.Add((IInequality)function);
     }
     else if (function is IEquality)
     {
         h.Add((IEquality)function);
     }
     else if (function is IObjectiveFunction)
     {
         f.Add((IObjectiveFunction)function);
     }
     else if (function is abstractConvergence)
     {
         ConvergenceMethods.Add((abstractConvergence)function);
     }
     else if (function is DesignSpaceDescription)
     {
         SpaceDescriptor = (DesignSpaceDescription)function;
     }
     else if (function is double[])
     {
         xStart = (double[])function;
     }
     else
     {
         throw (new Exception("Function, " + function + ", not of known type (needs "
                              + "to inherit from inequality, equality, or objectiveFunction."));
     }
 }
コード例 #2
0
        /// <summary>
        /// Adds the specified object to the optimization routine.
        /// </summary>
        /// <param name="function">The object, function.</param>
        internal virtual void Add(object function)
        {
            if (function is IOptFunction)
            {
                if (function is IInequality)
                {
                    g.Add((IInequality)function);
                }
                else if (function is IEquality)
                {
                    h.Add((IEquality)function);
                }
                else if (function is IObjectiveFunction)
                {
                    f.Add((IObjectiveFunction)function);
                }
            }
            else if (function is IDependentAnalysis)
            {
                dependentAnalysis = (IDependentAnalysis)function;
            }
            else if (function is abstractLineSearch)
            {
                lineSearchMethod = (abstractLineSearch)function;
                lineSearchMethod.SetOptimizationDetails(this);
            }
            else if (function is abstractSearchDirection)
            {
                searchDirMethod = (abstractSearchDirection)function;
            }
            else if (function is abstractMeritFunction)
            {
                meritFunction = (abstractMeritFunction)function;
            }
            else if (function is abstractConvergence)
            {
                if (ConvergenceMethods.Any(a => a.GetType() == function.GetType()))
                {
                    throw new Exception("You cannot add a convergence method of type " + function.GetType() +
                                        "to the optimization method since one already exists of this same type.");
                }
                else
                {
                    ConvergenceMethods.Add((abstractConvergence)function);
                }
            }
            else if (function is double[])
            {
                xStart = (double[])function;
            }

            else
            {
                throw (new Exception("Function, " + function + ", not of known type (needs "
                                     + "to inherit from inequality, equality, objectiveFunction, abstractLineSearch, " +
                                     "or abstractSearchDirection)."));
            }
        }
コード例 #3
0
 public Rosenbrock()
 {
     RequiresObjectiveFunction         = true;
     ConstraintsSolvedWithPenalties    = true;
     InequalitiesConvertedToEqualities = false;
     RequiresSearchDirectionMethod     = false;
     RequiresLineSearchMethod          = false;
     RequiresAnInitialPoint            = true;
     RequiresConvergenceCriteria       = true;
     RequiresFeasibleStartPoint        = false;
     RequiresDiscreteSpaceDescriptor   = false;
     stepTooSmallConvergence           = new DirectSearchStepTooSmallConvergence();
     ConvergenceMethods.Add(stepTooSmallConvergence);
 }
コード例 #4
0
 public HookeAndJeeves()
 {
     RequiresObjectiveFunction         = true;
     ConstraintsSolvedWithPenalties    = true;
     InequalitiesConvertedToEqualities = false;
     RequiresSearchDirectionMethod     = false;
     RequiresLineSearchMethod          = false;
     RequiresAnInitialPoint            = true;
     RequiresConvergenceCriteria       = true;
     RequiresFeasibleStartPoint        = false;
     RequiresDiscreteSpaceDescriptor   = false;
     stepTooSmallConvergence           = new DirectSearchStepTooSmallConvergence();
     ConvergenceMethods.Add(stepTooSmallConvergence);
     _sameCandidate = new sameCandidate(Parameters.ToleranceForSame);
 }
コード例 #5
0
 /// <summary>
 /// Adds the specified object to the optimization routine.
 /// </summary>
 /// <param name="function">The object, function.</param>
 /// <exception cref="Exception">You cannot add a convergence method of type " + function.GetType() +
 ///                                         "to the optimization method since one already exists of this same type.</exception>
 /// <exception cref="Exception">Function, " + function + ", not of known type (needs "
 ///                                      + "to inherit from inequality, equality, objectiveFunction, abstractLineSearch, " +
 ///                                      "or abstractSearchDirection).</exception>
 public virtual void Add(object function)
 {
     if (function is ProblemDefinition)
     {
         readInProblemDefinition((ProblemDefinition)function);
     }
     else if (function is IOptFunction)
     {
         functionData.Add((IOptFunction)function,
                          new RecentFunctionEvalStore((IOptFunction)function, sameCandComparer,
                                                      Parameters.DefaultFiniteDifferenceStepSize, Parameters.DefaultFiniteDifferenceMode));
         if (function is IInequality)
         {
             g.Add((IInequality)function);
         }
         else if (function is IEquality)
         {
             h.Add((IEquality)function);
         }
         else if (function is IObjectiveFunction)
         {
             f.Add((IObjectiveFunction)function);
         }
     }
     else if (function is IDependentAnalysis)
     {
         if (dependentAnalyses == null)
         {
             dependentAnalyses = new List <IDependentAnalysis>();
         }
         dependentAnalyses.Add((IDependentAnalysis)function);
     }
     else if (function is abstractLineSearch)
     {
         lineSearchMethod = (abstractLineSearch)function;
         lineSearchMethod.SetOptimizationDetails(this);
     }
     else if (function is abstractSearchDirection)
     {
         searchDirMethod = (abstractSearchDirection)function;
     }
     else if (function is abstractMeritFunction)
     {
         meritFunction = (abstractMeritFunction)function;
     }
     else if (function is abstractConvergence)
     {
         if (ConvergenceMethods.Any(a => a.GetType() == function.GetType()))
         {
             throw new Exception("You cannot add a convergence method of type " + function.GetType() +
                                 "to the optimization method since one already exists of this same type.");
         }
         else
         {
             ConvergenceMethods.Add((abstractConvergence)function);
         }
     }
     else if (function is double[])
     {
         xStart = (double[])function;
     }
     else if (function is DesignSpaceDescription)
     {
         spaceDescriptor = (DesignSpaceDescription)function;
         n = spaceDescriptor.n;
         for (int i = 0; i < n; i++)
         {
             if (spaceDescriptor.DiscreteVarIndices.Contains(i))
             {
                 continue;
             }
             Add(new greaterThanConstant
             {
                 constant = spaceDescriptor[i].LowerBound,
                 index    = i
             });
             Add(new lessThanConstant
             {
                 constant = spaceDescriptor[i].UpperBound,
                 index    = i
             });
         }
     }
     else
     {
         throw (new Exception("Function, " + function + ", not of known type (needs "
                              + "to inherit from inequality, equality, objectiveFunction, abstractLineSearch, " +
                              "or abstractSearchDirection)."));
     }
 }