/home/coin/SVN-release/OS-2.0.0/Bonmin/src/Apps/OaOriginalFeasibilityPump.cpp

Go to the documentation of this file.
00001 // (C) Copyright Carnegie Mellon University 2005
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // Authors :
00006 // Pierre Bonami, Carnegie Mellon University,
00007 //
00008 // Date : 06/18/2005
00009 
00010 #if defined(_MSC_VER)
00011 // Turn off compiler warning about long names
00012 #  pragma warning(disable:4786)
00013 #endif
00014 
00015 #include <cassert>
00016 #include <iomanip>
00017 
00018 
00019 // For Branch and bound
00020 #include "OsiSolverInterface.hpp"
00021 #include "OsiClpSolverInterface.hpp"
00022 #include "OsiCbcSolverInterface.hpp"
00023 #include "CbcModel.hpp"
00024 #include "CbcBranchUser.hpp"
00025 #include "CbcCompareUser.hpp"
00026 #include "CbcCompareActual.hpp"
00027 #include "CbcCutGenerator.hpp"
00028 //#include "CbcHeuristicUser.hpp"
00029 #include "SimpleIpoptInterface.hpp"
00030 #include "IpCbcDummyHeuristic.hpp"
00031 #include "IpCbcOACutGenerator.hpp"
00032 #include "IpCbcOACutGenerator2.hpp"
00033 
00034 #include "AmplTMINLP.hpp"
00035 
00036 #include "CglGomory.hpp"
00037 //#include "CglProbing.hpp"
00038 
00039 //#include "ClpQuadInterface.hpp"
00040 
00041 // Heuristics would need adapting
00042 
00043 //#include "CbcHeuristic.hpp"
00044 
00045 
00046 // Time
00047 #include "CoinTime.hpp"
00048 
00049 
00050 int main (int argc, char *argv[])
00051 {
00052 
00053   // Define a Solver which inherits from OsiClpsolverInterface -> OsiSolverInterface
00054 
00055   using namespace Ipopt;
00056 
00057   SmartPtr<IpoptApplication> app = new IpoptApplication();
00058 
00059   app->Jnlst()->Printf(J_ERROR, J_MAIN, "\n\n\n*************************************************************\n");
00060   app->Jnlst()->Printf(J_ERROR, J_MAIN, "*** Running minlp with AMPL Model  **************************\n");
00061   app->Jnlst()->Printf(J_ERROR, J_MAIN, "*************************************************************\n\n\n");
00062 
00063   // Read in model using argv[1]
00064   char * pbName = new char[strlen(argv[1])+1];
00065   strcpy(pbName, argv[1]);
00066   SmartPtr<TMINLP> ampl_tminlp = new AmplTMINLP(app->Jnlst(), argv);
00067   SimpleIpoptInterface solver1(app,ampl_tminlp);
00068 
00069   solver1.initialSolve();
00070   int nMajorIt = 0;
00071   bool solved = 0;
00072   double time=-CoinCpuTime();
00073   while(!solved && nMajorIt < 50) {
00074     nMajorIt++;
00075     const double * colsol = solver1.getColSolution();
00076     int * inds = new int[solver1.getNumCols()];
00077     double * x = new double[solver1.getNumCols()];
00078     int k = 0;
00079     for(int i = 0 ; i < solver1.getNumCols() ; i++) {
00080       if(solver1.isInteger(i)) {
00081         inds[k] = i;
00082         x[k++] = floor(colsol[i] + 0.5);
00083         std::cout<<"Var "<<i<<" value "<<x[k-1]<<std::endl;
00084       }
00085     }
00086     OsiCuts cs;
00087     double dist = solver1.getFeasibilityOuterApproximation( k, x, inds, cs);
00088     if(dist < 1e-06)
00089       solved = 1;
00090     //Change the objective of the MIP to get the closest point to rounding of NLP optimum
00091   }
00092   time+=CoinCpuTime();
00093   if(solved)
00094     std::cout<<pbName<<" Feasible solution found in "<<time<<" seconds, "<<nMajorIt<<" major iterations"<<std::endl;
00095   else {
00096     std::cout<<"Problem aborted on iteration limit elapsed time : "<<time<<",  "<<nMajorIt<<" major iterations"<<std::endl;
00097 
00098   }
00099   delete [] pbName;
00100   return 0;
00101 }

Generated on Mon Aug 3 03:02:18 2009 by  doxygen 1.4.7