-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathinstance_builder.hpp
More file actions
190 lines (149 loc) · 4.44 KB
/
instance_builder.hpp
File metadata and controls
190 lines (149 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#pragma once
#include "packingsolver/box/instance.hpp"
namespace packingsolver
{
namespace box
{
class InstanceBuilder
{
public:
/** Constructor. */
InstanceBuilder() { }
/** Set the objective. */
void set_objective(Objective objective) { instance_.objective_ = objective; }
/*
* Read from files
*/
/** Read parameters from a file. */
void read_parameters(const std::string& parameters_path);
/** Read bin types from a file. */
void read_bin_types(const std::string& bins_path);
/** Read item types from a file. */
void read_item_types(const std::string& items_path);
/*
* Set parameters
*/
/** Set parameters. */
void set_parameters(const Parameters& parameters) { instance_.parameters_ = parameters; }
/*
* Set bin types
*/
/** Add a bin type. */
BinTypeId add_bin_type(
Length x,
Length y,
Length z,
Profit cost = -1,
BinPos copies = 1,
BinPos copies_min = 0);
/** Set the maximum weight of a bin type. */
void set_bin_type_maximum_weight(
BinTypeId bin_type_id,
Weight maximum_weight);
/**
* Add a bin type from another bin type.
*
* This method is used in the column generation procedure.
*/
void add_bin_type(
const Instance& original_instance,
BinTypeId original_bin_type_id,
BinPos copies,
BinPos copies_min = 0);
/**
* For each bin type, set an infinite x.
*
* This method is used to transform a problem into a Strip Packing problem.
*/
void set_bin_types_infinite_x();
/**
* For each bin type, set an infinite y.
*
* This method is used to transform a problem into a Strip Packing problem.
*/
void set_bin_types_infinite_y();
/**
* Foe each bin type, set an infinite number of copies.
*
* This method should be used after reading bin files of Bin Packing
* Problems where the number of bin types is not given. By default, the
* number of bins would be set to 1.
*/
void set_bin_types_infinite_copies();
/**
* For each bin type, set its cost to its volume.
*
* This method is used to transform a Variable-sized Bin Packing Problem
* into an Unweighted Variable-sized Bin Packing Problem.
*/
void set_bin_types_unweighted();
/*
* Set item types
*/
/** Add an item type. */
ItemTypeId add_item_type(
Length x,
Length y,
Length z,
Profit p = -1,
ItemPos copies = 1,
int rotations = 1);
/** Set the weight of an item type. */
void set_item_type_weight(
ItemTypeId item_type_id,
Weight weight);
/**
* Add an item type from another item type.
*
* This method is used in the column generation procedure.
*/
void add_item_type(
const Instance& original_instance,
ItemTypeId original_item_type_id,
Profit profit,
ItemPos copies);
/** Set a default value for the item type profits. */
void set_item_types_profits_auto();
/**
* For each item type, set an infinite number of copies.
*
* This method is used to transform a Knapsack Problem into an Unbounded
* Knapsack Problem.
*/
void set_item_types_infinite_copies();
/**
* For each item type, set its profit to its volume.
*
* This method is used to transform a Knapsack Problem into an Unweighted
* Knapsack Problem.
*/
void set_item_types_unweighted();
/** For each item type, set 'oriented' to 'true'. */
void set_item_types_oriented();
/*
* Build
*/
/** Build. */
Instance build();
private:
/*
* Private methods
*/
/** Compute item type max length sum. */
Length compute_item_types_max_length_sum() const;
/** Compute bin attributes. */
void compute_bin_attributes();
/** Compute bin types volume max. */
Area compute_bin_types_volume_max() const;
/*
* Private attributes
*/
/** Instance. */
Instance instance_;
/** Mapping from original bin type IDs to sub-instance bin type IDs. */
std::vector<BinTypeId> orig_to_sub_bin_type_ids_;
/** Mapping from original item type IDs to sub-instance item type IDs. */
std::vector<ItemTypeId> orig_to_sub_item_type_ids_;
};
}
}