source: trunk/Bonmin/src/Apps/OaOriginalFeasibilityPump.cpp @ 1

Last change on this file since 1 was 1, checked in by andreasw, 13 years ago

imported initial code

  • Property svn:eol-style set to native
  • Property svn:keywords set to "Author Date Id Revision"
File size: 2.8 KB
Line 
1// (C) Copyright Carnegie Mellon University 2005
2// All Rights Reserved.
3// This code is published under the Common Public License.
4//
5// Authors :
6// Pierre Bonami, Carnegie Mellon University,
7//
8// Date : 06/18/2005
9
10#if defined(_MSC_VER)
11// Turn off compiler warning about long names
12#  pragma warning(disable:4786)
13#endif
14
15#include <cassert>
16#include <iomanip>
17
18
19// For Branch and bound
20#include "OsiSolverInterface.hpp"
21#include "OsiClpSolverInterface.hpp"
22#include "OsiCbcSolverInterface.hpp"
23#include "CbcModel.hpp"
24#include "CbcBranchUser.hpp"
25#include "CbcCompareUser.hpp"
26#include "CbcCompareActual.hpp"
27#include "CbcCutGenerator.hpp"
28//#include "CbcHeuristicUser.hpp"
29#include "SimpleIpoptInterface.hpp"
30#include "IpCbcDummyHeuristic.hpp"
31#include "IpCbcOACutGenerator.hpp"
32#include "IpCbcOACutGenerator2.hpp"
33
34#include "AmplTMINLP.hpp"
35
36#include "CglGomory.hpp"
37//#include "CglProbing.hpp"
38
39//#include "ClpQuadInterface.hpp"
40
41// Heuristics would need adapting
42
43//#include "CbcHeuristic.hpp"
44
45
46// Time
47#include "CoinTime.hpp"
48
49
50int main (int argc, char *argv[])
51{
52
53  // Define a Solver which inherits from OsiClpsolverInterface -> OsiSolverInterface
54
55  using namespace Ipopt;
56
57  SmartPtr<IpoptApplication> app = new IpoptApplication();
58
59  app->Jnlst()->Printf(J_ERROR, J_MAIN, "\n\n\n*************************************************************\n");
60  app->Jnlst()->Printf(J_ERROR, J_MAIN, "*** Running minlp with AMPL Model  **************************\n");
61  app->Jnlst()->Printf(J_ERROR, J_MAIN, "*************************************************************\n\n\n");
62
63  // Read in model using argv[1]
64  char * pbName = new char[strlen(argv[1])+1];
65  strcpy(pbName, argv[1]);
66  SmartPtr<TMINLP> ampl_tminlp = new AmplTMINLP(app->Jnlst(), argv);
67  SimpleIpoptInterface solver1(app,ampl_tminlp);
68
69  solver1.initialSolve();
70  int nMajorIt = 0;
71  bool solved = 0;
72  double time=-CoinCpuTime();
73  while(!solved && nMajorIt < 50) {
74    nMajorIt++;
75    const double * colsol = solver1.getColSolution();
76    int * inds = new int[solver1.getNumCols()];
77    double * x = new double[solver1.getNumCols()];
78    int k = 0;
79    for(int i = 0 ; i < solver1.getNumCols() ; i++) {
80      if(solver1.isInteger(i)) {
81        inds[k] = i;
82        x[k++] = floor(colsol[i] + 0.5);
83        std::cout<<"Var "<<i<<" value "<<x[k-1]<<std::endl;
84      }
85    }
86    OsiCuts cs;
87    double dist = solver1.getFeasibilityOuterApproximation( k, x, inds, cs);
88    if(dist < 1e-06)
89      solved = 1;
90    //Change the objective of the MIP to get the closest point to rounding of NLP optimum
91  }
92  time+=CoinCpuTime();
93  if(solved)
94    std::cout<<pbName<<" Feasible solution found in "<<time<<" seconds, "<<nMajorIt<<" major iterations"<<std::endl;
95  else {
96    std::cout<<"Problem aborted on iteration limit elapsed time : "<<time<<",  "<<nMajorIt<<" major iterations"<<std::endl;
97
98  }
99  delete [] pbName;
100  return 0;
101}
Note: See TracBrowser for help on using the repository browser.