source: trunk/Couenne/src/problem/CouenneProblemConstructors.cpp @ 110

Last change on this file since 110 was 110, checked in by stefan, 11 years ago

for compilation without ASL

  • Property svn:eol-style set to native
  • Property svn:keywords set to "Author Date Id Revision"
File size: 6.0 KB
Line 
1/*
2 * Name:    CouenneProblemConstructors.cpp
3 * Author:  Pietro Belotti
4 * Purpose: Constructors and destructors of the class CouenneProblem
5 *
6 * This file is licensed under the Common Public License (CPL)
7 */
8
9#include <vector>
10
11#include "CoinHelperFunctions.hpp"
12#include "CoinTime.hpp"
13
14#include "CouenneTypes.hpp"
15
16#include "expression.hpp"
17#include "exprConst.hpp"
18#include "exprQuad.hpp"
19#include "exprClone.hpp"
20#include "exprIVar.hpp"
21#include "exprAux.hpp"
22#include "exprOpp.hpp"
23
24#include "CouenneProblem.hpp"
25#include "CouenneProblemElem.hpp"
26#include "depGraph.hpp"
27#include "lqelems.hpp"
28
29/// constructor
30CouenneProblem::CouenneProblem (struct ASL *asl,
31                                Bonmin::BabSetupBase *base,
32                                JnlstPtr jnlst):
33  problemName_ (""),
34  auxSet_    (NULL), 
35  curnvars_  (-1),
36  nIntVars_  (0),
37  optimum_   (NULL),
38  bestObj_   (COIN_DBL_MAX),
39  quadIndex_ (NULL),
40  commuted_  (NULL),
41  numbering_ (NULL),
42  ndefined_  (0),
43  graph_     (NULL),
44  nOrigVars_ (0),
45  nOrigIntVars_ (0),
46  pcutoff_   (new GlobalCutOff (COIN_DBL_MAX)),
47  created_pcutoff_ (true),
48  doFBBT_    (true),
49  doOBBT_    (false),
50  doABT_     (true),
51  logObbtLev_(0),
52  logAbtLev_ (0),
53  jnlst_     (jnlst),
54  opt_window_ (COIN_DBL_MAX),
55  useQuadratic_ (false),
56  feas_tolerance_ (feas_tolerance_default),
57  integerRank_ (NULL),
58  maxCpuTime_  (COIN_DBL_MAX),
59  bonBase_     (base),
60#ifdef COIN_HAS_ASL
61  asl_         (asl),
62#endif
63  unusedOriginalsIndices_ (NULL),
64  nUnusedOriginals_ (-1) {
65
66  double now = CoinCpuTime ();
67
68  if (asl) {
69#if COIN_HAS_ASL
70    // read problem from AMPL structure
71    readnl (asl);
72#else
73    jnlst_ -> Printf (Ipopt::J_ERROR, J_PROBLEM, "Couenne was compiled without ASL library. Cannot process ASL structure.\n");
74    throw -1;
75#endif
76
77    if ((now = (CoinCpuTime () - now)) > 10.)
78      jnlst_ -> Printf (Ipopt::J_WARNING, J_PROBLEM,
79                        "Couenne: reading time %.3fs\n", now);
80  }
81
82  // create expression set for binary search
83  auxSet_ = new std::set <exprAux *, compExpr>;
84
85  if (base) {
86    std::string s;
87    base -> options() -> GetStringValue ("use_quadratic", s, "couenne."); 
88    useQuadratic_ = (s == "yes");
89  }
90
91  if (base) {
92
93    std::string s;
94
95    base -> options() -> GetStringValue ("feasibility_bt",  s, "couenne."); doFBBT_ = (s == "yes");
96    base -> options() -> GetStringValue ("optimality_bt",   s, "couenne."); doOBBT_ = (s == "yes");
97    base -> options() -> GetStringValue ("aggressive_fbbt", s, "couenne."); doABT_  = (s == "yes");
98
99    base -> options() -> GetIntegerValue ("log_num_obbt_per_level", logObbtLev_, "couenne.");
100    base -> options() -> GetIntegerValue ("log_num_abt_per_level",  logAbtLev_,  "couenne.");
101
102    base -> options() -> GetNumericValue ("feas_tolerance",  feas_tolerance_, "couenne.");
103    base -> options() -> GetNumericValue ("opt_window",      opt_window_,     "couenne.");
104  }
105}
106
107
108/// copy constructor
109
110CouenneProblem::CouenneProblem (const CouenneProblem &p):
111  problemName_  (p.problemName_),
112  domain_       (p.domain_),
113  curnvars_     (-1),
114  nIntVars_     (p.nIntVars_),
115  optimum_      (NULL),
116  bestObj_      (p.bestObj_),
117  commuted_     (NULL),
118  numbering_    (NULL),
119  ndefined_     (p.ndefined_),
120  graph_        (NULL),
121  nOrigVars_    (p.nOrigVars_),
122  nOrigCons_    (p.nOrigCons_),
123  nOrigIntVars_ (p.nOrigIntVars_),
124  pcutoff_      (p.pcutoff_),
125  created_pcutoff_ (false),
126  doFBBT_       (p. doFBBT_),
127  doOBBT_       (p. doOBBT_),
128  doABT_        (p. doABT_),
129  logObbtLev_   (p. logObbtLev_),
130  logAbtLev_    (p. logAbtLev_),
131  jnlst_        (p.jnlst_),
132  opt_window_   (p.opt_window_),    // needed only in standardize (), unnecessary to update it
133  useQuadratic_ (p.useQuadratic_),  // ditto
134  feas_tolerance_ (p.feas_tolerance_),
135  dependence_   (p.dependence_),
136  objects_      (p.objects_),
137  integerRank_  (NULL),
138  numberInRank_ (p.numberInRank_),
139  maxCpuTime_   (p.maxCpuTime_),
140  bonBase_      (p.bonBase_),
141#ifdef COIN_HAS_ASL
142  asl_          (p.asl_),
143#endif
144  unusedOriginalsIndices_ (NULL),
145  nUnusedOriginals_ (p.nUnusedOriginals_) {
146
147  for (int i=0; i < p.nVars (); i++)
148    variables_ . push_back (NULL);
149
150  for (int i=0; i < p.nVars (); i++) {
151    int ind = p.numbering_ [i];
152    variables_ [ind] = p.Var (ind) -> clone (&domain_);
153  }
154
155  if (p.numbering_)
156    numbering_ = CoinCopyOfArray (p.numbering_, nVars ());
157
158  // clone objectives and constraints (there's a leak around here)
159  for (int i=0; i < p.nObjs (); i++) objectives_  . push_back (p.Obj (i) -> clone (&domain_));
160  for (int i=0; i < p.nCons (); i++) constraints_ . push_back (p.Con (i) -> clone (&domain_));
161
162  if (p.optimum_) 
163    optimum_ = CoinCopyOfArray (p.optimum_, nVars ());
164   
165  // clear all spurious variables pointers not referring to the variables_ vector
166  realign ();
167
168  // copy integer rank (used in getIntegerCandidate)
169  if (p.integerRank_) {
170    integerRank_ = new int [nVars ()];
171    CoinCopyN (p.integerRank_, nVars (), integerRank_);
172  }
173
174  // copy unusedOriginals
175  if (nUnusedOriginals_ > 0) {
176    unusedOriginalsIndices_ = (int *) malloc (nUnusedOriginals_ * sizeof (int));
177    CoinCopyN (p.unusedOriginalsIndices_, nUnusedOriginals_, unusedOriginalsIndices_);
178  }
179}
180
181
182/// Destructor
183
184CouenneProblem::~CouenneProblem () {
185
186  // delete optimal solution (if any)
187  if (optimum_)
188    free (optimum_);
189
190  // delete objectives
191  for (std::vector <CouenneObjective *>::iterator i  = objectives_ . begin ();
192       i != objectives_ . end (); ++i)
193    delete (*i);
194
195  // delete constraints
196  for (std::vector <CouenneConstraint *>::iterator i = constraints_ . begin ();
197       i != constraints_ . end (); ++i)
198    delete (*i);
199
200  // delete variables
201  //for (std::vector <exprVar *>::iterator i = variables_ . begin ();
202  //i != variables_ . end (); ++i)
203  //delete (*i);
204
205  for (int i=nVars (); i--;) { // delete in inverse order
206    int ind = numbering_ [i];
207    delete variables_ [ind];
208  }
209
210  // delete extra structures
211  if (graph_)     delete    graph_;
212  if (commuted_)  delete [] commuted_;
213  if (numbering_) delete [] numbering_;
214
215  if (created_pcutoff_) delete pcutoff_;
216
217  if (integerRank_) delete [] integerRank_;
218
219  if (unusedOriginalsIndices_)
220    free (unusedOriginalsIndices_);
221}
Note: See TracBrowser for help on using the repository browser.