Changeset 687 for trunk/Cbc/src/CbcHeuristicFPump.cpp
 Timestamp:
 Jul 15, 2007 5:28:33 PM (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Cbc/src/CbcHeuristicFPump.cpp
r640 r687 175 175 double * betterSolution) 176 176 { 177 #define LEN_PRINT 132 178 char pumpPrint[LEN_PRINT]; 179 pumpPrint[0]='\0'; 177 180 if (!when()(when()==1&&model_>phase()!=1)) 178 181 return 0; // switched off … … 364 367 } 365 368 if (maximumTime_>0.0&&CoinCpuTime()>=startTime_+maximumTime_) break; 366 numberPasses++;367 369 memcpy(newSolution,solution,numberColumns*sizeof(double)); 368 370 int flip; 369 returnCode = rounds(solver,newSolution,saveObjective,numberIntegers,integerVariable, 370 roundExpensive_,defaultRounding_,&flip); 371 returnCode = rounds(solver, newSolution,saveObjective,numberIntegers,integerVariable, 372 pumpPrint,numberPasses,roundExpensive_,defaultRounding_,&flip); 373 numberPasses++; 371 374 if (returnCode) { 372 375 // SOLUTION IS INTEGER … … 382 385 newSolutionValue += saveObjective[i]*newSolution[i]; 383 386 newSolutionValue *= direction; 384 if (model_>logLevel()) 385 printf("  solution found of %g",newSolutionValue); 387 sprintf(pumpPrint+strlen(pumpPrint),"  solution found of %g",newSolutionValue); 386 388 newLineNeeded=false; 387 389 if (newSolutionValue<solutionValue) { … … 416 418 solutionFound=true; 417 419 if (general&&saveValue!=newSolutionValue) 418 printf("  cleaned solution of %g\n",solutionValue); 419 else 420 printf("\n"); 420 sprintf(pumpPrint+strlen(pumpPrint),"  cleaned solution of %g",solutionValue); 421 if (pumpPrint[0]!='\0') 422 model_>messageHandler()>message(CBC_FPUMP1,model_>messages()) 423 << pumpPrint 424 <<CoinMessageEol; 425 pumpPrint[0]='\0'; 421 426 } else { 422 if (model_>logLevel()) 423 printf("  not good enough after small branch and bound\n"); 427 sprintf(pumpPrint+strlen(pumpPrint),"  not good enough after mini branch and bound"); 428 model_>messageHandler()>message(CBC_FPUMP1,model_>messages()) 429 << pumpPrint 430 <<CoinMessageEol; 431 pumpPrint[0]='\0'; 424 432 } 425 433 } else { 426 if (model_>logLevel()) 427 printf("  not good enough\n"); 434 sprintf(pumpPrint+strlen(pumpPrint),"  not good enough"); 435 model_>messageHandler()>message(CBC_FPUMP1,model_>messages()) 436 << pumpPrint 437 <<CoinMessageEol; 438 pumpPrint[0]='\0'; 428 439 newLineNeeded=false; 429 440 returnCode=0; … … 448 459 if (matched  numberPasses%100 == 0) { 449 460 // perturbation 450 if (model_>logLevel()) 451 printf("Perturbation applied"); 461 sprintf(pumpPrint+strlen(pumpPrint)," perturbation applied"); 452 462 newLineNeeded=true; 453 463 for (i=0;i<numberIntegers;i++) { … … 531 541 memcpy(newSolution,solution,numberColumns*sizeof(double)); 532 542 int flip; 533 returnCode = rounds(solver,newSolution,saveObjective,numberIntegers,integerVariable, 534 roundExpensive_,defaultRounding_,&flip); 543 returnCode = rounds(solver, newSolution,saveObjective,numberIntegers,integerVariable, 544 pumpPrint,numberPasses,roundExpensive_,defaultRounding_,&flip); 545 numberPasses++; 535 546 if (returnCode) { 536 547 // solution  but may not be better … … 540 551 newSolutionValue += saveObjective[i]*newSolution[i]; 541 552 newSolutionValue *= direction; 542 if (model_>logLevel()) 543 printf("  intermediate solution found of %g",newSolutionValue); 553 sprintf(pumpPrint+strlen(pumpPrint),"  intermediate solution found of %g",newSolutionValue); 544 554 if (newSolutionValue<solutionValue) { 545 555 memcpy(betterSolution,newSolution,numberColumns*sizeof(double)); … … 636 646 } 637 647 } 638 if (model_>logLevel()) 639 printf("\npass %3d: obj. %10.5f > ", numberPasses+totalNumberPasses,solver>getObjValue()); 648 if (pumpPrint[0]!='\0') 649 model_>messageHandler()>message(CBC_FPUMP1,model_>messages()) 650 << pumpPrint 651 <<CoinMessageEol; 652 pumpPrint[0]='\0'; 653 sprintf(pumpPrint+strlen(pumpPrint),"Pass %3d: obj. %10.5f > ", numberPasses+totalNumberPasses,solver>getObjValue()); 640 654 if (closestSolution&&solver>getObjValue()<closestObjectiveValue) { 641 655 int i; … … 656 670 scaleFactor *= weightFactor_; 657 671 } // END WHILE 658 if (newLineNeeded&&model_>logLevel()) 659 printf("  no solution found\n"); 672 if (!solutionFound) { 673 sprintf(pumpPrint+strlen(pumpPrint),"No solution found this major pass"); 674 model_>messageHandler()>message(CBC_FPUMP1,model_>messages()) 675 << pumpPrint 676 <<CoinMessageEol; 677 pumpPrint[0]='\0'; 678 } 660 679 delete solver; 661 680 for ( j=0;j<NUMBER_OLD;j++) … … 724 743 newSolver>initialSolve(); 725 744 if (!newSolver>isProvenOptimal()) { 726 newSolver>writeMps("bad.mps");745 //newSolver>writeMps("bad.mps"); 727 746 assert (newSolver>isProvenOptimal()); 728 747 break; 729 748 } 730 printf("%d integers at bound fixed and %d continuous",749 sprintf(pumpPrint+strlen(pumpPrint),"Before mini branch and bound, %d integers at bound fixed and %d continuous", 731 750 nFix,nFixC); 732 if (nFixC2+nFixI==0) 733 printf("\n"); 734 else 735 printf(" of which %d were internal integer and %d internal continuous\n", 736 nFixI,nFixC2); 751 if (nFixC2+nFixI!=0) 752 sprintf(pumpPrint+strlen(pumpPrint)," of which %d were internal integer and %d internal continuous", 753 nFixI,nFixC2); 754 model_>messageHandler()>message(CBC_FPUMP1,model_>messages()) 755 << pumpPrint 756 <<CoinMessageEol; 757 pumpPrint[0]='\0'; 737 758 double saveValue = newSolutionValue; 738 759 returnCode = smallBranchAndBound(newSolver,numberNodes_,newSolution,newSolutionValue, 739 newSolutionValue,"CbcHeuristicLocalAfterFPump");760 cutoff,"CbcHeuristicLocalAfterFPump"); 740 761 if ((returnCode&2)!=0) { 741 762 // could add cut … … 743 764 } 744 765 if (returnCode) { 745 printf("old sol of %g new of %g\n",saveValue,newSolutionValue); 766 sprintf(pumpPrint+strlen(pumpPrint),"Mini branch and bound improved solution from %g to %g",saveValue,newSolutionValue); 767 model_>messageHandler()>message(CBC_FPUMP1,model_>messages()) 768 << pumpPrint 769 <<CoinMessageEol; 770 pumpPrint[0]='\0'; 746 771 memcpy(betterSolution,newSolution,numberColumns*sizeof(double)); 747 772 if (fixContinuous) { … … 763 788 double value = newSolver>getObjValue()*newSolver>getObjSense(); 764 789 if (value<newSolutionValue) { 765 printf("freeing continuous gives a solution of %g\n", value); 790 sprintf(pumpPrint+strlen(pumpPrint),"Freeing continuous variables gives a solution of %g", value); 791 model_>messageHandler()>message(CBC_FPUMP1,model_>messages()) 792 << pumpPrint 793 <<CoinMessageEol; 794 pumpPrint[0]='\0'; 766 795 newSolutionValue=value; 767 796 memcpy(betterSolution,newSolver>getColSolution(),numberColumns*sizeof(double)); 768 797 } 769 798 } else { 770 newSolver>writeMps("bad3.mps");799 //newSolver>writeMps("bad3.mps"); 771 800 } 772 801 } … … 786 815 double gap = relativeIncrement_*fabs(solutionValue); 787 816 cutoff = CoinMax(CoinMax(gap,absoluteIncrement_),model_>getCutoffIncrement()); 788 printf("round again with cutoff of %g\n",cutoff); 817 sprintf(pumpPrint+strlen(pumpPrint),"Round again with cutoff of %g",cutoff); 818 model_>messageHandler()>message(CBC_FPUMP1,model_>messages()) 819 << pumpPrint 820 <<CoinMessageEol; 821 pumpPrint[0]='\0'; 789 822 if ((accumulate_&3)<2&&usedColumn) 790 823 memset(usedColumn,0,numberColumns); 791 totalNumberPasses += numberPasses ;824 totalNumberPasses += numberPasses1; 792 825 } else { 793 826 break; … … 817 850 newSolver>addRow(numberIntegersOrig,closestSolution, 818 851 lastSolution,COIN_DBL_MAX,rhs+10.0); 819 double saveValue = newSolutionValue;852 //double saveValue = newSolutionValue; 820 853 //newSolver>writeMps("sub"); 821 854 int returnCode = smallBranchAndBound(newSolver,numberNodes_,newSolution,newSolutionValue, … … 857 890 const double * objective, 858 891 int numberIntegers, const int * integerVariable, 892 char * pumpPrint, int & iter, 859 893 bool roundExpensive, double downValue, int *flip) 860 894 { … … 865 899 int i; 866 900 867 static int iter = 0;868 901 int numberColumns = model_>getNumCols(); 869 902 // tmp contains the current obj coefficients … … 905 938 906 939 if (nnv > nn) nnv = nn; 907 if (iter != 0 &&model_>logLevel())908 printf("up = %5d , down = %5d", flip_up, flip_down); fflush(stdout);940 if (iter != 0) 941 sprintf(pumpPrint+strlen(pumpPrint),"up = %5d , down = %5d", flip_up, flip_down); 909 942 *flip = flip_up + flip_down; 910 943 delete [] tmp; … … 913 946 const double * columnUpper = solver>getColUpper(); 914 947 if (*flip == 0 && iter != 0) { 915 if(model_>logLevel()) 916 printf("  rand = %4d (%4d) ", nnv, nn); 948 sprintf(pumpPrint+strlen(pumpPrint),"  rand = %4d (%4d) ", nnv, nn); 917 949 for (i = 0; i < nnv; i++) { 918 950 // was solution[list[i]] = 1.  solution[list[i]]; but does that work for 7>=x>=6 … … 930 962 } 931 963 *flip = nnv; 932 } else if (model_>logLevel()){933 printf(" ");964 } else { 965 //sprintf(pumpPrint+strlen(pumpPrint)," "); 934 966 } 935 967 delete [] list; delete [] val; 936 iter++;968 //iter++; 937 969 938 970 const double * rowLower = solver>getRowLower();
Note: See TracChangeset
for help on using the changeset viewer.