/home/coin/SVN-release/OS-2.1.1/Bcp/src/TM/BCP_tm_user.cpp

Go to the documentation of this file.
00001 // Copyright (C) 2000, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #include "CoinTime.hpp"
00004 
00005 #include "BCP_vector.hpp"
00006 #include "BCP_tm_user.hpp"
00007 #include "BCP_tm.hpp"
00008 #include "BCP_lp.hpp"
00009 #include "BCP_solution.hpp"
00010 #include "BCP_var.hpp"
00011 #include "BCP_functions.hpp"
00012 
00013 //#############################################################################
00014 // Informational methods for the user
00015 double BCP_tm_user::upper_bound() const { return p->ub(); }
00016 
00017 //#############################################################################
00018 // Informational methods for the user
00019 /* Methods to get/set BCP parameters on the fly */
00020 char
00021 BCP_tm_user::get_param(const BCP_tm_par::chr_params key) const
00022 { return p->par.entry(key); }
00023 int
00024 BCP_tm_user::get_param(const BCP_tm_par::int_params key) const
00025 { return p->par.entry(key); }
00026 double
00027 BCP_tm_user::get_param(const BCP_tm_par::dbl_params key) const
00028 { return p->par.entry(key); }
00029 const BCP_string&
00030 BCP_tm_user::get_param(const BCP_tm_par::str_params key) const
00031 { return p->par.entry(key); }
00032 
00033 void BCP_tm_user::set_param(const BCP_tm_par::chr_params key, const bool val)
00034 { p->par.set_entry(key, val); }
00035 void BCP_tm_user::set_param(const BCP_tm_par::chr_params key, const char val)
00036 { p->par.set_entry(key, val); }
00037 void BCP_tm_user::set_param(const BCP_tm_par::int_params key, const int val)
00038 { p->par.set_entry(key, val); }
00039 void BCP_tm_user::set_param(const BCP_tm_par::dbl_params key, const double val)
00040 { p->par.set_entry(key, val); }
00041 void BCP_tm_user::set_param(const BCP_tm_par::str_params key, const char * val)
00042 { p->par.set_entry(key, val); }
00043 
00044 //#############################################################################
00045 
00046 void
00047 BCP_tm_user::pack_module_data(BCP_buffer& buf, BCP_process_t ptype) {}
00048 
00049 //-----------------------------------------------------------------------------
00050 // unpack an MIP feasible solution
00051 BCP_solution*
00052 BCP_tm_user::unpack_feasible_solution(BCP_buffer& buf)
00053 {
00054     if (p->param(BCP_tm_par::ReportWhenDefaultIsExecuted)) {
00055         printf(" TM: Default unpack_feasible_solution() executed.\n");
00056     }
00057 
00058     BCP_solution_generic* soln = new BCP_solution_generic;
00059 
00060     int varnum;
00061     buf.unpack(varnum);
00062 
00063     double val;
00064     int bcpind;
00065     while (--varnum >= 0) {
00066         buf.unpack(val);
00067         // these vars are stored only in the solution, so noone cares if we
00068         // flip negative bcpind's
00069         buf.unpack(bcpind);
00070         BCP_var* var = p->unpack_var_without_bcpind(buf);
00071         var->set_bcpind(bcpind < 0 ? -bcpind : bcpind);
00072         soln->add_entry(var, val);
00073     }
00074     buf.unpack(val);
00075     soln->set_objective_value(val);
00076 
00077     return soln;
00078 }
00079 
00080 //-----------------------------------------------------------------------------
00081 
00082 bool
00083 BCP_tm_user::replace_solution(const BCP_solution* old_sol,
00084                               const BCP_solution* new_sol)
00085 {
00086     return false;
00087 }
00088 
00089 //#############################################################################
00090 
00092 int
00093 BCP_tm_user::process_id() const
00094 {
00095     return p->get_process_id();
00096 }
00097 
00099 void
00100 BCP_tm_user::send_message(const int target, const BCP_buffer& buf)
00101 {
00102     p->msg_env->send(target, BCP_Msg_User, buf);
00103 }
00104 
00106 void
00107 BCP_tm_user::broadcast_message(const BCP_process_t proc_type,
00108                                const BCP_buffer& buf)
00109 {
00110     switch (proc_type) {
00111     case BCP_ProcessType_LP:
00112         p->msg_env->multicast(p->lp_procs.size(), &p->lp_procs[0],
00113                               BCP_Msg_User, buf);
00114         break;
00115     case BCP_ProcessType_CP:
00116         throw BCP_fatal_error("\
00117 BCP_tm_user::broadcast_message: CP not yet implemented\n");
00118         break;
00119     case BCP_ProcessType_VP:
00120         throw BCP_fatal_error("\
00121 BCP_tm_user::broadcast_message: VP not yet implemented\n");
00122         break;
00123 #if ! defined(BCP_ONLY_LP_PROCESS_HANDLING_WORKS)
00124     case BCP_ProcessType_CG:
00125         p->msg_env->multicast(*p->slaves.cg, BCP_Msg_User, buf);
00126         break;
00127     case BCP_ProcessType_VG:
00128         p->msg_env->multicast(*p->slaves.vg, BCP_Msg_User, buf);
00129         break;
00130 #endif
00131     case BCP_ProcessType_Any:
00132         p->msg_env->multicast(p->lp_procs.size(), &p->lp_procs[0],
00133                               BCP_Msg_User, buf);
00134 #if ! defined(BCP_ONLY_LP_PROCESS_HANDLING_WORKS)
00135         p->msg_env->multicast(*p->slaves.cg, BCP_Msg_User, buf);
00136         p->msg_env->multicast(*p->slaves.vg, BCP_Msg_User, buf);
00137 #endif
00138         break;
00139     case BCP_ProcessType_TM:
00140     case BCP_ProcessType_TS:
00141     case BCP_ProcessType_EndProcess:
00142         throw BCP_fatal_error("\
00143 BCP_tm_user::broadcast_message: broadcast to TM/TS/EndProcess...\n");
00144     default:
00145       throw BCP_fatal_error("BCP_tm_user::Unknown process type (%i)\n",
00146                             proc_type);
00147     }
00148 }
00149 
00152 void
00153 BCP_tm_user::process_message(BCP_buffer& buf)
00154 {
00155     throw BCP_fatal_error("\
00156 BCP_tm_user::process_message() invoked but not overridden!\n");
00157 }
00158 
00159 //#############################################################################
00160 // setting the core
00161 
00162 void
00163 BCP_tm_user::initialize_core(BCP_vec<BCP_var_core*>& vars,
00164                              BCP_vec<BCP_cut_core*>& cuts,
00165                              BCP_lp_relax*& matrix)
00166 {
00167     if (p->param(BCP_tm_par::ReportWhenDefaultIsExecuted)) {
00168         printf(" TM: Default BCP_tm_user::initialize_core() executed.\n");
00169     }
00170 }
00171 
00172 //--------------------------------------------------------------------------
00173 // create the root node
00174 void
00175 BCP_tm_user::create_root(BCP_vec<BCP_var*>& added_vars,
00176                          BCP_vec<BCP_cut*>& added_cuts,
00177                          BCP_user_data*& user_data)
00178 {
00179     if (p->param(BCP_tm_par::ReportWhenDefaultIsExecuted)) {
00180         printf(" TM: Default BCP_tm_user::create_root() executed.\n");
00181     }
00182 }
00183 
00184 //--------------------------------------------------------------------------
00185 // display a feasible solution
00186 void
00187 BCP_tm_user::display_feasible_solution(const BCP_solution* sol)
00188 {
00189     if (p->param(BCP_tm_par::ReportWhenDefaultIsExecuted)) {
00190         printf("\
00191  TM: Default BCP_tm_user::display_feasible_solution() executed.\n");
00192     }
00193 
00194     const BCP_solution_generic* gsol =
00195         dynamic_cast<const BCP_solution_generic*>(sol);
00196     if (! gsol) {
00197         throw BCP_fatal_error("\
00198 BCP_tm_user::display_feasible_solution() invoked with non-generic sol.\n");
00199     }
00200 
00201     gsol->display();
00202 }
00203 
00204 //-----------------------------------------------------------------------------
00207 void
00208 BCP_tm_user::display_node_information(BCP_tree& search_tree,
00209                                       const BCP_tm_node& node)
00210 {
00211 }
00212     
00213 //-----------------------------------------------------------------------------
00215 void
00216 BCP_tm_user::display_final_information(const BCP_lp_statistics& lp_stat)
00217 {
00218     if (p->param(BCP_tm_par::TmVerb_FinalStatistics)) {
00219         printf("TM: Running time: %.3f\n", CoinWallclockTime() - p->start_time);
00220         printf("TM: search tree size: %i   ( processed %i )   max depth: %i\n",
00221                int(p->search_tree.size()), int(p->search_tree.processed()),
00222                p->search_tree.maxdepth());
00223         lp_stat.display();
00224 
00225         if (! p->feas_sol) {
00226             printf("TM: No feasible solution is found\n");
00227         } else {
00228             printf("TM: The best solution found has value %f\n",
00229                    p->feas_sol->objective_value());
00230             if (p->param(BCP_tm_par::TmVerb_BestFeasibleSolution)) {
00231                 p->user->display_feasible_solution(p->feas_sol);
00232             }
00233         }
00234     }
00235 }
00236     
00237 //--------------------------------------------------------------------------
00238 // Initialize new phase 
00239 void
00240 BCP_tm_user::init_new_phase(int phase,
00241                             BCP_column_generation& colgen,
00242                             CoinSearchTreeBase*& candidates)
00243 {
00244     if (p->param(BCP_tm_par::ReportWhenDefaultIsExecuted)) {
00245         printf(" TM: Default init_new_phase() executed.\n");
00246     }
00247     colgen = BCP_DoNotGenerateColumns_Fathom;
00248     switch (p->param(BCP_tm_par::TreeSearchStrategy)) {
00249     case BCP_BestFirstSearch:
00250         candidates = new CoinSearchTree<CoinSearchTreeCompareBest>;
00251         break;
00252     case BCP_BreadthFirstSearch:
00253         candidates = new CoinSearchTree<CoinSearchTreeCompareBreadth>;
00254         break;
00255     case BCP_DepthFirstSearch:
00256         candidates = new CoinSearchTree<CoinSearchTreeCompareDepth>;
00257         break;
00258     case BCP_PreferredFirstSearch:
00259         candidates = new CoinSearchTree<CoinSearchTreeComparePreferred>;
00260         break;
00261     }
00262 }
00263 
00264 //--------------------------------------------------------------------------
00265 // Compare tree nodes
00266 void
00267 BCP_tm_user::change_candidate_heap(CoinSearchTreeManager& candidates,
00268                                    const bool new_solution)
00269 {
00270     if (new_solution) {
00271         candidates.newSolution(p->ub());
00272     } else {
00273         candidates.reevaluateSearchStrategy();
00274     }
00275 }

Generated on Mon May 3 03:05:13 2010 by  doxygen 1.4.7