CouenneProblemConstructors.cpp
Go to the documentation of this file.
1 /* $Id: CouenneProblemConstructors.cpp 1255 2018-08-27 22:56:09Z 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  FBBTperfIndicator_ (new CouenneBTPerfIndicator (this, "FBBT")),
89  OBBTperfIndicator_ (new CouenneBTPerfIndicator (this, "OBBT")),
90 
91  nauty_info (NULL),
92  sdpCutGen_ (NULL) {
93 
94  double now = CoinCpuTime ();
95 
96  if (asl) {
97 #if COIN_HAS_ASL
98  // read problem from AMPL structure
99  readnl (asl);
100 #else
101  jnlst_ -> Printf (Ipopt::J_ERROR, J_PROBLEM, "Couenne was compiled without the ASL library. Cannot process ASL structure.\n");
102  throw -1;
103 #endif
104 
105  if ((now = (CoinCpuTime () - now)) > 10.)
106  jnlst_ -> Printf (Ipopt::J_WARNING, J_PROBLEM,
107  "Couenne: reading time %.3fs\n", now);
108  }
109 
110  // create expression set for binary search
111  auxSet_ = new std::set <exprAux *, compExpr>;
112 
113  if (base)
114  initOptions (base -> options());
115 
117  lastPrioSort_ = 1000000;
118 
119  minDepthPrint_ = -1;
120  minNodePrint_ = -1;
121  doPrint_ = false;
122 }
123 
124 
126 
128  problemName_ (p.problemName_),
129  domain_ (p.domain_),
130  curnvars_ (-1),
131  nIntVars_ (p.nIntVars_),
132  optimum_ (NULL),
133  bestObj_ (p.bestObj_),
134  commuted_ (NULL),
135  numbering_ (NULL),
136  ndefined_ (p.ndefined_),
137  graph_ (NULL),
138  nOrigVars_ (p.nOrigVars_),
139  nOrigCons_ (p.nOrigCons_),
140  nOrigIntVars_ (p.nOrigIntVars_),
141  pcutoff_ (p.pcutoff_),
142  created_pcutoff_ (false),
143  doFBBT_ (p. doFBBT_),
144  doRCBT_ (p. doRCBT_),
145  doOBBT_ (p. doOBBT_),
146  doABT_ (p. doABT_),
147  logObbtLev_ (p. logObbtLev_),
148  logAbtLev_ (p. logAbtLev_),
149  jnlst_ (p.jnlst_),
150  opt_window_ (p.opt_window_), // needed only in standardize (), unnecessary to update it
151  useQuadratic_ (p.useQuadratic_), // ditto
152  feas_tolerance_ (p.feas_tolerance_),
153  dependence_ (p.dependence_),
154  objects_ (p.objects_), // NO! have to copy all of them
155  integerRank_ (NULL),
156  numberInRank_ (p.numberInRank_),
157  maxCpuTime_ (p.maxCpuTime_),
158  bonBase_ (p.bonBase_),
159 #ifdef COIN_HAS_ASL
160  asl_ (p.asl_),
161 #endif
162  unusedOriginalsIndices_ (NULL),
163  nUnusedOriginals_ (p.nUnusedOriginals_),
164  multilinSep_ (p.multilinSep_),
165  max_fbbt_iter_ (p.max_fbbt_iter_),
166  orbitalBranching_ (p.orbitalBranching_),
167  constObjVal_ (p.constObjVal_),
168  FBBTperfIndicator_ (new CouenneBTPerfIndicator (*(p.FBBTperfIndicator_))),
169  OBBTperfIndicator_ (new CouenneBTPerfIndicator (*(p.OBBTperfIndicator_))),
170  nauty_info (p.nauty_info) {
171 
172  sdpCutGen_ = new CouenneSdpCuts (*(p.sdpCutGen_));
173 
174  for (int i=0; i < p.nVars (); i++)
175  variables_ . push_back (NULL);
176 
177  for (int i=0; i < p.nVars (); i++) {
178  int ind = p.numbering_ [i];
179  variables_ [ind] = p.Var (ind) -> clone (&domain_);
180  }
181 
182  for (std::vector <CouenneObject *>::iterator i = objects_.begin ();
183  i != objects_.end (); ++i)
184  (*i) = (*i) -> clone ();
185 
186  if (p.numbering_)
187  numbering_ = CoinCopyOfArray (p.numbering_, nVars ());
188 
189  // clone objectives and constraints (there's a leak around here)
190  for (int i=0; i < p.nObjs (); i++) objectives_ . push_back (p.Obj (i) -> clone (&domain_));
191  for (int i=0; i < p.nCons (); i++) constraints_ . push_back (p.Con (i) -> clone (&domain_));
192 
193  if (p.optimum_)
194  optimum_ = CoinCopyOfArray (p.optimum_, nVars ());
195 
196  // clear all spurious variables pointers not referring to the variables_ vector
197  realign ();
198 
199  // copy integer rank (used in getIntegerCandidate)
200  if (p.integerRank_) {
201  integerRank_ = new int [nVars ()];
202  CoinCopyN (p.integerRank_, nVars (), integerRank_);
203  }
204 
205  // copy unusedOriginals
206  if (nUnusedOriginals_ > 0) {
207  unusedOriginalsIndices_ = (int *) malloc (nUnusedOriginals_ * sizeof (int));
209  }
210 
211  if (p.recBSol) recBSol = new CouenneRecordBestSol (*(p.recBSol));
212  else recBSol = new CouenneRecordBestSol ();
213 
215 
218  doPrint_ = p.doPrint_;
219 }
220 
221 
223 
225 
226  if (sdpCutGen_)
227  delete sdpCutGen_;
228 
229  delete auxSet_;
230 
231  if (FBBTperfIndicator_)
232  delete FBBTperfIndicator_;
233 
234  if (OBBTperfIndicator_)
235  delete OBBTperfIndicator_;
236 
237  // delete optimal solution (if any)
238  if (optimum_)
239  free (optimum_);
240 
241  // delete objectives
242  for (std::vector <CouenneObjective *>::iterator i = objectives_ . begin ();
243  i != objectives_ . end (); ++i)
244  delete (*i);
245 
246  // delete constraints
247  for (std::vector <CouenneConstraint *>::iterator i = constraints_ . begin ();
248  i != constraints_ . end (); ++i)
249  delete (*i);
250 
251  // deletion of variables should be done in reverse order w.r.t. the
252  // dependence. If numbering_ is available, use it.
253  if (numbering_) for (int i=nVars (); i--;) delete variables_ [numbering_ [i]];
254  else for (int i=nVars (); i--;) delete variables_ [i];
255 
256  // delete extra structures
257  if (graph_) delete graph_;
258  if (commuted_) delete [] commuted_;
259  if (numbering_) delete [] numbering_;
260 
261  if (created_pcutoff_) delete pcutoff_;
262 
263  if (integerRank_) delete [] integerRank_;
264 
267 
268  for (std::vector <CouenneObject *>::iterator i = objects_.begin ();
269  i != objects_.end (); ++i)
270  delete (*i);
271 
272 #ifdef COIN_HAS_NTY
273  if (nauty_info)
274  delete nauty_info;
275 #endif
276 
277  delete recBSol;
278 }
279 
280 
283 
284  assert(IsValid(options));
285 
286  std::string s;
287 
288  options -> GetStringValue ("use_quadratic", s, "couenne."); useQuadratic_ = (s == "yes");
289  options -> GetStringValue ("feasibility_bt", s, "couenne."); doFBBT_ = (s == "yes");
290  options -> GetStringValue ("redcost_bt", s, "couenne."); doRCBT_ = (s == "yes");
291  options -> GetStringValue ("optimality_bt", s, "couenne."); doOBBT_ = (s == "yes");
292  options -> GetStringValue ("aggressive_fbbt", s, "couenne."); doABT_ = (s == "yes");
293 
294  options -> GetIntegerValue ("log_num_obbt_per_level", logObbtLev_, "couenne.");
295  options -> GetIntegerValue ("log_num_abt_per_level", logAbtLev_, "couenne.");
296 
297  options -> GetIntegerValue ("max_fbbt_iter", max_fbbt_iter_, "couenne.");
298 
299  options -> GetNumericValue ("feas_tolerance", feas_tolerance_, "couenne.");
300  options -> GetNumericValue ("opt_window", opt_window_, "couenne.");
301 
302  options -> GetStringValue ("multilinear_separation", s, "couenne.");
303  multilinSep_ = (s == "none" ? CouenneProblem::MulSepNone :
304  s == "simple" ? CouenneProblem::MulSepSimple :
306 
307  options -> GetStringValue ("orbital_branching", s, "couenne."); orbitalBranching_ = (s == "yes");
308 
309  options -> GetStringValue ("quadrilinear_decomp", s, "couenne.");
310  if (s == "rAI") trilinDecompType_ = rAI;
311  else if (s == "tri+bi") trilinDecompType_ = tri_bi;
312  else if (s == "bi+tri") trilinDecompType_ = bi_tri;
313  else if (s == "hier-bi") trilinDecompType_ = treeDecomp;
314 }
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
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
CouenneBTPerfIndicator * OBBTperfIndicator_
Performance indicator for OBBT – to be moved away from CouenneProblem.
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)
CouenneBTPerfIndicator * FBBTperfIndicator_
Performance indicator for FBBT – to be moved away from CouenneProblem when we do it with FBBT...
bool doFBBT_
do Feasibility-based bound tightening