// Copyright (C) 2002, International Business Machines // Corporation and others. All Rights Reserved. #if defined(_MSC_VER) // Turn off compiler warning about long names # pragma warning(disable:4786) #endif #include #include /////ADDG #include "StringConv.h" #include "SbbCompareActual.hpp" ///ADDG // For Branch and bound #include "OsiSolverInterface.hpp" #include "SbbModel.hpp" #include "SbbBranchUser.hpp" #include "SbbCompareUser.hpp" #include "SbbHeuristicUser.hpp" #ifdef COIN_USE_CLP #include "OsiClpSolverInterface.hpp" #endif #ifdef COIN_USE_OSL #include "OsiOslSolverInterface.hpp" #endif // Cuts #include "CglGomory.hpp" #include "CglProbing.hpp" #include "CglKnapsackCover.hpp" #include "CglOddHole.hpp" // Heuristics #include "SbbHeuristic.hpp" // Time #include #if !defined(_MSC_VER) #include #include #include #endif static double cpuTime() { double cpu_temp; #if defined(_MSC_VER) unsigned int ticksnow; /* clock_t is same as int */ ticksnow = (unsigned int)clock(); cpu_temp = (double)((double)ticksnow/CLOCKS_PER_SEC); #else struct rusage usage; getrusage(RUSAGE_SELF,&usage); cpu_temp = usage.ru_utime.tv_sec; cpu_temp += 1.0e-6*((double) usage.ru_utime.tv_usec); #endif return cpu_temp; } //############################################################################# #ifdef NDEBUG #undef NDEBUG #endif /************************************************************************ This main program reads in an integer model from an mps file. It then sets up some Cgl cut generators and calls branch and cut. Branching is simple binary branching on integer variables. Node selection is depth first until first solution is found and then based on objective and number of unsatisfied integer variables. In this example the functionality is the same as default but it is a user comparison function. Variable branching selection is on maximum minimum-of-up-down change after strong branching on 5 variables closest to 0.5. A simple rounding heuristic is used. ////ADDG add arguments for thec range of node selection methods to test and the objective function estimate to use for the norm estomate ************************************************************************/ // ****** define comparison to choose best next node int main (int argc, const char *argv[]) { // Define your favorite OsiSolver #ifdef COIN_USE_CLP OsiClpSolverInterface solver1; //solver1.messageHandler()->setLogLevel(0); SbbModel model(solver1); solver1.getModelPtr()->setDualBound(1.0e10); #endif #ifdef COIN_USE_OSL OsiOslSolverInterface solver1; //solver1.messageHandler()->setLogLevel(0); SbbModel model(solver1); #endif model.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry); // Read in model using argv[1] // and assert that it is a clean model assert(!model.solver()->readMps(argv[1],"")); //////ADDG add arguments for thec range of node selection methods to test and the objective function estimate to use for the norm estomate ///assert(argc==4); ////ADDG // Set up some cut generators and defaults // Probing first as gets tight bounds on continuous CglProbing generator1; generator1.setUsingObjective(true); generator1.setMaxPass(3); generator1.setMaxProbe(100); generator1.setMaxLook(50); generator1.setRowCuts(3); CglGomory generator2; // try larger limit generator2.setLimit(300); CglKnapsackCover generator3; CglOddHole generator4; generator4.setMinimumViolation(0.005); generator4.setMinimumViolationPer(0.00002); // try larger limit generator4.setMaximumEntries(200); // Add in generators model.addCutGenerator(&generator1,-1,"Probing"); model.addCutGenerator(&generator2,-1,"Gomory"); model.addCutGenerator(&generator3,-1,"Knapsack"); model.addCutGenerator(&generator4,-1,"OddHole"); // Allow rounding heuristic SbbRounding heuristic1(model); model.addHeuristic(&heuristic1); // And local search when new solution found SbbLocalSearch heuristic2(model); model.addHeuristic(&heuristic2); // Redundant definition of default branching (as Default == User) SbbBranchUserDecision branch; model.setBranchingMethod(&branch); /////DDG int lowerIndex=fromString(std::string(argv[2])); int upperIndex=fromString(std::string(argv[3])); int normIndex=fromString(std::string(argv[4])); for (int index= lowerIndex; indexsetIntParam(OsiMaxNumIterationHotStart,100); // If time is given then stop after that number of minutes if (argc>2) { int minutes = atoi(argv[2]); std::cout<<"Stopping after "<=0); model.setDblParam(SbbModel::SbbMaximumSeconds,60.0*minutes); } // Switch off most output if (model.getNumCols()<3000) { model.messageHandler()->setLogLevel(1); //model.solver()->messageHandler()->setLogLevel(0); } else { model.messageHandler()->setLogLevel(2); model.solver()->messageHandler()->setLogLevel(1); } //model.messageHandler()->setLogLevel(2); //model.solver()->messageHandler()->setLogLevel(2); //model.setPrintFrequency(50); double time1 = cpuTime(); if (0) { // integer presolve SbbModel * model2 = model.integerPresolve(); if (model2) { // Do complete search model2->branchAndBound(); // get back solution model.originalModel(model2); } else { // infeasible exit(1); } } else { // Do complete search model.branchAndBound(); } std::cout<getNumCols(); const double * solution = model.solver()->getColSolution(); int iColumn; std::cout<1.0e-7&&model.solver()->isInteger(iColumn)) std::cout<