rquadprog

R - solve.QP.compact - Constraints are Inconsistent


I'm trying to use solve.QP.compact to solve my quadratic problem under linear constraint. The function to minimize can be written as Beta Dmat Beta with Beta representing convex coefficients that should be positive (Beta > 0 and sum of the beta = 1). Dmat is the following:

Dmat <- matrix(c(109372234737,56220334574,73429834051,91873541870,71984996802,26694299175,59466668488,72903058589,34863587167,69990189651,56220334574,30472842846,41528929013,47926044961,39275554021,15336150547,31555630939,46390008065,18268007279,37264936709,73429834051,41528929013,66139008296,63287127518,56359545680,23281467618,42187566934,81859897202,23713602850,48982965873,91873541870,47926044961,63287127518,79910583327,62808190600,22813816846,50498032289,61764252981,29834680574,60303335045,71984996802,39275554021,56359545680,62808190600,61526678668,20293546244,40774759080,65131530787,23760877095,48696449409,26694299175,15336150547,23281467618,22813816846,20293546244,10710118459,16315334904,40553546897,8572539401,18248955543,59466668488,31555630939,42187566934,50498032289,40774759080,16315334904,34293058435,49072014208,19333916546,38891422022,72903058589,46390008065,81859897202,61764252981,65131530787,40553546897,49072014208,201860304636,23395941080,50359726205,34863587167,18268007279,23713602850,29834680574,23760877095,8572539401,19333916546,23395941080,11528523792,23285654687,69990189651,37264936709,48982965873,60303335045,48696449409,18248955543,38891422022,50359726205,23285654687,48461629142), nrow=10, ncol=10)

As solve.QP.compact, solves function -d^Tb + 1/2 b^TDb, I have

dvec <- rep(0,nrow(Dmat))`

and the constraints are defined by

Amat = matrix(data=0, nrow=nrow(Dmat), ncol=nrow(Dmat)+1)
Amat[1,] = 1
Amat[,1] = 1

and

Aind = matrix(data=0, nrow=nrow(Dmat)+1, ncol=nrow(Dmat)+1)
Aind[1,] = 1
Aind[1,1] = nrow(Dmat)
Aind[2,] = c(1, seq(1:nrow(Dmat)))
Aind[,1] = c(nrow(Dmat), seq(1:nrow(Dmat)))

The sum should equal to 1, and all other values should be positive, so I have bvec defined by

bvec = rep(0,nrow(Dmat)+1)
bvec[1] = 1

And I use solve.QP.compact

solve.QP.compact(Dmat = Dmat, dvec = dvec, Amat = Amat, Aind=Aind, bvec = bvec)

This results by the following error

constraints are inconsistent, no solution!

What am I doing wrong ?


Solution

  • There's something wrong with the huge numbers in Dmat.

    Probably the elements of solution vector b as they are getting indistinguishable from 0 (see .Machine$double.eps) still resolve in b^T D b being too big and something inside quadprog makes constraints inconsistent.

    Looks like this should help:

       Dmat <- Dmat / 10^6