MCF2_var.cpp
Go to the documentation of this file.
1 #include "MCF2_var.hpp"
2 
3 //#############################################################################
4 
5 void MCF2_var::pack(BCP_buffer& buf) const
6 {
7  buf.pack(commodity);
8  int numarcs = flow.getNumElements();
9  buf.pack(flow.getIndices(), numarcs);
10  buf.pack(flow.getElements(), numarcs);
11  buf.pack(weight);
12 }
13 
14 /*---------------------------------------------------------------------------*/
15 
17  // we don't know the onj coeff (weight) yet, so temporarily set it to 0
19 {
20  buf.unpack(commodity);
21  int numarcs;
22  int* ind;
23  double* val;
24  buf.unpack(ind, numarcs);
25  buf.unpack(val, numarcs);
26  flow.assignVector(numarcs, ind, val, false /*don't test for duplicates*/);
27  buf.unpack(weight);
28  set_obj(weight);
29 }
30 
31 /*===========================================================================*/
32 
34 {
35  buf.pack(commodity);
36  buf.pack(arc_index);
37  buf.pack(lb_child0);
38  buf.pack(ub_child0);
39  buf.pack(lb_child1);
40  buf.pack(ub_child1);
41 }
42 
43 /*---------------------------------------------------------------------------*/
44 
46  BCP_var_algo(BCP_BinaryVar, 0, 0, 1)
47 {
48  buf.unpack(commodity);
49  buf.unpack(arc_index);
50  buf.unpack(lb_child0);
51  buf.unpack(ub_child0);
52  buf.unpack(lb_child1);
53  buf.unpack(ub_child1);
54 }
55 
56 /*===========================================================================*/
57 
58 void MCF2_pack_var(const BCP_var_algo* var, BCP_buffer& buf)
59 {
60  const MCF2_var* v = dynamic_cast<const MCF2_var*>(var);
61  if (v) {
62  int type = 0;
63  buf.pack(type);
64  v->pack(buf);
65  return;
66  }
67  const MCF2_branching_var* bv = dynamic_cast<const MCF2_branching_var*>(var);
68  if (bv) {
69  int type = 1;
70  buf.pack(type);
71  bv->pack(buf);
72  return;
73  }
74 }
75 
76 /*---------------------------------------------------------------------------*/
77 
79 {
80  int type;
81  buf.unpack(type);
82  switch (type) {
83  case 0: return new MCF2_var(buf);
84  case 1: return new MCF2_branching_var(buf);
85  default: throw BCP_fatal_error("MCF2_unpack_var: bad var type");
86  }
87  return NULL; // fake return
88 }
89 
Binary (0-1) variable.
Definition: BCP_enum.hpp:163
BCP_buffer & pack(const T &value)
Pack a single object of type T.
Definition: BCP_buffer.hpp:177
BCP_buffer & unpack(T &value)
Unpack a single object of type T.
Definition: BCP_buffer.hpp:186
MCF2_var(int com, const CoinPackedVector &f, double w)
Definition: MCF2_var.hpp:28
double weight
Definition: MCF2_var.hpp:25
void pack(BCP_buffer &buf) const
Definition: MCF2_var.cpp:33
BCP_var_algo * MCF2_unpack_var(BCP_buffer &buf)
Definition: MCF2_var.cpp:78
MCF2_branching_var(int comm, int ind, int lb0, int ub0, int lb1, int ub1)
Definition: MCF2_var.hpp:51
Continuous variable.
Definition: BCP_enum.hpp:167
Currently there isn&#39;t any error handling in BCP.
Definition: BCP_error.hpp:20
void pack(BCP_buffer &buf) const
Definition: MCF2_var.cpp:5
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 set_obj(const double obj)
Set the objective coefficient.
Definition: BCP_var.hpp:143
CoinPackedVector flow
Definition: MCF2_var.hpp:24
void MCF2_pack_var(const BCP_var_algo *var, BCP_buffer &buf)
Definition: MCF2_var.cpp:58
int commodity
Definition: MCF2_var.hpp:23