Skip to content

Commit f8ee236

Browse files
Add initial code for paper (#1)
1 parent dda0559 commit f8ee236

27 files changed

+6800
-1
lines changed

AUTHORS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Mathijs Barkel <m.j.barkel[at]tilburguniversity[dot]edu>
2+
Maxence Delorme <m.delorme[at]tilburguniversity[dot]edu>
3+
Enrico Malaguti <enrico.malaguti[at]unibo[dot]it>
4+
Michele Monaci <michele.monaci[at]unibo[dot]it>

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,94 @@
1-
# 2024.0972
1+
[![INFORMS Journal on Computing Logo](https://INFORMSJoC.github.io/logos/INFORMS_Journal_on_Computing_Header.jpg)](https://pubsonline.informs.org/journal/ijoc)
2+
3+
# ILP models for the Bin Packing Problem with Minimum Color Fragmentation
4+
5+
This archive is distributed in association with the [INFORMS Journal on
6+
Computing](https://pubsonline.informs.org/journal/ijoc) under the [GNU GENERAL PUBLIC LICENSE](LICENSE).
7+
8+
The software and data in this repository are a snapshot of the software and data
9+
that were used in the research reported on in the paper
10+
[Pseudo-Polynomial Formulations for the Bin Packing Problem with Minimum Color Fragmentation](https://doi.org/10.1287/ijoc.2024.0972) by Mathijs Barkel, Maxence Delorme, Enrico Malaguti and Michele Monaci.
11+
12+
**Important: This code is being developed on an on-going basis at
13+
https://github.com/MathijsBarkel/BPPMCF2. Please go there if you would like to
14+
get a more recent version or would like support.**
15+
16+
## Cite
17+
18+
To cite the contents of this repository, please cite both the paper and this repo, using their respective DOIs.
19+
20+
https://doi.org/10.1287/ijoc.2024.0972
21+
22+
https://doi.org/10.1287/ijoc.2024.0972.cd
23+
24+
Below is the BibTex for citing this snapshot of the repository.
25+
26+
```
27+
@misc{CodeBPPMCF,
28+
author = {Mathijs Barkel and Maxence Delorme and Enrico Malaguti and Michele Monaci},
29+
publisher = {INFORMS Journal on Computing},
30+
title = {Pseudo-Polynomial Formulations for the Bin Packing Problem with Minimum Color Fragmentation},
31+
year = {2025},
32+
doi = {10.1287/ijoc.2024.0972.cd},
33+
url = {https://github.com/INFORMSJoC/2024.0972},
34+
note = {Available for download at https://github.com/INFORMSJoC/2024.0972},
35+
}
36+
```
37+
38+
## Description
39+
40+
The goal of this software is to evaluate different ILP models for solving the Bin Packing Problem with Minimum Color Fragmentation (BPPMCF),
41+
and also to investigate the effect of changing the number of bins on the optimal solution value.
42+
43+
## Details of code
44+
45+
All algorithms are coded in C++ and part of our methods require the commercial solver Gurobi (we used version 11.0.2). The files have the following contents:
46+
47+
| Name | Description |
48+
| ------------- | ------------- |
49+
| main.h/cpp | example of front-end code for calling our methods to solve a given instance |
50+
| BPPLB.h/cpp | code required for the algorithm BPP-LB (introduced by Barkel et al. (2025)) |
51+
| BPPUB.h/cpp | code required for the algorithms BPP-UB (introduced by Barkel et al. (2025)) |
52+
| TS.h/cpp | code required for the algorithm TS (introduced by Barkel et al. (2025)) |
53+
| AFCSP.h/cpp | code required for the arcflow formulation (which is used by our algorithms) |
54+
| IP2RE.h/cpp | code required for our re-implementation of method IP2 by Mehrani et al. (2022) |
55+
| RM2GIFFRE.h/cpp | code required for our re-implementation of method RM2-GIFF by Mehrani et al. (2022) |
56+
| LF.h/cpp | code required for method LayerFlow. |
57+
| HF.h/cpp | code required for method HierarchyFlow |
58+
| MFMB.h/cpp | code required for method MonoFlow-MultiBin |
59+
| helper_functions.h/cpp | code containing miscellaneous simple/supportive functions |
60+
61+
## Details of instances
62+
Moreover, "InstancesBPPMCF.zip" contains a txt-file for each of our test instances. These are spread over 5 folders, each corresponding to a different data set: "Dataset 1", "Dataset 2", "Dataset 3" and "Dataset 4" correspond to datasets D1, D2, D3 and D4 as introduced by Mehrani et al. (2022) (see https://github.com/saharnazmehrani/BPPMCF-IJOC), and "Triplets" corresponds to D5*. Instances D1*, D2*, D3* and D4* (introduced by Barkel et al. (2025) are obtained by setting the number of bins to the minimum number of required bins (see main.cpp), where the minimum number of required bins per instance is saved in the file "minNumberOfBinsPerInstance.txt".
63+
64+
Each instance file is structured as follows:
65+
66+
For Datasets 1,2,3 and 4:
67+
- The first line is always a 1.
68+
- The second line contains the number of bins (B).
69+
- The third line contains the bin capacity (W).
70+
- Then a blank line, followed by a 0-matrix of size BxW, followed by three more blank lines.
71+
- The next line contains the number of colors (C).
72+
- The next line contains the number of items (I).
73+
- Then follows a blank line.
74+
- Finally there is a matrix of size Ix2, where each row i gives the color c and the weight w of item i.
75+
76+
For Dataset 5 (Triplets):
77+
- The first line contains the number of items I.
78+
- The remaining lines contain a matrix of size Ix2, where each row i gives the color c and the weight w of item i.
79+
80+
## References
81+
82+
Barkel, M., Delorme, M., Malaguti, E., and Monaci, M. (2025). Bounds and heuristic algorithms for the bin packing problem with minimum color fragmentation. European Journal of Operational Research, 320(1):57–68.
83+
84+
Mehrani, S., Cardonha, C., and Bergman, D. (2022). Models and algorithms for the bin-packing problem with minimum color fragmentation. INFORMS Journal on Computing, 34:1070–1085.
85+
86+
## Ongoing Development
87+
88+
This code is being developed on an on-going basis at the author's
89+
[GitHub site](https://github.com/MathijsBarkel/BPPMCF2).
90+
91+
## Support
92+
93+
For support in using this software, submit an
94+
[issue](https://github.com/MathijsBarkel/BPPMCF2/issues/new).

data/InstancesBPPMCF.zip

476 KB
Binary file not shown.

results/Raw results.xlsx

457 KB
Binary file not shown.

scripts/main.cpp

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#include "main.h"
2+
3+
int main() {
4+
// -------------------------------------------------------------------------
5+
// Part 1: Instance selection and pre-processing
6+
7+
// Select an instance
8+
// string filename = "InstancesBPPMCF/Dataset 1/70-8/70-8-1.txt";
9+
// string filename = "InstancesBPPMCF/Dataset 2/120-2/120-2-1.txt";
10+
// string filename = "InstancesBPPMCF/Dataset 3/15-100-8/15-100-8-5.txt";
11+
// string filename = "InstancesBPPMCF/Dataset 4/50-400-3/50-400-3-1.txt";
12+
string filename = "InstancesBPPMCF/Triplets/t60_00.txt";
13+
Instance inst = readInstance(filename);
14+
// Instance inst = createInstance("Test_instance", 10, 4, 3, 6, { {0,4},{0,3},{0,1},{1,3},{1,2},{1,2},{1,1},{2,3},{2,2},{2,1} });
15+
// Instance inst = createInstance("Test_instance", 19, 9, 4, 24, { {0,16}, {0,15}, {0,13}, {0,13}, {1,15}, {1,14}, {1,2}, {2,8}, {2,7}, {2,3}, {2,3}, {2,1}, {3,8}, {3,8}, {3,6}, {3,6}, {3,3}, {3,3}, {3,3} });
16+
// Instance inst = createInstance("Weird_instance", 18, 6, 4, 24, { {1,14},{3,7},{2,3},{0,13},{3,8},{2,3},{0,15}, {2,6},{3,3},{0,13},{2,8},{3,3},{0,16},{2,6},{1,2},{1,15},{2,8},{3,1} });
17+
18+
// Do pre-processing of the instance
19+
inst.preprocessing();
20+
21+
// Find the minimum number of required bins
22+
string filenameBmin = "InstancesBPPMCF/minNumberOfBinsPerInstance.txt";
23+
inst.findMinNumberOfBins(filenameBmin);
24+
25+
// Set the number of bins equal to the minimum number of required bins
26+
if (inst.Bmin > 0) { inst.B = inst.Bmin; } // change the number of bins
27+
28+
// Find the L2-lower bounds
29+
inst.findL2();
30+
31+
// Print information about the instance
32+
inst.print();
33+
34+
// --------------------------------------------------------------
35+
// Part 2: Bounding procedures
36+
37+
// Apply BPP-LB
38+
vector<int> LBs(inst.C);
39+
Solution solBPPLB = solveBPPLB(inst, LBs);
40+
solBPPLB.print(true);
41+
42+
// Apply BPP-UB
43+
Solution solBPPUB = solveBPPUB(inst);
44+
solBPPUB.print(true);
45+
46+
// Apply TS
47+
int maxNIterNoImprovement = 1000; // Change the maximum number of iterations without improvement after which the algorithm terminates
48+
Solution solTS = solveTS(inst, solBPPUB, 50, 40, maxNIterNoImprovement, true, 1000000);
49+
solTS.print(true);
50+
51+
// --------------------------------------------------------------
52+
// Part 3: Methods without warm start
53+
54+
// Set a time limit
55+
double timeLimit = 1800;
56+
57+
// Apply a reimplementation of IP2
58+
Solution solIP2RE = solveIP2RE(inst, false, timeLimit);
59+
solIP2RE.print(true);
60+
61+
// Apply a reimplementation of RM2-GIFF
62+
Solution solRM2GIFFRE = solveModelAfterOrdering(inst, false, timeLimit, "RM2GIFF");
63+
solRM2GIFFRE.print(true);
64+
65+
// Apply LayerFlow
66+
Solution solLF = solveModelAfterOrdering(inst, false, timeLimit);
67+
solLF.print(true);
68+
69+
// Apply HierarchyFlow
70+
Solution solHF = solveHF(inst, false, timeLimit);
71+
solHF.print(true);
72+
73+
// Apply MonoFlow-MultiBin
74+
Solution solMFMB = solveMFMB(inst, solTS, false, timeLimit - solTS.timeT);
75+
solMFMB.print(true);
76+
77+
// --------------------------------------------------------------
78+
// Part 4: Methods with warm start
79+
if (not solBPPLB.opt && not solTS.opt) {
80+
81+
// Update the L2 bounds to the L* bounds
82+
inst.LBs = LBs;
83+
inst.LBtot = 0; for (int c = 0; c < inst.C; c++) { inst.LBtot += LBs[c]; }
84+
85+
// Save the feasible solution found by TS in the instance object
86+
inst.feasSol = solTS.binPacking;
87+
88+
// Find the time that was already spent on the bounding procedures
89+
double preTime = solBPPLB.timeT + solTS.timeT;
90+
91+
// Apply a reimplementation of IP2(W)
92+
Solution solIP2REW = solveIP2RE(inst, true, timeLimit - preTime);
93+
solIP2REW.timeT += preTime;
94+
solIP2REW.print(true);
95+
96+
// Apply a reimplementation of RM2-GIFF(W)
97+
Solution solRM2GIFFREW = solveModelAfterOrdering(inst, true, timeLimit - preTime, "RM2GIFF");
98+
solRM2GIFFREW.timeT += preTime;
99+
solRM2GIFFREW.print(true);
100+
101+
// Apply LayerFlow(W)
102+
Solution solLFW = solveModelAfterOrdering(inst, true, timeLimit - preTime);
103+
solLFW.timeT += preTime;
104+
solLFW.print(true);
105+
106+
// Apply HierarchyFlow(W)
107+
Solution solHFW = solveHF(inst, true, timeLimit - preTime);
108+
solHFW.timeT += preTime;
109+
solHFW.print(true);
110+
111+
// Apply MonoFlow-MultiBin(W)
112+
Solution solMFMBW = solveMFMB(inst, solTS, true, timeLimit - preTime);
113+
solMFMBW.timeT += preTime;
114+
solMFMBW.print(true);
115+
116+
// Apply a reimplementation of RM2-GIFF(W), using the setup of Mehrani et al.
117+
inst.preprocessing(true, true); // First re-order the items
118+
Solution solRM2GIFFREMehraniW = solveRM2GIFFSetupMehrani(inst, true, timeLimit - preTime);
119+
solRM2GIFFREMehraniW.timeT += preTime;
120+
solRM2GIFFREMehraniW.print(true);
121+
}
122+
}

0 commit comments

Comments
 (0)