Exemplo n.º 1
0
        public IEnumerable <double> Solve(IEnumerable <double> startPosition)
        {
            if (startPosition.Count() != domainDimension)
            {
                throw new ArgumentException("Parameter 'startPosition' has the wrong number of items.");
            }

            IntPtr position = startPosition.Copy();

            lock (GeneralNative.Synchronization)
            {
                IpoptNative.IpoptSolverSetInitialPosition(solver, position, domainDimension);

                string returnStatus = IpoptNative.IpoptSolverSolve(solver);

                if (returnStatus != "Solve_Succeeded" && returnStatus != "Solved_To_Acceptable_Level")
                {
                    throw new InvalidOperationException(returnStatus);
                }

                IpoptNative.IpoptSolverGetResultPosition(solver, position, domainDimension);
            }

            IEnumerable <double> resultPosition = position.Read <double>(domainDimension);

            Marshal.FreeCoTaskMem(position);

            return(resultPosition);
        }
Exemplo n.º 2
0
        public void Dispose()
        {
            if (!disposed)
            {
                disposed = true;

                lock (GeneralNative.Synchronization) IpoptNative.IpoptSolverDispose(solver);

                GC.SuppressFinalize(this);
            }
        }
Exemplo n.º 3
0
        public void Dispose()
        {
            if (!disposed)
            {
                disposed = true;

                lock (GeneralNative.Synchronization) IpoptNative.IpoptProblemDispose(problem);

                GC.SuppressFinalize(this);
            }
        }
Exemplo n.º 4
0
        public IpoptProblem Substitute(IEnumerable <Substitution> substitutions)
        {
            IntPtr variablesPointer = substitutions.Select(substitution => substitution.Variable.Value).Copy();
            IntPtr valuesPointer    = substitutions.Select(substitution => substitution.Value.Value).Copy();

            IntPtr newProblem;

            lock (GeneralNative.Synchronization) newProblem = IpoptNative.IpoptProblemSubstitute(problem, variablesPointer, valuesPointer, substitutions.Count());

            Marshal.FreeCoTaskMem(variablesPointer);
            Marshal.FreeCoTaskMem(valuesPointer);

            return(new IpoptProblem(newProblem, domainDimension));
        }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
0
        public IpoptSolver(IpoptProblem problem, Settings settings)
        {
            if (problem == null)
            {
                throw new ArgumentNullException("problem");
            }
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            lock (GeneralNative.Synchronization)
            {
                this.solver          = IpoptNative.IpoptSolverCreate(problem.Problem);
                this.domainDimension = problem.DomainDimension;

                settings.Apply(solver);

                IpoptNative.IpoptSolverInitialize(solver, problem.Problem);
            }
        }