Hi,
I'm getting a NullReferenceException when running the following
code multiple times:
Code:
// Using ALGLIB to solve a quadratic program
// cf. example_minqp_d_lc1 example on ALGLIBs page
double[,] a = C.ToArray(); // <-- quadratic term in objective function
double[] b = new double[C.RowCount]; // <-- no linear term in objective function
double[] bndl = new double[C.RowCount]; // <-- lower box bound
double[] bndu = Enumerable.Repeat<double>(Double.PositiveInfinity, C.RowCount).ToArray();
double[] cnstrRow = gainPredictorsAt.Append(1.0).ToArray(); // <-- expected gain = 1 constraint coeffs
double[,] cnstr = new double[1, cnstrRow.Length]; // <-- expected gain = 1 constraint
for (var i = 0; i < cnstrRow.Length; i++) cnstr[0, i] = cnstrRow[i];
int[] cnstrType = new int[] { 0 }; // <-- linear constraint type - equality
double[] ret;
alglib.minqpstate state;
alglib.minqpreport rep;
// create solver, set quadratic/linear terms
alglib.minqpcreate(C.RowCount, out state);
alglib.minqpsetquadraticterm(state, a);
alglib.minqpsetlinearterm(state, b);
alglib.minqpsetbc(state, bndl, bndu);
alglib.minqpsetlc(state, cnstr, cnstrType);
// set scale
alglib.minqpsetscaleautodiag(state);
// optimize using BLEIC-based QP solver
alglib.minqpsetalgobleic(state, 0.0, 1e-5, 0.0, 10000);
alglib.minqpoptimize(state);
C is a MathNet matrix.
The crash is not deterministic with respect to the inputs. Several first input data sets give
me a definite answer, then the exception is thrown. If I permute the input data sets, again a
few first input data sets give me a definite answer, though these often correspond to inputs
that have previously yielded the exception.
The code runs on a single thread as far as I know.
Stack trace looks the following way:
Quote:
at alglib.ablasf.rgemv(Int32 m, Int32 n, Double alpha, Double[,] a, Int32 opa, Double[] x, Double beta, Double[] y, xparams _params)
at alglib.optserv.feasibilityerror(Double[,] ce, Double[] x, Int32 nmain, Int32 nslack, Int32 k, Double[]& tmp0, xparams _params)
at alglib.optserv.findfeasiblepoint(Double[]& x, Double[] bndl, Boolean[] havebndl, Double[] bndu, Boolean[] havebndu, Int32 nmain, Int32 nslack, Double[,] ce, Int32 k, Double epsi, Int32& qpits, Int32& gpaits, xparams _params)
at alglib.sactivesets.sasstartoptimization(sactiveset state, Double[] x, xparams _params)
at alglib.minbleic.minbleiciteration(minbleicstate state, xparams _params)
at alglib.qpbleicsolver.qpbleicoptimize(convexquadraticmodel a, sparsematrix sparsea, Int32 akind, Boolean sparseaupper, Double absasum, Double absasum2, Double[] b, Double[] bndl, Double[] bndu, Double[] s, Double[] xorigin, Int32 n, Double[,] cleic, Int32 nec, Int32 nic, qpbleicsettings settings, qpbleicbuffers sstate, Boolean& firstcall, Double[]& xs, Int32& terminationtype, xparams _params)
at alglib.minqp.minqpoptimize(minqpstate state, xparams _params)
at alglib.minqpoptimize(minqpstate state)
at QuantTools.Portfolios.PortfolioWeightAllocationMethods.InverseCovarianceMatrixAlloc
Is there any important detail I'm missing about how alglib should be used?
Ćukasz