示例#1
0
        public static ValueTerm IntegrateTrapezoid(FunctionTerm function, OrderedRange <double> bounds, int segmentCount)
        {
            if (segmentCount < 1)
            {
                throw new ArgumentOutOfRangeException("segmentCount");
            }

            ValueTerm segmentWidth = Terms.Constant(bounds.Length() / segmentCount);

            IEnumerable <ValueTerm> values =
                (
                    from segmentPosition in Scalars.GetIntermediateValuesSymmetric(bounds.Start, bounds.End, segmentCount)
                    select function.Apply(Terms.Constant(segmentPosition))
                )
                .ToArray();

            return(Terms.Product
                   (
                       segmentWidth,
                       Terms.Sum
                       (
                           Enumerables.Concatenate
                           (
                               Enumerables.Create(Terms.Product(Terms.Constant(0.5), values.First())),
                               values.Skip(1).SkipLast(1),
                               Enumerables.Create(Terms.Product(Terms.Constant(0.5), values.Last()))
                           )
                       )
                   ));
        }
示例#2
0
        public static IEnumerable <FunctionTerm> FunctionDerivatives(FunctionTerm function)
        {
            lock (GeneralNative.Synchronization)
            {
                IntPtr derivatives = Enumerable.Repeat(IntPtr.Zero, function.DomainDimension).Copy();

                TermsNative.FunctionDerivatives(function.Function, derivatives);

                IEnumerable <IntPtr> result = derivatives.Read <IntPtr>(function.DomainDimension);

                Marshal.FreeCoTaskMem(derivatives);

                return(result.Select(derivative => new FunctionTerm(derivative)).ToArray());
            }
        }
示例#3
0
        public static IpoptProblem Create(FunctionTerm objectiveFunction, FunctionTerm constraintFunction, IEnumerable <Range <ValueTerm> > constraintRanges)
        {
            IntPtr constraintLowerBoundsPointer = constraintRanges.Select(range => range.Start.Value).Copy();
            IntPtr constraintUpperBoundsPointer = constraintRanges.Select(range => range.End.Value).Copy();

            IntPtr problem;

            lock (GeneralNative.Synchronization) problem = IpoptNative.IpoptProblemCreate(objectiveFunction.Function, constraintFunction.Function, constraintLowerBoundsPointer, constraintUpperBoundsPointer);

            Marshal.FreeCoTaskMem(constraintLowerBoundsPointer);
            Marshal.FreeCoTaskMem(constraintUpperBoundsPointer);

            int domainDimension = Items.Equal(objectiveFunction.DomainDimension, constraintFunction.DomainDimension);

            return(new IpoptProblem(problem, domainDimension));
        }
示例#4
0
 public static ValueTerm Application(FunctionTerm function, ValueTerm value)
 {
     lock (GeneralNative.Synchronization) return(new ValueTerm(TermsNative.Application(function.Function, value.Value)));
 }
示例#5
0
 public static void DisposeFunction(FunctionTerm function)
 {
     lock (GeneralNative.Synchronization) TermsNative.DisposeFunction(function.Function);
 }
示例#6
0
 public static FunctionTerm FunctionSimplify(FunctionTerm function)
 {
     lock (GeneralNative.Synchronization) return(new FunctionTerm(TermsNative.FunctionSimplify(function.Function)));
 }
示例#7
0
 public static int FunctionCodomainDimension(FunctionTerm function)
 {
     lock (GeneralNative.Synchronization) return(TermsNative.FunctionCodomainDimension(function.Function));
 }
示例#8
0
 public static string FunctionToString(FunctionTerm function)
 {
     lock (GeneralNative.Synchronization) return(TermsNative.FunctionToString(function.Function));
 }
示例#9
0
 public static ValueTerm Apply(this FunctionTerm function, params ValueTerm[] parameters)
 {
     return(function.Apply((IEnumerable <ValueTerm>)parameters));
 }
示例#10
0
 public static ValueTerm Apply(this FunctionTerm function, IEnumerable <ValueTerm> parameters)
 {
     return(Application(function, Vector(parameters)));
 }
示例#11
0
 public static ValueTerm Application(FunctionTerm function, ValueTerm value)
 {
     return(TermsWrapped.Application(function, value));
 }