BonAmplSetup.cpp
Go to the documentation of this file.
1 // (C) Copyright International Business Machines Corporation 2007
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // Pierre Bonami, International Business Machines Corporation
7 //
8 // Date : 04/15/2007
9 
10 #include "BonAmplSetup.hpp"
11 #include "BonSolReader.hpp"
12 namespace Bonmin
13 {
14  void BonminAmplSetup::initialize(char **& argv)
15  {
17  /* Read the model.*/
19  argv, NULL, "bonmin", NULL);
20  mayPrintDoc();
21  BonminSetup::initialize(GetRawPtr(model), true);
22 #if 1
23  int ival;
24  options()->GetEnumValue("read_solution_file", ival, "bonmin.");
25  if(ival){
26  printf("Reading solution file");
27  SolReader read(argv[1], ".dbg_sol");
28  read.set_n_cols(nonlinearSolver()->getNumCols());
29  read.readFile();
30  nonlinearSolver()->activateRowCutDebugger(read.x());
31  }
32 #endif
33  }
34 
35  void
37  {
38  Ipopt::SmartPtr<TNLPSolver> solver = toFill.solver();
39  setOptionsAndJournalist(solver->roptions(),
40  solver->options(),
41  solver->journalist());
42  /* Get the basic options. */
44  /* Read the model.*/
46  options(), argv, NULL, "bonmin", NULL);
47  mayPrintDoc();
49  BonminSetup::initialize(toFill, true);
50  }
51 
53  void
54  BonminAmplSetup::initialize(char **& argv, std::string& opt_file_content, std::string& nl_file_content, bool createContinuousSolver /*= false*/)
55  {
56  /* Get the basic options. */
57  readOptionsString(opt_file_content);
58  /* read nl file by creating AmplTMINLP.*/
60  options(), argv, NULL, "bonmin", &nl_file_content);
61  mayPrintDoc();
62  BonminSetup::initialize(GetRawPtr(model), createContinuousSolver);
63  }
64 
65 
67  void
68  BonminAmplSetup::initialize(AmplInterface &toFill, char **& argv, std::string& opt_file_content,
69  std::string& nl_file_content, bool createContinuousSolver /*= false*/
70  )
71  {
72  /* Get the basic options. */
73  readOptionsString(opt_file_content);
74  /* read nl file by creating AmplTMINLP.*/
76  options(), argv, NULL, "bonmin", &nl_file_content);
77  mayPrintDoc();
79  BonminSetup::initialize(toFill, createContinuousSolver);
80  }
81 
83  void BonminAmplSetup::fillOsiInterface(AmplInterface &toFill, char ** &argv, std::string & options,
84  std::string & nl, bool createContinuousSolver /*= false*/)
85  {
86 
87  /* Get the basic options. */
88  readOptionsString(options);
89  /* Read the model.*/
92  roptions_,
93  options_,
94  argv, NULL, "bonmin", &nl);
95  toFill.initialize(roptions(), options_, journalist(), prefix(), GetRawPtr(model));
96  }
97 
98 }
99 
void initialize(char **&argv)
initialize bonmin with ampl model using the command line arguments.
void set_n_cols(int n)
Set the number of variables in the problem.
const double * x()
Ipopt::SmartPtr< Ipopt::Journalist > journalist()
Acces storage of Journalist for output.
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions()
Access registered Options.
void setOptionsAndJournalist(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions, Ipopt::SmartPtr< Ipopt::OptionsList > options, Ipopt::SmartPtr< Ipopt::Journalist > journalist)
Set the value for options, output...
void fillOsiInterface(AmplInterface &toFill, char **&argv, std::string &options, std::string &nl, bool createContinuousSolver=true)
For Bcp.
Class for providing an Osi interface to Ipopt with an ampl nl file as input.
const Bonmin::TNLPSolver * solver() const
OSSmartPtr< const U > ConstPtr(const OSSmartPtr< U > &smart_ptr)
Definition: OSSmartPtr.hpp:458
A class for reading a .col or .row file containing name for variables and constraints (usually ampl g...
U * GetRawPtr(const OSSmartPtr< U > &smart_ptr)
Definition: OSSmartPtr.hpp:452
Ipopt::SmartPtr< Ipopt::OptionsList > options_
List of Options.
Ipopt::SmartPtr< Ipopt::Journalist > journalist_
Storage of Journalist for output.
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions_
Registered Options.
Ampl MINLP Interface.
bool readFile()
Reads the .sol file.
OsiTMINLPInterface * nonlinearSolver()
Pointer to the non-linear solver used.
Ipopt::SmartPtr< Ipopt::OptionsList > options()
Acces list of Options.
void initialize(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions, Ipopt::SmartPtr< Ipopt::OptionsList > options, Ipopt::SmartPtr< Ipopt::Journalist > journalist, const std::string &prefix, Ipopt::SmartPtr< TMINLP > tminlp)
Facilitator to initialize interface.
void mayPrintDoc()
May print documentation of options if options print_options_documentation is set to yes...
virtual void readOptionsFile()
Get the options from default text file (bonmin.opt) if don&#39;t already have them.
const char * prefix() const
Get prefix to use for options.
void readOptionsString(std::string opt_string)
Get the options from long string containing all.
void initialize(Ipopt::SmartPtr< TMINLP > tminlp, bool createContinuousSolver=true)
Initialize, read options and create appropriate bonmin setup.