Changeset 1552 for trunk/Clp/examples/modify.cpp
 Timestamp:
 May 24, 2010 9:03:59 PM (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Clp/examples/modify.cpp
r1370 r1552 10 10 int main (int argc, const char *argv[]) 11 11 { 12 ClpSimplex model; 13 // model is as exmip1.mps from Data/samples 14 int numberRows=5; 15 int numberColumns=8; 16 int numberElements=14; 17 // matrix data  column ordered 18 CoinBigIndex start[9]={0,2,4,6,8,10,11,12,14}; 19 int length[8]={2,2,2,2,2,1,1,2}; 20 int rows[14]={0,4,0,1,1,2,0,3,0,4,2,3,0,4}; 21 double elements[14]={3,5.6,1,2,1.1,1,2,2.8,1,1,1,1.2,1,1.9}; 22 CoinPackedMatrix matrix(true,numberRows,numberColumns,numberElements,elements,rows,start,length); 23 24 // rim data 25 double objective[8]={1,0,0,0,2,0,0,1}; 26 double rowLower[5]={2.5,COIN_DBL_MAX,4,1.8,3}; 27 double rowUpper[5]={COIN_DBL_MAX,2.1,4,5,15}; 28 double colLower[8]={2.5,0,0,0,0.5,0,0,0}; 29 double colUpper[8]={COIN_DBL_MAX,4.1,1,1,4,COIN_DBL_MAX,COIN_DBL_MAX,4.3}; 30 // load problem 31 model.loadProblem(matrix,colLower,colUpper,objective, 32 rowLower,rowUpper); 33 // mark integer (really for Cbc/examples/modify.cpp 34 model.setInteger(2); 35 model.setInteger(3); 12 ClpSimplex model; 13 // model is as exmip1.mps from Data/samples 14 int numberRows = 5; 15 int numberColumns = 8; 16 int numberElements = 14; 17 // matrix data  column ordered 18 CoinBigIndex start[9] = {0, 2, 4, 6, 8, 10, 11, 12, 14}; 19 int length[8] = {2, 2, 2, 2, 2, 1, 1, 2}; 20 int rows[14] = {0, 4, 0, 1, 1, 2, 0, 3, 0, 4, 2, 3, 0, 4}; 21 double elements[14] = {3, 5.6, 1, 2, 1.1, 1, 2, 2.8, 1, 1, 1, 1.2, 1, 1.9}; 22 CoinPackedMatrix matrix(true, numberRows, numberColumns, numberElements, elements, rows, start, length); 36 23 37 // Solve 38 model.initialSolve(); 24 // rim data 25 double objective[8] = {1, 0, 0, 0, 2, 0, 0, 1}; 26 double rowLower[5] = {2.5, COIN_DBL_MAX, 4, 1.8, 3}; 27 double rowUpper[5] = {COIN_DBL_MAX, 2.1, 4, 5, 15}; 28 double colLower[8] = {2.5, 0, 0, 0, 0.5, 0, 0, 0}; 29 double colUpper[8] = {COIN_DBL_MAX, 4.1, 1, 1, 4, COIN_DBL_MAX, COIN_DBL_MAX, 4.3}; 30 // load problem 31 model.loadProblem(matrix, colLower, colUpper, objective, 32 rowLower, rowUpper); 33 // mark integer (really for Cbc/examples/modify.cpp 34 model.setInteger(2); 35 model.setInteger(3); 39 36 40 // Solution 41 const double * solution = model.primalColumnSolution(); 42 int i; 43 for (i=0;i<numberColumns;i++) 44 if (solution[i]) 45 printf("Column %d has value %g\n",i,solution[i]); 37 // Solve 38 model.initialSolve(); 46 39 47 // Change objective 48 double * objective2 = model.objective(); 49 objective2[0]=100.0; 40 // Solution 41 const double * solution = model.primalColumnSolution(); 42 int i; 43 for (i = 0; i < numberColumns; i++) 44 if (solution[i]) 45 printf("Column %d has value %g\n", i, solution[i]); 50 46 51 // Solve  primal as primal feasible 52 model.primal(1); 47 // Change objective 48 double * objective2 = model.objective(); 49 objective2[0] = 100.0; 53 50 54 // Solution (array won't have changed) 55 for (i=0;i<numberColumns;i++) 56 if (solution[i]) 57 printf("Column %d has value %g\n",i,solution[i]); 51 // Solve  primal as primal feasible 52 model.primal(1); 58 53 59 // Add constraint60 int column[8]={0,1,2,3,4,5,6,7};61 double element2[8] ={1,1,1,1,1,1,1,1};62 model.addRow(8,column,element2,7.8,COIN_DBL_MAX);54 // Solution (array won't have changed) 55 for (i = 0; i < numberColumns; i++) 56 if (solution[i]) 57 printf("Column %d has value %g\n", i, solution[i]); 63 58 64 // Solve  dual as dual feasible 65 model.dual(); 59 // Add constraint 60 int column[8] = {0, 1, 2, 3, 4, 5, 6, 7}; 61 double element2[8] = {1, 1, 1, 1, 1, 1, 1, 1}; 62 model.addRow(8, column, element2, 7.8, COIN_DBL_MAX); 66 63 67 /* Solution 68 This time we have changed arrays of solver so  69 array won't have changed as column array and we added a row 70  but be on safe side 71 */ 72 solution = model.primalColumnSolution(); 73 for (i=0;i<numberColumns;i++) 74 if (solution[i]) 75 printf("Column %d has value %g\n",i,solution[i]); 64 // Solve  dual as dual feasible 65 model.dual(); 76 66 77 return 0; 78 } 67 /* Solution 68 This time we have changed arrays of solver so  69 array won't have changed as column array and we added a row 70  but be on safe side 71 */ 72 solution = model.primalColumnSolution(); 73 for (i = 0; i < numberColumns; i++) 74 if (solution[i]) 75 printf("Column %d has value %g\n", i, solution[i]); 76 77 return 0; 78 }
Note: See TracChangeset
for help on using the changeset viewer.