OS_packer.cpp
Go to the documentation of this file.
1 /* $Id: OS_packer.cpp 2698 2009-06-09 04:14:07Z kmartin $ */
2 // Last edit: 5/20/07
3 //
4 // Name: OS_packer.cpp
5 // Author: Francois Margot
6 // Tepper School of Business
7 // Carnegie Mellon University, Pittsburgh, PA 15213
8 // email: fmargot@andrew.cmu.edu
9 // Date: 5/18/07
10 //-----------------------------------------------------------------------------
11 // Copyright (C) 2007, Francois Margot, IBM and others. All Rights Reserved.
12 
13 #include "BCP_buffer.hpp"
14 #include "OS_cut.hpp"
15 #include "OS_var.hpp"
16 #include "OS_user_data.hpp"
17 #include "OS_packer.hpp"
18 
19 using namespace std;
20 
21 /****************************************************************************/
22 
24  // we don't have indexed cuts so simplify
25  // int typ;
26  const OS_cut* bb_cut = dynamic_cast<const OS_cut*>(cut);
27  //if (bb_cut) {
28  // typ = 1;
29  // buf.pack(typ);
30  // std::cout << "INSIDE pack_cut_algo " << std::endl;
31  bb_cut->pack(buf);
32  return;
33  //}
34  throw BCP_fatal_error("OS_pack_cut(): unknown cut type.");
35 }
36 
37 /****************************************************************************/
38 
40 {
41  // we don't have indexed cuts so simplify
42  //int typ;
43  //buf.unpack(typ);
44  //switch (typ) {
45  //case 0:
46  // throw BCP_fatal_error("OS_unpack_cut(): unknown cut type.");
47  //return new OS_indexed_cut(buf);
48  //case 1:
49  //std::cout << "INSIDE unpack_cut_algo " << std::endl;
50 
51  return new OS_cut( buf);
52  //default:
53  // throw BCP_fatal_error("OS_unpack_cut(): unknown cut type.");
54  // break;
55  // }
56  //return NULL; // fake return
57 }
58 
59 
60 
62 
63  const OS_var* v = dynamic_cast<const OS_var*>(var);
64  // don't worry about type, only one kind of variable
65  //int type = 0;
66  //buf.pack( type);
67 
68  v->pack( buf);
69  return;
70 
71 }
72 
73 /*---------------------------------------------------------------------------*/
74 
76 
77 
78  // int type;
79  // buf.unpack( type);
80 
81  return new OS_var( buf);
82 
83 }
84 
85 
86 
87 /****************************************************************************/
88 
90 // Normally, no modifications required.
91 {
92  const MY_user_data *mud = dynamic_cast<const MY_user_data*> (ud);
93  if(!mud)
94  throw BCP_fatal_error("OS_lp::pack_user_data() : unknown data type!\n");
95 
96  printf("OS_lp::pack_user_data:\n");
97  mud->print();
98  mud->pack(buf);
99 }
100 
101 /****************************************************************************/
102 
104  // Normally, no modifications required.
105 {
106  MY_user_data *p_ud = new MY_user_data(buf);
107  printf("OS_lp::unpack_user_data:\n");
108  p_ud->print();
109 
110  if (p_ud->is_processed) {
111  p_ud->p_rud = NULL;
112  delete(p_ud);
113  p_ud = NULL;
114  printf("user_data deleted\n");
115  }
116 
117  return(p_ud);
118 }
Simple representation of a cut by storing non zero coefficients only.
Definition: OS_cut.hpp:17
virtual BCP_cut_algo * unpack_cut_algo(BCP_buffer &buf)
Unpack an algorithmic cut.
Definition: OS_packer.cpp:39
This is the class from which the user should derive her own algorithmic cuts.
Definition: BCP_cut.hpp:242
virtual void pack_cut_algo(const BCP_cut_algo *cut, BCP_buffer &buf)
Pack an algorithmic cut.
Definition: OS_packer.cpp:23
void print() const
Dump the fields of the class.
real_user_data * p_rud
Pointer on an object holding the user data itself.
virtual void pack_var_algo(const BCP_var_algo *var, BCP_buffer &buf)
Pack warmstarting information.
Definition: OS_packer.cpp:61
void pack(BCP_buffer &buf) const
Packing to buffer.
void pack(BCP_buffer &buf) const
Definition: OS_var.cpp:43
Class taking care of interaction between user data and Bcp.
virtual BCP_user_data * unpack_user_data(BCP_buffer &buf)
Unpack an user data.
Definition: OS_packer.cpp:103
virtual BCP_var_algo * unpack_var_algo(BCP_buffer &buf)
Unpack an algorithmic variable.
Definition: OS_packer.cpp:75
Currently there isn&#39;t any error handling in BCP.
Definition: BCP_error.hpp:20
virtual void pack_user_data(const BCP_user_data *ud, BCP_buffer &buf)
Pack an user data.
Definition: OS_packer.cpp:89
int is_processed
Indicator for mmory management: If is_processed = 1, the associated user data may be erased...
This is the class from which the user should derive her own algorithmic variables.
Definition: BCP_var.hpp:277
This class describes the message buffer used for all processes of BCP.
Definition: BCP_buffer.hpp:39
void pack(BCP_buffer &buf) const
Packing cut to a buffer.
Definition: OS_cut.cpp:11