Changeset 1752 for stable/2.7/Cbc/src/CbcSolverExpandKnapsack.cpp
 Timestamp:
 Oct 31, 2011 7:34:55 PM (8 years ago)
 Location:
 stable/2.7/Cbc
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

stable/2.7/Cbc
 Property svn:mergeinfo changed
/trunk/Cbc merged: 17501751
 Property svn:mergeinfo changed

stable/2.7/Cbc/src/CbcSolverExpandKnapsack.cpp
r1573 r1752 528 528 529 529 530 // Fills in original solution (coinModel length) 531 void 532 afterKnapsack(const CoinModel & coinModel2, const int * whichColumn, const int * knapsackStart, 533 const int * knapsackRow, int numberKnapsack, 534 const double * knapsackSolution, double * solution, int logLevel) 535 { 536 CoinModel coinModel = coinModel2; 537 int numberColumns = coinModel.numberColumns(); 538 int iColumn; 539 // associate all columns to stop possible error messages 540 for (iColumn=0;iColumn<numberColumns;iColumn++) { 541 coinModel.associateElement(coinModel.columnName(iColumn),1.0); 542 } 543 CoinZeroN(solution,numberColumns); 544 int nCol=knapsackStart[0]; 545 for (iColumn=0;iColumn<nCol;iColumn++) { 546 int jColumn = whichColumn[iColumn]; 547 solution[jColumn]=knapsackSolution[iColumn]; 548 } 549 int * buildRow = new int [numberColumns]; // wild overkill 550 double * buildElement = new double [numberColumns]; 551 int iKnapsack; 552 for (iKnapsack=0;iKnapsack<numberKnapsack;iKnapsack++) { 553 int k=1; 554 double value=0.0; 555 for (iColumn=knapsackStart[iKnapsack];iColumn<knapsackStart[iKnapsack+1];iColumn++) { 556 if (knapsackSolution[iColumn]>1.0e5) { 557 if (k>=0) { 558 printf("Two nonzero values for knapsack %d at (%d,%g) and (%d,%g)\n",iKnapsack, 559 k,knapsackSolution[k],iColumn,knapsackSolution[iColumn]); 560 abort(); 561 } 562 k=iColumn; 563 value=floor(knapsackSolution[iColumn]+0.5); 564 assert (fabs(valueknapsackSolution[iColumn])<1.0e5); 565 } 566 } 567 if (k>=0) { 568 int iRow = knapsackRow[iKnapsack]; 569 int nCreate = 10000; 570 int nel=coinModel.expandKnapsack(iRow,nCreate,NULL,NULL,buildRow,buildElement,kknapsackStart[iKnapsack]); 571 assert (nel); 572 if (logLevel>0) 573 printf("expanded column %d in knapsack %d has %d nonzero entries:\n", 574 kknapsackStart[iKnapsack],iKnapsack,nel); 575 for (int i=0;i<nel;i++) { 576 int jColumn = buildRow[i]; 577 double value = buildElement[i]; 578 if (logLevel>0) 579 printf("%d  original %d has value %g\n",i,jColumn,value); 580 solution[jColumn]=value; 581 } 582 } 583 } 584 delete [] buildRow; 585 delete [] buildElement; 586 #if 0 587 for (iColumn=0;iColumn<numberColumns;iColumn++) { 588 if (solution[iColumn]>1.0e5&&coinModel.isInteger(iColumn)) 589 printf("%d %g\n",iColumn,solution[iColumn]); 590 } 591 #endif 592 }
Note: See TracChangeset
for help on using the changeset viewer.