BonNodeSolver.cpp
Go to the documentation of this file.
1 // (C) Copyright International Business Machines Corporation and Carnegie Mellon University 2006
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // Andreas Waechter, International Business Machines Corporation
7 // Pierre Bonami, Carnegie Mellon University,
8 //
9 // Date : 02/15/2006
10 
11 
12 #include <cassert>
13 #include <iomanip>
14 
15 #include "BonminConfig.h"
16 
17 #include "CoinPragma.hpp"
18 #include "BonAmplInterface.hpp"
19 #include "BonIpoptSolver.hpp"
20 #include "BonBoundsReader.hpp"
21 #include "BonStartPointReader.hpp"
22 #include "CoinTime.hpp"
23 
24 #include "BonAmplSetup.hpp"
25 
26 
27 /************************************************************************
28 
29 This mains is used for resolving the problem with fixed bounds and eventually a starting point
30 
31 ************************************************************************/
32 
33 int main (int argc, char *argv[])
34 {
35 
36  using namespace Ipopt;
37  using namespace Bonmin;
38 
39  // Read in model using argv[1]
40  char * pbName = new char[strlen(argv[1])+1];
41  strcpy(pbName, argv[1]);
42  std::string nodeFileName;
43  if(argc > 2)
44  nodeFileName=argv[2];
45  std::string startingPointFile ="";
46  if(argc>3)
47  startingPointFile = argv[3];
48 
49  //Give ampl an argv which doesn't crash him.
50  char ** myArgv = new char *[3];
51  myArgv[0]=new char[strlen(argv[0])+1];
52  strcpy(myArgv[0],argv[0]);
53  myArgv[1]=new char[strlen(argv[1])+1];
54  strcpy(myArgv[1],argv[1]);
55  myArgv[2]= NULL;//new char[1];
56 
57 
58  BonminAmplSetup bonmin;
59  bonmin.initialize(myArgv);
60  Bonmin::OsiTMINLPInterface& nlpSolver = *bonmin.nonlinearSolver();
61 
63  nlpSolver.options();
64 
65  nlpSolver.messageHandler()->setLogLevel(2);
66 
67  try
68  {
69  std::cout<<nodeFileName<<std::endl;
70  // Read the bounds and change them in Ipopt
71  if(argc>2) {
72  Bonmin::BoundsReader bounds(nodeFileName);
73  bounds.readAndApply(&nlpSolver);
74  }
75  if(argc>3) {
76  Bonmin::StartPointReader init(startingPointFile);
77  init.readAndApply(&nlpSolver);
78  }
79 
80  nlpSolver.solver()->forceSolverOutput(4);
81  nlpSolver.initialSolve();
82 
83  //Print out integer variable values
84  for(int i = 0 ; i <nlpSolver.getNumCols() ; i++) {
85  if (nlpSolver.isInteger(i)) {
86  std::cout<<"x[ "<<i<<"] = "<<nlpSolver.getColSolution()[i]<<std::endl;
87  }
88  }
89  }
91  std::cerr<<E.className()<<"::"<<E.methodName()
92  <<std::endl
93  <<E.message()<<std::endl;
94  }
95  catch(CoinError &E) {
96  std::cerr<<E.className()<<"::"<<E.methodName()
97  <<std::endl
98  <<E.message()<<std::endl;
99  }
100  catch(...) {
101  std::cerr<<pbName<<" unrecognized excpetion"<<std::endl;
102  std::cerr<<pbName<<"\t Finished \t exception"<<std::endl;
103  throw;
104  }
105 
106 
107  delete [] pbName;
108  delete [] myArgv[0];
109  delete [] myArgv[1];
110  delete [] myArgv;
111  return 0;
112 }
void initialize(char **&argv)
initialize bonmin with ampl model using the command line arguments.
int main(int argc, char *argv[])
Definition: BB_tm.cpp:32
This is class provides an Osi interface for a Mixed Integer Linear Program expressed as a TMINLP (so ...
bool readAndApply(OsiTMINLPInterface *solver)
Read warmstart info and apply to an IpoptInterface.
This class reads a file with a starting point for Ipopt initalization.
Error class to throw exceptions from OsiTMINLPInterface.
Reads a file containing change bounds for variables.
void readAndApply(OsiTMINLPInterface *solver)