[Cbc] please help me

Ivan Meireles Costa ivan.costa at gapso.com.br
Tue Oct 2 08:01:07 EDT 2012


you need call initial solve before branchAndBound.

 CbcModel solver(solver1);
 solver.initialSolve();
 solver.branchAndBound();

Att.
Ivan

On Wed, Sep 19, 2012 at 4:45 AM, 刘峰 <liufengaarr at gmail.com> wrote:

> Dear Sir:
>          My name is LiuFeng, I am a student of Computer Science In Ji Lin
> University of China. I am learning to use CBC Library to solve some MIP
> problems. I met a problem,but I don't know how to solve it.
>          The problem is as follows.
>           It is an Integer Programming problem.
>           The target function is Min z=x1 + x2 + x3 + x4
>           The Constraints are
>                                              4*x1 + 3*x2  +
> 2*x3             =2
>                                                             x2 +  2*x3 +
> 5*x4 = 2
>                                              xi >= 0 (i=1,2,3,4) all of
> them have the constraint of integer.
>
>           The CBC Codes is as follows:
> int _tmain(int argc, _TCHAR* argv[])
> {
>      OsiClpSolverInterface solver1;
>      const int numcols = 4;
>      const int numrows = 2;
>      int nnz = 6;
>     CoinBigIndex *start = new int[numcols+1];
>     int* index = new int[nnz];
>     double* value = new double[nnz];
>     double *collb = new double[numcols];
>     double *colub = new double[numcols];
>     double *obj = new double[numcols];
>     double *rowlb = new double[numrows];
>     double *rowub = new double[numrows];
>  //object
>  obj[0] = -1.0; obj[1] = -1.0; obj[2]=-1.0; obj[3]=-1.0;
>   // column bounds
>     collb[0] = 0;  colub[0] = solver1.getInfinity();
>     collb[1] = 0;  colub[1] = solver1.getInfinity();
>     collb[2] = 0;  colub[2] = solver1.getInfinity();
>     collb[3] = 0;  colub[3] = solver1.getInfinity();
>  // matrix
>  start[0]=0; index[0] = 0; value[0] = 4.0;
>  start[1]=1; index[1] = 0; value[4] = 3.0;
>     index[2] = 1; value[5] = 1.0;
>  start[2]=3; index[3] = 0; value[6] = 2.0;
>     index[4] = 1; value[7] = 2.0;
>  start[3]=5; index[5] = 1; value[8] = 5.0;
>  start[4]=6;
>  // row bounds
>  rowlb[0] = 2.; rowub[0] = 2.;
>     rowlb[1] = 2.; rowub[1] = 2.;
>  solver1.loadProblem(numcols, numrows, start, index, value, collb, colub,
> obj, rowlb, rowub);
>  solver1.setInteger(0); // Sets x0 to integer
>  solver1.setInteger(1); // Sets x1 to integer
>  solver1.setInteger(2); // Sets x2 to integer
>  solver1.setInteger(3); // Sets x3 to integer
>  solver1.setObjSense(-1000.0); // Maximise
>  CbcModel solver(solver1);
>  solver.branchAndBound();
>  bool optimal = solver.isProvenOptimal();
>  const double *val = solver.getColSolution();
>  printf("Solution %g %g %g %g\n", val[0], val[1], val[2], val[3]);
>  return 0;
> }
>
>        I can't get the result. Would you please tell me how to solve
> them?Thank you very much!
>
> _______________________________________________
> Cbc mailing list
> Cbc at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/cbc
>
>


-- 
*Ivan Meireles Costa*
*Estágiario em otimização*
 *Telefone:* 31 3508-1323
 *Celular:* 31 9869-6987
   A Gapso é a escolha das empresas que buscam se diferenciar pela gestão
da complexidade.
Desenvolvemos sistemas analíticos de planejamento, que auxiliam a definir
estratégias,
planejar operações, reduzir riscos e lidar melhor com as incertezas do
futuro.
www.gapso.com.br
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cbc/attachments/20121002/d8499ceb/attachment.html>


More information about the Cbc mailing list