source: stable/0.2/Couenne/src/problem/CouenneProblemConstructors.cpp @ 159

Last change on this file since 159 was 159, checked in by pbelotti, 11 years ago

created new stable branch 0.2 from trunk (rev. 157)

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