00001
00002
00003
00004 #include <cassert>
00005 #include "BCP_message_tag.hpp"
00006 #include "BCP_buffer.hpp"
00007 #include "BCP_var.hpp"
00008 #include "BCP_cut.hpp"
00009
00010 #include "BCP_cg.hpp"
00011 #include "BCP_cg_user.hpp"
00012
00013
00014
00015 double BCP_cg_user::upper_bound() const { return p->ub(); }
00016 int BCP_cg_user::current_phase() const { return p->phase; }
00017 int BCP_cg_user::current_level() const { return p->node_level; }
00018 int BCP_cg_user::current_index() const { return p->node_index; }
00019 int BCP_cg_user::current_iteration() const { return p->node_iteration; }
00020
00021
00022
00023
00024 char
00025 BCP_cg_user::get_param(const BCP_cg_par::chr_params key) const
00026 { return p->par.entry(key); }
00027 int
00028 BCP_cg_user::get_param(const BCP_cg_par::int_params key) const
00029 { return p->par.entry(key); }
00030 double
00031 BCP_cg_user::get_param(const BCP_cg_par::dbl_params key) const
00032 { return p->par.entry(key); }
00033 const BCP_string&
00034 BCP_cg_user::get_param(const BCP_cg_par::str_params key) const
00035 { return p->par.entry(key); }
00036
00037 void BCP_cg_user::set_param(const BCP_cg_par::chr_params key, const bool val)
00038 { p->par.set_entry(key, val); }
00039 void BCP_cg_user::set_param(const BCP_cg_par::chr_params key, const char val)
00040 { p->par.set_entry(key, val); }
00041 void BCP_cg_user::set_param(const BCP_cg_par::int_params key, const int val)
00042 { p->par.set_entry(key, val); }
00043 void BCP_cg_user::set_param(const BCP_cg_par::dbl_params key, const double val)
00044 { p->par.set_entry(key, val); }
00045 void BCP_cg_user::set_param(const BCP_cg_par::str_params key, const char * val)
00046 { p->par.set_entry(key, val); }
00047
00048
00049
00050 void
00051 BCP_cg_user::send_cut(const BCP_cut& cut)
00052 {
00053 BCP_buffer& buf = p->msg_buf;
00054 buf.clear();
00055 const int bcpind = cut.bcpind();
00056 const BCP_object_t obj_t = cut.obj_type();
00057 const BCP_obj_status stat = cut.status();
00058 const double lb = cut.lb();
00059 const double ub = cut.ub();
00060 buf.pack(bcpind).pack(obj_t).pack(stat).pack(lb).pack(ub);
00061 assert(obj_t == BCP_AlgoObj);
00062 p->packer->pack_cut_algo(&dynamic_cast<const BCP_cut_algo&>(cut), buf);
00063 p->msg_env->send(p->sender, BCP_Msg_CutDescription, buf);
00064 }
00065
00066
00067
00068 void
00069 BCP_cg_user::unpack_module_data(BCP_buffer& buf)
00070 {
00071 if (p->par.entry(BCP_cg_par::ReportWhenDefaultIsExecuted)) {
00072 printf(" CG: Default unpack_module_data() executed.\n");
00073 }
00074 }
00075
00076
00077
00078 void
00079 BCP_cg_user::unpack_primal_solution(BCP_buffer& buf)
00080 {
00081 if (p->par.entry(BCP_cg_par::ReportWhenDefaultIsExecuted)) {
00082 printf(" CG: Default unpack_primal_solution() executed.\n");
00083 }
00084
00085 if (buf.msgtag() == BCP_Msg_ForCG_User) {
00086 throw BCP_fatal_error("\
00087 CG: BCP_Msg_LpSolution_User message arrived but the unpack_primal_solution()\n\
00088 function is not overridden.\n");
00089 } else {
00090 int varnum;
00091 buf.unpack(varnum);
00092 if (varnum > 0) {
00093
00094
00095 purge_ptr_vector(p->vars);
00096 p->x.clear();
00097 p->vars.reserve(varnum);
00098 p->x.reserve(varnum);
00099 double val;
00100 while (--varnum >= 0) {
00101 buf.unpack(val);
00102 p->x.unchecked_push_back(val);
00103 p->vars.unchecked_push_back(p->unpack_var());
00104 }
00105 }
00106 }
00107 }
00108
00109
00110
00111 void
00112 BCP_cg_user::generate_cuts(BCP_vec<BCP_var*>& vars, BCP_vec<double>& x)
00113 {
00114 if (p->par.entry(BCP_cg_par::ReportWhenDefaultIsExecuted)) {
00115 printf(" CG: Default generate_cuts() executed.\n");
00116 }
00117 }