coin-Bcp
MKC_var.hpp
Go to the documentation of this file.
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 #ifndef _MKC_VAR_H
4 #define _MKC_VAR_H
5 
6 #include <cfloat>
7 #include "BCP_vector.hpp"
8 #include "BCP_var.hpp"
9 #include "BCP_buffer.hpp"
10 
11 enum MKC_var_t {
14 };
15 
16 class MKC_var : public BCP_var_algo {
17 public:
18  double cost; // the cost of this variable
19  int entry_num; // 1 + the number of objects put into the KS.
20  int * entries; // the first entry is the index of the KS this var belongs
21  // to, ks_index the orders put into the KS.
22  int color[2]; // the two colors of the variable
23 public:
24  MKC_var(const double c, const int num, int *& entr, const int clr[2]) :
25  BCP_var_algo(BCP_BinaryVar, c, 0.0, 1.0),
26  cost(c), entry_num(num), entries(entr) {
27  entr = 0;
28  color[0] = clr[0];
29  color[1] = clr[1];
30  }
31  MKC_var(const MKC_var& x) :
32  BCP_var_algo(BCP_BinaryVar, x.cost, 0.0, 1.0),
33  cost(x.cost), entry_num(x.entry_num), entries(new int[x.entry_num]) {
34  memcpy(entries, x.entries, x.entry_num * sizeof(int));
35  color[0] = x.color[0];
36  color[1] = x.color[1];
37  }
39  BCP_var_algo(BCP_BinaryVar, 0.0, 0.0, 1.0),
40  cost(0.0), entry_num(0), entries(0) {
42  .unpack(color[0]).unpack(color[1]);
43  set_obj(cost);
44  }
45 
47  delete[] entries;
48  }
49 
50 public:
51  double dj(const double* dual) const {
52  double red_cost = cost;
53  for (int i = entry_num - 1; i >= 0; --i)
54  red_cost -= dual[entries[i]];
55  return red_cost;
56  }
57 
58  void pack(BCP_buffer& buf) const {
60  }
61 };
62 
63 //#############################################################################
64 
66 public:
67  // the index of the order that is assigned to a list of slabs
69  int slab_num;
70  int * slab_list;
71 public:
72  MKC_branching_var(const int order_ind, const int num, int *& slist) :
73  BCP_var_algo(BCP_ContinuousVar, 0.0, 0.0, 1e40),
74  order_index(order_ind), slab_num(num), slab_list(slist) {
75  slist = 0;
76  }
78  BCP_var_algo(BCP_ContinuousVar, 0.0, 0.0, 1e40),
79  order_index(-1), slab_num(0), slab_list(0) {
81  }
82 
84  delete[] slab_list;
85  }
86 
87  void pack(BCP_buffer& buf) const {
89  }
90 };
91 
92 //#############################################################################
93 
94 inline BCP_var_algo*
96 {
97  int type;
98  buf.unpack(type);
99  switch (type) {
100  case MKC_RegularVar: return new MKC_var(buf);
101  case MKC_BranchingVar: return new MKC_branching_var(buf);
102  }
103  throw BCP_fatal_error("MKC: Unknown variable type in MKC_var_unpack().\n");
104  return 0; // fake return
105 }
106 
107 //#############################################################################
108 
109 inline void
111 {
112  const MKC_var* regular_var = dynamic_cast<const MKC_var*>(var);
113  if (regular_var) {
114  const int type = MKC_RegularVar;
115  buf.pack(type);
116  regular_var->pack(buf);
117  return;
118  }
119 
120  const MKC_branching_var* b_var = dynamic_cast<const MKC_branching_var*>(var);
121  if (b_var) {
122  const int type = MKC_BranchingVar;
123  buf.pack(type);
124  b_var->pack(buf);
125  return;
126  }
127 
128  throw BCP_fatal_error("MKC: Unknown variable type in MKC_var_pack().\n");
129 }
130 
131 #endif
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
int entry_num
Definition: MKC_var.hpp:19
double dj(const double *dual) const
Definition: MKC_var.hpp:51
int color[2]
Definition: MKC_var.hpp:22
MKC_var(const MKC_var &x)
Definition: MKC_var.hpp:31
~MKC_var()
Definition: MKC_var.hpp:46
MKC_branching_var(const int order_ind, const int num, int *&slist)
Definition: MKC_var.hpp:72
void pack(BCP_buffer &buf) const
Definition: MKC_var.hpp:58
Continuous variable.
Definition: BCP_enum.hpp:167
double cost
Definition: MKC_var.hpp:18
Currently there isn&#39;t any error handling in BCP.
Definition: BCP_error.hpp:20
void pack(BCP_buffer &buf) const
Definition: MKC_var.hpp:87
MKC_var_t
Definition: MKC_var.hpp:11
This is the class from which the user should derive her own algorithmic variables.
Definition: BCP_var.hpp:277
void MKC_var_pack(const BCP_var_algo *var, BCP_buffer &buf)
Definition: MKC_var.hpp:110
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
BCP_var_algo * MKC_var_unpack(BCP_buffer &buf)
Definition: MKC_var.hpp:95
MKC_branching_var(BCP_buffer &buf)
Definition: MKC_var.hpp:77
int * entries
Definition: MKC_var.hpp:20
MKC_var(const double c, const int num, int *&entr, const int clr[2])
Definition: MKC_var.hpp:24
MKC_var(BCP_buffer &buf)
Definition: MKC_var.hpp:38