[Cbc] please help me
刘峰
liufengaarr at gmail.com
Wed Sep 19 03:45:28 EDT 2012
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!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cbc/attachments/20120919/fd164885/attachment.html>
More information about the Cbc
mailing list