Exemple #1
0
 /// <summary>Sets the real-valued function to minimize.
 /// </summary>
 /// <param name="function">The objective function with respect to the NLopt function pointer representation.</param>
 /// <param name="data">The 'data' argument of the objective function in its <see cref="GCHandle"/> representation.</param>
 /// <exception cref="ArgumentNullException">Thrown, if <paramref name="function"/> is <c>null</c>.</exception>
 public void SetFunction(NLoptObjectiveFunction function, GCHandle data)
 {
     if (function == null)
     {
         throw new ArgumentNullException(nameof(function));
     }
     if (m_NLopPtr == IntPtr.Zero)
     {
         throw new ObjectDisposedException("NLoptPtr");
     }
     nlopt_set_min_objective(m_NLopPtr, function, GCHandle.ToIntPtr(data));
 }
 /// <summary>Creates a specific <see cref="NLoptFunction"/> object.
 /// </summary>
 /// <param name="dimension">The dimension of the feasible region.</param>
 /// <param name="objectiveFunction">The objective function in its <see cref="NLoptObjectiveFunction"/> representation.</param>
 /// <returns>A specific <see cref="NLoptFunction"/> object with respect to the specified optimization algorithm.</returns>
 public NLoptFunction Create(int dimension, NLoptObjectiveFunction objectiveFunction)
 {
     return(new NLoptFunction(this, dimension, objectiveFunction));
 }
Exemple #3
0
 private static extern NLoptResultCode nlopt_set_min_objective(IntPtr opt, [MarshalAs(UnmanagedType.FunctionPtr)] NLoptObjectiveFunction f, IntPtr data);
 /// <summary>Initializes a new instance of the <see cref="NLoptFunction" /> class.
 /// </summary>
 /// <param name="nloptFunctionDescriptor">The <see cref="NLoptFunctionFactory"/> object that has been used as factory of the current instance.</param>
 /// <param name="dimension">The dimension of the feasible region.</param>
 /// <param name="nloptObjectiveFunction">The objective function in its <see cref="NLoptObjectiveFunction"/> representation.</param>
 internal NLoptFunction(NLoptFunctionFactory nloptFunctionDescriptor, int dimension, NLoptObjectiveFunction nloptObjectiveFunction)
 {
     m_NLoptFunctionDescriptor = nloptFunctionDescriptor;
     Dimension = dimension;
     NLoptObjectiveFunction = nloptObjectiveFunction;
 }