00001
00002
00003
00004
00005
00006
00007
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
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
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_),
00118 useQuadratic_ (p.useQuadratic_),
00119 feas_tolerance_ (p.feas_tolerance_),
00120 dependence_ (p.dependence_),
00121 objects_ (p.objects_),
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 for (std::vector <CouenneObject *>::iterator i = objects_.begin ();
00141 i != objects_.end (); ++i)
00142 (*i) = (*i) -> clone ();
00143
00144 if (p.numbering_)
00145 numbering_ = CoinCopyOfArray (p.numbering_, nVars ());
00146
00147
00148 for (int i=0; i < p.nObjs (); i++) objectives_ . push_back (p.Obj (i) -> clone (&domain_));
00149 for (int i=0; i < p.nCons (); i++) constraints_ . push_back (p.Con (i) -> clone (&domain_));
00150
00151 if (p.optimum_)
00152 optimum_ = CoinCopyOfArray (p.optimum_, nVars ());
00153
00154
00155 realign ();
00156
00157
00158 if (p.integerRank_) {
00159 integerRank_ = new int [nVars ()];
00160 CoinCopyN (p.integerRank_, nVars (), integerRank_);
00161 }
00162
00163
00164 if (nUnusedOriginals_ > 0) {
00165 unusedOriginalsIndices_ = (int *) malloc (nUnusedOriginals_ * sizeof (int));
00166 CoinCopyN (p.unusedOriginalsIndices_, nUnusedOriginals_, unusedOriginalsIndices_);
00167 }
00168 }
00169
00170
00172
00173 CouenneProblem::~CouenneProblem () {
00174
00175
00176 if (optimum_)
00177 free (optimum_);
00178
00179
00180 for (std::vector <CouenneObjective *>::iterator i = objectives_ . begin ();
00181 i != objectives_ . end (); ++i)
00182 delete (*i);
00183
00184
00185 for (std::vector <CouenneConstraint *>::iterator i = constraints_ . begin ();
00186 i != constraints_ . end (); ++i)
00187 delete (*i);
00188
00189
00190
00191
00192
00193
00194 if (numbering_) for (int i=nVars (); i--;) delete variables_ [numbering_ [i]];
00195 else for (int i=nVars (); i--;) delete variables_ [i];
00196
00197
00198 if (graph_) delete graph_;
00199 if (commuted_) delete [] commuted_;
00200 if (numbering_) delete [] numbering_;
00201
00202 if (created_pcutoff_) delete pcutoff_;
00203
00204 if (integerRank_) delete [] integerRank_;
00205
00206 if (unusedOriginalsIndices_)
00207 free (unusedOriginalsIndices_);
00208
00209 for (std::vector <CouenneObject *>::iterator i = objects_.begin ();
00210 i != objects_.end (); ++i)
00211 delete (*i);
00212 }
00213
00215 void CouenneProblem::initOptions(SmartPtr<OptionsList> options)
00216 {
00217 assert(IsValid(options));
00218
00219 std::string s;
00220 options -> GetStringValue ("use_quadratic", s, "couenne."); useQuadratic_ = (s == "yes");
00221 options -> GetStringValue ("feasibility_bt", s, "couenne."); doFBBT_ = (s == "yes");
00222 options -> GetStringValue ("redcost_bt", s, "couenne."); doRCBT_ = (s == "yes");
00223 options -> GetStringValue ("optimality_bt", s, "couenne."); doOBBT_ = (s == "yes");
00224 options -> GetStringValue ("aggressive_fbbt", s, "couenne."); doABT_ = (s == "yes");
00225
00226 options -> GetIntegerValue ("log_num_obbt_per_level", logObbtLev_, "couenne.");
00227 options -> GetIntegerValue ("log_num_abt_per_level", logAbtLev_, "couenne.");
00228
00229 options -> GetNumericValue ("feas_tolerance", feas_tolerance_, "couenne.");
00230 options -> GetNumericValue ("opt_window", opt_window_, "couenne.");
00231 }