Changeset 1153 for trunk/Clp/examples
 Timestamp:
 Jan 18, 2008 10:50:10 AM (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Clp/examples/addRows.cpp
r560 r1153 143 143 printf("Time for 10000 addRow using CoinModel is %g\n",CoinCpuTime()time1); 144 144 model.dual(); 145 model.writeMps("b.mps"); 146 // Method using least memory  but most complicated 147 time1 = CoinCpuTime(); 148 // Assumes we know exact size of model and matrix 149 // Empty model 150 ClpSimplex model2; 151 { 152 // Create space for 3 columns and 10000 rows 153 int numberRows=10000; 154 int numberColumns=3; 155 // This is fully dense  but would not normally be so 156 int numberElements = numberRows*numberColumns; 157 // Arrays will be set to default values 158 model2.resize(numberRows,numberColumns); 159 double * elements = new double [numberElements]; 160 CoinBigIndex * starts = new CoinBigIndex [numberColumns+1]; 161 int * rows = new int [numberElements];; 162 int * lengths = new int[numberColumns]; 163 // Now fill in  totally unsafe but .... 164 // no need as defaults to 0.0 double * columnLower = model2.columnLower(); 165 double * columnUpper = model2.columnUpper(); 166 double * objective = model2.objective(); 167 double * rowLower = model2.rowLower(); 168 double * rowUpper = model2.rowUpper(); 169 // Columns  objective was packed 170 for (k=0;k<2;k++) { 171 int iColumn = objIndex[k]; 172 objective[iColumn]=objValue[k]; 173 } 174 for (k=0;k<numberColumns;k++) 175 columnUpper[k]=upper[k]; 176 // Rows 177 for (k=0;k<numberRows;k++) { 178 rowLower[k]=1.0; 179 rowUpper[k]=1.0; 180 } 181 // Now elements 182 double row2Value[]={1.0,5.0,1.0}; 183 CoinBigIndex put=0; 184 for (k=0;k<numberColumns;k++) { 185 starts[k]=put; 186 lengths[k]=numberRows; 187 double value=row2Value[k]; 188 for (int i=0;i<numberRows;i++) { 189 rows[put]=i; 190 elements[put]=value; 191 put++; 192 } 193 } 194 starts[numberColumns]=put; 195 // assign to matrix 196 CoinPackedMatrix * matrix = new CoinPackedMatrix(true,0.0,0.0); 197 matrix>assignMatrix(true,numberRows,numberColumns,numberElements, 198 elements,rows,starts,lengths); 199 ClpPackedMatrix * clpMatrix = new ClpPackedMatrix(matrix); 200 model2.replaceMatrix(clpMatrix,true); 201 printf("Time for 10000 addRow using hand written code is %g\n",CoinCpuTime()time1); 202 // If matrix is really big could switch off creation of row copy 203 // model2.setSpecialOptions(256); 204 } 205 model2.dual(); 206 model2.writeMps("a.mps"); 145 207 // Print column solution 146 208 int numberColumns = model.numberColumns();
Note: See TracChangeset
for help on using the changeset viewer.