コード例 #1
0
ファイル: QpSolver.cs プロジェクト: CatchemAl/QPTests
        public QpReport Solve(IQpProblem problem)
        {
            double[]           x;
            alglib.minqpstate  state;
            alglib.minqpreport report;

            var watch = new Stopwatch();

            watch.Start();

            // Convert constraints to ALGLIB format.
            ConstraintsAdapter constraints = new ConstraintsAdapter(problem);

            // Create the solver, set QP terms and linear constraints.
            alglib.minqpcreate(problem.Q.GetLength(0), out state);
            alglib.minqpsetquadraticterm(state, problem.Q);
            alglib.minqpsetlinearterm(state, problem.C);
            alglib.minqpsetlc(state, constraints.ConstraintMatrix, constraints.ConstraintTypes);

            // Set the scale of the parameters and the algorithm choice.
            alglib.minqpsetscale(state, constraints.ScaleFactors);
            alglib.minqpsetalgobleic(state, 0.0, 0.0, 0.0, 0);

            // Run the optimisation and report.
            alglib.minqpoptimize(state);
            alglib.minqpresults(state, out x, out report);
            watch.Stop();

            return(new QpReport(
                       x,
                       report.outeriterationscount,
                       GetSolveStatus(report.terminationtype),
                       watch.ElapsedMilliseconds));
        }
コード例 #2
0
ファイル: QpSolver.cs プロジェクト: CatchemAl/QPTests
            public ConstraintsAdapter(IQpProblem problem)
            {
                this.problem = problem;

                this.numVars          = this.problem.Q.GetLength(0);
                this.numConstraints   = ComputeNumberOfConstraints();
                this.constraintMatrix = BuildConstraintMatrix();
                this.constraintVector = BuildConstraintVector();
                this.scaleFactors     = BuildScaleFactors();
            }