BCP_lp.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 "BCP_math.hpp"
5 #include "BCP_buffer.hpp"
6 #include "BCP_message.hpp"
7 #include "BCP_problem_core.hpp"
8 #include "BCP_lp_node.hpp"
9 #include "BCP_lp.hpp"
10 #include "OsiSolverInterface.hpp"
11 #include "BCP_lp_result.hpp"
12 #include "BCP_lp_pool.hpp"
13 
14 #include "BCP_lp_user.hpp"
15 
16 #include "BCP_warmstart.hpp"
17 
18 //#############################################################################
19 
20 void
22 {
28 }
29 void
31 {
37 }
38 void
40 {
41  printf("LP statistics:\n");
42  printf(" time in cut generation : %12.3f sec\n", time_cut_generation);
43  printf(" time in var generation : %12.3f sec\n", time_var_generation);
44  printf(" time in heuristics : %12.3f sec\n", time_heuristics);
45  printf(" time in solving LPs : %12.3f sec\n", time_lp_solving);
46  printf(" time in strong branching: %12.3f sec\n", time_branching);
47  printf("\n");
48 }
49 void
51 {
57 }
58 
59 //#############################################################################
60 
61 BCP_lp_prob::BCP_lp_prob(int my_id, int parent) :
62  BCP_process(my_id, parent),
63  user(0),
64  master_lp(0),
65  lp_solver(0),
66  msg_env(0),
67  core(new BCP_problem_core),
68  core_as_change(new BCP_problem_core_change),
69  node(new BCP_lp_node),
70  parent(new BCP_lp_parent),
71  warmstartRoot(NULL),
72  lp_result(new BCP_lp_result),
73  var_bound_changes_since_logical_fixing(0),
74  local_var_pool(new BCP_lp_var_pool),
75  local_cut_pool(new BCP_lp_cut_pool),
76  next_var_index(0),
77  last_var_index(0),
78  next_cut_index(0),
79  last_cut_index(0),
80  upper_bound(BCP_DBL_MAX),
81  phase(0)
82 {}
83 
85 
86  delete user;
87  delete packer;
88  delete master_lp;
89  delete lp_solver;
90 
91  delete core;
92  delete core_as_change;
93 
94  delete node;
95  delete parent;
96  delete warmstartRoot;
97 
98  delete lp_result;
100 
101  delete local_var_pool;
102  delete local_cut_pool;
103 
104  // these are vectors of ptrs, but they need not be purged. they just point
105  // into the appropriate fields of p.node->vars/cuts
106  // purge_ptr_vector(all_vars);
107  // purge_ptr_vector(all_cuts);
108 
109  // delete tree_manager; this pointer must NOT be deleted!!!
110 }
111 
112 //=============================================================================
113 
114 void
116 {
117  const int bcpind = var.bcpind();
118  msg_buf.pack(bcpind);
119  const BCP_object_t obj_t = var.obj_type();
120  const BCP_obj_status varstat = var.status();
121  const BCP_var_t var_t = var.var_type();
122  const double obj = var.obj();
123  const double lb = var.lb();
124  const double ub = var.ub();
125  msg_buf.pack(obj_t).pack(varstat).pack(var_t).pack(obj).pack(lb).pack(ub);
126  switch (obj_t) {
127  case BCP_CoreObj:
128  break;
129  case BCP_AlgoObj:
130  packer->pack_var_algo(&dynamic_cast<const BCP_var_algo&>(var), msg_buf);
131  break;
132  default:
133  throw BCP_fatal_error("BCP_lp_prob::_pack_var(): unexpected obj_t.\n");
134  }
135 }
136 
137 //-----------------------------------------------------------------------------
138 
139 BCP_var*
141 {
142  BCP_object_t obj_t;
143  int bcpind;
144  BCP_var_t var_t;
145  double obj, lb, ub;
146  BCP_obj_status varstat;
147  msg_buf.unpack(bcpind)
148  .unpack(obj_t).unpack(varstat)
149  .unpack(var_t).unpack(obj).unpack(lb).unpack(ub);
150 
151  BCP_var* var = 0;
152  switch (obj_t) {
153  case BCP_CoreObj:
154  var = new BCP_var_core(var_t, obj, lb, ub);
155  break;
156  case BCP_AlgoObj:
158  var->set_var_type(var_t);
159  var->change_bounds(lb, ub);
160  var->set_obj(obj);
161  break;
162  default:
163  throw BCP_fatal_error("BCP_lp_prob::_unpack_var(): unexpected obj_t.\n");
164  }
165  var->set_bcpind(bcpind);
166  var->set_status(varstat);
167 
168  return var;
169 }
170 
171 //#############################################################################
172 
173 void
175 {
176  const int bcpind = cut.bcpind();
177  msg_buf.pack(bcpind);
178  const BCP_object_t obj_t = cut.obj_type();
179  const BCP_obj_status cutstat = cut.status();
180  const double lb = cut.lb();
181  const double ub = cut.ub();
182  msg_buf.pack(obj_t).pack(cutstat).pack(lb).pack(ub);
183  switch (obj_t) {
184  case BCP_CoreObj:
185  break;
186  case BCP_AlgoObj:
187  packer->pack_cut_algo(&dynamic_cast<const BCP_cut_algo&>(cut), msg_buf);
188  break;
189  default:
190  throw BCP_fatal_error("BCP_lp_prob::_pack_cut(): unexpected obj_t.\n");
191  }
192 }
193 
194 //-----------------------------------------------------------------------------
195 
196 BCP_cut*
198 {
199  BCP_object_t obj_t;
200  int bcpind;
201  double lb, ub;
202  BCP_obj_status cutstat;
203  msg_buf.unpack(bcpind).unpack(obj_t).unpack(cutstat).unpack(lb).unpack(ub);
204 
205  BCP_cut* cut = 0;
206  switch (obj_t) {
207  case BCP_CoreObj:
208  cut = new BCP_cut_core(lb, ub);
209  break;
210  case BCP_AlgoObj:
212  cut->change_bounds(lb, ub);
213  break;
214  default:
215  throw BCP_fatal_error("BCP_lp_prob::_unpack_cut(): unexpected obj_t.\n");
216  }
217  cut->set_bcpind(bcpind);
218  cut->set_status(cutstat);
219 
220  return cut;
221 }
This class describes changes in the core of the problem.
This class describes the core of the MIP problem, the variables/cuts in it as well as the matrix corr...
BCP_buffer & pack(const T &value)
Pack a single object of type T.
Definition: BCP_buffer.hpp:177
BCP_lp_node * node
Description he current search tree node.
Definition: BCP_lp.hpp:168
BCP_buffer & unpack(T &value)
Unpack a single object of type T.
Definition: BCP_buffer.hpp:186
void set_var_type(const BCP_var_t type)
Set the integrality type of the variable.
Definition: BCP_var.hpp:141
BCP_lp_parent * parent
Description of the parent of the current node.
Definition: BCP_lp.hpp:170
void add(const BCP_lp_statistics &stat)
Add the argument statistics to this one.
Definition: BCP_lp.cpp:50
Abstract base class that defines members common to all types of cuts.
Definition: BCP_cut.hpp:29
virtual BCP_cut_algo * unpack_cut_algo(BCP_buffer &buf)
Unpack an algorithmic cut.
Definition: BCP_USER.hpp:109
void set_bcpind(const int bcpind)
Set the internal index of the cut.
Definition: BCP_cut.hpp:149
void set_bcpind(const int bcpind)
Set the internal index of the variable.
Definition: BCP_var.hpp:176
OsiSolverInterface * master_lp
A class that holds the methods about how to pack things.
Definition: BCP_lp.hpp:135
double time_branching
Definition: BCP_lp.hpp:69
Core cuts are the cuts that always stay in the LP formulation.
Definition: BCP_cut.hpp:195
double ub() const
Return the upper bound on the cut.
Definition: BCP_cut.hpp:84
void pack_var(const BCP_var &var)
Definition: BCP_lp.cpp:115
NO OLD DOC.
Definition: BCP_lp.hpp:56
Core variables are the variables that always stay in the LP formulation.
Definition: BCP_var.hpp:230
double time_var_generation
Definition: BCP_lp.hpp:63
virtual ~BCP_lp_prob()
Definition: BCP_lp.cpp:84
BCP_obj_status
This enumerative constant gives the status of an object (variable or cut).
Definition: BCP_enum.hpp:105
void change_bounds(const double lb, const double ub)
Change the lower and upper bounds to the given values.
Definition: BCP_var.hpp:170
#define BCP_DBL_MAX
Definition: BCP_math.hpp:6
double lb() const
Return the lower bound on the cut.
Definition: BCP_cut.hpp:82
BCP_lp_cut_pool * local_cut_pool
Definition: BCP_lp.hpp:193
double ub() const
Return the upper bound.
Definition: BCP_var.hpp:91
virtual void pack_cut_algo(const BCP_cut_algo *cut, BCP_buffer &buf)
Pack an algorithmic cut.
Definition: BCP_USER.hpp:102
BCP_lp_user * user
A class that holds the methods about how to pack things.
Definition: BCP_lp.hpp:131
BCP_lp_prob(const BCP_lp_prob &)
NO OLD DOC.
Definition: BCP_lp_node.hpp:92
void unpack(BCP_buffer &buf)
Definition: BCP_lp.cpp:30
OsiSolverInterface * lp_solver
A class that holds the methods about how to pack things.
Definition: BCP_lp.hpp:137
BCP_lp_result * lp_result
Definition: BCP_lp.hpp:185
void fint fint fint * phase
CoinWarmStart * warmstartRoot
Description of the warmstart info from the end of the root node.
Definition: BCP_lp.hpp:174
BCP_obj_status status() const
Return the status of the cut.
Definition: BCP_cut.hpp:91
double obj() const
Return the objective coefficient.
Definition: BCP_var.hpp:87
double ub() const
Definition: BCP_lp.hpp:300
void set_status(const BCP_obj_status stat)
Set the status of the cut.
Definition: BCP_cut.hpp:156
BCP_lp_var_pool * local_var_pool
Definition: BCP_lp.hpp:191
virtual BCP_object_t obj_type() const =0
Return the type of the variable.
BCP_var_t var_type() const
Return the integrality type of the variable.
Definition: BCP_var.hpp:85
NO OLD DOC.
Definition: BCP_lp_node.hpp:42
void pack_cut(const BCP_cut &cut)
Definition: BCP_lp.cpp:174
Abstract base class that defines members common to all types of variables.
Definition: BCP_var.hpp:28
double time_lp_solving
Definition: BCP_lp.hpp:67
Currently there isn&#39;t any error handling in BCP.
Definition: BCP_error.hpp:20
BCP_cut * unpack_cut()
Definition: BCP_lp.cpp:197
void display() const
Print out the statistics.
Definition: BCP_lp.cpp:39
int bcpind() const
Return the internal index of the variable.
Definition: BCP_var.hpp:93
BCP_vec< BCP_cut * > slack_pool
Definition: BCP_lp.hpp:189
Algorithmic object.
Definition: BCP_enum.hpp:53
BCP_obj_status status() const
Return the status of the variable.
Definition: BCP_var.hpp:98
virtual BCP_var_algo * unpack_var_algo(BCP_buffer &buf)
Unpack an algorithmic variable.
Definition: BCP_USER.hpp:93
BCP_var * unpack_var()
Definition: BCP_lp.cpp:140
This class describes the message buffer used for all processes of BCP.
Definition: BCP_buffer.hpp:39
void change_bounds(const double lb, const double ub)
Change just the lower/upper bounds.
Definition: BCP_cut.hpp:142
void set_obj(const double obj)
Set the objective coefficient.
Definition: BCP_var.hpp:143
virtual void pack_var_algo(const BCP_var_algo *var, BCP_buffer &buf)
Pack an algorithmic variable.
Definition: BCP_USER.hpp:86
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real char real * user
BCP_problem_core * core
Definition: BCP_lp.hpp:153
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
This class holds the results after solving an LP relaxation.
void set_status(const BCP_obj_status status)
Set the status of the variable.
Definition: BCP_var.hpp:183
BCP_problem_core_change * core_as_change
Definition: BCP_lp.hpp:155
void pack(BCP_buffer &buf)
Definition: BCP_lp.cpp:21
double time_heuristics
Definition: BCP_lp.hpp:65
int bcpind() const
Return the internal index of the cut.
Definition: BCP_cut.hpp:86
double time_cut_generation
Definition: BCP_lp.hpp:61
BCP_object_t
This enumerative constant describes the possible types of objects (variables and cuts).
Definition: BCP_enum.hpp:49
BCP_buffer msg_buf
Definition: BCP_lp.hpp:239
virtual BCP_object_t obj_type() const =0
Return the type of the variable.
Base object.
Definition: BCP_enum.hpp:51
BCP_var_t
This enumerative constant describes the integrality type of a variable.
Definition: BCP_enum.hpp:161
BCP_user_pack * packer
A class that holds the methods about how to pack things.
Definition: BCP_lp.hpp:133