Changeset 1883 for stable/2.8/Cbc/src/CbcModel.cpp
 Timestamp:
 Apr 6, 2013 9:33:15 AM (7 years ago)
 Location:
 stable/2.8/Cbc
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

stable/2.8/Cbc
 Property svn:mergeinfo changed
/trunk/Cbc merged: 18761877,18801882
 Property svn:mergeinfo changed

stable/2.8/Cbc/src/CbcModel.cpp
r1879 r1883 24 24 #include <cmath> 25 25 #include <cfloat> 26 27 26 #ifdef COIN_HAS_CLP 28 27 // include Presolve from Clp … … 447 446 if (!numberContinuousObj && numberIntegerObj <= 5 && numberIntegerWeight <= 100 && 448 447 numberIntegerObj*3 < numberObjects_ && !parentModel_ && solver_>getNumRows() > 100) 449 iType = 3 + 4;448 iType = 1 + 4 + ((moreSpecialOptions_&536870912)==0) ? 2 : 0; 450 449 else if (!numberContinuousObj && numberIntegerObj <= 100 && 451 450 numberIntegerObj*5 < numberObjects_ && numberIntegerWeight <= 100 && 452 451 !parentModel_ && 453 452 solver_>getNumRows() > 100 && cost != COIN_DBL_MAX) 454 iType = 2 + 4;453 iType = 4 + ((moreSpecialOptions_&536870912)==0) ? 2 : 0; 455 454 else if (!numberContinuousObj && numberIntegerObj <= 100 && 456 455 numberIntegerObj*5 < numberObjects_ && … … 511 510 << general << CoinMessageEol ; 512 511 // switch off clp type branching 513 fastNodeDepth_ = 1;512 // no ? fastNodeDepth_ = 1; 514 513 int highPriority = (branchOnSatisfied) ? 999 : 100; 515 514 for (int i = 0; i < numberObjects_; i++) { … … 1072 1071 messages()) 1073 1072 << value << CoinMessageEol ; 1074 setDblParam(CbcModel::CbcCutoffIncrement, value*0.999) ;1073 setDblParam(CbcModel::CbcCutoffIncrement, CoinMax(value*0.999,value1.0e4)) ; 1075 1074 } 1076 1075 } … … 1596 1595 1597 1596 { 1597 if (!parentModel_) 1598 1598 /* 1599 1599 Capture a time stamp before we start (unless set). … … 1674 1674 // preprocessing done 1675 1675 if (strategy_>preProcessState() < 0) { 1676 // infeasible 1677 handler_>message(CBC_INFEAS, messages_) << CoinMessageEol ; 1676 // infeasible (or unbounded) 1678 1677 status_ = 0 ; 1679 secondaryStatus_ = 1; 1678 if (!solver_>isProvenDualInfeasible()) { 1679 handler_>message(CBC_INFEAS, messages_) << CoinMessageEol ; 1680 secondaryStatus_ = 1; 1681 } else { 1682 handler_>message(CBC_UNBOUNDED, 1683 messages_) << CoinMessageEol ; 1684 secondaryStatus_ = 7; 1685 } 1680 1686 originalContinuousObjective_ = COIN_DBL_MAX; 1681 1687 if (flipObjective) … … 2153 2159 handler_>message(CBC_HEURISTICS_OFF, messages_) << numberOdd << CoinMessageEol ; 2154 2160 } 2161 // If odd switch off AddIntegers 2162 specialOptions_ &= ~65536; 2155 2163 } else if (numberSOS) { 2156 2164 specialOptions_ = 128; // say can do SOS in dynamic mode 2157 2165 // switch off fast nodes for now 2158 2166 fastNodeDepth_ = 1; 2167 moreSpecialOptions_ &= ~33554432; // no diving 2159 2168 } 2160 2169 if (numberThreads_ > 0) { … … 2225 2234 2226 2235 // add cutoff as constraint if wanted 2227 if ( (moreSpecialOptions_&16777216)!=0) {2236 if (cutoffRowNumber_==2) { 2228 2237 if (!parentModel_) { 2229 2238 int numberColumns=solver_>getNumCols(); … … 2239 2248 if (n) { 2240 2249 double cutoff=getCutoff(); 2250 // relax a little bit 2251 cutoff += 1.0e4; 2241 2252 double offset; 2242 2253 solver_>getDblParam(OsiObjOffset, offset); 2254 cutoffRowNumber_ = solver_>getNumRows(); 2243 2255 solver_>addRow(n,indices,obj,COIN_DBL_MAX,CoinMin(cutoff,1.0e25)+offset); 2244 2256 } else { 2245 2257 // no objective! 2246 moreSpecialOptions_ &= ~16777216;2258 cutoffRowNumber_ = 1; 2247 2259 } 2248 2260 delete [] indices; … … 2250 2262 } else { 2251 2263 // switch off 2252 moreSpecialOptions_ &= ~16777216;2264 cutoffRowNumber_ = 1; 2253 2265 } 2254 2266 } … … 2487 2499 } 2488 2500 CoinWarmStartBasis * basis = dynamic_cast<CoinWarmStartBasis *> (solver_>getEmptyWarmStart()); 2501 int numberIterations=0; 2489 2502 for (int i=0;i<numberModels;i++) { 2490 2503 rootModels[i]=new CbcModel(*this); … … 2496 2509 // use seed 2497 2510 rootModels[i]>setSpecialOptions(specialOptions_ (41943048388608)); 2511 rootModels[i]>setMoreSpecialOptions(moreSpecialOptions_ & 2512 (~134217728)); 2498 2513 rootModels[i]>solver_>setWarmStart(basis); 2499 2514 #ifdef COIN_HAS_CLP … … 2501 2516 = dynamic_cast<OsiClpSolverInterface *> (rootModels[i]>solver_); 2502 2517 if (clpSolver) { 2503 clpSolver>getModelPtr()>setRandomSeed(newSeed+20000000*i); 2504 clpSolver>getModelPtr()>allSlackBasis(); 2518 ClpSimplex * simplex = clpSolver>getModelPtr(); 2519 if (defaultHandler_) 2520 simplex>setDefaultMessageHandler(); 2521 simplex>setRandomSeed(newSeed+20000000*i); 2522 simplex>allSlackBasis(); 2523 int logLevel=simplex>logLevel(); 2524 if (logLevel==1) 2525 simplex>setLogLevel(0); 2526 if (i!=0) { 2527 double random = simplex>randomNumberGenerator()>randomDouble(); 2528 int bias = static_cast<int>(random*(numberIterations/4)); 2529 simplex>setMaximumIterations(numberIterations/2+bias); 2530 simplex>primal(); 2531 simplex>setMaximumIterations(COIN_INT_MAX); 2532 simplex>dual(); 2533 } else { 2534 simplex>primal(); 2535 numberIterations=simplex>numberIterations(); 2536 } 2537 simplex>setLogLevel(logLevel); 2538 clpSolver>setWarmStart(NULL); 2505 2539 } 2506 2540 #endif 2541 for (int j=0;j<numberHeuristics_;j++) 2542 rootModels[i]>heuristic_[j]>setSeed(rootModels[i]>heuristic_[j]>getSeed()+100000000*i); 2543 for (int j=0;j<numberCutGenerators_;j++) 2544 rootModels[i]>generator_[j]>generator()>refreshSolver(rootModels[i]>solver_); 2507 2545 } 2508 2546 delete basis; … … 2661 2699 } 2662 2700 // replace solverType 2701 double * tightBounds = NULL; 2663 2702 if (solverCharacteristics_>tryCuts()) { 2664 2703 … … 2667 2706 if (!eventHappened_ && feasible) { 2668 2707 if (rootModels) { 2708 // for fixings 2709 int numberColumns=solver_>getNumCols(); 2710 tightBounds = new double [2*numberColumns]; 2711 { 2712 const double * lower = solver_>getColLower(); 2713 const double * upper = solver_>getColUpper(); 2714 for (int i=0;i<numberColumns;i++) { 2715 tightBounds[2*i+0]=lower[i]; 2716 tightBounds[2*i+1]=upper[i]; 2717 } 2718 } 2669 2719 int numberModels = multipleRootTries_%100; 2670 2720 const OsiSolverInterface ** solvers = new … … 2674 2724 for (int i=0;i<numberModels;i++) { 2675 2725 solvers[i]=rootModels[i]>solver(); 2726 const double * lower = solvers[i]>getColLower(); 2727 const double * upper = solvers[i]>getColUpper(); 2728 for (int j=0;j<numberColumns;j++) { 2729 tightBounds[2*j+0]=CoinMax(lower[j],tightBounds[2*j+0]); 2730 tightBounds[2*j+1]=CoinMin(upper[j],tightBounds[2*j+1]); 2731 } 2676 2732 int numberRows2=solvers[i]>getNumRows(); 2677 2733 assert (numberRows2>=numberRows); … … 2685 2741 generator_[j]>scaleBackStatistics(numberModels); 2686 2742 } 2687 CbcRowCuts rowCut(maxCuts); 2743 //CbcRowCuts rowCut(maxCuts); 2744 const OsiRowCutDebugger *debugger = NULL; 2745 if ((specialOptions_&1) != 0) 2746 debugger = solver_>getRowCutDebugger() ; 2688 2747 for (int iModel=0;iModel<numberModels;iModel++) { 2689 2748 int numberRows2=solvers[iModel]>getNumRows(); … … 2701 2760 CoinBigIndex start = rowStart[iRow]; 2702 2761 rc.setRow(rowLength[iRow],column+start,elements+start,false); 2703 rowCut.addCutIfNotDuplicate(rc); 2762 if (debugger) 2763 CoinAssert (!debugger>invalidCut(rc)); 2764 globalCuts_.addCutIfNotDuplicate(rc); 2704 2765 } 2705 //int cutsAdded= rowCut.numberCuts()numberCuts;2766 //int cutsAdded=globalCuts_.numberCuts()numberCuts; 2706 2767 //numberCuts += cutsAdded; 2707 2768 //printf("Model %d gave %d cuts (out of %d possible)\n", 2708 2769 // iModel,cutsAdded,numberRows2numberRows); 2709 2770 } 2710 rowCut.addCuts(cuts); 2771 // normally replace global cuts 2772 //if (!globalCuts_.()) 2773 //globalCuts_=rowCutrowCut.addCuts(globalCuts_); 2774 //rowCut.addCuts(globalCuts_); 2775 int nTightened=0; 2776 bool feasible=true; 2777 { 2778 double tolerance=1.0e5; 2779 const double * lower = solver_>getColLower(); 2780 const double * upper = solver_>getColUpper(); 2781 for (int i=0;i<numberColumns;i++) { 2782 if (tightBounds[2*i+0]>tightBounds[2*i+1]) { 2783 feasible=false; 2784 printf("Bad bounds on %d %g,%g was %g,%g\n", 2785 i,tightBounds[2*i+0],tightBounds[2*i+1], 2786 lower[i],upper[i]); 2787 } 2788 //int k=0; 2789 double oldLower=lower[i]; 2790 double oldUpper=upper[i]; 2791 if (tightBounds[2*i+0]>oldLower+tolerance) { 2792 nTightened++; 2793 //k++; 2794 solver_>setColLower(i,tightBounds[2*i+0]); 2795 } 2796 if (tightBounds[2*i+1]<oldUppertolerance) { 2797 nTightened++; 2798 //k++; 2799 solver_>setColUpper(i,tightBounds[2*i+1]); 2800 } 2801 //if (k) 2802 //printf("new bounds on %d %g,%g was %g,%g\n", 2803 // i,tightBounds[2*i+0],tightBounds[2*i+1], 2804 // oldLower,oldUpper); 2805 } 2806 if (!feasible) 2807 abort(); // deal with later 2808 } 2809 delete [] tightBounds; 2810 tightBounds=NULL; 2711 2811 char printBuffer[200]; 2712 2812 sprintf(printBuffer,"%d solvers added %d different cuts out of pool of %d", 2713 numberModels, cuts.sizeRowCuts(),maxCuts);2813 numberModels,globalCuts_.sizeRowCuts(),maxCuts); 2714 2814 messageHandler()>message(CBC_GENERAL, messages()) 2715 2815 << printBuffer << CoinMessageEol ; 2816 if (nTightened) { 2817 sprintf(printBuffer,"%d bounds were tightened", 2818 nTightened); 2819 messageHandler()>message(CBC_GENERAL, messages()) 2820 << printBuffer << CoinMessageEol ; 2821 } 2716 2822 delete [] solvers; 2823 } 2824 if (!parentModel_&&(moreSpecialOptions_&67108864) != 0) { 2825 // load cuts from file 2826 FILE * fp = fopen("global.cuts","rb"); 2827 if (fp) { 2828 size_t nRead; 2829 int numberColumns=solver_>getNumCols(); 2830 int numCols; 2831 nRead = fread(&numCols, sizeof(int), 1, fp); 2832 if (nRead != 1) 2833 throw("Error in fread"); 2834 if (numberColumns!=numCols) { 2835 printf("Mismatch on columns %d %d\n",numberColumns,numCols); 2836 fclose(fp); 2837 } else { 2838 // If rootModel just do some 2839 double threshold=1.0; 2840 if (!multipleRootTries_) 2841 threshold=0.5; 2842 int initialCuts=0; 2843 int initialGlobal = globalCuts_.sizeRowCuts(); 2844 double * elements = new double [numberColumns+2]; 2845 int * indices = new int [numberColumns]; 2846 int numberEntries=1; 2847 while (numberEntries>0) { 2848 nRead = fread(&numberEntries, sizeof(int), 1, fp); 2849 if (nRead != 1) 2850 throw("Error in fread"); 2851 double randomNumber=randomNumberGenerator_.randomDouble(); 2852 if (numberEntries>0) { 2853 initialCuts++; 2854 nRead = fread(elements, sizeof(double), numberEntries+2, fp); 2855 if (nRead != static_cast<size_t>(numberEntries+2)) 2856 throw("Error in fread"); 2857 nRead = fread(indices, sizeof(int), numberEntries, fp); 2858 if (nRead != static_cast<size_t>(numberEntries)) 2859 throw("Error in fread"); 2860 if (randomNumber>threshold) { 2861 OsiRowCut rc; 2862 rc.setLb(elements[numberEntries]); 2863 rc.setUb(elements[numberEntries+1]); 2864 rc.setRow(numberEntries,indices,elements, 2865 false); 2866 rc.setGloballyValidAsInteger(2); 2867 globalCuts_.addCutIfNotDuplicate(rc) ; 2868 } 2869 } 2870 } 2871 fclose(fp); 2872 // fixes 2873 int nTightened=0; 2874 fp = fopen("global.fix","rb"); 2875 if (fp) { 2876 nRead = fread(indices, sizeof(int), 2, fp); 2877 if (nRead != 2) 2878 throw("Error in fread"); 2879 if (numberColumns!=indices[0]) { 2880 printf("Mismatch on columns %d %d\n",numberColumns, 2881 indices[0]); 2882 } else { 2883 indices[0]=1; 2884 while (indices[0]>=0) { 2885 nRead = fread(indices, sizeof(int), 2, fp); 2886 if (nRead != 2) 2887 throw("Error in fread"); 2888 int iColumn=indices[0]; 2889 if (iColumn>=0) { 2890 nTightened++; 2891 nRead = fread(elements, sizeof(double), 4, fp); 2892 if (nRead != 4) 2893 throw("Error in fread"); 2894 solver_>setColLower(iColumn,elements[0]); 2895 solver_>setColUpper(iColumn,elements[1]); 2896 } 2897 } 2898 } 2899 } 2900 if (fp) 2901 fclose(fp); 2902 char printBuffer[200]; 2903 sprintf(printBuffer,"%d cuts read in of which %d were unique, %d bounds tightened", 2904 initialCuts, 2905 globalCuts_.sizeRowCuts()initialGlobal,nTightened); 2906 messageHandler()>message(CBC_GENERAL, messages()) 2907 << printBuffer << CoinMessageEol ; 2908 delete [] elements; 2909 delete [] indices; 2910 } 2911 } 2717 2912 } 2718 2913 feasible = solveWithCuts(cuts, maximumCutPassesAtRoot_, 2719 2914 NULL); 2915 if (multipleRootTries_&& 2916 (moreSpecialOptions_&134217728)!=0) { 2917 FILE * fp=NULL; 2918 size_t nRead; 2919 int numberColumns=solver_>getNumCols(); 2920 int initialCuts=0; 2921 if ((moreSpecialOptions_&134217728)!=0) { 2922 // append so go down to end 2923 fp = fopen("global.cuts","r+b"); 2924 if (fp) { 2925 int numCols; 2926 nRead = fread(&numCols, sizeof(int), 1, fp); 2927 if (nRead != 1) 2928 throw("Error in fread"); 2929 if (numberColumns!=numCols) { 2930 printf("Mismatch on columns %d %d\n",numberColumns,numCols); 2931 fclose(fp); 2932 fp=NULL; 2933 } 2934 } 2935 } 2936 double * elements = new double [numberColumns+2]; 2937 int * indices = new int [numberColumns]; 2938 if (fp) { 2939 int numberEntries=1; 2940 while (numberEntries>0) { 2941 fpos_t position; 2942 fgetpos(fp, &position); 2943 nRead = fread(&numberEntries, sizeof(int), 1, fp); 2944 if (nRead != 1) 2945 throw("Error in fread"); 2946 if (numberEntries>0) { 2947 initialCuts++; 2948 nRead = fread(elements, sizeof(double), numberEntries+2, fp); 2949 if (nRead != static_cast<size_t>(numberEntries+2)) 2950 throw("Error in fread"); 2951 nRead = fread(indices, sizeof(int), numberEntries, fp); 2952 if (nRead != static_cast<size_t>(numberEntries)) 2953 throw("Error in fread"); 2954 } else { 2955 // end 2956 fsetpos(fp, &position); 2957 } 2958 } 2959 } else { 2960 fp = fopen("global.cuts","wb"); 2961 size_t nWrite; 2962 nWrite=fwrite(&numberColumns,sizeof(int),1,fp); 2963 if (nWrite != 1) 2964 throw("Error in fwrite"); 2965 } 2966 size_t nWrite; 2967 // now append binding cuts 2968 int numberC=continuousSolver_>getNumRows(); 2969 int numberRows=solver_>getNumRows(); 2970 printf("Saving %d cuts (up from %d)\n", 2971 initialCuts+numberRowsnumberC,initialCuts); 2972 const double * rowLower = solver_>getRowLower(); 2973 const double * rowUpper = solver_>getRowUpper(); 2974 // Row copy 2975 CoinPackedMatrix matrixByRow(*solver_>getMatrixByRow()); 2976 const double * elementByRow = matrixByRow.getElements(); 2977 const int * column = matrixByRow.getIndices(); 2978 const CoinBigIndex * rowStart = matrixByRow.getVectorStarts(); 2979 const int * rowLength = matrixByRow.getVectorLengths(); 2980 for (int iRow=numberC;iRow<numberRows;iRow++) { 2981 int n=rowLength[iRow]; 2982 assert (n); 2983 CoinBigIndex start=rowStart[iRow]; 2984 memcpy(elements,elementByRow+start,n*sizeof(double)); 2985 memcpy(indices,column+start,n*sizeof(int)); 2986 elements[n]=rowLower[iRow]; 2987 elements[n+1]=rowUpper[iRow]; 2988 nWrite=fwrite(&n,sizeof(int),1,fp); 2989 if (nWrite != 1) 2990 throw("Error in fwrite"); 2991 nWrite=fwrite(elements,sizeof(double),n+2,fp); 2992 if (nWrite != static_cast<size_t>(n+2)) 2993 throw("Error in fwrite"); 2994 nWrite=fwrite(indices,sizeof(int),n,fp); 2995 if (nWrite != static_cast<size_t>(n)) 2996 throw("Error in fwrite"); 2997 } 2998 // eof marker 2999 int eofMarker=1; 3000 nWrite=fwrite(&eofMarker,sizeof(int),1,fp); 3001 if (nWrite != 1) 3002 throw("Error in fwrite"); 3003 fclose(fp); 3004 // do tighter bounds (? later extra to original columns) 3005 int nTightened=0; 3006 const double * lower = solver_>getColLower(); 3007 const double * upper = solver_>getColUpper(); 3008 const double * originalLower = continuousSolver_>getColLower(); 3009 const double * originalUpper = continuousSolver_>getColUpper(); 3010 double tolerance=1.0e5; 3011 for (int i=0;i<numberColumns;i++) { 3012 if (lower[i]>originalLower[i]+tolerance) { 3013 nTightened++; 3014 } 3015 if (upper[i]<originalUpper[i]tolerance) { 3016 nTightened++; 3017 } 3018 } 3019 if (nTightened) { 3020 fp = fopen("global.fix","wb"); 3021 size_t nWrite; 3022 indices[0]=numberColumns; 3023 if (originalColumns_) 3024 indices[1]=COIN_INT_MAX; 3025 else 3026 indices[1]=1; 3027 nWrite=fwrite(indices,sizeof(int),2,fp); 3028 if (nWrite != 2) 3029 throw("Error in fwrite"); 3030 for (int i=0;i<numberColumns;i++) { 3031 int nTightened=0; 3032 if (lower[i]>originalLower[i]+tolerance) { 3033 nTightened++; 3034 } 3035 if (upper[i]<originalUpper[i]tolerance) { 3036 nTightened++; 3037 } 3038 if (nTightened) { 3039 indices[0]=i; 3040 if (originalColumns_) 3041 indices[1]=originalColumns_[i]; 3042 elements[0]=lower[i]; 3043 elements[1]=upper[i]; 3044 elements[2]=originalLower[i]; 3045 elements[3]=originalUpper[i]; 3046 nWrite=fwrite(indices,sizeof(int),2,fp); 3047 if (nWrite != 2) 3048 throw("Error in fwrite"); 3049 nWrite=fwrite(elements,sizeof(double),4,fp); 3050 if (nWrite != 4) 3051 throw("Error in fwrite"); 3052 } 3053 } 3054 // eof marker 3055 indices[0]=1; 3056 nWrite=fwrite(indices,sizeof(int),2,fp); 3057 if (nWrite != 2) 3058 throw("Error in fwrite"); 3059 fclose(fp); 3060 } 3061 delete [] elements; 3062 delete [] indices; 3063 } 2720 3064 if ((specialOptions_&524288) != 0 && !parentModel_ 2721 3065 && storedRowCuts_) { … … 2974 3318 } 2975 3319 #endif 3320 if (!parentModel_&&(moreSpecialOptions_&268435456) != 0) { 3321 // try idiotic idea 3322 CbcObject * obj = new CbcIdiotBranch(this); 3323 obj>setPriority(1); // temp 3324 addObjects(1, &obj); 3325 delete obj; 3326 } 3327 2976 3328 /* 2977 3329 A hook to use clp to quickly explore some part of the tree. … … 2983 3335 obj>setPriority(1); 2984 3336 addObjects(1, &obj); 3337 delete obj; 2985 3338 } 2986 3339 int saveNumberSolves = numberSolves_; 2987 3340 int saveNumberIterations = numberIterations_; 2988 if (fastNodeDepth_ >= 0 &&/*!parentModel_*/(specialOptions_&2048) == 0) { 3341 if ((fastNodeDepth_ >= 0(moreSpecialOptions_&33554432)!=0) 3342 &&/*!parentModel_*/(specialOptions_&2048) == 0) { 2989 3343 // add in a general depth object doClp 2990 3344 int type = (fastNodeDepth_ <= 100) ? fastNodeDepth_ : (fastNodeDepth_  100); 3345 if ((moreSpecialOptions_&33554432)!=0) 3346 type=12; 3347 else 3348 fastNodeDepth_ += 1000000; // mark as done 2991 3349 CbcObject * obj = 2992 3350 new CbcGeneralDepth(this, type); 2993 3351 addObjects(1, &obj); 2994 // mark as done2995 fastNodeDepth_ += 1000000;2996 3352 delete obj; 2997 3353 // fake number of objects … … 3695 4051 Decide if we want to do a restart. 3696 4052 */ 3697 if (saveSolver ) {4053 if (saveSolver && (specialOptions_&(512 + 32768)) != 0) { 3698 4054 bool tryNewSearch = solverCharacteristics_>reducedCostsAccurate() && 3699 4055 (getCutoff() < 1.0e20 && getCutoff() < checkCutoffForRestart); … … 4050 4406 if (!node  node>objectiveValue() > cutoff) 4051 4407 continue; 4052 4053 4408 // Do main work of solving node here 4409 doOneNode(this, node, createdNode); 4054 4410 #ifdef JJF_ZERO 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4411 if (node) { 4412 if (createdNode) { 4413 printf("Node %d depth %d, created %d depth %d\n", 4414 node>nodeNumber(), node>depth(), 4415 createdNode>nodeNumber(), createdNode>depth()); 4416 } else { 4417 printf("Node %d depth %d, no created node\n", 4418 node>nodeNumber(), node>depth()); 4419 } 4420 } else if (createdNode) { 4421 printf("Node exhausted, created %d depth %d\n", 4422 createdNode>nodeNumber(), createdNode>depth()); 4423 } else { 4424 printf("Node exhausted, no created node\n"); 4425 numberConsecutiveInfeasible = 2; 4426 } 4071 4427 #endif 4072 4428 //if (createdNode) … … 4451 4807 setCutoff(1.0e50) ; // As best solution should be worse than cutoff 4452 4808 // change cutoff as constraint if wanted 4453 if ( (moreSpecialOptions_&16777216)!=0) {4454 if (solver_>getNumRows()> =numberRowsAtContinuous_)4455 solver_>setRowUpper( numberRowsAtContinuous_1,1.0e50);4809 if (cutoffRowNumber_>=0) { 4810 if (solver_>getNumRows()>cutoffRowNumber_) 4811 solver_>setRowUpper(cutoffRowNumber_,1.0e50); 4456 4812 } 4457 4813 // also in continuousSolver_ … … 4516 4872 delete globalConflictCuts_; 4517 4873 globalConflictCuts_=NULL; 4518 if (!bestSolution_ ) {4874 if (!bestSolution_ && (specialOptions_&8388608)==0) { 4519 4875 // make sure lp solver is infeasible 4520 4876 int numberColumns = solver_>getNumCols(); … … 4543 4899 } 4544 4900 #endif 4545 if (fastNodeDepth_ >= 1000000 && !parentModel_) { 4546 // delete object off end 4547 delete object_[numberObjects_]; 4901 if ((fastNodeDepth_ >= 1000000  (moreSpecialOptions_&33554432)!=0) 4902 && !parentModel_) { 4903 // delete object off end 4904 delete object_[numberObjects_]; 4905 if ((moreSpecialOptions_&33554432)==0) 4548 4906 fastNodeDepth_ = 1000000; 4549 4907 } … … 4726 5084 numberIntegers_(0), 4727 5085 numberRowsAtContinuous_(0), 5086 cutoffRowNumber_(1), 4728 5087 maximumNumberCuts_(0), 4729 5088 phase_(0), … … 4773 5132 ownObjects_(true), 4774 5133 originalColumns_(NULL), 4775 howOftenGlobalScan_( 1),5134 howOftenGlobalScan_(3), 4776 5135 numberGlobalViolations_(0), 4777 5136 numberExtraIterations_(0), … … 4892 5251 secondaryStatus_(1), 4893 5252 numberRowsAtContinuous_(0), 5253 cutoffRowNumber_(1), 4894 5254 maximumNumberCuts_(0), 4895 5255 phase_(0), … … 4936 5296 ownObjects_(true), 4937 5297 originalColumns_(NULL), 4938 howOftenGlobalScan_( 1),5298 howOftenGlobalScan_(3), 4939 5299 numberGlobalViolations_(0), 4940 5300 numberExtraIterations_(0), … … 5063 5423 } 5064 5424 5425 static int * resizeInt(int * array,int oldLength, int newLength) 5426 { 5427 if (!array) 5428 return NULL; 5429 assert (newLength>oldLength); 5430 int * newArray = new int [newLength]; 5431 memcpy(newArray,array,oldLength*sizeof(int)); 5432 delete [] array; 5433 memset(newArray+oldLength,0,(newLengtholdLength)*sizeof(int)); 5434 return newArray; 5435 } 5436 static double * resizeDouble(double * array,int oldLength, int newLength) 5437 { 5438 if (!array) 5439 return NULL; 5440 assert (newLength>oldLength); 5441 double * newArray = new double [newLength]; 5442 memcpy(newArray,array,oldLength*sizeof(double)); 5443 delete [] array; 5444 memset(newArray+oldLength,0,(newLengtholdLength)*sizeof(double)); 5445 return newArray; 5446 } 5065 5447 /* 5066 5448 Assign a solver to the model (model assumes ownership) … … 5086 5468 5087 5469 { 5088 // resize best solutionif exists5089 if ( bestSolution_ &&solver && solver_) {5470 // resize stuff if exists 5471 if (solver && solver_) { 5090 5472 int nOld = solver_>getNumCols(); 5091 5473 int nNew = solver>getNumCols(); 5092 5474 if (nNew > nOld) { 5093 double * temp = new double[nNew]; 5094 memcpy(temp, bestSolution_, nOld*sizeof(double)); 5095 memset(temp + nOld, 0, (nNew  nOld)*sizeof(double)); 5096 delete [] bestSolution_; 5097 bestSolution_ = temp; 5475 originalColumns_ = resizeInt(originalColumns_,nOld,nNew); 5476 usedInSolution_ = resizeInt(usedInSolution_,nOld,nNew); 5477 continuousSolution_ = resizeDouble(continuousSolution_,nOld,nNew); 5478 hotstartSolution_ = resizeDouble(hotstartSolution_,nOld,nNew); 5479 bestSolution_ = resizeDouble(bestSolution_,nOld,nNew); 5480 currentSolution_ = resizeDouble(currentSolution_,nOld,nNew); 5481 if (savedSolutions_) { 5482 for (int i = 0; i < maximumSavedSolutions_; i++) 5483 savedSolutions_[i] = resizeDouble(savedSolutions_[i],nOld,nNew); 5484 } 5098 5485 } 5099 5486 } … … 5386 5773 testSolution_ = currentSolution_; 5387 5774 numberRowsAtContinuous_ = rhs.numberRowsAtContinuous_; 5775 cutoffRowNumber_ = rhs.cutoffRowNumber_; 5388 5776 maximumNumberCuts_ = rhs.maximumNumberCuts_; 5389 5777 phase_ = rhs.phase_; … … 5713 6101 } 5714 6102 numberRowsAtContinuous_ = rhs.numberRowsAtContinuous_; 6103 cutoffRowNumber_ = rhs.cutoffRowNumber_; 5715 6104 maximumNumberCuts_ = rhs.maximumNumberCuts_; 5716 6105 phase_ = rhs.phase_; … … 6005 6394 int i; 6006 6395 for (i = 0; i < numberCutGenerators_; i++) { 6007 if (mode < 2) 6396 if (mode < 2) { 6008 6397 generator_[i] = new CbcCutGenerator(*rhs.generator_[i]); 6009 else 6398 } else { 6010 6399 generator_[i] = new CbcCutGenerator(*rhs.virginGenerator_[i]); 6400 // But copy across maximumTries 6401 generator_[i]>setMaximumTries(rhs.generator_[i]>maximumTries()); 6402 } 6011 6403 virginGenerator_[i] = new CbcCutGenerator(*rhs.virginGenerator_[i]); 6012 6404 } … … 6070 6462 strongInfo_[6] = rhs.strongInfo_[6]; 6071 6463 numberRowsAtContinuous_ = rhs.numberRowsAtContinuous_; 6464 cutoffRowNumber_ = rhs.cutoffRowNumber_; 6072 6465 maximumDepth_ = rhs.maximumDepth_; 6073 6466 } … … 6259 6652 heuristic_[where]>setHeuristicName(name) ; 6260 6653 heuristic_[where]>setSeed(987654321 + where); 6261 if (randomSeed_!=1)6262 heuristic_[where]>setSeed(randomSeed_);6263 6654 numberHeuristics_++ ; 6264 6655 } … … 6286 6677 { 6287 6678 int nNode = 0; 6679 CbcNodeInfo * nodeInfo = node>nodeInfo(); 6288 6680 int numberColumns = getNumCols(); 6289 CbcNodeInfo * nodeInfo = node>nodeInfo();6290 6681 6291 6682 /* … … 6543 6934 # endif 6544 6935 addCuts[numberToAdd++] = addedCuts_[i]; 6936 #if 1 6937 if ((specialOptions_&1) != 0) { 6938 const OsiRowCutDebugger * debugger = solver_>getRowCutDebugger() ; 6939 if (debugger) 6940 CoinAssert (!debugger>invalidCut(*addedCuts_[i])); 6941 } 6942 #endif 6545 6943 } else { 6546 6944 # ifdef CHECK_CUT_COUNTS … … 6650 7048 delete [] which; 6651 7049 } 7050 //#define CHECK_DEBUGGER 7051 #ifdef CHECK_DEBUGGER 7052 if ((specialOptions_&1) != 0 ) { 7053 const OsiRowCutDebugger * debugger = 7054 solver_>getRowCutDebugger(); 7055 if (debugger) { 7056 for (int j=0;j<numberToAdd;j++) 7057 CoinAssert (!debugger>invalidCut(*addCuts[j])); 7058 //addCuts[j]>print(); 7059 } 7060 } 7061 #endif 6652 7062 //int n2=solver_>getNumRows(); 6653 7063 //for (int j=0;j<numberToAdd;j++) … … 6707 7117 CbcModel::synchronizeHandlers(int /*makeDefault*/) 6708 7118 { 7119 bool defaultHandler = defaultHandler_; 6709 7120 if (!defaultHandler_) { 6710 7121 // Must have clone … … 6713 7124 } 6714 7125 #ifdef COIN_HAS_CLP 6715 OsiClpSolverInterface * solver; 6716 solver = dynamic_cast<OsiClpSolverInterface *>(solver_) ; 6717 if (solver) { 7126 if (!defaultHandler) { 7127 OsiClpSolverInterface * solver; 7128 solver = dynamic_cast<OsiClpSolverInterface *>(solver_) ; 7129 if (solver) { 6718 7130 solver>passInMessageHandler(handler_); 6719 7131 solver>getModelPtr()>passInMessageHandler(handler_); 6720 }6721 solver = dynamic_cast<OsiClpSolverInterface *>(continuousSolver_) ;6722 if (solver) {7132 } 7133 solver = dynamic_cast<OsiClpSolverInterface *>(continuousSolver_) ; 7134 if (solver) { 6723 7135 solver>passInMessageHandler(handler_); 6724 7136 solver>getModelPtr()>passInMessageHandler(handler_); 7137 } 6725 7138 } 6726 7139 #endif … … 6985 7398 if ((specialOptions_&1) != 0) { 6986 7399 debugger = continuousSolver_>getRowCutDebugger() ; 6987 if (debugger) 7400 if (debugger) { 6988 7401 if (debugger>invalidCut(*cut)) { 6989 7402 continuousSolver_>applyRowCuts(1,cut); … … 6991 7404 } 6992 7405 CoinAssert (!debugger>invalidCut(*cut)); 7406 } 6993 7407 } 6994 7408 } else { … … 7272 7686 allowZeroIterations = true; 7273 7687 } 7688 int saveNumberTries=numberTries; 7274 7689 /* 7275 7690 Is it time to scan the cuts in order to remove redundant cuts? If so, set … … 7290 7705 // Really primalIntegerTolerance; relates to an illposed problem with various 7291 7706 // integer solutions depending on integer tolerance. 7292 double primalTolerance = 1.0e7 ;7707 //double primalTolerance = 1.0e7 ; 7293 7708 // We may need to keep going on 7294 7709 bool keepGoing = false; … … 7340 7755 */ 7341 7756 int numberViolated = 0; 7342 if ( currentPassNumber_ == 1&& howOftenGlobalScan_ > 0 &&7757 if ((currentPassNumber_ == 1 !numberNodes_) && howOftenGlobalScan_ > 0 && 7343 7758 (numberNodes_ % howOftenGlobalScan_) == 0 && 7344 7759 (doCutsNow(1)  true)) { 7345 7760 // global column cuts now done in node at top of tree 7346 int numberCuts = globalCuts_.sizeRowCuts() ; 7347 // possibly extend whichGenerator 7348 resizeWhichGenerator(numberViolated, numberViolated + numberCuts); 7349 for (int i = 0; i < numberCuts; i++) { 7761 int numberCuts = numberCutGenerators_ ? globalCuts_.sizeRowCuts() : 0; 7762 if (numberCuts) { 7763 // possibly extend whichGenerator 7764 resizeWhichGenerator(numberViolated, numberViolated + numberCuts); 7765 // only add new cuts up to 10% of current elements 7766 int numberElements = solver_>getNumElements(); 7767 int numberColumns = solver_>getNumCols(); 7768 int maximumAdd = CoinMax(numberElements/10,2*numberColumns)+100; 7769 double * violations = new double[numberCuts]; 7770 int * which = new int[numberCuts]; 7771 int numberPossible=0; 7772 for (int i = 0; i < numberCuts; i++) { 7350 7773 OsiRowCut * thisCut = globalCuts_.rowCutPtr(i) ; 7351 if (thisCut>violated(cbcColSolution_) > primalTolerance  7352 thisCut>effectiveness() == COIN_DBL_MAX) { 7774 double violation = thisCut>violated(cbcColSolution_); 7775 if(thisCut>effectiveness() == COIN_DBL_MAX) { 7776 // see if already there 7777 int j; 7778 for (j = 0; j < currentNumberCuts_; j++) { 7779 if (addedCuts_[j]==thisCut) 7780 break; 7781 } 7782 if (j==currentNumberCuts_) 7783 violation = COIN_DBL_MAX; 7784 //else 7785 //printf("already done??\n"); 7786 } 7787 if (violation > 0.005) { 7788 violations[numberPossible]=violation; 7789 which[numberPossible++]=i; 7790 } 7791 } 7792 CoinSort_2(violations,violations+numberPossible,which); 7793 for (int i = 0; i < numberPossible; i++) { 7794 int k=which[i]; 7795 OsiRowCut * thisCut = globalCuts_.rowCutPtr(k) ; 7796 assert (thisCut>violated(cbcColSolution_) > 0.005/*primalTolerance*/  7797 thisCut>effectiveness() == COIN_DBL_MAX); 7798 #define CHECK_DEBUGGER 7799 #ifdef CHECK_DEBUGGER 7800 if ((specialOptions_&1) != 0 ) { 7801 const OsiRowCutDebugger * debugger = 7802 solver_>getRowCutDebuggerAlways(); 7803 CoinAssert (!debugger>invalidCut(*thisCut)); 7804 } 7805 #endif 7353 7806 #if 0 //ndef NDEBUG 7354 7355 7356 #endif 7357 7807 printf("Global cut added  violation %g\n", 7808 thisCut>violated(cbcColSolution_)) ; 7809 #endif 7810 whichGenerator_[numberViolated++] = 1; 7358 7811 #ifndef GLOBAL_CUTS_JUST_POINTERS 7359 7812 theseCuts.insert(*thisCut) ; 7360 7813 #else 7361 theseCuts.insert(thisCut) ; 7362 #endif 7363 } 7364 } 7365 numberGlobalViolations_ += numberViolated; 7814 theseCuts.insert(thisCut) ; 7815 #endif 7816 if (violations[i]!=COIN_DBL_MAX) 7817 maximumAdd = thisCut>row().getNumElements(); 7818 if (maximumAdd<0) 7819 break; 7820 } 7821 delete [] which; 7822 delete [] violations; 7823 numberGlobalViolations_ += numberViolated; 7824 } 7366 7825 } 7367 7826 /* … … 7719 8178 //solver_>setHintParam(OsiDoDualInResolve,true,OsiHintTry); 7720 8179 if ( maximumSecondsReached() ) { 7721 numberTries = 0; // exit8180 numberTries = 1000; // exit 7722 8181 feasible = false; 7723 8182 break; … … 7877 8336 // maybe give it one more try 7878 8337 if (numberLastAttempts > 2  currentDepth_  experimentBreak < 2) 7879 break;8338 numberTries=0 ; 7880 8339 else 7881 8340 numberLastAttempts++; … … 7911 8370 keepGoing=false; 7912 8371 } 7913 if (numberTries <=0 && feasible && !keepGoing && !parentModel_ && !numberNodes_) {8372 if (numberTries ==0 && feasible && !keepGoing && !parentModel_ && !numberNodes_) { 7914 8373 for (int i = 0; i < numberCutGenerators_; i++) { 7915 8374 if (generator_[i]>whetherCallAtEnd() 7916 8375 &&!generator_[i]>whetherInMustCallAgainMode()) { 7917 keepGoing= true; 7918 break; 8376 // give it some goes and switch off 8377 numberTries=(saveNumberTries+4)/5; 8378 generator_[i]>setWhetherCallAtEnd(false); 7919 8379 } 7920 8380 } … … 7986 8446 } 7987 8447 if (!feasible) { //node will be fathomed 8448 lockThread(); 7988 8449 for (int i = 0; i < currentNumberCuts_; i++) { 7989 8450 // take off node … … 7994 8455 } 7995 8456 } 8457 unlockThread(); 7996 8458 } 7997 8459 } … … 8137 8599 */ 8138 8600 if (!numberNodes_) { 8601 if (!parentModel_) { 8602 //printf("%d global cuts\n",globalCuts_.sizeRowCuts()) ; 8603 if ((specialOptions_&1) != 0) { 8604 //specialOptions_ &= ~1; 8605 int numberCuts = globalCuts_.sizeRowCuts(); 8606 const OsiRowCutDebugger *debugger = 8607 continuousSolver_>getRowCutDebugger() ; 8608 if (debugger) { 8609 for (int i = 0; i < numberCuts; i++) { 8610 OsiRowCut * cut = globalCuts_.rowCutPtr(i) ; 8611 if (debugger>invalidCut(*cut)) { 8612 continuousSolver_>applyRowCuts(1,cut); 8613 continuousSolver_>writeMps("bad"); 8614 printf("BAD cut\n"); 8615 } 8616 //CoinAssert (!debugger>invalidCut(*cut)); 8617 } 8618 } 8619 } 8620 } 8139 8621 //solver_>writeMps("second"); 8140 8622 if (numberRowsAdded) … … 8285 8767 willBeCutsInTree = 0; 8286 8768 } 8287 if (!numberNodes_) 8769 if (!numberNodes_) { 8288 8770 handler_>message(CBC_ROOT, messages_) 8289 8771 << numberNewCuts_ … … 8291 8773 << currentPassNumber_ 8292 8774 << CoinMessageEol ; 8775 } 8293 8776 /* 8294 8777 Count the number of cuts produced by each cut generator on this call. Not … … 8401 8884 howOften = 99; // switch off 8402 8885 } 8886 if (generator_[i]>maximumTries()!=1) 8887 howOften = 99; // switch off 8403 8888 /* 8404 8889 Below 99, this generator is switched off. There's no need to consider 8405 8890 further. Then again, there was no point in persisting this far! 8406 8891 */ 8407 if (howOften < 99) 8408 continue ; 8892 if (howOften < 99) { 8893 // may have been switched off  report 8894 if (!numberNodes_) { 8895 int n = generator_[i]>numberCutsInTotal(); 8896 if (n) { 8897 double average = 0.0; 8898 average = generator_[i]>numberElementsInTotal(); 8899 average /= n; 8900 handler_>message(CBC_GENERATOR, messages_) 8901 << i 8902 << generator_[i]>cutGeneratorName() 8903 << n 8904 << average 8905 << generator_[i]>numberColumnCuts() 8906 << generator_[i]>numberCutsActive() 8907 + generator_[i]>numberColumnCuts(); 8908 handler_>printing(generator_[i]>timing()) 8909 << generator_[i]>timeInCutGenerator(); 8910 handler_>message() 8911 << 100 8912 << CoinMessageEol ; 8913 } 8914 } 8915 continue ; 8916 } 8409 8917 /* 8410 8918 Adjust, if howOften is adjustable. … … 8728 9236 specialOptions_ &= ~256; // mark as full scan done 8729 9237 } 8730 # ifdef COIN_HAS_CLP 8731 if (!node && !parentModel_ && intParam_[CbcMaxNumNode] == 123456) { 8732 OsiClpSolverInterface * clpSolver 8733 = dynamic_cast<OsiClpSolverInterface *> (solver_); 8734 if (clpSolver) { 8735 clpSolver>lexSolve(); 8736 } 9238 # if 0 //def COIN_HAS_CLP 9239 // check basis 9240 OsiClpSolverInterface * clpSolver 9241 = dynamic_cast<OsiClpSolverInterface *> (solver_); 9242 if (clpSolver) { 9243 ClpSimplex * simplex = clpSolver>getModelPtr(); 9244 int numberTotal=simplex>numberRows()+simplex>numberColumns(); 9245 int superbasic=0; 9246 for (int i=0;i<numberTotal;i++) { 9247 if (simplex>getStatus(i)==ClpSimplex::superBasic) 9248 superbasic++; 9249 } 9250 if (superbasic) { 9251 printf("%d superbasic!\n",superbasic); 9252 clpSolver>resolve(); 9253 superbasic=0; 9254 for (int i=0;i<numberTotal;i++) { 9255 if (simplex>getStatus(i)==ClpSimplex::superBasic) 9256 superbasic++; 9257 } 9258 assert (!superbasic); 9259 } 8737 9260 } 8738 9261 # endif … … 8762 9285 } 8763 9286 } 9287 if (generator_[i]>whetherCallAtEnd()) 9288 generate=false; 8764 9289 const OsiRowCutDebugger * debugger = NULL; 8765 9290 bool onOptimalPath = false; … … 8896 9421 if (thisCut>lb() > thisCut>ub()) 8897 9422 status = 1; // subproblem is infeasible 8898 if (thisCut>globallyValid() ) {9423 if (thisCut>globallyValid()!numberNodes_) { 8899 9424 // add to global list 8900 9425 OsiRowCut newCut(*thisCut); … … 9221 9746 } 9222 9747 } 9223 #ifdef COIN_HAS_CLP9748 #ifdef COIN_HAS_CLP 9224 9749 OsiClpSolverInterface * clpSolver 9225 9750 = dynamic_cast<OsiClpSolverInterface *> (solver_); … … 10513 11038 int n = CoinMax(obj2>numberTimesDown(), 10514 11039 obj2>numberTimesUp()); 10515 if (n >= value) 10516 obj2>setNumberBeforeTrust(n + 1); 11040 if (n >= value) { 11041 value = CoinMin(CoinMin(n+1,3*(value+1)/2),5*numberBeforeTrust_); 11042 obj2>setNumberBeforeTrust(value); 11043 } 10517 11044 } 10518 11045 } … … 11451 11978 setCutoff(cutoff); 11452 11979 // change cutoff as constraint if wanted 11453 if ( (moreSpecialOptions_&16777216)!=0) {11454 if (solver_>getNumRows()> =numberRowsAtContinuous_) {11980 if (cutoffRowNumber_>=0) { 11981 if (solver_>getNumRows()>cutoffRowNumber_) { 11455 11982 double offset; 11456 11983 solver_>getDblParam(OsiObjOffset, offset); 11457 solver_>setRowUpper( numberRowsAtContinuous_1,cutoff+offset);11984 solver_>setRowUpper(cutoffRowNumber_,cutoff+offset); 11458 11985 } 11459 11986 } … … 11631 12158 setCutoff(cutoff); 11632 12159 // change cutoff as constraint if wanted 11633 if ( (moreSpecialOptions_&16777216)!=0) {11634 if (solver_>getNumRows()> =numberRowsAtContinuous_) {12160 if (cutoffRowNumber_>=0) { 12161 if (solver_>getNumRows()>cutoffRowNumber_) { 11635 12162 double offset; 11636 12163 solver_>getDblParam(OsiObjOffset, offset); 11637 solver_>setRowUpper( numberRowsAtContinuous_1,cutoff+offset);12164 solver_>setRowUpper(cutoffRowNumber_,cutoff+offset); 11638 12165 } 11639 12166 } … … 12356 12883 // Make partial cut into a global cut and save 12357 12884 void 12358 CbcModel::makePartialCut(const OsiRowCut * partialCut) 12885 CbcModel::makePartialCut(const OsiRowCut * partialCut, 12886 const OsiSolverInterface * solver) 12359 12887 { 12360 12888 // get greedy cut 12361 12889 double bSum = partialCut>lb(); 12362 12890 assert (bSum<0.0); 12891 if (!solver) 12892 solver=solver_; 12363 12893 int nConflict = partialCut>row().getNumElements(); 12364 12894 const int * column = partialCut>row().getIndices(); 12365 12895 const double * element = partialCut>row().getElements(); 12366 12896 double * originalLower = topOfTree_>mutableLower(); 12367 const double * columnLower = solver _>getColLower();12897 const double * columnLower = solver>getColLower(); 12368 12898 double * originalUpper = topOfTree_>mutableUpper(); 12369 const double * columnUpper = solver _>getColUpper();12899 const double * columnUpper = solver>getColUpper(); 12370 12900 int nC=nConflict; 12371 12901 while (nConflict) { … … 12403 12933 printf("CUTa has %d (started at %d)  final bSum %g\n",nConflict,nC,bSum); 12404 12934 if (nConflict>1) { 12935 if ((specialOptions_&1) != 0) { 12936 const OsiRowCutDebugger *debugger = continuousSolver_>getRowCutDebugger() ; 12937 if (debugger) { 12938 if (debugger>invalidCut(newCut)) { 12939 continuousSolver_>applyRowCuts(1,&newCut); 12940 continuousSolver_>writeMps("bad"); 12941 } 12942 CoinAssert (!debugger>invalidCut(newCut)); 12943 } 12944 } 12405 12945 newCut.setGloballyValidAsInteger(2); 12406 12946 newCut.mutableRow().setTestForDuplicateIndex(false); … … 13145 13685 int totalNodes = numberNodes_ + numberExtraNodes_; 13146 13686 int totalIterations = numberIterations_ + numberExtraIterations_; 13687 bool diving=false; 13688 if ((moreSpecialOptions_&33554432)!=0) { 13689 testDepth=COIN_INT_MAX; 13690 if (oldNode&&(oldNode>depth()==2oldNode>depth()==4)) 13691 diving=true; 13692 } 13147 13693 if (totalNodes*40 < totalIterations  numberNodes_ < 1000) { 13148 13694 doClp = false; … … 13152 13698 // totalNodes,totalIterations,doClp ? 'Y' : 'N'); 13153 13699 } 13154 if (oldNode && fastNodeDepth_ >= 0 && oldNode>depth() >= testDepth &&/*!parentModel_*/(specialOptions_&2048) == 0 13155 && doClp && !cuts.sizeRowCuts()) { 13700 if (oldNode && 13701 ((fastNodeDepth_ >= 0 && oldNode>depth() >= testDepth && doClp)diving) &&/*!parentModel_*/(specialOptions_&2048) == 0 13702 && !cuts.sizeRowCuts()) { 13156 13703 OsiClpSolverInterface * clpSolver 13157 13704 = dynamic_cast<OsiClpSolverInterface *> (solver_); … … 13164 13711 #endif 13165 13712 #ifdef COIN_HAS_CLP 13166 int save ;13713 int save=0; 13167 13714 OsiClpSolverInterface * clpSolver 13168 13715 = dynamic_cast<OsiClpSolverInterface *> (solver_); … … 13344 13891 assert (numberProblems); 13345 13892 int nProbMinus1 = numberProblems  1; 13893 lockThread(); 13346 13894 for (int i = 0; i < currentNumberCuts_; i++) { 13347 13895 if (addedCuts_[i]) 13348 13896 addedCuts_[i]>increment(nProbMinus1) ; 13349 13897 } 13898 unlockThread(); 13350 13899 for (int i = 0; i < numberProblems; i++) { 13351 13900 double objectiveValue; … … 13566 14115 setCutoff(cutoff) ; 13567 14116 // change cutoff as constraint if wanted 13568 if ( (moreSpecialOptions_&16777216)!=0) {13569 if (solver_>getNumRows()> =numberRowsAtContinuous_) {14117 if (cutoffRowNumber_>=0) { 14118 if (solver_>getNumRows()>cutoffRowNumber_) { 13570 14119 double offset; 13571 14120 solver_>getDblParam(OsiObjOffset, offset); 13572 solver_>setRowUpper( numberRowsAtContinuous_1,cutoff+offset);14121 solver_>setRowUpper(cutoffRowNumber_,cutoff+offset); 13573 14122 } 13574 14123 } … … 14067 14616 // Set original columns as created by preprocessing 14068 14617 void 14069 CbcModel::setOriginalColumns(const int * originalColumns )14618 CbcModel::setOriginalColumns(const int * originalColumns,int numberGood) 14070 14619 { 14071 14620 int numberColumns = getNumCols(); 14072 14621 delete [] originalColumns_; 14073 originalColumns_ = CoinCopyOfArray(originalColumns, numberColumns); 14622 originalColumns_ = new int [numberColumns]; 14623 int numberCopy=CoinMin(numberColumns,numberGood); 14624 memcpy(originalColumns_,originalColumns,numberCopy*sizeof(int)); 14625 for (int i=numberCopy;i<numberColumns;i++) 14626 originalColumns_[i]=1; 14074 14627 } 14075 14628 // Set the cut modifier method … … 14098 14651 { 14099 14652 int foundSolution = 0; 14653 int saveNumberCutGenerators=numberCutGenerators_; 14654 if ((moreSpecialOptions_&33554432)!=0 && (specialOptions_&2048)==0) { 14655 if (node&&(node>depth()==2node>depth()==4)) 14656 numberCutGenerators_=0; // so can dive and branch 14657 } 14100 14658 int currentNumberCuts = 0 ; 14101 14659 currentNode_ = node; // so can be accessed elsewhere … … 14195 14753 CbcBranchingObject * branch = static_cast <CbcBranchingObject *>(branch2) ; 14196 14754 #endif 14755 #if 1 14197 14756 branch>setModel(this); 14198 14757 branchesLeft = node>branch(NULL); // old way 14758 #else 14759 branchesLeft = node>branch(solver_); 14760 #endif 14199 14761 if (parallelMode() >= 0) 14200 14762 branch>setModel(baseModel); … … 14601 15163 solver_>writeMpsNative("infeas2.mps", NULL, NULL, 2); 14602 15164 solver_>getRowCutDebuggerAlways()>printOptimalSolution(*solver_); 14603 assert (solver_>getRowCutDebugger()) ; 15165 const OsiRowCutDebugger * debugger = solver_>getRowCutDebugger() ; 15166 assert (debugger) ; 15167 int numberRows0=continuousSolver_>getNumRows(); 15168 int numberRows=solver_>getNumRows(); 15169 const CoinPackedMatrix * rowCopy = solver_>getMatrixByRow(); 15170 const int * rowLength = rowCopy>getVectorLengths(); 15171 const double * elements = rowCopy>getElements(); 15172 const int * column = rowCopy>getIndices(); 15173 const CoinBigIndex * rowStart = rowCopy>getVectorStarts(); 15174 const double * rowLower = solver_>getRowLower(); 15175 const double * rowUpper = solver_>getRowUpper(); 15176 for (int iRow=numberRows0;iRow<numberRows;iRow++) { 15177 OsiRowCut rc; 15178 rc.setLb(rowLower[iRow]); 15179 rc.setUb(rowUpper[iRow]); 15180 CoinBigIndex start = rowStart[iRow]; 15181 rc.setRow(rowLength[iRow],column+start,elements+start,false); 15182 CoinAssert (!debugger>invalidCut(rc)); 15183 } 14604 15184 assert (feasible); 14605 15185 } … … 14872 15452 if (parallelMode() >= 0) 14873 15453 newNode = new CbcNode() ; 15454 #if 0 15455 // Try diving 15456 if (parallelMode() >= 0 && (specialOptions_&2048) == 0) { 15457 // See if any diving heuristics set to do dive+save 15458 CbcHeuristicDive * dive=NULL; 15459 for (int i = 0; i < numberHeuristics_; i++) { 15460 CbcHeuristicDive * possible = dynamic_cast<CbcHeuristicDive *>(heuristic_[i]); 15461 if (possible&&possible>maxSimplexIterations()==COIN_INT_MAX) { 15462 // if more than one then rotate later? 15463 //if (possible>canHeuristicRun()) { 15464 if (node>depth()==0node>depth()==5) { 15465 dive=possible; 15466 break; 15467 } 15468 } 15469 } 15470 if (dive) { 15471 int numberNodes; 15472 CbcSubProblem ** nodes=NULL; 15473 int branchState=dive>fathom(this,numberNodes,nodes); 15474 if (branchState) { 15475 printf("new solution\n"); 15476 } 15477 if (0) { 15478 for (int iNode=0;iNode<numberNodes;iNode++) { 15479 //tree_>push(nodes[iNode]) ; 15480 } 15481 assert (node>nodeInfo()); 15482 if (node>nodeInfo()>numberBranchesLeft()) { 15483 tree_>push(node) ; 15484 } else { 15485 node>setActive(false); 15486 } 15487 } 15488 delete [] nodes; 15489 } 15490 } 15491 // end try diving 15492 #endif 14874 15493 // Set objective value (not so obvious if NLP etc) 14875 15494 setObjectiveValue(newNode, node); … … 15263 15882 unlockThread(); 15264 15883 } 15884 numberCutGenerators_=saveNumberCutGenerators; 15265 15885 return foundSolution; 15266 15886 } … … 15520 16140 for (int i = 0; i < numberHeuristics_; i++) { 15521 16141 CbcHeuristicDive * heuristic = dynamic_cast<CbcHeuristicDive *> (heuristic_[i]); 15522 if (heuristic ) {16142 if (heuristic && heuristic>maxSimplexIterations()!=COIN_INT_MAX) { 15523 16143 heuristic>setMaxSimplexIterations(nTree); 15524 16144 heuristic>setMaxSimplexIterationsAtRoot(nRoot); … … 16889 17509 char general[200]; 16890 17510 if (clpSolver) { 16891 clpSolver>getModelPtr()>dual(); // to get more randomness17511 clpSolver>getModelPtr()>dual(); // probably not needed 16892 17512 clpSolver>setWarmStart(NULL); 16893 sprintf(general,"Starting multiple root solver  %d iterations in initialSolve", 16894 clpSolver>getIterationCount()); 17513 sprintf(general,"Starting multiple root solver"); 16895 17514 } else { 16896 17515 #endif … … 16911 17530 return NULL; 16912 17531 } 16913 16914 17532 OsiRowCut * 17533 CbcModel::conflictCut(const OsiSolverInterface * solver, bool & localCuts) 17534 { 17535 OsiRowCut * cut=NULL; 17536 localCuts=false; 17537 # ifdef COIN_HAS_CLP 17538 const OsiClpSolverInterface * clpSolver 17539 = dynamic_cast<const OsiClpSolverInterface *> (solver); 17540 if (clpSolver&&topOfTree_) { 17541 int debugMode=0; 17542 const double * originalLower = topOfTree_>lower(); 17543 const double * originalUpper = topOfTree_>upper(); 17544 int typeCut = 1; 17545 ClpSimplex * simplex = clpSolver>getModelPtr(); 17546 assert(simplex>status()==1); 17547 if(simplex>ray()) { 17548 { 17549 int numberRows=simplex>numberRows(); 17550 double * saveRay=CoinCopyOfArray(simplex>ray(),numberRows); 17551 #define SAFE_RAY 17552 #ifdef SAFE_RAY 17553 ClpSimplex & tempSimplex=*simplex; 17554 #else 17555 ClpSimplex tempSimplex=*simplex; 17556 #endif 17557 int logLevel=simplex>logLevel(); 17558 tempSimplex.setLogLevel(63); 17559 tempSimplex.scaling(0); 17560 tempSimplex.dual(); 17561 tempSimplex.setLogLevel(logLevel); 17562 if (!tempSimplex.numberIterations()) { 17563 double * ray = tempSimplex.ray(); 17564 int nBad=0; 17565 for (int i=0;i<numberRows;i++) { 17566 if (fabs(ray[i]saveRay[i])>1.0e3) { 17567 if (debugMode) 17568 printf("row %d true %g bad %g  diff %g\n", 17569 i,ray[i],saveRay[i],ray[i]saveRay[i]); 17570 nBad++; 17571 } 17572 } 17573 if (nBad) 17574 printf("%d mismatch crunch ray values\n",nBad); 17575 } 17576 delete [] saveRay; 17577 } 17578 // make sure we use nonscaled versions 17579 ClpPackedMatrix * saveMatrix = simplex>swapScaledMatrix(NULL); 17580 double * saveScale = simplex>swapRowScale(NULL); 17581 //printf("Could do normal cut\n"); 17582 // could use existing arrays 17583 int numberRows=simplex>numberRows(); 17584 int numberColumns=simplex>numberColumns(); 17585 double * farkas = new double [2*numberColumns+numberRows]; 17586 double * bound = farkas + numberColumns; 17587 double * effectiveRhs = bound + numberColumns; 17588 // sign as internally for dual  so swap if primal 17589 /*const*/ double * ray = simplex>ray(); 17590 // have to get rid of local cut rows 17591 if (whichGenerator_) { 17592 const int * whichGenerator = whichGenerator_  numberRowsAtContinuous_; 17593 int badRows=0; 17594 for (int iRow=numberRowsAtContinuous_;iRow<numberRows;iRow++) { 17595 int iType=whichGenerator[iRow]; 17596 if ((iType>=0&&iType<10000)iType<1) { 17597 if (fabs(ray[iRow])>1.0e10) { 17598 badRows++; 17599 } else { 17600 ray[iRow]=0.0; 17601 } 17602 } 17603 } 17604 if (badRows) { 17605 if ((debugMode&1)!=0) 17606 printf("%d rows from local cuts\n",badRows); 17607 localCuts=true; 17608 } 17609 } 17610 // get farkas row 17611 memset(farkas,0,(2*numberColumns+numberRows)*sizeof(double)); 17612 simplex>transposeTimes(1.0,ray,farkas); 17613 //const char * integerInformation = simplex>integerType_; 17614 //assert (integerInformation); 17615 17616 int sequenceOut = simplex>sequenceOut(); 17617 // Put nonzero bounds in bound 17618 const double * columnLower = simplex>columnLower(); 17619 const double * columnUpper = simplex>columnUpper(); 17620 int numberBad=0; 17621 for (int i=0;i<numberColumns;i++) { 17622 double value = farkas[i]; 17623 double boundValue=0.0; 17624 if (simplex>getStatus(i)==ClpSimplex::basic) { 17625 // treat as zero if small 17626 if (fabs(value)<1.0e8) { 17627 value=0.0; 17628 farkas[i]=0.0; 17629 } 17630 if (value) { 17631 //printf("basic %d direction %d farkas %g\n", 17632 // i,simplex>directionOut(),value); 17633 if (value<0.0) 17634 boundValue=columnLower[i]; 17635 else 17636 boundValue=columnUpper[i]; 17637 } 17638 } else if (fabs(value)>1.0e10) { 17639 if (value<0.0) 17640 boundValue=columnLower[i]; 17641 else 17642 boundValue=columnUpper[i]; 17643 } 17644 bound[i]=boundValue; 17645 if (fabs(boundValue)>1.0e10) 17646 numberBad++; 17647 } 17648 const double * rowLower = simplex>rowLower(); 17649 const double * rowUpper = simplex>rowUpper(); 17650 //int pivotRow = simplex>spareIntArray_[3]; 17651 //bool badPivot=pivotRow<0; 17652 for (int i=0;i<numberRows;i++) { 17653 double value = ray[i]; 17654 double rhsValue=0.0; 17655 if (simplex>getRowStatus(i)==ClpSimplex::basic) { 17656 // treat as zero if small 17657 if (fabs(value)<1.0e8) { 17658 value=0.0; 17659 ray[i]=0.0; 17660 } 17661 if (value) { 17662 //printf("row basic %d direction %d ray %g\n", 17663 // i,simplex>directionOut(),value); 17664 if (value<0.0) 17665 rhsValue=rowLower[i]; 17666 else 17667 rhsValue=rowUpper[i]; 17668 } 17669 } else if (fabs(value)>1.0e10) { 17670 if (value<0.0) 17671 rhsValue=rowLower[i]; 17672 else 17673 rhsValue=rowUpper[i]; 17674 } 17675 effectiveRhs[i]=rhsValue; 17676 } 17677 simplex>times(1.0,bound,effectiveRhs); 17678 simplex>swapRowScale(saveScale); 17679 simplex>swapScaledMatrix(saveMatrix); 17680 double bSum=0.0; 17681 for (int i=0;i<numberRows;i++) { 17682 bSum += effectiveRhs[i]*ray[i]; 17683 } 17684 if (numberBadbSum>1.0e4) { 17685 #ifndef NDEBUG 17686 printf("bad BOUND bSum %g  %d bad\n", 17687 bSum,numberBad); 17688 #endif 17689 } else { 17690 const char * integerInformation = simplex>integerInformation(); 17691 assert (integerInformation); 17692 int * conflict = new int[numberColumns]; 17693 double * sort = new double [numberColumns]; 17694 double relax=0.0; 17695 int nConflict=0; 17696 int nOriginal=0; 17697 int nFixed=0; 17698 for (int iColumn=0;iColumn<numberColumns;iColumn++) { 17699 if (integerInformation[iColumn]) { 17700 if ((debugMode&1)!=0) 17701 printf("%d status %d %g <= %g <=%g (orig %g, %g) farkas %g\n", 17702 iColumn,simplex>getStatus(iColumn),columnLower[iColumn], 17703 simplex>primalColumnSolution()[iColumn],columnUpper[iColumn], 17704 originalLower[iColumn],originalUpper[iColumn], 17705 farkas[iColumn]); 17706 double gap = originalUpper[iColumn]originalLower[iColumn]; 17707 if (!gap) 17708 continue; 17709 if (gap==columnUpper[iColumn]columnLower[iColumn]) 17710 nOriginal++; 17711 if (columnUpper[iColumn]==columnLower[iColumn]) 17712 nFixed++; 17713 if (fabs(farkas[iColumn])<1.0e15) { 17714 farkas[iColumn]=0.0; 17715 continue; 17716 } 17717 // temp 17718 if (gap>=20000.0&&false) { 17719 // can't use 17720 if (farkas[iColumn]<0.0) { 17721 assert(originalLower[iColumn]columnLower[iColumn]<=0.0); 17722 // farkas is negative  relax lower bound all way 17723 relax += 17724 farkas[iColumn]*(originalLower[iColumn]columnLower[iColumn]); 17725 } else { 17726 assert(originalUpper[iColumn]columnUpper[iColumn]>=0.0); 17727 // farkas is positive  relax upper bound all way 17728 relax += 17729 farkas[iColumn]*(originalUpper[iColumn]columnUpper[iColumn]); 17730 } 17731 continue; 17732 } 17733 if (originalLower[iColumn]==columnLower[iColumn]) { 17734 if (farkas[iColumn]>0.0&&(simplex>getStatus(iColumn)==ClpSimplex::atUpperBound 17735 simplex>getStatus(iColumn)==ClpSimplex::isFixed 17736 iColumn==sequenceOut)) { 17737 // farkas is positive  add to list 17738 gap=originalUpper[iColumn]columnUpper[iColumn]; 17739 if (gap) { 17740 sort[nConflict]=farkas[iColumn]*gap; 17741 conflict[nConflict++]=iColumn; 17742 } 17743 //assert (gap>columnUpper[iColumn]columnLower[iColumn]); 17744 } 17745 } else if (originalUpper[iColumn]==columnUpper[iColumn]) { 17746 if (farkas[iColumn]<0.0&&(simplex>getStatus(iColumn)==ClpSimplex::atLowerBound 17747 simplex>getStatus(iColumn)==ClpSimplex::isFixed 17748 iColumn==sequenceOut)) { 17749 // farkas is negative  add to list 17750 gap=columnLower[iColumn]originalLower[iColumn]; 17751 if (gap) { 17752 sort[nConflict]=farkas[iColumn]*gap; 17753 conflict[nConflict++]=iColumn; 17754 } 17755 //assert (gap>columnUpper[iColumn]columnLower[iColumn]); 17756 } 17757 } else { 17758 // can't use 17759 if (farkas[iColumn]<0.0) { 17760 assert(originalLower[iColumn]columnLower[iColumn]<=0.0); 17761 // farkas is negative  relax lower bound all way 17762 relax += 17763 farkas[iColumn]*(originalLower[iColumn]columnLower[iColumn]); 17764 } else { 17765 assert(originalUpper[iColumn]columnUpper[iColumn]>=0.0); 17766 // farkas is positive  relax upper bound all way 17767 relax += 17768 farkas[iColumn]*(originalUpper[iColumn]columnUpper[iColumn]); 17769 } 17770 } 17771 assert(relax>=0.0); 17772 } else { 17773 // not integer  but may have been got at 17774 double gap = originalUpper[iColumn]originalLower[iColumn]; 17775 if (gap>columnUpper[iColumn]columnLower[iColumn]) { 17776 // can't use 17777 if (farkas[iColumn]<0.0) { 17778 assert(originalLower[iColumn]columnLower[iColumn]<=0.0); 17779 // farkas is negative  relax lower bound all way 17780 relax += 17781 farkas[iColumn]*(originalLower[iColumn]columnLower[iColumn]); 17782 } else { 17783 assert(originalUpper[iColumn]columnUpper[iColumn]>=0.0); 17784 // farkas is positive  relax upper bound all way 17785 relax += 17786 farkas[iColumn]*(originalUpper[iColumn]columnUpper[iColumn]); 17787 } 17788 } 17789 } 17790 } 17791 if (relax+bSum>1.0e4!nConflict) { 17792 if (relax+bSum>1.0e4) { 17793 #ifndef NDEBUG 17794 printf("General integers relax bSum to %g\n",relax+bSum); 17795 #endif 17796 } else { 17797 printf("All variables relaxed and still infeasible  what does this mean?\n"); 17798 int nR=0; 17799 for (int i=0;i<numberRows;i++) { 17800 if (fabs(ray[i])>1.0e10) 17801 nR++; 17802 else 17803 ray[i]=0.0; 17804 } 17805 int nC=0; 17806 for (int i=0;i<numberColumns;i++) { 17807 if (fabs(farkas[i])>1.0e10) 17808 nC++; 17809 else 17810 farkas[i]=0.0; 17811 } 17812 if (nR<3&&nC<5) { 17813 printf("BAD %d nonzero rows, %d nonzero columns\n",nR,nC); 17814 } 17815 } 17816 } else { 17817 printf("BOUNDS violation bSum %g (relaxed %g)  %d at original bounds, %d fixed  %d in conflict\n",bSum, 17818 relax+bSum,nOriginal,nFixed,nConflict); 17819 CoinSort_2(sort,sort+nConflict,conflict); 17820 int nC=nConflict; 17821 bSum+=relax; 17822 double saveBsum = bSum; 17823 while (nConflict) { 17824 //int iColumn=conflict[nConflict1]; 17825 double change=sort[nConflict1]; 17826 if (bSum+change>1.0e4) 17827 break; 17828 nConflict; 17829 bSum += change; 17830 } 17831 if (!nConflict) { 17832 int nR=0; 17833 for (int i=0;i<numberRows;i++) { 17834 if (fabs(ray[i])>1.0e10) 17835 nR++; 17836 else 17837 ray[i]=0.0; 17838 } 17839 int nC=0; 17840 for (int i=0;i<numberColumns;i++) { 17841 if (fabs(farkas[i])>1.0e10) 17842 nC++; 17843 else 17844 farkas[i]=0.0; 17845 } 17846 if (nR<3&&nC<5) { 17847 printf("BAD2 %d nonzero rows, %d nonzero columns\n",nR,nC); 17848 } 17849 } 17850 // no point doing if no reduction (or big?) ? 17851 if (nConflict<nC+1&&nConflict<500) { 17852 cut=new OsiRowCut(); 17853 cut>setUb(COIN_DBL_MAX); 17854 if (!typeCut) { 17855 double lo=1.0; 17856 for (int i=0;i<nConflict;i++) { 17857 int iColumn = conflict[i]; 17858 if (originalLower[iColumn]==columnLower[iColumn]) { 17859 // must be at least one higher 17860 sort[i]=1.0; 17861 lo += originalLower[iColumn]; 17862 } else { 17863 // must be at least one lower 17864 sort[i]=1.0; 17865 lo = originalUpper[iColumn]; 17866 } 17867 } 17868 cut>setLb(lo); 17869 cut>setRow(nConflict,conflict,sort); 17870 printf("CUT has %d (started at %d)  final bSum %g\n",nConflict,nC,bSum); 17871 } else { 17872 // just save for use later 17873 // first take off small 17874 int nC2=nC; 17875 while (nC2) { 17876 //int iColumn=conflict[nConflict1]; 17877 double change=sort[nC21]; 17878 if (saveBsum+change>1.0e4change>1.0e4) 17879 break; 17880 nC2; 17881 saveBsum += change; 17882 } 17883 cut>setLb(saveBsum); 17884 for (int i=0;i<nC2;i++) { 17885 int iColumn = conflict[i]; 17886 sort[i]=farkas[iColumn]; 17887 } 17888 cut>setRow(nC2,conflict,sort); 17889 printf("Stem CUT has %d (greedy %d  with small %d)  saved bSum %g final greedy bSum %g\n", 17890 nC2,nConflict,nC,saveBsum,bSum); 17891 } 17892 } 17893 } 17894 delete [] conflict; 17895 delete [] sort; 17896 } 17897 delete [] farkas; 17898 } else { 17899 printf("No dual ray\n"); 17900 } 17901 } 17902 #endif 17903 return cut; 17904 } 17905
Note: See TracChangeset
for help on using the changeset viewer.