CouenneProblemConstructors.cpp
Go to the documentation of this file.
1 /* $Id: CouenneProblemConstructors.cpp 937 2013-01-01 21:10:42Z pbelotti $
2  *
3  * Name: CouenneProblemConstructors.cpp
4  * Author: Pietro Belotti
5  * Purpose: Constructors and destructors of the class CouenneProblem
6  *
7  * (C) Carnegie-Mellon University, 2009-11.
8  * This file is licensed under the Eclipse Public License (EPL)
9  */
10 
11 #include <vector>
12 
13 #include "CoinHelperFunctions.hpp"
14 #include "CoinTime.hpp"
15 
16 #include "BonBabSetupBase.hpp"
17 
18 #include "CouenneTypes.hpp"
19 
20 #include "CouenneExpression.hpp"
21 #include "CouenneExprConst.hpp"
22 #include "CouenneExprQuad.hpp"
23 #include "CouenneExprClone.hpp"
24 #include "CouenneExprIVar.hpp"
25 #include "CouenneExprAux.hpp"
26 #include "CouenneExprOpp.hpp"
27 
28 #include "CouenneProblem.hpp"
29 #include "CouenneProblemElem.hpp"
30 #include "CouenneGlobalCutOff.hpp"
31 #include "CouenneDepGraph.hpp"
32 #include "CouenneLQelems.hpp"
33 
34 #include "CouenneObject.hpp"
35 
36 #include "CouenneRecordBestSol.hpp"
38 #include "CouenneSdpCuts.hpp"
39 
40 #ifdef COIN_HAS_NTY
41 #include "Nauty.h"
42 #endif
43 
44 using namespace Couenne;
45 
46 #define MAX_FBBT_ITER 3
47 
51  JnlstPtr jnlst):
52  problemName_ (""),
53  auxSet_ (NULL),
54  curnvars_ (-1),
55  nIntVars_ (0),
56  optimum_ (NULL),
57  bestObj_ (COIN_DBL_MAX),
58  commuted_ (NULL),
59  numbering_ (NULL),
60  ndefined_ (0),
61  graph_ (NULL),
62  nOrigVars_ (0),
63  nOrigIntVars_ (0),
64  pcutoff_ (new GlobalCutOff (COIN_DBL_MAX)),
65  created_pcutoff_ (true),
66  doFBBT_ (true),
67  doRCBT_ (true),
68  doOBBT_ (true),
69  doABT_ (true),
70  logObbtLev_(0),
71  logAbtLev_ (0),
72  jnlst_ (jnlst),
73  opt_window_ (COIN_DBL_MAX),
74  useQuadratic_ (false),
75  feas_tolerance_ (feas_tolerance_default),
76  integerRank_ (NULL),
77  maxCpuTime_ (COIN_DBL_MAX),
78  bonBase_ (base),
79 #ifdef COIN_HAS_ASL
80  asl_ (asl),
81 #endif
82  unusedOriginalsIndices_ (NULL),
83  nUnusedOriginals_ (-1),
84  multilinSep_ (CouenneProblem::MulSepNone),
85  max_fbbt_iter_ (MAX_FBBT_ITER),
86  orbitalBranching_ (false),
87  constObjVal_ (0.),
88  perfIndicator_ (new CouenneBTPerfIndicator (this, "FBBT")),
89 
90  nauty_info (NULL),
91  sdpCutGen_ (NULL) {
92 
93  double now = CoinCpuTime ();
94 
95  if (asl) {
96 #if COIN_HAS_ASL
97  // read problem from AMPL structure
98  readnl (asl);
99 #else
100  jnlst_ -> Printf (Ipopt::J_ERROR, J_PROBLEM, "Couenne was compiled without the ASL library. Cannot process ASL structure.\n");
101  throw -1;
102 #endif
103 
104  if ((now = (CoinCpuTime () - now)) > 10.)
105  jnlst_ -> Printf (Ipopt::J_WARNING, J_PROBLEM,
106  "Couenne: reading time %.3fs\n", now);
107  }
108 
109  // create expression set for binary search
110  auxSet_ = new std::set <exprAux *, compExpr>;
111 
112  if (base)
113  initOptions (base -> options());
114 
116  lastPrioSort_ = 1000000;
117 
118  minDepthPrint_ = -1;
119  minNodePrint_ = -1;
120  doPrint_ = false;
121 }
122 
123 
125 
127  problemName_ (p.problemName_),
128  domain_ (p.domain_),
129  curnvars_ (-1),
130  nIntVars_ (p.nIntVars_),
131  optimum_ (NULL),
132  bestObj_ (p.bestObj_),
133  commuted_ (NULL),
134  numbering_ (NULL),
135  ndefined_ (p.ndefined_),
136  graph_ (NULL),
137  nOrigVars_ (p.nOrigVars_),
138  nOrigCons_ (p.nOrigCons_),
139  nOrigIntVars_ (p.nOrigIntVars_),
140  pcutoff_ (p.pcutoff_),
141  created_pcutoff_ (false),
142  doFBBT_ (p. doFBBT_),
143  doRCBT_ (p. doRCBT_),
144  doOBBT_ (p. doOBBT_),
145  doABT_ (p. doABT_),
146  logObbtLev_ (p. logObbtLev_),
147  logAbtLev_ (p. logAbtLev_),
148  jnlst_ (p.jnlst_),
149  opt_window_ (p.opt_window_), // needed only in standardize (), unnecessary to update it
150  useQuadratic_ (p.useQuadratic_), // ditto
151  feas_tolerance_ (p.feas_tolerance_),
152  dependence_ (p.dependence_),
153  objects_ (p.objects_), // NO! have to copy all of them
154  integerRank_ (NULL),
155  numberInRank_ (p.numberInRank_),
156  maxCpuTime_ (p.maxCpuTime_),
157  bonBase_ (p.bonBase_),
158 #ifdef COIN_HAS_ASL
159  asl_ (p.asl_),
160 #endif
161  unusedOriginalsIndices_ (NULL),
162  nUnusedOriginals_ (p.nUnusedOriginals_),
163  multilinSep_ (p.multilinSep_),
164  max_fbbt_iter_ (p.max_fbbt_iter_),
165  orbitalBranching_ (p.orbitalBranching_),
166  constObjVal_ (p.constObjVal_),
167  perfIndicator_ (new CouenneBTPerfIndicator (*(p.perfIndicator_))),
168  nauty_info (p.nauty_info) {
169 
170  sdpCutGen_ = new CouenneSdpCuts (*(p.sdpCutGen_));
171 
172  for (int i=0; i < p.nVars (); i++)
173  variables_ . push_back (NULL);
174 
175  for (int i=0; i < p.nVars (); i++) {
176  int ind = p.numbering_ [i];
177  variables_ [ind] = p.Var (ind) -> clone (&domain_);
178  }
179 
180  for (std::vector <CouenneObject *>::iterator i = objects_.begin ();
181  i != objects_.end (); ++i)
182  (*i) = (*i) -> clone ();
183 
184  if (p.numbering_)
185  numbering_ = CoinCopyOfArray (p.numbering_, nVars ());
186 
187  // clone objectives and constraints (there's a leak around here)
188  for (int i=0; i < p.nObjs (); i++) objectives_ . push_back (p.Obj (i) -> clone (&domain_));
189  for (int i=0; i < p.nCons (); i++) constraints_ . push_back (p.Con (i) -> clone (&domain_));
190 
191  if (p.optimum_)
192  optimum_ = CoinCopyOfArray (p.optimum_, nVars ());
193 
194  // clear all spurious variables pointers not referring to the variables_ vector
195  realign ();
196 
197  // copy integer rank (used in getIntegerCandidate)
198  if (p.integerRank_) {
199  integerRank_ = new int [nVars ()];
200  CoinCopyN (p.integerRank_, nVars (), integerRank_);
201  }
202 
203  // copy unusedOriginals
204  if (nUnusedOriginals_ > 0) {
205  unusedOriginalsIndices_ = (int *) malloc (nUnusedOriginals_ * sizeof (int));
207  }
208 
209  if (p.recBSol) recBSol = new CouenneRecordBestSol (*(p.recBSol));
210  else recBSol = new CouenneRecordBestSol ();
211 
213 
216  doPrint_ = p.doPrint_;
217 }
218 
219 
221 
223 
224  if (sdpCutGen_)
225  delete sdpCutGen_;
226 
227  delete auxSet_;
228 
229  if (perfIndicator_)
230  delete perfIndicator_;
231 
232  // delete optimal solution (if any)
233  if (optimum_)
234  free (optimum_);
235 
236  // delete objectives
237  for (std::vector <CouenneObjective *>::iterator i = objectives_ . begin ();
238  i != objectives_ . end (); ++i)
239  delete (*i);
240 
241  // delete constraints
242  for (std::vector <CouenneConstraint *>::iterator i = constraints_ . begin ();
243  i != constraints_ . end (); ++i)
244  delete (*i);
245 
246  // deletion of variables should be done in reverse order w.r.t. the
247  // dependence. If numbering_ is available, use it.
248  if (numbering_) for (int i=nVars (); i--;) delete variables_ [numbering_ [i]];
249  else for (int i=nVars (); i--;) delete variables_ [i];
250 
251  // delete extra structures
252  if (graph_) delete graph_;
253  if (commuted_) delete [] commuted_;
254  if (numbering_) delete [] numbering_;
255 
256  if (created_pcutoff_) delete pcutoff_;
257 
258  if (integerRank_) delete [] integerRank_;
259 
262 
263  for (std::vector <CouenneObject *>::iterator i = objects_.begin ();
264  i != objects_.end (); ++i)
265  delete (*i);
266 
267 #ifdef COIN_HAS_NTY
268  if (nauty_info)
269  delete nauty_info;
270 #endif
271 
272  delete recBSol;
273 }
274 
275 
278 
279  assert(IsValid(options));
280 
281  std::string s;
282 
283  options -> GetStringValue ("use_quadratic", s, "couenne."); useQuadratic_ = (s == "yes");
284  options -> GetStringValue ("feasibility_bt", s, "couenne."); doFBBT_ = (s == "yes");
285  options -> GetStringValue ("redcost_bt", s, "couenne."); doRCBT_ = (s == "yes");
286  options -> GetStringValue ("optimality_bt", s, "couenne."); doOBBT_ = (s == "yes");
287  options -> GetStringValue ("aggressive_fbbt", s, "couenne."); doABT_ = (s == "yes");
288 
289  options -> GetIntegerValue ("log_num_obbt_per_level", logObbtLev_, "couenne.");
290  options -> GetIntegerValue ("log_num_abt_per_level", logAbtLev_, "couenne.");
291 
292  options -> GetIntegerValue ("max_fbbt_iter", max_fbbt_iter_, "couenne.");
293 
294  options -> GetNumericValue ("feas_tolerance", feas_tolerance_, "couenne.");
295  options -> GetNumericValue ("opt_window", opt_window_, "couenne.");
296 
297  options -> GetStringValue ("multilinear_separation", s, "couenne.");
298  multilinSep_ = (s == "none" ? CouenneProblem::MulSepNone :
299  s == "simple" ? CouenneProblem::MulSepSimple :
301 
302  options -> GetStringValue ("orbital_branching", s, "couenne."); orbitalBranching_ = (s == "yes");
303 
304  options -> GetStringValue ("quadrilinear_decomp", s, "couenne.");
305  if (s == "rAI") trilinDecompType_ = rAI;
306  else if (s == "tri+bi") trilinDecompType_ = tri_bi;
307  else if (s == "bi+tri") trilinDecompType_ = bi_tri;
308  else if (s == "hier-bi") trilinDecompType_ = treeDecomp;
309 }
void realign()
clear all spurious variables pointers not referring to the variables_ vector
Definition: problem.cpp:392
GlobalCutOff * pcutoff_
Pointer to a global cutoff object.
const CouNumber feas_tolerance_default
int nVars() const
Total number of variables.
#define COIN_HAS_ASL
CouenneProblem(ASL *=NULL, Bonmin::BabSetupBase *base=NULL, JnlstPtr jnlst=NULL)
Constructor.
int max_fbbt_iter_
number of FBBT iterations
std::vector< CouenneObjective * > objectives_
Objectives.
bool doABT_
do Aggressive bound tightening
CouenneBTPerfIndicator * perfIndicator_
Performance indicator for FBBT – to be moved away from CouenneProblem when we do it with FBBT...
DepGraph * graph_
Dependence (acyclic) graph: shows dependence of all auxiliary variables on one another and on origina...
int * integerRank_
each element is true if variable is integer and, if auxiliary, depends on no integer ...
CouenneSdpCuts * sdpCutGen_
Temporary pointer to SDP cut generator.
bool IsValid(const OSSmartPtr< U > &smart_ptr)
Definition: OSSmartPtr.hpp:465
std::set< exprAux *, compExpr > * auxSet_
Expression map for comparison in standardization and to count occurrences of an auxiliary.
These are cuts of the form.
int logAbtLev_
frequency of Aggressive bound tightening
bool doOBBT_
do Optimality-based bound tightening
int nUnusedOriginals_
number of unused originals
void initOptions(Ipopt::SmartPtr< Ipopt::OptionsList > options)
initializes parameters like doOBBT
std::vector< CouenneObject * > objects_
vector of pointer to CouenneObjects.
A class to have all elements necessary to setup a branch-and-bound.
CouenneProblem * clone() const
Clone method (for use within CouenneCutGenerator::clone)
CouNumber opt_window_
window around known optimum (for testing purposes)
std::vector< CouenneConstraint * > constraints_
Constraints.
fint end
CouenneConstraint * Con(int i) const
i-th constraint
bool created_pcutoff_
flag indicating if this class is creator of global cutoff object
Class for MINLP problems with symbolic information.
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real * s
exprVar * Var(int i) const
Return pointer to i-th variable.
std::vector< exprVar * > variables_
Variables (original, auxiliary, and defined)
CouenneRecordBestSol * recBSol
bool * commuted_
Variables that have commuted to auxiliary.
enum TrilinDecompType trilinDecompType_
return type of decomposition of quadrilinear terms
Domain domain_
current point and bounds;
int * numbering_
numbering of variables.
CouNumber * optimum_
Best solution known to be loaded from file – for testing purposes.
bool orbitalBranching_
use orbital branching?
#define MAX_FBBT_ITER
CouNumber feas_tolerance_
feasibility tolerance (to be used in checkNLP)
bool useQuadratic_
Use quadratic expressions?
int logObbtLev_
frequency of Optimality-based bound tightening
enum multiSep multilinSep_
Type of Multilinear separation.
int nCons() const
Get number of constraints.
int * unusedOriginalsIndices_
some originals may be unused due to their zero multiplicity (that happens when they are duplicates)...
JnlstPtr jnlst_
SmartPointer to the Journalist.
CouenneObjective * Obj(int i) const
i-th objective
bool doRCBT_
do reduced cost bound tightening
int nObjs() const
Get number of objectives.
const Ipopt::EJournalCategory J_PROBLEM(Ipopt::J_USER4)
bool doFBBT_
do Feasibility-based bound tightening