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

Last change on this file since 151 was 151, checked in by pbelotti, 12 years ago

ignore defined variables (aka common expressions) in nlp interface

  • Property svn:eol-style set to native
  • Property svn:keywords set to "Author Date Id Revision"
File size: 6.5 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  doRCBT_    (true),
50  doOBBT_    (true),
51  doABT_     (true),
52  logObbtLev_(0),
53  logAbtLev_ (0),
54  jnlst_     (jnlst),
55  opt_window_ (COIN_DBL_MAX),
56  useQuadratic_ (false),
57  feas_tolerance_ (feas_tolerance_default),
58  integerRank_ (NULL),
59  maxCpuTime_  (COIN_DBL_MAX),
60  bonBase_     (base),
61#ifdef COIN_HAS_ASL
62  asl_         (asl),
63#endif
64  unusedOriginalsIndices_ (NULL),
65  nUnusedOriginals_ (-1) {
66
67  double now = CoinCpuTime ();
68
69  if (asl) {
70#if COIN_HAS_ASL
71    // read problem from AMPL structure
72    readnl (asl);
73#else
74    jnlst_ -> Printf (Ipopt::J_ERROR, J_PROBLEM, "Couenne was compiled without ASL library. Cannot process ASL structure.\n");
75    throw -1;
76#endif
77
78    if ((now = (CoinCpuTime () - now)) > 10.)
79      jnlst_ -> Printf (Ipopt::J_WARNING, J_PROBLEM,
80                        "Couenne: reading time %.3fs\n", now);
81  }
82
83  // create expression set for binary search
84  auxSet_ = new std::set <exprAux *, compExpr>;
85
86  if (base) {
87    std::string s;
88    base -> options() -> GetStringValue ("use_quadratic", s, "couenne."); 
89    useQuadratic_ = (s == "yes");
90  }
91
92  if (base) {
93
94    std::string s;
95
96    base -> options() -> GetStringValue ("feasibility_bt",  s, "couenne."); doFBBT_ = (s == "yes");
97    base -> options() -> GetStringValue ("redcost_bt",      s, "couenne."); doRCBT_ = (s == "yes");
98    base -> options() -> GetStringValue ("optimality_bt",   s, "couenne."); doOBBT_ = (s == "yes");
99    base -> options() -> GetStringValue ("aggressive_fbbt", s, "couenne."); doABT_  = (s == "yes");
100
101    base -> options() -> GetIntegerValue ("log_num_obbt_per_level", logObbtLev_, "couenne.");
102    base -> options() -> GetIntegerValue ("log_num_abt_per_level",  logAbtLev_,  "couenne.");
103
104    base -> options() -> GetNumericValue ("feas_tolerance",  feas_tolerance_, "couenne.");
105    base -> options() -> GetNumericValue ("opt_window",      opt_window_,     "couenne.");
106  }
107}
108
109
110/// copy constructor
111
112CouenneProblem::CouenneProblem (const CouenneProblem &p):
113  problemName_  (p.problemName_),
114  domain_       (p.domain_),
115  curnvars_     (-1),
116  nIntVars_     (p.nIntVars_),
117  optimum_      (NULL),
118  bestObj_      (p.bestObj_),
119  commuted_     (NULL),
120  numbering_    (NULL),
121  ndefined_     (p.ndefined_),
122  graph_        (NULL),
123  nOrigVars_    (p.nOrigVars_),
124  nOrigCons_    (p.nOrigCons_),
125  nOrigIntVars_ (p.nOrigIntVars_),
126  pcutoff_      (p.pcutoff_),
127  created_pcutoff_ (false),
128  doFBBT_       (p. doFBBT_),
129  doRCBT_       (p. doRCBT_),
130  doOBBT_       (p. doOBBT_),
131  doABT_        (p. doABT_),
132  logObbtLev_   (p. logObbtLev_),
133  logAbtLev_    (p. logAbtLev_),
134  jnlst_        (p.jnlst_),
135  opt_window_   (p.opt_window_),    // needed only in standardize (), unnecessary to update it
136  useQuadratic_ (p.useQuadratic_),  // ditto
137  feas_tolerance_ (p.feas_tolerance_),
138  dependence_   (p.dependence_),
139  objects_      (p.objects_),
140  integerRank_  (NULL),
141  numberInRank_ (p.numberInRank_),
142  maxCpuTime_   (p.maxCpuTime_),
143  bonBase_      (p.bonBase_),
144#ifdef COIN_HAS_ASL
145  asl_          (p.asl_),
146#endif
147  unusedOriginalsIndices_ (NULL),
148  nUnusedOriginals_ (p.nUnusedOriginals_) {
149
150  for (int i=0; i < p.nVars (); i++)
151    variables_ . push_back (NULL);
152
153  for (int i=0; i < p.nVars (); i++) {
154    int ind = p.numbering_ [i];
155    variables_ [ind] = p.Var (ind) -> clone (&domain_);
156  }
157
158  if (p.numbering_)
159    numbering_ = CoinCopyOfArray (p.numbering_, nVars ());
160
161  // clone objectives and constraints (there's a leak around here)
162  for (int i=0; i < p.nObjs (); i++) objectives_  . push_back (p.Obj (i) -> clone (&domain_));
163  for (int i=0; i < p.nCons (); i++) constraints_ . push_back (p.Con (i) -> clone (&domain_));
164
165  if (p.optimum_) 
166    optimum_ = CoinCopyOfArray (p.optimum_, nVars ());
167   
168  // clear all spurious variables pointers not referring to the variables_ vector
169  realign ();
170
171  // copy integer rank (used in getIntegerCandidate)
172  if (p.integerRank_) {
173    integerRank_ = new int [nVars ()];
174    CoinCopyN (p.integerRank_, nVars (), integerRank_);
175  }
176
177  // copy unusedOriginals
178  if (nUnusedOriginals_ > 0) {
179    unusedOriginalsIndices_ = (int *) malloc (nUnusedOriginals_ * sizeof (int));
180    CoinCopyN (p.unusedOriginalsIndices_, nUnusedOriginals_, unusedOriginalsIndices_);
181  }
182}
183
184
185/// Destructor
186
187CouenneProblem::~CouenneProblem () {
188
189  // delete optimal solution (if any)
190  if (optimum_)
191    free (optimum_);
192
193  // delete objectives
194  for (std::vector <CouenneObjective *>::iterator i  = objectives_ . begin ();
195       i != objectives_ . end (); ++i)
196    delete (*i);
197
198  // delete constraints
199  for (std::vector <CouenneConstraint *>::iterator i = constraints_ . begin ();
200       i != constraints_ . end (); ++i)
201    delete (*i);
202
203  // delete variables
204  //for (std::vector <exprVar *>::iterator i = variables_ . begin ();
205  //i != variables_ . end (); ++i)
206  //delete (*i);
207
208  for (int i=nVars (); i--;) { // delete in inverse order
209    int ind = numbering_ [i];
210    delete variables_ [ind];
211  }
212
213  // delete extra structures
214  if (graph_)     delete    graph_;
215  if (commuted_)  delete [] commuted_;
216  if (numbering_) delete [] numbering_;
217
218  if (created_pcutoff_) delete pcutoff_;
219
220  if (integerRank_) delete [] integerRank_;
221
222  if (unusedOriginalsIndices_)
223    free (unusedOriginalsIndices_);
224
225  // clear objects_, but only those elements that were copied from the
226  // nullObject in fillDependence.cpp
227  for (std::vector <CouenneObject *>::iterator i = objects_.begin ();
228       i != objects_. end (); ++i)
229    if ((*i) -> Reference () == NULL)
230      delete (*i);
231}
Note: See TracBrowser for help on using the repository browser.