[Coin-lpsolver] Problems coding mex interface
Johan Löfberg
loefberg at control.ee.ethz.ch
Thu Jan 20 13:06:17 EST 2005
Hi all,
I sat down today to finish a mex (MATLAB) interface to the CLP solvers, but
I seem to get into trouble regarding the QP solver.
I have essentially two problems
1: The simplex method for QP does not return any duals, and the dual simplex
fails. This is expected right?, from reading the FAQ.
2: The barrier method for QP gives wrong solutions and crashes. This is
probably due to some mistake by me.
The pseudo-code below shows the structure of my code. For LP problems, it
work as expected. I get the correct solution for all different solvers, and
correct dual variables. For QP problems, simplex method work fine (except
the dual variables) but the barrier method fails.
Any hints?
Best,
johan lofberg
//And yes, IANACP (I am not a C programmer)
**** PSEUDO MEX INTERFACE (returns primals in x and duals in lambda)
if simplex
ClpSimplex * model = new ClpSimplex();
else
ClpInterior * model = new ClpInterior();
end
model->loadProblem(ncols,nrows,cmatbeg,cmatind,cmatval,lower,upper,obj,lhs,r
hs);
model->loadQuadraticObjective(ncols,cmatbegQ,cmatindQ,cmatvalQ);
switch (solverchoice)
{
case simplex primal:
{
model->primal();
}
case simplex dual:
{
model->dual();
}
case barrier:
{
ClpCholeskyDense * cholesky = new ClpCholeskyDense();
model->setCholesky(cholesky);
model->primalDual();
}
double *primal;
double *dual;
primal = model->primalColumnSolution();
dual = model->dualRowSolution();
*returncode = model->status();
for ( i=0;i<ncols;i++)
{
x[i] = primal[i];
}
for ( i=0;i<nrows;i++)
{
lambda[i] = dual[i];
}
More information about the Clp
mailing list