Changeset 500
 Timestamp:
 Dec 8, 2006 3:31:14 PM (13 years ago)
 Location:
 branches/devel/Cbc/src
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

branches/devel/Cbc/src/CbcLinked.cpp
r497 r500 392 392 int numberColumns = quadraticModel_>numberColumns(); 393 393 double * gradient = new double [numberColumns+1]; 394 memcpy(gradient,quadraticModel_>objectiveAsObject()>gradient(quadraticModel_,bestSolution_,offset,true,2), 395 numberColumns*sizeof(double)); 394 // gradient from bilinear 395 int i; 396 CoinZeroN(gradient,numberColumns+1); 397 //const double * objective = modelPtr_>objective(); 398 assert (objectiveRow_>=0); 399 const double * element = originalRowCopy_>getElements(); 400 const int * column2 = originalRowCopy_>getIndices(); 401 const CoinBigIndex * rowStart = originalRowCopy_>getVectorStarts(); 402 //const int * rowLength = originalRowCopy_>getVectorLengths(); 403 //int numberColumns2 = coinModel_.numberColumns(); 404 for ( i=rowStart[objectiveRow_];i<rowStart[objectiveRow_+1];i++) 405 gradient[column2[i]] = element[i]; 406 for ( i =0;i<numberObjects_;i++) { 407 OsiBiLinear * obj = dynamic_cast<OsiBiLinear *> (object_[i]); 408 if (obj) { 409 int xColumn = obj>xColumn(); 410 int yColumn = obj>yColumn(); 411 if (xColumn!=yColumn) { 412 double coefficient = 2.0*obj>coefficient(); 413 gradient[xColumn] += coefficient*solution[yColumn]; 414 gradient[yColumn] += coefficient*solution[xColumn]; 415 offset += coefficient*solution[xColumn]*solution[yColumn]; 416 } else { 417 double coefficient = obj>coefficient(); 418 gradient[xColumn] += 2.0*coefficient*solution[yColumn]; 419 offset += coefficient*solution[xColumn]*solution[yColumn]; 420 } 421 } 422 } 396 423 // assume convex 397 424 double rhs = 0.0; … … 545 572 int numberColumns = quadraticModel_>numberColumns(); 546 573 double * gradient = new double [numberColumns+1]; 547 // for testing do gradient from bilinear 548 if (false) { 549 int i; 550 double offset=0.0; 551 CoinZeroN(gradient,numberColumns+1); 552 const double * objective = modelPtr_>objective(); 553 int numberColumns2 = coinModel_.numberColumns(); 554 for ( i=0;i<numberColumns2;i++) 555 gradient[i] = objective[i]; 556 for ( i =0;i<numberObjects_;i++) { 557 OsiBiLinear * obj = dynamic_cast<OsiBiLinear *> (object_[i]); 558 if (obj) { 559 int xColumn = obj>xColumn(); 560 int yColumn = obj>yColumn(); 561 double coefficient = obj>coefficient(); 562 assert (obj>xyRow()<0); // objective 574 // gradient from bilinear 575 int i; 576 CoinZeroN(gradient,numberColumns+1); 577 //const double * objective = modelPtr_>objective(); 578 assert (objectiveRow_>=0); 579 const double * element = originalRowCopy_>getElements(); 580 const int * column2 = originalRowCopy_>getIndices(); 581 const CoinBigIndex * rowStart = originalRowCopy_>getVectorStarts(); 582 //const int * rowLength = originalRowCopy_>getVectorLengths(); 583 //int numberColumns2 = coinModel_.numberColumns(); 584 for ( i=rowStart[objectiveRow_];i<rowStart[objectiveRow_+1];i++) 585 gradient[column2[i]] = element[i]; 586 for ( i =0;i<numberObjects_;i++) { 587 OsiBiLinear * obj = dynamic_cast<OsiBiLinear *> (object_[i]); 588 if (obj) { 589 int xColumn = obj>xColumn(); 590 int yColumn = obj>yColumn(); 591 if (xColumn!=yColumn) { 592 double coefficient = 2.0*obj>coefficient(); 563 593 gradient[xColumn] += coefficient*solution[yColumn]; 564 594 gradient[yColumn] += coefficient*solution[xColumn]; 565 595 offset += coefficient*solution[xColumn]*solution[yColumn]; 596 } else { 597 double coefficient = obj>coefficient(); 598 gradient[xColumn] += 2.0*coefficient*solution[yColumn]; 599 offset += coefficient*solution[xColumn]*solution[yColumn]; 566 600 } 567 601 } 568 printf("what about offset %g\n",offset);569 602 } 570 memcpy(gradient,quadraticModel_>objectiveAsObject()>gradient(quadraticModel_,solution,offset,true,2),571 numberColumns*sizeof(double));572 603 // assume convex 573 604 double rhs = 0.0; … … 1205 1236 info_[i] = OsiLinkedBound(this,which[i],0,NULL,NULL,NULL); 1206 1237 } 1238 // Do row copy but just part 1239 int numberRows2 = objectiveRow_>=0 ? numberRows+1 : numberRows; 1240 int * whichRows = new int [numberRows2]; 1241 int * whichColumns = new int [numberColumns]; 1242 CoinIotaN(whichRows,numberRows2,0); 1243 CoinIotaN(whichColumns,numberColumns,0); 1244 originalRowCopy_ = new CoinPackedMatrix(*getMatrixByRow(), 1245 numberRows2,whichRows, 1246 numberColumns,whichColumns); 1247 delete [] whichRows; 1248 delete [] whichColumns; 1207 1249 } 1208 1250 } … … 1320 1362 if (!justNullify) { 1321 1363 delete matrix_; 1364 delete originalRowCopy_; 1322 1365 delete [] info_; 1323 1366 delete [] bestSolution_; … … 1325 1368 } 1326 1369 matrix_ = NULL; 1370 originalRowCopy_ = NULL; 1327 1371 quadraticModel_ = NULL; 1328 1372 cbcModel_ = NULL; … … 1358 1402 else 1359 1403 matrix_=NULL; 1404 if (rhs.originalRowCopy_) 1405 originalRowCopy_ = new CoinPackedMatrix(*rhs.originalRowCopy_); 1406 else 1407 originalRowCopy_=NULL; 1360 1408 info_ = new OsiLinkedBound [numberVariables_]; 1361 1409 for (int i=0;i<numberVariables_;i++) { 
branches/devel/Cbc/src/CbcLinked.hpp
r493 r500 116 116 CoinPackedMatrix * cleanMatrix() const 117 117 { return matrix_;}; 118 /** Row copy of matrix 119 Just genuine columns and rows 120 Linear part 121 */ 122 CoinPackedMatrix * originalRowCopy() const 123 { return originalRowCopy_;}; 118 124 /// Copy of quadratic model if one 119 125 ClpSimplex * quadraticModel() const … … 167 173 */ 168 174 CoinPackedMatrix * matrix_; 175 /** Row copy of matrix 176 Just genuine columns and rows 177 */ 178 CoinPackedMatrix * originalRowCopy_; 169 179 /// Copy of quadratic model if one 170 180 ClpSimplex * quadraticModel_;
Note: See TracChangeset
for help on using the changeset viewer.