/home/coin/SVN-release/OS-2.4.2/Bonmin/experimental/Bcp/BM_pack.cpp

Go to the documentation of this file.
00001 // (C) Copyright International Business Machines Corporation and Carnegie Mellon University 2006, 2007
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // Authors :
00006 // Laszlo Ladanyi, International Business Machines Corporation
00007 
00008 #include "BM.hpp"
00009 #include "BCP_lp.hpp"
00010 
00011 #include "BonAmplSetup.hpp"
00012 
00013 //#############################################################################
00014 
00015 void
00016 BM_tm::pack_module_data(BCP_buffer& buf, BCP_process_t ptype)
00017 {
00018     // possible process types looked up in BCP_enum_process_t.hpp
00019     switch (ptype) {
00020     case BCP_ProcessType_LP:
00021         par.pack(buf);
00022         buf.pack(nl_file_content);
00023         buf.pack(ipopt_file_content);
00024         break;
00025     case BCP_ProcessType_TS:
00026         break;
00027     default:
00028         abort();
00029     }
00030 }
00031 
00032 /****************************************************************************/
00033 
00034 void
00035 BM_lp::unpack_module_data(BCP_buffer& buf)
00036 {
00037     using namespace Bonmin;
00038 
00039     par.unpack(buf);
00040     buf.unpack(nl_file_content);
00041     buf.unpack(ipopt_file_content);
00042 
00043     char* argv_[3];
00044     char** argv = argv_;
00045     argv[0] = NULL;
00046     argv[1] = strdup("dont_even_try_to_open_it.nl");
00047     argv[2] = NULL;
00048     std::string ipopt_content(ipopt_file_content.c_str());
00049     std::string nl_content(nl_file_content.c_str());
00050 
00051     /* PIERRE create the setup for algorithm, last argument indicates that
00052       continuous relaxation should not be created.*/
00053     bonmin_.initialize(argv, ipopt_content, nl_content, false);
00054     bonmin_.nonlinearSolver()->setExposeWarmStart(true);
00055 
00056     free(argv[1]);
00057 
00058     /* synchronize bonmin & BCP parameters */
00059     Ipopt::SmartPtr<Ipopt::OptionsList> options = bonmin_.options();
00060 
00063     integerTolerance_ = bonmin_.getDoubleParameter(BabSetupBase::IntTol);
00064     // cutOffDecrement_ could be negative
00065     double cutOffDecrement =
00066       bonmin_.getDoubleParameter(BabSetupBase::CutoffDecr);
00067 
00068     BCP_lp_prob* bcp_lp = getLpProblemPointer();
00069     const double bcp_intTol = bcp_lp->par.entry(BCP_lp_par::IntegerTolerance);
00070     const double bcp_cutoffIncr = bcp_lp->par.entry(BCP_lp_par::Granularity);
00071 
00072     if (fabs(integerTolerance_ - bcp_intTol) > 1e-10) {
00073         printf("WARNING!\n");
00074         printf("   The integrality tolerance parameters are different for\n");
00075         printf("   BCP (%f) and bonmin (%f). They should be identical.\n",
00076                bcp_intTol, integerTolerance_);
00077         printf("   For now both will be set to that of bonmin.\n");
00078     }
00079     if (fabs(bcp_cutoffIncr - cutOffDecrement) > 1e-10) {
00080         printf("WARNING!\n");
00081         printf("   The granularity (cutoff increment) parameters are different\n");
00082         printf("   BCP (%f) and bonmin (%f). They should be identical.\n",
00083                bcp_cutoffIncr, cutOffDecrement);
00084         printf("   For now both will be set to that of bonmin.\n");
00085     }
00086     bcp_lp->par.set_entry(BCP_lp_par::IntegerTolerance, integerTolerance_);
00087     bcp_lp->par.set_entry(BCP_lp_par::Granularity, cutOffDecrement);
00088 
00089     /* If pure BB is selected then a number of BCP parameters are changed */
00090     if (bonmin_.getAlgorithm() == 0 /* pure B&B */) {
00091         /* disable strong branching */
00092         bcp_lp->par.set_entry(BCP_lp_par::MaxPresolveIter, -1);
00093         /* disable a bunch of printing, all of which are meaningless, since the
00094            LP relaxation is meaningless */
00095         bcp_lp->par.set_entry(BCP_lp_par::LpVerb_ReportLocalCutPoolSize, false);
00096         bcp_lp->par.set_entry(BCP_lp_par::LpVerb_ReportLocalVarPoolSize, false);
00097         bcp_lp->par.set_entry(BCP_lp_par::LpVerb_GeneratedCutCount, false);
00098         bcp_lp->par.set_entry(BCP_lp_par::LpVerb_GeneratedVarCount, false);
00099         bcp_lp->par.set_entry(BCP_lp_par::LpVerb_RowEffectivenessCount, false);
00100     }
00101 
00102     /* extract the sos constraints */
00103     Bonmin::OsiTMINLPInterface& nlp = *bonmin_.nonlinearSolver();
00104     const Bonmin::TMINLP::SosInfo * sos = nlp.model()->sosConstraints();
00105     
00106     int i;
00107     const int numCols = nlp.getNumCols();
00108     const double* clb = nlp.getColLower();
00109     const double* cub = nlp.getColUpper();
00110     const int* cPrio = nlp.getPriorities();
00111 
00112     /* Find first the integer variables and then the SOS constraints */
00113     int nObj = 0;
00114     OsiObject** osiObj = new OsiObject*[numCols + sos->num];
00115     for (i = 0; i < numCols; ++i) {
00116         if (nlp.isInteger(i)) {
00117             osiObj[nObj] = new OsiSimpleInteger(i, clb[i], cub[i]);
00118             if (cPrio) {
00119               osiObj[nObj]->setPriority(cPrio[i]);
00120             }
00121             ++nObj;
00122         }
00123     }
00124 #if ! defined(BM_DISREGARD_SOS)
00125     const int* starts = sos->starts;
00126     for (i = 0; i < sos->num; ++i) {
00127         OsiSOS* so = new OsiSOS(NULL, /* FIXME: why does the constr need */
00128                                 starts[i+1] - starts[i],
00129                                 sos->indices + starts[i],
00130                                 sos->weights + starts[i],
00131                                 sos->types[i]);
00132         so->setPriority(sos->priorities ? sos->priorities[i] : 1);
00133         osiObj[nObj++] = so;
00134     }
00135 #endif
00136     nlp.addObjects(nObj, osiObj);
00137 
00138     objNum_ = nObj;
00139     /* Allocate the storage arrays */
00140     infInd_ = new int[objNum_];
00141     infUseful_ = new double[objNum_];
00142     feasInd_ = new int[objNum_];
00143     feasUseful_ = new double[objNum_];
00144     sbResult_ = new BM_SB_result[objNum_];
00145 
00146     /* Sort the objects based on their priority */
00147     int* prio = new int[objNum_];
00148     objInd_ = new int[objNum_];
00149     for (i = 0; i < objNum_; ++i) {
00150       sbResult_[i].colInd = osiObj[i]->columnNumber();
00151       objInd_[i] = i;
00152       prio[i] = osiObj[i]->priority();
00153     }
00154     CoinSort_2(prio, prio+objNum_, objInd_);
00155     delete[] prio;
00156     
00157     for (i = 0; i < nObj; ++i) {
00158         delete osiObj[i];
00159     }
00160     delete[] osiObj;
00161 }
00162 
00163 //#############################################################################
00164 
00165 void
00166 BM_pack::pack_user_data(const BCP_user_data* ud, BCP_buffer& buf)
00167 {
00168     const BM_node* data = dynamic_cast<const BM_node*>(ud);
00169     data->pack(buf);
00170     BM_tm* tm = dynamic_cast<BM_tm*>(user_class);
00171     if (tm) {
00172       tm->pack_pseudo_costs(buf);
00173     }
00174 }
00175 
00176 /*---------------------------------------------------------------------------*/
00177 
00178 BCP_user_data*
00179 BM_pack::unpack_user_data(BCP_buffer& buf)
00180 {
00181     BM_node* node = new BM_node(buf);
00182     BM_lp* lp = dynamic_cast<BM_lp*>(user_class);
00183     if (lp) {
00184       lp->unpack_pseudo_costs(buf);
00185     }
00186     return node;
00187 }
00188 
00189 /*---------------------------------------------------------------------------*/
00190 
00191 void
00192 BM_pack::pack_cut_algo(const BCP_cut_algo* cut, BCP_buffer& buf)
00193 {
00194     const BB_cut* bb_cut = dynamic_cast<const BB_cut*>(cut);
00195     if (!bb_cut)
00196         throw BCP_fatal_error("pack_cut_algo() : unknown cut type!\n");
00197     bb_cut->pack(buf);
00198 }
00199 
00200 /*---------------------------------------------------------------------------*/
00201 BCP_cut_algo* BM_pack::unpack_cut_algo(BCP_buffer& buf)
00202 {
00203     return new BB_cut(buf);
00204 }

Generated on Wed Nov 30 03:03:52 2011 by  doxygen 1.4.7