 Timestamp:
 May 15, 2008 5:44:08 AM (12 years ago)
 Location:
 stable/2.1/Cbc/src
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

stable/2.1/Cbc/src/CbcModel.cpp
r929 r941 10905 10905 } 10906 10906 void 10907 CbcModel::setBestSolution(const double * solution,int numberColumns,double objectiveValue) 10907 CbcModel::setBestSolution(const double * solution,int numberColumns, 10908 double objectiveValue, bool checkSolution) 10908 10909 { 10910 // May be odd discontinuities  so only chaeck if asked 10911 if (checkSolution) { 10912 assert (numberColumns==solver_>getNumCols()); 10913 double * saveLower = CoinCopyOfArray(solver_>getColLower(),numberColumns); 10914 double * saveUpper = CoinCopyOfArray(solver_>getColUpper(),numberColumns); 10915 // Fix integers 10916 for (int i=0;i<numberColumns;i++) { 10917 if (solver_>isInteger(i)) { 10918 double value = solution[i]; 10919 double intValue = floor(value+0.5); 10920 assert (fabs(valueintValue)<1.0e4); 10921 solver_>setColLower(i,intValue); 10922 solver_>setColUpper(i,intValue); 10923 } 10924 } 10925 // Save basis 10926 CoinWarmStart * saveBasis = solver_>getWarmStart(); 10927 // Solve 10928 solver_>initialSolve(); 10929 char printBuffer[200]; 10930 bool looksGood = solver_>isProvenOptimal(); 10931 if (looksGood) { 10932 double direction = solver_>getObjSense() ; 10933 double objValue =direction*solver_>getObjValue(); 10934 if (objValue>objectiveValue + 1.0e8*(1.0+fabs(objectiveValue))) { 10935 sprintf(printBuffer,"Given objective value %g, computed %g", 10936 objectiveValue,objValue); 10937 messageHandler()>message(CBC_FPUMP1,messages()) 10938 << printBuffer << CoinMessageEol ; 10939 } 10940 // Use this as objective value and solution 10941 objectiveValue = objValue; 10942 solution = solver_>getColSolution(); 10943 // Save current basis 10944 CoinWarmStartBasis* ws = 10945 dynamic_cast <CoinWarmStartBasis*>(solver_>getWarmStart()) ; 10946 assert(ws); 10947 setBestSolutionBasis(*ws); 10948 delete ws; 10949 } 10950 // Restore basis 10951 solver_>setWarmStart(saveBasis); 10952 delete saveBasis; 10953 // Restore bounds 10954 solver_>setColLower(saveLower); 10955 delete [] saveLower; 10956 solver_>setColUpper(saveUpper); 10957 delete [] saveUpper; 10958 // Return if no good 10959 if (!looksGood) { 10960 messageHandler()>message(CBC_FPUMP1,messages()) 10961 << "Error solution not saved as not feasible" << CoinMessageEol ; 10962 return; 10963 } else { 10964 // message 10965 sprintf(printBuffer,"Solution with objective value %g saved", 10966 objectiveValue); 10967 messageHandler()>message(CBC_FPUMP1,messages()) 10968 << printBuffer << CoinMessageEol ; 10969 } 10970 } 10909 10971 bestObjective_ = objectiveValue; 10910 10972 int n = CoinMax(numberColumns,solver_>getNumCols()); 
stable/2.1/Cbc/src/CbcModel.hpp
r871 r941 1092 1092 inline double * bestSolution() const 1093 1093 { return bestSolution_;} 1094 void setBestSolution(const double * solution,int numberColumns,double objectiveValue); 1094 /** User callable setBestSolution. 1095 If check false does not check valid 1096 If true then sees if feasible and warns if objective value 1097 worse than given (so just set to COIN_DBL_MAX if you don't care). 1098 If check true then does not save solution if not feasible 1099 */ 1100 void setBestSolution(const double * solution,int numberColumns, 1101 double objectiveValue,bool check=false); 1095 1102 1096 1103 /// Get number of solutions
Note: See TracChangeset
for help on using the changeset viewer.