coin-Bcp
MKC_knapsack.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_KNAPSACK_H
4 #define _MKC_KNAPSACK_H
5 
6 #include "BCP_vector.hpp"
7 
8 class BCP_buffer;
9 
10 //#############################################################################
11 
12 // This structure corresponds to an order
14  int orig_index; // it's index in the original list of vars
15  int index; // the index of the order
16  int color;
17  double weight;
18  double orig_cost; // the original cost of the order
19  double cost; // the costof the entry in the knapsack subproblems
20  double ratio; // the cost/weight ratio in the knapsack subproblems
21 public:
23  weight(0.0), orig_cost(0.0), cost(0.0), ratio(0.0) {}
25  void pack(BCP_buffer& buf);
26  void unpack(BCP_buffer& buf);
27 };
28 
29 //#############################################################################
30 
32  const MKC_knapsack_entry& order1)
33 {
34  return order0.color < order1.color;
35 }
36 
38  const MKC_knapsack_entry& order1)
39 {
40  return order0.ratio > order1.ratio;
41 }
42 
44  const MKC_knapsack_entry& order1)
45 {
46  return order0.weight < order1.weight;
47 }
48 
50  const MKC_knapsack_entry& order1)
51 {
52  return order0.weight < order1.weight;
53 }
54 
55 //#############################################################################
56 
58 public:
59  // An entry in the char vector is
60  // 0: if the order can't be in the corresponding knapsack
61  // 1: if there are no restrictions for that order
62  // Note: those that must be in the KS are already listed in the fixed
63  // entries, thus they will have a 0 in fixing.
66  int * fixed_entries; // index in the KS
67  int * fixed_entries_ind; // index of the order
68  double fixed_cost;
69  double fixed_weight;
70 public:
73  fixed_cost(0.0), fixed_weight(0.0) {}
75  delete[] fixed_entries_ind;
76  delete[] fixed_entries;
77  }
78 };
79 
80 //#############################################################################
81 
82 // This structure corresponds to a slab
83 class MKC_knapsack {
84 public:
85  double cost; // the cost of using this slab at all
86  double capacity;
87  int size; // the numbor of KS entries (orders) that can go into this
88  // KS (slab) at all.
89  MKC_knapsack_entry * entries; // the orders that can go into this slab
90  // These entries are ordered by color
91  int color_num; // the number of different colors among the entries
92  int * color_beg; // length: color_num + 1; the positions where the colors
93  // start in entries (remember, it's ordered by color)
94  int orig_index; // the index of the corresponding z variable in the
95  // original list of vars
96 public:
98  cost(0.0), capacity(0.0), size(0), entries(0),
99  color_num(0), color_beg(0), orig_index(-1) {}
101  delete[] entries;
102  delete[] color_beg;
103  }
104 
105  void pack(BCP_buffer& buf);
106  void unpack(BCP_buffer& buf);
107 };
108 
109 //#############################################################################
110 
112 public:
113  int order_num; // the number of orders (KS entries)
114  int ks_num; // the number of slabs (knapsacks)
115  MKC_knapsack* ks_list; // the description of the KSs
118  double * orig_row_0;
119  double * orig_row_1;
120 public:
122  order_num(0), ks_num(0), ks_list(0),
125  delete[] ks_list;
126  if (orig_name_list) {
127  for (int i = 0; i < orig_var_num; ++i)
128  delete[] orig_name_list[i];
129  delete[] orig_name_list;
130  }
131  delete[] orig_row_0;
132  delete[] orig_row_1;
133  }
134 
135  void pack(BCP_buffer& buf);
136  void unpack(BCP_buffer& buf);
137 };
138 
139 #endif
void pack(BCP_buffer &buf)
bool MKC_ks_entry_weight_descend(const MKC_knapsack_entry &order0, const MKC_knapsack_entry &order1)
int color
MKC_knapsack_entry()
~MKC_knapsack_entry()
double cost
double weight
double orig_cost
bool MKC_ks_entry_weight_ascend(const MKC_knapsack_entry &order0, const MKC_knapsack_entry &order1)
MKC_knapsack_entry * entries
bool MKC_ks_entry_ratio_descend(const MKC_knapsack_entry &order0, const MKC_knapsack_entry &order1)
void unpack(BCP_buffer &buf)
void unpack(BCP_buffer &buf)
void pack(BCP_buffer &buf)
bool MKC_ks_entry_color_ascend(const MKC_knapsack_entry &order0, const MKC_knapsack_entry &order1)
int orig_index
This class describes the message buffer used for all processes of BCP.
Definition: BCP_buffer.hpp:39
int index
BCP_vec< char > fixing
double ratio
void pack(BCP_buffer &buf)
void unpack(BCP_buffer &buf)
MKC_knapsack * ks_list