00001
00002
00003 #if defined(_MSC_VER)
00004
00005 # pragma warning(disable:4786)
00006 #endif
00007
00008 #include <cassert>
00009
00010
00011 #include "OsiSolverInterface.hpp"
00012 #include "SbbModel.hpp"
00013
00014 #ifdef COIN_USE_CLP
00015 #include "OsiClpSolverInterface.hpp"
00016 #endif
00017 #include "ClpPresolve.hpp"
00018 #include "SbbCompareUser.hpp"
00019 #include "CglProbing.hpp"
00020
00021
00022
00023 #ifdef NDEBUG
00024 #undef NDEBUG
00025 #endif
00026
00027
00028 #include <time.h>
00029 #if !defined(_MSC_VER)
00030 #include <sys/times.h>
00031 #include <sys/resource.h>
00032 #include <unistd.h>
00033 #endif
00034 static double cpuTime()
00035 {
00036 double cpu_temp;
00037 #if defined(_MSC_VER)
00038 unsigned int ticksnow;
00039
00040 ticksnow = (unsigned int)clock();
00041
00042 cpu_temp = (double)((double)ticksnow/CLOCKS_PER_SEC);
00043 #else
00044 struct rusage usage;
00045 getrusage(RUSAGE_SELF,&usage);
00046 cpu_temp = usage.ru_utime.tv_sec;
00047 cpu_temp += 1.0e-6*((double) usage.ru_utime.tv_usec);
00048 #endif
00049 return cpu_temp;
00050 }
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 int main (int argc, const char *argv[])
00078 {
00079
00080
00081
00082 #ifdef COIN_USE_CLP
00083 ClpSimplex simplex;
00084 #endif
00085 double time0 = cpuTime();
00086 double time1 = time0;
00087 double time2;
00088
00089
00090
00091
00092 assert(!simplex.readMps(argv[1],""));
00093 time2 = cpuTime();
00094 std::cout<<"Input took "<<time2-time1<<" seconds"<<std::endl;;
00095 time1 = time2;
00096
00097 ClpPresolve pinfo;
00098 ClpSimplex * simplex2 = pinfo.presolvedModel(simplex,1.0e-8);
00099 time2 = cpuTime();
00100 std::cout<<"Presolve took "<<time2-time1<<" seconds"<<std::endl;;
00101 time1 = time2;
00102 OsiClpSolverInterface solver1(simplex2);
00103 solver1.writeMps("bad2");
00104
00105 solver1.initialSolve();
00106 time2 = cpuTime();
00107 std::cout<<"Continuous solve took "<<time2-time1<<" seconds"<<std::endl;;
00108 time1 = time2;
00109 solver1.messageHandler()->setLogLevel(0);
00110 SbbModel model(solver1);
00111
00112 SbbCompareUser compare;
00113 model.setNodeComparison(compare);
00114
00115
00116
00117 CglProbing generator1;
00118 generator1.setUsingObjective(true);
00119 generator1.setMaxPass(3);
00120 generator1.setMaxProbe(100);
00121 generator1.setMaxLook(50);
00122 generator1.setRowCuts(3);
00123
00124
00125
00126
00127
00128 model.setNumberStrong(0);
00129 model.solver()->setIntParam(OsiMaxNumIterationHotStart,100);
00130
00131
00132 if (model.getNumCols()<3000) {
00133 model.messageHandler()->setLogLevel(1);
00134 model.solver()->messageHandler()->setLogLevel(0);
00135 } else {
00136 model.messageHandler()->setLogLevel(2);
00137 model.solver()->messageHandler()->setLogLevel(1);
00138 }
00139
00140
00141
00142 model.branchAndBound();
00143 time2 = cpuTime();
00144 std::cout<<"Search took "<<time2-time1<<" seconds"<<std::endl;
00145
00146 OsiClpSolverInterface * clpSolver
00147 = dynamic_cast<OsiClpSolverInterface *> (model.solver());
00148 assert (clpSolver);
00149 ClpSimplex * clp = clpSolver->getModelPtr();
00150 *simplex2 = *clp;
00151 pinfo.postsolve(true);
00152 time1 = time2;
00153
00154 const int * original = pinfo.originalColumns();
00155 double * lower2 = simplex2->columnLower();
00156 double * upper2 = simplex2->columnUpper();
00157 const char * info2 = simplex2->integerInformation();
00158 double * lower = simplex.columnLower();
00159 double * upper = simplex.columnUpper();
00160 int i;
00161 for (i=0;i<simplex2->numberColumns();i++) {
00162 if (info2[i]) {
00163 int iSeq = original[i];
00164 upper[iSeq]=upper2[i];
00165 lower[iSeq]=lower2[i];
00166 }
00167 }
00168
00169 simplex.primal();
00170 time2 = cpuTime();
00171 std::cout<<"Cleanup took "<<time2-time1<<" seconds"<<std::endl;;
00172 std::cout<<"Total time "<<time2-time0<<" seconds"<<std::endl;;
00173 return 0;
00174 }