/home/coin/SVN-release/OS-2.0.0/Couenne/src/problem/CouenneProblemConstructors.cpp

Go to the documentation of this file.
00001 /* $Id: CouenneProblemConstructors.cpp 159 2009-06-24 14:54:00Z pbelotti $
00002  *
00003  * Name:    CouenneProblemConstructors.cpp
00004  * Author:  Pietro Belotti
00005  * Purpose: Constructors and destructors of the class CouenneProblem
00006  *
00007  * This file is licensed under the Common Public License (CPL)
00008  */
00009 
00010 #include <vector>
00011 
00012 #include "CoinHelperFunctions.hpp"
00013 #include "CoinTime.hpp"
00014 
00015 #include "CouenneTypes.hpp"
00016 
00017 #include "expression.hpp"
00018 #include "exprConst.hpp"
00019 #include "exprQuad.hpp"
00020 #include "exprClone.hpp"
00021 #include "exprIVar.hpp"
00022 #include "exprAux.hpp"
00023 #include "exprOpp.hpp"
00024 
00025 #include "CouenneProblem.hpp"
00026 #include "CouenneProblemElem.hpp"
00027 #include "depGraph.hpp"
00028 #include "lqelems.hpp"
00029 
00031 CouenneProblem::CouenneProblem (struct ASL *asl,
00032                                 Bonmin::BabSetupBase *base,
00033                                 JnlstPtr jnlst):
00034   problemName_ (""),
00035   auxSet_    (NULL), 
00036   curnvars_  (-1),
00037   nIntVars_  (0),
00038   optimum_   (NULL),
00039   bestObj_   (COIN_DBL_MAX),
00040   quadIndex_ (NULL),
00041   commuted_  (NULL),
00042   numbering_ (NULL),
00043   ndefined_  (0),
00044   graph_     (NULL),
00045   nOrigVars_ (0),
00046   nOrigIntVars_ (0),
00047   pcutoff_   (new GlobalCutOff (COIN_DBL_MAX)),
00048   created_pcutoff_ (true),
00049   doFBBT_    (true),
00050   doRCBT_    (true),
00051   doOBBT_    (true),
00052   doABT_     (true),
00053   logObbtLev_(0),
00054   logAbtLev_ (0),
00055   jnlst_     (jnlst),
00056   opt_window_ (COIN_DBL_MAX),
00057   useQuadratic_ (false),
00058   feas_tolerance_ (feas_tolerance_default),
00059   integerRank_ (NULL),
00060   maxCpuTime_  (COIN_DBL_MAX),
00061   bonBase_     (base),
00062 #ifdef COIN_HAS_ASL
00063   asl_         (asl),
00064 #endif
00065   unusedOriginalsIndices_ (NULL),
00066   nUnusedOriginals_ (-1) {
00067 
00068   double now = CoinCpuTime ();
00069 
00070   if (asl) {
00071 #if COIN_HAS_ASL
00072     // read problem from AMPL structure
00073     readnl (asl);
00074 #else
00075     jnlst_ -> Printf (Ipopt::J_ERROR, J_PROBLEM, "Couenne was compiled without ASL library. Cannot process ASL structure.\n");
00076     throw -1;
00077 #endif
00078 
00079     if ((now = (CoinCpuTime () - now)) > 10.)
00080       jnlst_ -> Printf (Ipopt::J_WARNING, J_PROBLEM,
00081                         "Couenne: reading time %.3fs\n", now);
00082   }
00083 
00084   // create expression set for binary search
00085   auxSet_ = new std::set <exprAux *, compExpr>;
00086 
00087   if (base) {
00088     std::string s;
00089     base -> options() -> GetStringValue ("use_quadratic", s, "couenne."); 
00090     useQuadratic_ = (s == "yes");
00091   }
00092 
00093   if (base) {
00094 
00095     std::string s;
00096 
00097     base -> options() -> GetStringValue ("feasibility_bt",  s, "couenne."); doFBBT_ = (s == "yes");
00098     base -> options() -> GetStringValue ("redcost_bt",      s, "couenne."); doRCBT_ = (s == "yes");
00099     base -> options() -> GetStringValue ("optimality_bt",   s, "couenne."); doOBBT_ = (s == "yes");
00100     base -> options() -> GetStringValue ("aggressive_fbbt", s, "couenne."); doABT_  = (s == "yes");
00101 
00102     base -> options() -> GetIntegerValue ("log_num_obbt_per_level", logObbtLev_, "couenne.");
00103     base -> options() -> GetIntegerValue ("log_num_abt_per_level",  logAbtLev_,  "couenne.");
00104 
00105     base -> options() -> GetNumericValue ("feas_tolerance",  feas_tolerance_, "couenne.");
00106     base -> options() -> GetNumericValue ("opt_window",      opt_window_,     "couenne.");
00107   }
00108 }
00109 
00110 
00112 
00113 CouenneProblem::CouenneProblem (const CouenneProblem &p):
00114   problemName_  (p.problemName_),
00115   domain_       (p.domain_),
00116   curnvars_     (-1),
00117   nIntVars_     (p.nIntVars_),
00118   optimum_      (NULL),
00119   bestObj_      (p.bestObj_),
00120   commuted_     (NULL),
00121   numbering_    (NULL),
00122   ndefined_     (p.ndefined_),
00123   graph_        (NULL),
00124   nOrigVars_    (p.nOrigVars_),
00125   nOrigCons_    (p.nOrigCons_),
00126   nOrigIntVars_ (p.nOrigIntVars_),
00127   pcutoff_      (p.pcutoff_),
00128   created_pcutoff_ (false),
00129   doFBBT_       (p. doFBBT_),
00130   doRCBT_       (p. doRCBT_),
00131   doOBBT_       (p. doOBBT_),
00132   doABT_        (p. doABT_),
00133   logObbtLev_   (p. logObbtLev_),
00134   logAbtLev_    (p. logAbtLev_),
00135   jnlst_        (p.jnlst_),
00136   opt_window_   (p.opt_window_),    // needed only in standardize (), unnecessary to update it
00137   useQuadratic_ (p.useQuadratic_),  // ditto
00138   feas_tolerance_ (p.feas_tolerance_),
00139   dependence_   (p.dependence_),
00140   objects_      (p.objects_), // NO! have to copy all of them 
00141   integerRank_  (NULL),
00142   numberInRank_ (p.numberInRank_),
00143   maxCpuTime_   (p.maxCpuTime_),
00144   bonBase_      (p.bonBase_),
00145 #ifdef COIN_HAS_ASL
00146   asl_          (p.asl_),
00147 #endif
00148   unusedOriginalsIndices_ (NULL),
00149   nUnusedOriginals_ (p.nUnusedOriginals_) {
00150 
00151   for (int i=0; i < p.nVars (); i++)
00152     variables_ . push_back (NULL);
00153 
00154   for (int i=0; i < p.nVars (); i++) {
00155     int ind = p.numbering_ [i];
00156     variables_ [ind] = p.Var (ind) -> clone (&domain_);
00157   }
00158 
00159   if (p.numbering_)
00160     numbering_ = CoinCopyOfArray (p.numbering_, nVars ());
00161 
00162   // clone objectives and constraints (there's a leak around here)
00163   for (int i=0; i < p.nObjs (); i++) objectives_  . push_back (p.Obj (i) -> clone (&domain_));
00164   for (int i=0; i < p.nCons (); i++) constraints_ . push_back (p.Con (i) -> clone (&domain_));
00165 
00166   if (p.optimum_) 
00167     optimum_ = CoinCopyOfArray (p.optimum_, nVars ());
00168     
00169   // clear all spurious variables pointers not referring to the variables_ vector
00170   realign ();
00171 
00172   // copy integer rank (used in getIntegerCandidate)
00173   if (p.integerRank_) {
00174     integerRank_ = new int [nVars ()];
00175     CoinCopyN (p.integerRank_, nVars (), integerRank_);
00176   }
00177 
00178   // copy unusedOriginals
00179   if (nUnusedOriginals_ > 0) {
00180     unusedOriginalsIndices_ = (int *) malloc (nUnusedOriginals_ * sizeof (int));
00181     CoinCopyN (p.unusedOriginalsIndices_, nUnusedOriginals_, unusedOriginalsIndices_);
00182   }
00183 }
00184 
00185 
00187 
00188 CouenneProblem::~CouenneProblem () {
00189 
00190   // delete optimal solution (if any)
00191   if (optimum_)
00192     free (optimum_);
00193 
00194   // delete objectives
00195   for (std::vector <CouenneObjective *>::iterator i  = objectives_ . begin ();
00196        i != objectives_ . end (); ++i)
00197     delete (*i);
00198 
00199   // delete constraints
00200   for (std::vector <CouenneConstraint *>::iterator i = constraints_ . begin ();
00201        i != constraints_ . end (); ++i)
00202     delete (*i);
00203 
00204   // delete variables
00205   //for (std::vector <exprVar *>::iterator i = variables_ . begin ();
00206   //i != variables_ . end (); ++i)
00207   //delete (*i);
00208 
00209   for (int i=nVars (); i--;) { // delete in inverse order
00210     int ind = numbering_ [i];
00211     delete variables_ [ind];
00212   }
00213 
00214   // delete extra structures
00215   if (graph_)     delete    graph_;
00216   if (commuted_)  delete [] commuted_;
00217   if (numbering_) delete [] numbering_;
00218 
00219   if (created_pcutoff_) delete pcutoff_;
00220 
00221   if (integerRank_) delete [] integerRank_;
00222 
00223   if (unusedOriginalsIndices_)
00224     free (unusedOriginalsIndices_);
00225 }

Generated on Mon Aug 3 03:02:21 2009 by  doxygen 1.4.7