-
Notifications
You must be signed in to change notification settings - Fork 0
/
bpp.h
148 lines (119 loc) · 4.27 KB
/
bpp.h
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
/*
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 2011 <copyright holder> <email>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BPP_H
#define BPP_H
#include <boost/unordered_set.hpp>
using namespace boost;
#include <vector>
#include <list>
#include "graph.h"
#include <algorithm>
using namespace std;
#define INF 1000000
/**
* \brief Classe que define um Bin Packing Problem.
*/
class BPP
{
private:
int capacity; ///< A capacidade das caixas.
vector<int> items; ///< O vetor com o tamanho de cada um dos itens.
public:
/**
* \brief Construtor.
*
* Inicializa o problema do bin packing problem.
*
* \param _capacity a capacidade das caixas do problema.
*/
BPP(int _capacity);
/**
* \brief Construtor de cópia.
*
* Inicializa um clone de um BPP.
*
* \param other problema BPP a ser clonado.
*/
BPP(const BPP& other);
/**
* \brief Destrutor
*/
virtual ~BPP();
/**
* \brief Clona os dados de outro BPP.
*
* \param other problema BPP a ser clonado.
*/
virtual BPP& operator=(const BPP& other);
/**
* \brief Getter do vetor de itens de um BPP.
*
* Obtém os tamanhos de cada um dos itens do problema em um vetor.
*
* \return Vetor com os tamanhos de cada um dos itens, na ordem em que foram setados.
*/
vector<int> get_items();
int get_items_size();
/**
* \brief Getter da capacidade das caixas do problema.
*
* \return Capacidade das caixas do problema.
*/
int get_capacity();
/**
* \brief Insere um novo item no BPP.
*
* Insere um novo item no vetor de itens, com peso weight.
*
* \param weight o peso do item a ser inserido.
*/
void add_item(int weight);
/**
* \brief Cálculo simples de limitante inferior do BPP.
*
* Método de cálculo: \n
* 1. Soma todos os pesos e divide pela capacidade das caixas. \n
* 2. Retorna o menor inteiro com valor maior ou igual ao do resultado do passo 1.
*
* \return Limitante inferior do Bin Packing Problem.
*/
int lower_bound_0();
double average_weight();
int upper_bound_ffd(Graph & conflicts, list<vector<pair<int,list<int> > > > & pool, unordered_set<pair<int,list<int> > > & feasible_bins);
int upper_bound_bf(Graph & conflicts, list<vector<pair<int,list<int> > > > & pool, unordered_set<pair<int,list<int> > > & feasible_bins);
int upper_bound_wf(Graph & conflicts, list<vector<pair<int,list<int> > > > & pool, unordered_set<pair<int,list<int> > > & feasible_bins);
int upper_bound_ffd(Graph & conflicts, vector<int> &sub_items, list<vector<pair<int,list<int> > > > & pool, unordered_set<pair<int,list<int> > > & feasible_bins);
int upper_bound_bf(Graph & conflicts,vector<int> & sub_items, list<vector<pair<int,list<int> > > > & pool, unordered_set<pair<int,list<int> > > & feasible_bins);
int upper_bound_wf(Graph & conflicts,vector<int> & sub_items, list<vector<pair<int,list<int> > > > & pool, unordered_set<pair<int,list<int> > > & feasible_bins);
void order(list<int> & a);
/**
*
*/
void add_size_conflicts(Graph & conflicts);
int transportation(list<int> & items, Graph & conflicts);
int transport_problem(vector<int> & a, vector<int> & b, vector<vector<int> > & c, vector<vector<int> > & x);
int calc_transportation(int l, vector<bool> ¬_used_items, vector<int> & residuals, list<int> & prev_items, Graph & conflicts, int min_index, int min);
vector<int> get_surrogate_bpp(double alpha, Graph & conflicts);
int item_weight(int i);
private:
/**
* \internal
* \brief Seta os dados do objeto iguais aos de arg1.
*
* \param arg1 BPP a ser copiado.
*/
void set_parameters(const BPP & arg1);
};
#endif // BPP_H