BCP_vg_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_vg.hpp"
11 #include "BCP_vg_user.hpp"
12 
13 //#############################################################################
14 // Informational methods for the user
15 double BCP_vg_user::upper_bound() const { return p->ub(); }
16 int BCP_vg_user::current_phase() const { return p->phase; }
17 int BCP_vg_user::current_level() const { return p->node_level; }
18 int BCP_vg_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_vg_user::set_param(const BCP_vg_par::chr_params key, const bool val)
38 { p->par.set_entry(key, val); }
39 void BCP_vg_user::set_param(const BCP_vg_par::chr_params key, const char val)
40 { p->par.set_entry(key, val); }
41 void BCP_vg_user::set_param(const BCP_vg_par::int_params key, const int val)
42 { p->par.set_entry(key, val); }
43 void BCP_vg_user::set_param(const BCP_vg_par::dbl_params key, const double val)
44 { p->par.set_entry(key, val); }
45 void BCP_vg_user::set_param(const BCP_vg_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 = var.bcpind();
56  const BCP_object_t obj_t = var.obj_type();
57  const BCP_obj_status stat = var.status();
58  const BCP_var_t var_t = var.var_type();
59  const double obj = var.obj();
60  const double lb = var.lb();
61  const double ub = var.ub();
62  buf.pack(bcpind)
63  .pack(obj_t).pack(stat).pack(var_t).pack(obj).pack(lb).pack(ub);
64  assert(obj_t == BCP_AlgoObj);
65  p->packer->pack_var_algo(&dynamic_cast<const BCP_var_algo&>(var), buf);
67 }
68 
69 //#############################################################################
70 
71 void
73 {
75  printf(" VG: Default unpack_module_data() executed.\n");
76  }
77 }
78 
79 //#############################################################################
80 
81 void
83 {
85  printf(" VG: Default unpack_dual_solution() executed.\n");
86  }
87 
88  if (buf.msgtag() == BCP_Msg_ForVG_User) {
89  throw BCP_fatal_error("\
90 VG: BCP_Msg_LpSolution_User message arrived but the unpack_dual_solution() \n\
91  function is not overridden.\n");
92  } else {
93  int cutnum;
94  buf.unpack(cutnum);
95  if (cutnum > 0) {
96  // Just to be on the safe side... If it's already empty, it won't
97  // take long.
99  p->pi.clear();
100  p->cuts.reserve(cutnum);
101  p->pi.reserve(cutnum);
102  double val;
103  while (--cutnum >= 0) {
104  buf.unpack(val);
105  p->pi.unchecked_push_back(val);
107  }
108  }
109  }
110 }
111 
112 //#############################################################################
113 
114 void
116 {
118  printf(" VG: Default generate_vars() executed.\n");
119  }
120 }
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.
BCP_buffer & pack(const T &value)
Pack a single object of type T.
Definition: BCP_buffer.hpp:177
int current_level() const
Return the level of the search tree node for which cuts are being generated.
Definition: BCP_vg_user.cpp:17
BCP_buffer & unpack(T &value)
Unpack a single object of type T.
Definition: BCP_buffer.hpp:186
int current_iteration() const
Return the iteration count within the search tree node for which cuts are being generated.
Definition: BCP_vg_user.cpp:19
void clear()
Delete every entry.
virtual void unpack_dual_solution(BCP_buffer &buf)
Unpack the LP solution arriving from the LP process.
Definition: BCP_vg_user.cpp:82
double upper_bound() const
Return what is the best known upper bound (might be BCP_DBL_MAX)
Definition: BCP_vg_user.cpp:15
Print out a message when the default version of an overridable method is executed.
BCP_message_environment * msg_env
The message passing environment.
Definition: BCP_vg.hpp:57
char entry(const chr_params key) const
void set_param(const BCP_vg_par::chr_params key, const bool val)
Definition: BCP_vg_user.cpp:37
int phase
The phase the algorithm is in.
Definition: BCP_vg.hpp:89
BCP_buffer msg_buf
The message buffer of the Variable Generator process.
Definition: BCP_vg.hpp:60
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
static const CouNumber pi
Definition: exprCos.cpp:23
BCP_obj_status
This enumerative constant gives the status of an object (variable or cut).
Definition: BCP_enum.hpp:105
int sender
The process id of the LP process that sent the solution.
Definition: BCP_vg.hpp:86
BCP_vg_prob * p
Definition: BCP_vg_user.hpp:53
double ub() const
Return the current upper bound (BCP_DBL_MAX/10 if there&#39;s no upper bound found yet.)
Definition: BCP_vg.hpp:116
The user packed everything.
char get_param(const BCP_vg_par::chr_params key) const
Definition: BCP_vg_user.cpp:25
double ub() const
Return the upper bound.
Definition: BCP_var.hpp:91
int node_index
The index of search tree node where the solution was generated.
Definition: BCP_vg.hpp:93
void set_entry(const chr_params key, const char val)
BCP_cut * unpack_cut()
Unpack a cut.
Definition: BCP_vg.cpp:50
The message contains the description of a variable.
double obj() const
Return the objective coefficient.
Definition: BCP_var.hpp:87
void clear()
Completely clear the buffer.
Definition: BCP_buffer.hpp:168
BCP_parameter_set< BCP_vg_par > par
The parameters controlling the Variable Generator process.
Definition: BCP_vg.hpp:63
virtual void generate_vars(BCP_vec< BCP_cut * > &cuts, BCP_vec< double > &pi)
Perform the actual variable generation.
BCP_message_tag msgtag() const
Return the message tag of the message in the buffer.
Definition: BCP_buffer.hpp:90
BCP_var_t var_type() const
Return the integrality type of the variable.
Definition: BCP_var.hpp:85
Abstract base class that defines members common to all types of variables.
Definition: BCP_var.hpp:28
Currently there isn&#39;t any error handling in BCP.
Definition: BCP_error.hpp:20
int node_level
The level of search tree node where the solution was generated.
Definition: BCP_vg.hpp:91
int bcpind() const
Return the internal index of the variable.
Definition: BCP_var.hpp:93
Algorithmic object.
Definition: BCP_enum.hpp:53
int current_index() const
Return the internal index of the search tree node for which cuts are being generated.
Definition: BCP_vg_user.cpp:18
BCP_obj_status status() const
Return the status of the variable.
Definition: BCP_var.hpp:98
This class describes the message buffer used for all processes of BCP.
Definition: BCP_buffer.hpp:39
virtual void pack_var_algo(const BCP_var_algo *var, BCP_buffer &buf)
Pack an algorithmic variable.
Definition: BCP_USER.hpp:86
void unchecked_push_back(const_reference x)
Append x to the end of the vector.
int node_iteration
The iteration within the search tree node where the solution was generated.
Definition: BCP_vg.hpp:96
double lb() const
Return the lower bound.
Definition: BCP_var.hpp:89
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
void send_var(const BCP_var &var)
Pack the argument into the message buffer and send it to the sender of the LP solution.
Definition: BCP_vg_user.cpp:51
BCP_user_pack * packer
A class that holds the methods about how to pack things.
Definition: BCP_vg.hpp:52
BCP_vec< BCP_cut * > cuts
Variables are to be generated for the LP solution given by these cuts and their values (next member)...
Definition: BCP_vg.hpp:82
int current_phase() const
Return the phase the algorithm is in.
Definition: BCP_vg_user.cpp:16
BCP_object_t
This enumerative constant describes the possible types of objects (variables and cuts).
Definition: BCP_enum.hpp:49
BCP_vec< double > pi
The dual values corresponding to the cuts above.
Definition: BCP_vg.hpp:84
virtual BCP_object_t obj_type() const =0
Return the type of the variable.
virtual void unpack_module_data(BCP_buffer &buf)
Unpack the initial information sent to the Variable Generator process by the Tree Manager...
Definition: BCP_vg_user.cpp:72
BCP_var_t
This enumerative constant describes the integrality type of a variable.
Definition: BCP_enum.hpp:161