BM_pack.cpp
Go to the documentation of this file.
1 // (C) Copyright International Business Machines Corporation and Carnegie Mellon University 2006, 2007
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // Laszlo Ladanyi, International Business Machines Corporation
7 
8 #include "BM.hpp"
9 #include "BCP_lp.hpp"
10 
11 #include "BonAmplSetup.hpp"
12 
13 //#############################################################################
14 
15 void
17 {
18  // possible process types looked up in BCP_enum_process_t.hpp
19  switch (ptype) {
20  case BCP_ProcessType_LP:
21  par.pack(buf);
22  buf.pack(nl_file_content);
24  break;
25  case BCP_ProcessType_TS:
26  break;
27  default:
28  abort();
29  }
30 }
31 
32 /****************************************************************************/
33 
34 void
36 {
37  using namespace Bonmin;
38 
39  par.unpack(buf);
42 
43  char* argv_[3];
44  char** argv = argv_;
45  argv[0] = NULL;
46  argv[1] = strdup("dont_even_try_to_open_it.nl");
47  argv[2] = NULL;
48  std::string ipopt_content(ipopt_file_content.c_str());
49  std::string nl_content(nl_file_content.c_str());
50 
51  /* PIERRE create the setup for algorithm, last argument indicates that
52  continuous relaxation should not be created.*/
53  bonmin_.initialize(argv, ipopt_content, nl_content, false);
54  bonmin_.nonlinearSolver()->setExposeWarmStart(true);
55 
56  free(argv[1]);
57 
58  /* synchronize bonmin & BCP parameters */
60 
63  integerTolerance_ = bonmin_.getDoubleParameter(BabSetupBase::IntTol);
64  // cutOffDecrement_ could be negative
65  double cutOffDecrement =
66  bonmin_.getDoubleParameter(BabSetupBase::CutoffDecr);
67 
68  BCP_lp_prob* bcp_lp = getLpProblemPointer();
69  const double bcp_intTol = bcp_lp->par.entry(BCP_lp_par::IntegerTolerance);
70  const double bcp_cutoffIncr = bcp_lp->par.entry(BCP_lp_par::Granularity);
71 
72  if (fabs(integerTolerance_ - bcp_intTol) > 1e-10) {
73  printf("WARNING!\n");
74  printf(" The integrality tolerance parameters are different for\n");
75  printf(" BCP (%f) and bonmin (%f). They should be identical.\n",
76  bcp_intTol, integerTolerance_);
77  printf(" For now both will be set to that of bonmin.\n");
78  }
79  if (fabs(bcp_cutoffIncr - cutOffDecrement) > 1e-10) {
80  printf("WARNING!\n");
81  printf(" The granularity (cutoff increment) parameters are different\n");
82  printf(" BCP (%f) and bonmin (%f). They should be identical.\n",
83  bcp_cutoffIncr, cutOffDecrement);
84  printf(" For now both will be set to that of bonmin.\n");
85  }
86  bcp_lp->par.set_entry(BCP_lp_par::IntegerTolerance, integerTolerance_);
87  bcp_lp->par.set_entry(BCP_lp_par::Granularity, cutOffDecrement);
88 
89  /* If pure BB is selected then a number of BCP parameters are changed */
90  if (bonmin_.getAlgorithm() == 0 /* pure B&B */) {
91  /* disable strong branching */
92  bcp_lp->par.set_entry(BCP_lp_par::MaxPresolveIter, -1);
93  /* disable a bunch of printing, all of which are meaningless, since the
94  LP relaxation is meaningless */
95  bcp_lp->par.set_entry(BCP_lp_par::LpVerb_ReportLocalCutPoolSize, false);
96  bcp_lp->par.set_entry(BCP_lp_par::LpVerb_ReportLocalVarPoolSize, false);
97  bcp_lp->par.set_entry(BCP_lp_par::LpVerb_GeneratedCutCount, false);
98  bcp_lp->par.set_entry(BCP_lp_par::LpVerb_GeneratedVarCount, false);
99  bcp_lp->par.set_entry(BCP_lp_par::LpVerb_RowEffectivenessCount, false);
100  }
101 
102  /* extract the sos constraints */
104  const Bonmin::TMINLP::SosInfo * sos = nlp.model()->sosConstraints();
105 
106  int i;
107  const int numCols = nlp.getNumCols();
108  const double* clb = nlp.getColLower();
109  const double* cub = nlp.getColUpper();
110  const int* cPrio = nlp.getPriorities();
111 
112  /* Find first the integer variables and then the SOS constraints */
113  int nObj = 0;
114  OsiObject** osiObj = new OsiObject*[numCols + sos->num];
115  for (i = 0; i < numCols; ++i) {
116  if (nlp.isInteger(i)) {
117  osiObj[nObj] = new OsiSimpleInteger(i, clb[i], cub[i]);
118  if (cPrio) {
119  osiObj[nObj]->setPriority(cPrio[i]);
120  }
121  ++nObj;
122  }
123  }
124 #if ! defined(BM_DISREGARD_SOS)
125  const int* starts = sos->starts;
126  for (i = 0; i < sos->num; ++i) {
127  OsiSOS* so = new OsiSOS(NULL, /* FIXME: why does the constr need */
128  starts[i+1] - starts[i],
129  sos->indices + starts[i],
130  sos->weights + starts[i],
131  sos->types[i]);
132  so->setPriority(sos->priorities ? sos->priorities[i] : 1);
133  osiObj[nObj++] = so;
134  }
135 #endif
136  nlp.addObjects(nObj, osiObj);
137 
138  objNum_ = nObj;
139  /* Allocate the storage arrays */
140  infInd_ = new int[objNum_];
141  infUseful_ = new double[objNum_];
142  feasInd_ = new int[objNum_];
143  feasUseful_ = new double[objNum_];
145 
146  /* Sort the objects based on their priority */
147  int* prio = new int[objNum_];
148  objInd_ = new int[objNum_];
149  for (i = 0; i < objNum_; ++i) {
150  sbResult_[i].colInd = osiObj[i]->columnNumber();
151  objInd_[i] = i;
152  prio[i] = osiObj[i]->priority();
153  }
154  CoinSort_2(prio, prio+objNum_, objInd_);
155  delete[] prio;
156 
157  for (i = 0; i < nObj; ++i) {
158  delete osiObj[i];
159  }
160  delete[] osiObj;
161 }
162 
163 //#############################################################################
164 
165 void
167 {
168  const BM_node* data = dynamic_cast<const BM_node*>(ud);
169  data->pack(buf);
170  BM_tm* tm = dynamic_cast<BM_tm*>(user_class);
171  if (tm) {
172  tm->pack_pseudo_costs(buf);
173  }
174 }
175 
176 /*---------------------------------------------------------------------------*/
177 
180 {
181  BM_node* node = new BM_node(buf);
182  BM_lp* lp = dynamic_cast<BM_lp*>(user_class);
183  if (lp) {
184  lp->unpack_pseudo_costs(buf);
185  }
186  return node;
187 }
188 
189 /*---------------------------------------------------------------------------*/
190 
191 void
193 {
194  const BB_cut* bb_cut = dynamic_cast<const BB_cut*>(cut);
195  if (!bb_cut)
196  throw BCP_fatal_error("pack_cut_algo() : unknown cut type!\n");
197  bb_cut->pack(buf);
198 }
199 
200 /*---------------------------------------------------------------------------*/
202 {
203  return new BB_cut(buf);
204 }
void initialize(char **&argv)
initialize bonmin with ampl model using the command line arguments.
Values not further from an integer value than the value of this parameter are considered to be intege...
double * feasUseful_
Definition: BM.hpp:317
BCP_buffer & pack(const T &value)
Pack a single object of type T.
Definition: BCP_buffer.hpp:177
Definition: BM.hpp:26
Upper limit on the number of iterations performed in each of the children of the search tree node whe...
The minimum difference between the objective value of any two feasible solution (with different objec...
BCP_buffer & unpack(T &value)
Unpack a single object of type T.
Definition: BCP_buffer.hpp:186
Print the number of cuts generated during this iteration (since the LP was resolved last time)...
Print the number of variables generated during this iteration.
This is class provides an Osi interface for a Mixed Integer Linear Program expressed as a TMINLP (so ...
void pack_pseudo_costs(BCP_buffer &buf)
Definition: BM_tm.cpp:335
This is the class from which the user should derive her own algorithmic cuts.
Definition: BCP_cut.hpp:242
BCP_process_t
This enumerative constant describes the various process types.
const char * c_str() const
Definition: BCP_string.hpp:19
Class to store sos constraints for model.
Definition: BonTMINLP.hpp:72
BCP_string nl_file_content
Definition: BM.hpp:281
NO OLD DOC.
Definition: BCP_lp.hpp:102
Definition: BM.hpp:273
int objNum_
Definition: BM.hpp:303
int * feasInd_
Definition: BM.hpp:316
Print the current number of cuts in the cut pool.
void unpack_pseudo_costs(BCP_buffer &buf)
Similar as above for variables.
void fint fint fint real fint real real real real real real real real real * e
Bonmin::Algorithm getAlgorithm()
Get the algorithm used.
double integerTolerance_
Definition: BM.hpp:289
Bonmin::BonminAmplSetup bonmin_
This contains the setup for running Bonmin in particular nlp solver, continuous solver, cut generators,...
Definition: BM.hpp:287
int * infInd_
Every time when branching decisions are to be made, we create 6 arrays, 3 for those objects that are ...
Definition: BM.hpp:313
void pack(BCP_buffer &buf) const
Definition: BM.hpp:40
int colInd
Definition: BM.hpp:248
virtual void pack_cut_algo(const BCP_cut_algo *cut, BCP_buffer &buf)
Pack an algorithmic cut.
Definition: BM_pack.cpp:192
void pack(BCP_buffer &buf) const
Packing cut to a buffer.
Definition: BB_cut.cpp:33
void fint fint fint real fint real real real real real real real real real fint real fint * lp
BCP_lp_prob * getLpProblemPointer()
Get the pointer.
Definition: BCP_lp_user.hpp:95
BCP_string ipopt_file_content
Definition: BM.hpp:280
Simple representation of a cut by storing non zero coefficients only.
Definition: BB_cut.hpp:64
virtual void pack_user_data(const BCP_user_data *ud, BCP_buffer &buf)
Pack an user data.
Definition: BM_pack.cpp:166
Definition: BM.hpp:170
int * objInd_
These are the indices of the integral (i.e., things that can be branched on) objects in the solver...
Definition: BM.hpp:302
virtual BCP_cut_algo * unpack_cut_algo(BCP_buffer &buf)
Unpack an algorithmic cut.
Definition: BM_pack.cpp:201
Currently there isn&#39;t any error handling in BCP.
Definition: BCP_error.hpp:20
double * infUseful_
Definition: BM.hpp:314
BCP_string ipopt_file_content
Definition: BM.hpp:175
BCP_parameter_set< BM_par > par
Definition: BM.hpp:282
This class describes the message buffer used for all processes of BCP.
Definition: BCP_buffer.hpp:39
BCP_parameter_set< BM_par > par
Definition: BM.hpp:177
OsiTMINLPInterface * nonlinearSolver()
Pointer to the non-linear solver used.
Ipopt::SmartPtr< Ipopt::OptionsList > options()
Acces list of Options.
double getDoubleParameter(const DoubleParameter &p) const
Return value of double parameter.
virtual BCP_user_data * unpack_user_data(BCP_buffer &buf)
Unpack an user data.
Definition: BM_pack.cpp:179
Print the number of ineffective rows in the current problem.
virtual void pack_module_data(BCP_buffer &buf, BCP_process_t ptype)
Pack the initial information (info that the user wants to send over) for the process specified by the...
Definition: BM_pack.cpp:16
BM_SB_result * sbResult_
This is where we keep the results in case of distributed strong branching.
Definition: BM.hpp:322
void unpack(BCP_buffer &buf)
Unpack the parameter set from the buffer.
void pack(BCP_buffer &buf)
Pack the parameter set into the buffer.
virtual void unpack_module_data(BCP_buffer &buf)
Unpack the initial information sent to the LP process by the Tree Manager.
Definition: BM_pack.cpp:35
BCP_string nl_file_content
Definition: BM.hpp:176