BCP_cg_user.cpp
Go to the documentation of this file.
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 
4 #include <cassert>
5 #include "BCP_message_tag.hpp"
6 #include "BCP_buffer.hpp"
7 #include "BCP_var.hpp"
8 #include "BCP_cut.hpp"
9 
10 #include "BCP_cg.hpp"
11 #include "BCP_cg_user.hpp"
12 
13 //#############################################################################
14 // Informational methods for the user
15 double BCP_cg_user::upper_bound() const { return p->ub(); }
16 int BCP_cg_user::current_phase() const { return p->phase; }
17 int BCP_cg_user::current_level() const { return p->node_level; }
18 int BCP_cg_user::current_index() const { return p->node_index; }
20 
21 //#############################################################################
22 // Informational methods for the user
23 /* Methods to get/set BCP parameters on the fly */
24 char
26 { return p->par.entry(key); }
27 int
29 { return p->par.entry(key); }
30 double
32 { return p->par.entry(key); }
33 const BCP_string&
35 { return p->par.entry(key); }
36 
37 void BCP_cg_user::set_param(const BCP_cg_par::chr_params key, const bool val)
38 { p->par.set_entry(key, val); }
39 void BCP_cg_user::set_param(const BCP_cg_par::chr_params key, const char val)
40 { p->par.set_entry(key, val); }
41 void BCP_cg_user::set_param(const BCP_cg_par::int_params key, const int val)
42 { p->par.set_entry(key, val); }
43 void BCP_cg_user::set_param(const BCP_cg_par::dbl_params key, const double val)
44 { p->par.set_entry(key, val); }
45 void BCP_cg_user::set_param(const BCP_cg_par::str_params key, const char * val)
46 { p->par.set_entry(key, val); }
47 
48 //#############################################################################
49 
50 void
52 {
53  BCP_buffer& buf = p->msg_buf;
54  buf.clear();
55  const int bcpind = cut.bcpind();
56  const BCP_object_t obj_t = cut.obj_type();
57  const BCP_obj_status stat = cut.status();
58  const double lb = cut.lb();
59  const double ub = cut.ub();
60  buf.pack(bcpind).pack(obj_t).pack(stat).pack(lb).pack(ub);
61  assert(obj_t == BCP_AlgoObj);
62  p->packer->pack_cut_algo(&dynamic_cast<const BCP_cut_algo&>(cut), buf);
64 }
65 
66 //#############################################################################
67 
68 void
70 {
72  printf(" CG: Default unpack_module_data() executed.\n");
73  }
74 }
75 
76 //#############################################################################
77 
78 void
80 {
82  printf(" CG: Default unpack_primal_solution() executed.\n");
83  }
84 
85  if (buf.msgtag() == BCP_Msg_ForCG_User) {
86  throw BCP_fatal_error("\
87 CG: BCP_Msg_LpSolution_User message arrived but the unpack_primal_solution()\n\
88  function is not overridden.\n");
89  } else {
90  int varnum;
91  buf.unpack(varnum);
92  if (varnum > 0) {
93  // Just to be on the safe side... If it's already empty, it won't
94  // take long.
96  p->x.clear();
97  p->vars.reserve(varnum);
98  p->x.reserve(varnum);
99  double val;
100  while (--varnum >= 0) {
101  buf.unpack(val);
102  p->x.unchecked_push_back(val);
104  }
105  }
106  }
107 }
108 
109 //#############################################################################
110 
111 void
113 {
115  printf(" CG: Default generate_cuts() executed.\n");
116  }
117 }
virtual void send(const int target, const BCP_message_tag tag)=0
Send an empty message (message tag only) to the process given by the frist argument.
int current_iteration() const
Return the iteration count within the search tree node for which cuts are being generated.
Definition: BCP_cg_user.cpp:19
BCP_buffer & pack(const T &value)
Pack a single object of type T.
Definition: BCP_buffer.hpp:177
int node_index
The index of search tree node where the solution was generated.
Definition: BCP_cg.hpp:95
The message contains the description of a cut.
BCP_vec< double > x
The primal values corresponding to the variables above.
Definition: BCP_cg.hpp:85
BCP_buffer & unpack(T &value)
Unpack a single object of type T.
Definition: BCP_buffer.hpp:186
int sender
The process id of the LP process that sent the solution.
Definition: BCP_cg.hpp:87
void clear()
Delete every entry.
Abstract base class that defines members common to all types of cuts.
Definition: BCP_cut.hpp:29
int_params
Integer parameters.
char entry(const chr_params key) const
int current_phase() const
Return the phase the algorithm is in.
Definition: BCP_cg_user.cpp:16
double ub() const
Return the upper bound on the cut.
Definition: BCP_cut.hpp:84
void reserve(const size_t n)
Reallocate the object to make space for n entries.
This class is a very simple impelementation of a constant length string.
Definition: BCP_string.hpp:13
The user packed everything.
virtual void unpack_primal_solution(BCP_buffer &buf)
Unpack the LP solution arriving from the LP process.
Definition: BCP_cg_user.cpp:79
BCP_obj_status
This enumerative constant gives the status of an object (variable or cut).
Definition: BCP_enum.hpp:105
int current_index() const
Return the internal index of the search tree node for which cuts are being generated.
Definition: BCP_cg_user.cpp:18
void set_param(const BCP_cg_par::chr_params key, const bool val)
Definition: BCP_cg_user.cpp:37
double lb() const
Return the lower bound on the cut.
Definition: BCP_cut.hpp:82
BCP_vec< BCP_var * > vars
Cuts are to be generated for the LP solution given by these variables and their values (next member)...
Definition: BCP_cg.hpp:83
double upper_bound() const
Return what is the best known upper bound (might be BCP_DBL_MAX)
Definition: BCP_cg_user.cpp:15
virtual void pack_cut_algo(const BCP_cut_algo *cut, BCP_buffer &buf)
Pack an algorithmic cut.
Definition: BCP_USER.hpp:102
int phase
The phase the algorithm is in.
Definition: BCP_cg.hpp:91
char get_param(const BCP_cg_par::chr_params key) const
Definition: BCP_cg_user.cpp:25
void set_entry(const chr_params key, const char val)
void send_cut(const BCP_cut &cut)
Pack the argument into the message buffer and send it to the sender of the LP solution.
Definition: BCP_cg_user.cpp:51
BCP_obj_status status() const
Return the status of the cut.
Definition: BCP_cut.hpp:91
Print out a message when the default version of an overridable method is executed.
virtual BCP_object_t obj_type() const =0
Return the type of the variable.
void clear()
Completely clear the buffer.
Definition: BCP_buffer.hpp:168
BCP_message_tag msgtag() const
Return the message tag of the message in the buffer.
Definition: BCP_buffer.hpp:90
BCP_buffer msg_buf
The message buffer of the Cut Generator process.
Definition: BCP_cg.hpp:61
Currently there isn&#39;t any error handling in BCP.
Definition: BCP_error.hpp:20
virtual void unpack_module_data(BCP_buffer &buf)
Unpack the initial information sent to the Cut Generator process by the Tree Manager.
Definition: BCP_cg_user.cpp:69
Algorithmic object.
Definition: BCP_enum.hpp:53
virtual void generate_cuts(BCP_vec< BCP_var * > &vars, BCP_vec< double > &x)
Perform the actual cut generation.
int node_iteration
The iteration within the search tree node where the solution was generated.
Definition: BCP_cg.hpp:98
BCP_cg_prob * p
Definition: BCP_cg_user.hpp:52
This class describes the message buffer used for all processes of BCP.
Definition: BCP_buffer.hpp:39
str_params
String parameters.
void unchecked_push_back(const_reference x)
Append x to the end of the vector.
void purge_ptr_vector(BCP_vec< T * > &pvec, typename BCP_vec< T * >::iterator first, typename BCP_vec< T * >::iterator last)
This function purges the entries [first,last) from the vector of pointers pvec.
Definition: BCP_vector.hpp:266
BCP_user_pack * packer
A class that holds the methods about how to pack things.
Definition: BCP_cg.hpp:53
dbl_params
There are no double parameters.
BCP_message_environment * msg_env
The message passing environment.
Definition: BCP_cg.hpp:58
chr_params
Character parameters.
int bcpind() const
Return the internal index of the cut.
Definition: BCP_cut.hpp:86
BCP_var * unpack_var()
Unpack a variable.
Definition: BCP_cg.cpp:55
BCP_object_t
This enumerative constant describes the possible types of objects (variables and cuts).
Definition: BCP_enum.hpp:49
int node_level
The level of search tree node where the solution was generated.
Definition: BCP_cg.hpp:93
BCP_parameter_set< BCP_cg_par > par
The parameters controlling the Cut Generator process.
Definition: BCP_cg.hpp:64
double ub() const
Return the current upper bound (BCP_DBL_MAX if there&#39;s no upper bound found yet.) ...
Definition: BCP_cg.hpp:118
void fint fint fint real fint real * x
int current_level() const
Return the level of the search tree node for which cuts are being generated.
Definition: BCP_cg_user.cpp:17