coin-Bcp
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
tmp
Bcp-1.4.4
Applications
Mkc
include
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
13
struct
MKC_knapsack_entry
{
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
:
22
MKC_knapsack_entry
() :
orig_index
(-2),
index
(-2),
color
(-2),
23
weight
(0.0),
orig_cost
(0.0),
cost
(0.0),
ratio
(0.0) {}
24
~MKC_knapsack_entry
() {}
25
void
pack
(
BCP_buffer
& buf);
26
void
unpack
(
BCP_buffer
& buf);
27
};
28
29
//#############################################################################
30
31
inline
bool
MKC_ks_entry_color_ascend
(
const
MKC_knapsack_entry
& order0,
32
const
MKC_knapsack_entry
& order1)
33
{
34
return
order0.
color
< order1.
color
;
35
}
36
37
inline
bool
MKC_ks_entry_ratio_descend
(
const
MKC_knapsack_entry
& order0,
38
const
MKC_knapsack_entry
& order1)
39
{
40
return
order0.
ratio
> order1.
ratio
;
41
}
42
43
inline
bool
MKC_ks_entry_weight_ascend
(
const
MKC_knapsack_entry
& order0,
44
const
MKC_knapsack_entry
& order1)
45
{
46
return
order0.
weight
< order1.
weight
;
47
}
48
49
inline
bool
MKC_ks_entry_weight_descend
(
const
MKC_knapsack_entry
& order0,
50
const
MKC_knapsack_entry
& order1)
51
{
52
return
order0.
weight
< order1.
weight
;
53
}
54
55
//#############################################################################
56
57
class
MKC_knapsack_fixing
{
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.
64
BCP_vec<char>
fixing
;
//
65
int
fixed_entry_num
;
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
:
71
MKC_knapsack_fixing
() :
72
fixed_entry_num
(0),
fixed_entries
(0),
fixed_entries_ind
(0),
73
fixed_cost
(0.0),
fixed_weight
(0.0) {}
74
~MKC_knapsack_fixing
() {
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
:
97
MKC_knapsack
() :
98
cost
(0.0),
capacity
(0.0),
size
(0),
entries
(0),
99
color_num
(0),
color_beg
(0),
orig_index
(-1) {}
100
~MKC_knapsack
() {
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
111
class
MKC_knapsack_set
{
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
116
int
orig_var_num
;
117
char
**
orig_name_list
;
118
double
*
orig_row_0
;
119
double
*
orig_row_1
;
120
public
:
121
MKC_knapsack_set
() :
122
order_num
(0),
ks_num
(0),
ks_list
(0),
123
orig_var_num
(0),
orig_name_list
(0),
orig_row_0
(0),
orig_row_1
(0) {}
124
~MKC_knapsack_set
() {
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
BCP_vector.hpp
MKC_knapsack_entry
Definition:
MKC_knapsack.hpp:13
MKC_knapsack_set::orig_row_0
double * orig_row_0
Definition:
MKC_knapsack.hpp:118
MKC_knapsack_set::ks_num
int ks_num
Definition:
MKC_knapsack.hpp:114
MKC_knapsack::size
int size
Definition:
MKC_knapsack.hpp:87
MKC_knapsack_set
Definition:
MKC_knapsack.hpp:111
MKC_knapsack_set::MKC_knapsack_set
MKC_knapsack_set()
Definition:
MKC_knapsack.hpp:121
MKC_knapsack::MKC_knapsack
MKC_knapsack()
Definition:
MKC_knapsack.hpp:97
MKC_knapsack_entry::pack
void pack(BCP_buffer &buf)
MKC_knapsack_fixing::MKC_knapsack_fixing
MKC_knapsack_fixing()
Definition:
MKC_knapsack.hpp:71
MKC_knapsack_set::orig_row_1
double * orig_row_1
Definition:
MKC_knapsack.hpp:119
MKC_knapsack::capacity
double capacity
Definition:
MKC_knapsack.hpp:86
MKC_ks_entry_weight_descend
bool MKC_ks_entry_weight_descend(const MKC_knapsack_entry &order0, const MKC_knapsack_entry &order1)
Definition:
MKC_knapsack.hpp:49
MKC_knapsack_fixing
Definition:
MKC_knapsack.hpp:57
MKC_knapsack_entry::color
int color
Definition:
MKC_knapsack.hpp:16
MKC_knapsack_fixing::fixed_cost
double fixed_cost
Definition:
MKC_knapsack.hpp:68
MKC_knapsack_entry::MKC_knapsack_entry
MKC_knapsack_entry()
Definition:
MKC_knapsack.hpp:22
MKC_knapsack_fixing::fixed_entries_ind
int * fixed_entries_ind
Definition:
MKC_knapsack.hpp:67
MKC_knapsack_entry::~MKC_knapsack_entry
~MKC_knapsack_entry()
Definition:
MKC_knapsack.hpp:24
MKC_knapsack_entry::cost
double cost
Definition:
MKC_knapsack.hpp:19
MKC_knapsack_entry::weight
double weight
Definition:
MKC_knapsack.hpp:17
MKC_knapsack_set::orig_var_num
int orig_var_num
Definition:
MKC_knapsack.hpp:116
MKC_knapsack_set::order_num
int order_num
Definition:
MKC_knapsack.hpp:113
MKC_knapsack
Definition:
MKC_knapsack.hpp:83
MKC_knapsack_entry::orig_cost
double orig_cost
Definition:
MKC_knapsack.hpp:18
MKC_knapsack_fixing::fixed_entry_num
int fixed_entry_num
Definition:
MKC_knapsack.hpp:65
MKC_knapsack_fixing::fixed_entries
int * fixed_entries
Definition:
MKC_knapsack.hpp:66
MKC_ks_entry_weight_ascend
bool MKC_ks_entry_weight_ascend(const MKC_knapsack_entry &order0, const MKC_knapsack_entry &order1)
Definition:
MKC_knapsack.hpp:43
MKC_knapsack::entries
MKC_knapsack_entry * entries
Definition:
MKC_knapsack.hpp:89
MKC_ks_entry_ratio_descend
bool MKC_ks_entry_ratio_descend(const MKC_knapsack_entry &order0, const MKC_knapsack_entry &order1)
Definition:
MKC_knapsack.hpp:37
MKC_knapsack_entry::unpack
void unpack(BCP_buffer &buf)
MKC_knapsack::color_num
int color_num
Definition:
MKC_knapsack.hpp:91
MKC_knapsack::~MKC_knapsack
~MKC_knapsack()
Definition:
MKC_knapsack.hpp:100
MKC_knapsack_set::unpack
void unpack(BCP_buffer &buf)
MKC_knapsack_set::pack
void pack(BCP_buffer &buf)
MKC_ks_entry_color_ascend
bool MKC_ks_entry_color_ascend(const MKC_knapsack_entry &order0, const MKC_knapsack_entry &order1)
Definition:
MKC_knapsack.hpp:31
MKC_knapsack_entry::orig_index
int orig_index
Definition:
MKC_knapsack.hpp:14
BCP_vec< char >
BCP_buffer
This class describes the message buffer used for all processes of BCP.
Definition:
BCP_buffer.hpp:39
MKC_knapsack_entry::index
int index
Definition:
MKC_knapsack.hpp:15
MKC_knapsack_set::~MKC_knapsack_set
~MKC_knapsack_set()
Definition:
MKC_knapsack.hpp:124
MKC_knapsack_fixing::fixed_weight
double fixed_weight
Definition:
MKC_knapsack.hpp:69
MKC_knapsack_fixing::fixing
BCP_vec< char > fixing
Definition:
MKC_knapsack.hpp:64
MKC_knapsack_entry::ratio
double ratio
Definition:
MKC_knapsack.hpp:20
MKC_knapsack::pack
void pack(BCP_buffer &buf)
MKC_knapsack_set::orig_name_list
char ** orig_name_list
Definition:
MKC_knapsack.hpp:117
MKC_knapsack::unpack
void unpack(BCP_buffer &buf)
MKC_knapsack::cost
double cost
Definition:
MKC_knapsack.hpp:85
MKC_knapsack::color_beg
int * color_beg
Definition:
MKC_knapsack.hpp:92
MKC_knapsack::orig_index
int orig_index
Definition:
MKC_knapsack.hpp:94
MKC_knapsack_set::ks_list
MKC_knapsack * ks_list
Definition:
MKC_knapsack.hpp:115
MKC_knapsack_fixing::~MKC_knapsack_fixing
~MKC_knapsack_fixing()
Definition:
MKC_knapsack.hpp:74
Generated by
1.8.5