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

Go to the documentation of this file.
00001 /* $Id: CouenneProblemConstructors.cpp 251 2009-08-22 13:03:41Z stefan $
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         initOptions(base -> options());
00089 }
00090 
00091 
00093 
00094 CouenneProblem::CouenneProblem (const CouenneProblem &p):
00095   problemName_  (p.problemName_),
00096   domain_       (p.domain_),
00097   curnvars_     (-1),
00098   nIntVars_     (p.nIntVars_),
00099   optimum_      (NULL),
00100   bestObj_      (p.bestObj_),
00101   commuted_     (NULL),
00102   numbering_    (NULL),
00103   ndefined_     (p.ndefined_),
00104   graph_        (NULL),
00105   nOrigVars_    (p.nOrigVars_),
00106   nOrigCons_    (p.nOrigCons_),
00107   nOrigIntVars_ (p.nOrigIntVars_),
00108   pcutoff_      (p.pcutoff_),
00109   created_pcutoff_ (false),
00110   doFBBT_       (p. doFBBT_),
00111   doRCBT_       (p. doRCBT_),
00112   doOBBT_       (p. doOBBT_),
00113   doABT_        (p. doABT_),
00114   logObbtLev_   (p. logObbtLev_),
00115   logAbtLev_    (p. logAbtLev_),
00116   jnlst_        (p.jnlst_),
00117   opt_window_   (p.opt_window_),    // needed only in standardize (), unnecessary to update it
00118   useQuadratic_ (p.useQuadratic_),  // ditto
00119   feas_tolerance_ (p.feas_tolerance_),
00120   dependence_   (p.dependence_),
00121   objects_      (p.objects_), // NO! have to copy all of them 
00122   integerRank_  (NULL),
00123   numberInRank_ (p.numberInRank_),
00124   maxCpuTime_   (p.maxCpuTime_),
00125   bonBase_      (p.bonBase_),
00126 #ifdef COIN_HAS_ASL
00127   asl_          (p.asl_),
00128 #endif
00129   unusedOriginalsIndices_ (NULL),
00130   nUnusedOriginals_ (p.nUnusedOriginals_) {
00131 
00132   for (int i=0; i < p.nVars (); i++)
00133     variables_ . push_back (NULL);
00134 
00135   for (int i=0; i < p.nVars (); i++) {
00136     int ind = p.numbering_ [i];
00137     variables_ [ind] = p.Var (ind) -> clone (&domain_);
00138   }
00139 
00140   if (p.numbering_)
00141     numbering_ = CoinCopyOfArray (p.numbering_, nVars ());
00142 
00143   // clone objectives and constraints (there's a leak around here)
00144   for (int i=0; i < p.nObjs (); i++) objectives_  . push_back (p.Obj (i) -> clone (&domain_));
00145   for (int i=0; i < p.nCons (); i++) constraints_ . push_back (p.Con (i) -> clone (&domain_));
00146 
00147   if (p.optimum_) 
00148     optimum_ = CoinCopyOfArray (p.optimum_, nVars ());
00149     
00150   // clear all spurious variables pointers not referring to the variables_ vector
00151   realign ();
00152 
00153   // copy integer rank (used in getIntegerCandidate)
00154   if (p.integerRank_) {
00155     integerRank_ = new int [nVars ()];
00156     CoinCopyN (p.integerRank_, nVars (), integerRank_);
00157   }
00158 
00159   // copy unusedOriginals
00160   if (nUnusedOriginals_ > 0) {
00161     unusedOriginalsIndices_ = (int *) malloc (nUnusedOriginals_ * sizeof (int));
00162     CoinCopyN (p.unusedOriginalsIndices_, nUnusedOriginals_, unusedOriginalsIndices_);
00163   }
00164 }
00165 
00166 
00168 
00169 CouenneProblem::~CouenneProblem () {
00170 
00171   // delete optimal solution (if any)
00172   if (optimum_)
00173     free (optimum_);
00174 
00175   // delete objectives
00176   for (std::vector <CouenneObjective *>::iterator i  = objectives_ . begin ();
00177        i != objectives_ . end (); ++i)
00178     delete (*i);
00179 
00180   // delete constraints
00181   for (std::vector <CouenneConstraint *>::iterator i = constraints_ . begin ();
00182        i != constraints_ . end (); ++i)
00183     delete (*i);
00184 
00185   // delete variables
00186   //for (std::vector <exprVar *>::iterator i = variables_ . begin ();
00187   //i != variables_ . end (); ++i)
00188   //delete (*i);
00189 
00190   for (int i=nVars (); i--;) { // delete in inverse order
00191     int ind = numbering_ [i];
00192     delete variables_ [ind];
00193   }
00194 
00195   // delete extra structures
00196   if (graph_)     delete    graph_;
00197   if (commuted_)  delete [] commuted_;
00198   if (numbering_) delete [] numbering_;
00199 
00200   if (created_pcutoff_) delete pcutoff_;
00201 
00202   if (integerRank_) delete [] integerRank_;
00203 
00204   if (unusedOriginalsIndices_)
00205     free (unusedOriginalsIndices_);
00206 }
00207 
00209 void CouenneProblem::initOptions(SmartPtr<OptionsList> options)
00210 {
00211         assert(IsValid(options));
00212 
00213   std::string s;
00214   options -> GetStringValue ("use_quadratic",   s, "couenne."); useQuadratic_ = (s == "yes");
00215   options -> GetStringValue ("feasibility_bt",  s, "couenne."); doFBBT_ = (s == "yes");
00216   options -> GetStringValue ("redcost_bt",      s, "couenne."); doRCBT_ = (s == "yes");
00217   options -> GetStringValue ("optimality_bt",   s, "couenne."); doOBBT_ = (s == "yes");
00218   options -> GetStringValue ("aggressive_fbbt", s, "couenne."); doABT_  = (s == "yes");
00219 
00220   options -> GetIntegerValue ("log_num_obbt_per_level", logObbtLev_, "couenne.");
00221   options -> GetIntegerValue ("log_num_abt_per_level",  logAbtLev_,  "couenne.");
00222 
00223   options -> GetNumericValue ("feas_tolerance",  feas_tolerance_, "couenne.");
00224   options -> GetNumericValue ("opt_window",      opt_window_,     "couenne.");
00225 }

Generated on Thu Oct 8 03:02:57 2009 by  doxygen 1.4.7