BCP_tm_statistics.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 <cstdio>
5 
6 #include "BCP_vg.hpp"
7 #include "BCP_cg.hpp"
8 #include "BCP_lp.hpp"
9 #include "BCP_tm.hpp"
10 #include "BCP_solution.hpp"
11 #include "BCP_tm_user.hpp"
12 #include "BCP_node_change.hpp"
13 
14 static inline void
16 {
17  BCP_buffer& buf = tm->msg_buf;
18  const BCP_object_t obj_t = cut.obj_type();
19  const BCP_obj_status stat = cut.status();
20  const double lb = cut.lb();
21  const double ub = cut.ub();
22  buf.pack(obj_t).pack(stat).pack(lb).pack(ub);
23  switch (obj_t) {
24  case BCP_CoreObj:
25  break;
26  case BCP_AlgoObj:
27  tm->packer->pack_cut_algo(&dynamic_cast<const BCP_cut_algo&>(cut), buf);
28  break;
29  default:
30  throw BCP_fatal_error("BCP_tm_pack_root_cut: unexpected obj_t.\n");
31  }
32 }
33 
34 //#############################################################################
35 
36 void
38 {
39  if (! tm->cuts_remote.empty()) {
40  throw BCP_fatal_error("\
41 BCP: saving root cuts does not work at the moment. Must collect cuts from \n\
42 the TMS processes before the root cuts could be saved. \n");
43  }
44  const BCP_string& cutfile = tm->param(BCP_tm_par::SaveRootCutsTo);
45  if (cutfile.length() > 0 &&
46  tm->phase == 0) {
47  BCP_buffer& buf = tm->msg_buf;
48  buf.clear();
49  const BCP_obj_set_change& ch =
50  tm->search_tree.root()->_data._desc->cut_change;
51  if (ch.storage() != BCP_Storage_Explicit)
52  throw BCP_fatal_error("Non-explicit cut storage in root!\n");
53  const int num = ch._new_objs.size();
54  buf.pack(num);
55  for (int i = 0; i < num; ++i) {
56  BCP_tm_pack_root_cut(tm, *tm->cuts_local[i]);
57  }
58  FILE* f = fopen(cutfile.c_str(), "w");
59  size_t size = buf.size();
60  if (fwrite(&size, 1, sizeof(size), f) != sizeof(size))
61  throw BCP_fatal_error("SaveRootCutsTo write error.\n");
62  if (fwrite(buf.data(), 1, size, f) != size)
63  throw BCP_fatal_error("SaveRootCutsTo write error.\n");
64  fclose(f);
65  }
66 }
67 
68 //#############################################################################
69 
70 void
72  BCP_cg_prob* cg, BCP_vg_prob* vg, bool final_stat)
73 {
75 
76  // Collect the statistics and print it out
77  if (!tm->lp_stat)
78  tm->lp_stat = new BCP_lp_statistics;
79 
80  if (! lp) {
81  // Now ask every process
82  const std::vector<int>& lps = tm->lp_procs;
83  const int num_lp = lps.size();
84  BCP_lp_statistics* lp_stats = new BCP_lp_statistics[num_lp];
85  BCP_lp_statistics this_lp_stat;
86 
87  int i;
88  for (i = 0; i < num_lp; ++i) {
89  while (true) {
90  tm->msg_env->receive(lps[i],
92  tm->msg_buf, 1);
93  BCP_message_tag msgtag = tm->msg_buf.msgtag();
94  if (msgtag == BCP_Msg_NoMessage) {
95  // test if the LP is still alive
96  if (! tm->msg_env->alive(lps[i]))
97  break;
98  } else {
99  break;
100  }
101  }
102  lp_stats[i].unpack(tm->msg_buf);
103  tm->lp_stat->add(lp_stats[i]);
104  }
105  for (i = 0; i < num_lp; ++i) {
106  printf("LP # %i : node idle: %12.6f SB idle: %12.6f\n",
107  lps[i], tm->lp_scheduler.node_idle(lps[i]),
108  tm->lp_scheduler.sb_idle(lps[i]));
109  }
110  delete[] lp_stats;
111  }
112 
113  tm->stat.print(true /* final stat */, 0);
114 
115  tm->user->display_final_information(lp ? lp->stat : *tm->lp_stat);
116 }
BCP_tree search_tree
Definition: BCP_tm.hpp:239
BCP_buffer msg_buf
members to measure how long it took to process the root node.
Definition: BCP_tm.hpp:183
BCP_message_tag
This enumerative constant describes the message tags different processes of BCP understand.
This class stores data about how an object set (set of vars or set of cuts) changes.
BCP_buffer & pack(const T &value)
Pack a single object of type T.
Definition: BCP_buffer.hpp:177
void print(bool final, double t)
Definition: BCP_tm.cpp:50
Used to indicate that there is no message in the buffer of a process.
std::map< int, int > cuts_remote
Definition: BCP_tm.hpp:226
virtual void receive(const int source, const BCP_message_tag tag, BCP_buffer &buf, const double timeout)=0
Blocking receive with timeout.
void add(const BCP_lp_statistics &stat)
Add the argument statistics to this one.
Definition: BCP_lp.cpp:50
std::map< int, Coin::SmartPtr< BCP_cut > > cuts_local
Definition: BCP_tm.hpp:224
The message contains the statistics the LP process collected.
Abstract base class that defines members common to all types of cuts.
Definition: BCP_cut.hpp:29
BCP_lp_statistics stat
Definition: BCP_lp.hpp:213
virtual void display_final_information(const BCP_lp_statistics &lp_stat)
Display information after BCP finished processing the search tree.
const char * c_str() const
Definition: BCP_string.hpp:19
static void BCP_tm_pack_root_cut(BCP_tm_prob *tm, const BCP_cut &cut)
This class is the central class of the Cut Generator process.
Definition: BCP_cg.hpp:32
double ub() const
Return the upper bound on the cut.
Definition: BCP_cut.hpp:84
The name of the file where those cuts should be saved that were in the root node in the 0-th phase at...
NO OLD DOC.
Definition: BCP_lp.hpp:102
BCP_vec< int > _new_objs
NO OLD DOC.
Definition: BCP_lp.hpp:56
This class is a very simple impelementation of a constant length string.
Definition: BCP_string.hpp:13
void fint fint fint real fint real real real real * f
BCP_obj_status
This enumerative constant gives the status of an object (variable or cut).
Definition: BCP_enum.hpp:105
The data stored is an explicit listing of values.
Definition: BCP_enum.hpp:88
double lb() const
Return the lower bound on the cut.
Definition: BCP_cut.hpp:82
virtual void pack_cut_algo(const BCP_cut_algo *cut, BCP_buffer &buf)
Pack an algorithmic cut.
Definition: BCP_USER.hpp:102
void fint fint fint real fint real real real real real real real real real fint real fint * lp
Coin::SmartPtr< BCP_node_change > _desc
Definition: BCP_tm_node.hpp:53
BCP_lp_statistics * lp_stat
Definition: BCP_tm.hpp:160
int length() const
Definition: BCP_string.hpp:16
void unpack(BCP_buffer &buf)
Definition: BCP_lp.cpp:30
NO OLD DOC.
Definition: BCP_tm.hpp:136
BCP_tm_node_data _data
BCP_obj_status status() const
Return the status of the cut.
Definition: BCP_cut.hpp:91
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_tm_stat stat
Definition: BCP_tm.hpp:265
BCP_message_tag msgtag() const
Return the message tag of the message in the buffer.
Definition: BCP_buffer.hpp:90
void BCP_tm_wrapup(BCP_tm_prob *tm, BCP_lp_prob *lp, BCP_cg_prob *cg, BCP_vg_prob *vg, bool final_stat)
BCP_tm_node * root()
BCP_storage_t storage() const
Currently there isn&#39;t any error handling in BCP.
Definition: BCP_error.hpp:20
BCP_message_environment * msg_env
A class that holds the methods about how to pack things.
Definition: BCP_tm.hpp:156
BCP_user_pack * packer
A class that holds the methods about how to pack things.
Definition: BCP_tm.hpp:153
size_t size() const
Return the current number of entries.
Definition: BCP_vector.hpp:116
Algorithmic object.
Definition: BCP_enum.hpp:53
std::vector< int > lp_procs
members to measure how long it took to process the root node.
Definition: BCP_tm.hpp:186
This class describes the message buffer used for all processes of BCP.
Definition: BCP_buffer.hpp:39
void BCP_tm_save_root_cuts(BCP_tm_prob *tm)
BCP_scheduler lp_scheduler
members to measure how long it took to process the root node.
Definition: BCP_tm.hpp:188
const char * data() const
Return a const pointer to the data stored in the buffer.
Definition: BCP_buffer.hpp:97
BCP_tm_user * user
A class that holds the methods about how to pack things.
Definition: BCP_tm.hpp:151
virtual bool alive(const int pid)=0
Test if the process given by the argument is alive or not.
This class is the central class of the Variable Generator process.
Definition: BCP_vg.hpp:32
BCP_object_t
This enumerative constant describes the possible types of objects (variables and cuts).
Definition: BCP_enum.hpp:49
double node_idle(int p)
Return how much time did process p spent idling as a node process.
char param(BCP_tm_par::chr_params key) const
Definition: BCP_tm.hpp:298
Base object.
Definition: BCP_enum.hpp:51
double sb_idle(int p)
Return how much time did process p spent idling as a SB process.
int size() const
Return the size of the current message in the buffer.
Definition: BCP_buffer.hpp:95