From c4e7ef7a7c08e1bc696920c98096e3fb7bb04fb3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 26 Dec 2023 00:19:06 +0100 Subject: [PATCH 01/47] Bump com.fasterxml.jackson.core:jackson-databind from 2.16.0 to 2.16.1 (#818) Bumps [com.fasterxml.jackson.core:jackson-databind](https://github.com/FasterXML/jackson) from 2.16.0 to 2.16.1. - [Commits](https://github.com/FasterXML/jackson/commits) --- updated-dependencies: - dependency-name: com.fasterxml.jackson.core:jackson-databind dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 18823ca0..439af7cf 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ 3.24.2 5.3.2 1.15.3 - 2.16.0 + 2.16.1 2.41.1 From cb81b1575673d08d75bb1801329afed2c401c290 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 26 Dec 2023 00:19:30 +0100 Subject: [PATCH 02/47] Update dependency org.apache.maven.plugins:maven-compiler-plugin to v3.12.1 (#816) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 439af7cf..28110c7e 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ 3.1.0 2.10 0.8.10 - 3.12.0 + 3.12.1 3.5.1 1.8.2 3.24.2 From fb2d370d68a8d5f6132bdb5ab7c98a3a8b6b7c1f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Jan 2024 21:55:57 +0100 Subject: [PATCH 03/47] Bump org.assertj:assertj-core from 3.24.2 to 3.25.0 (#820) Bumps [org.assertj:assertj-core](https://github.com/assertj/assertj) from 3.24.2 to 3.25.0. - [Release notes](https://github.com/assertj/assertj/releases) - [Commits](https://github.com/assertj/assertj/compare/assertj-build-3.24.2...assertj-build-3.25.0) --- updated-dependencies: - dependency-name: org.assertj:assertj-core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 28110c7e..d11bf930 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ 3.12.1 3.5.1 1.8.2 - 3.24.2 + 3.25.0 5.3.2 1.15.3 2.16.1 From 34e04d8099a9f120229dce21c23b1be0a6310b11 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 Jan 2024 21:56:10 +0100 Subject: [PATCH 04/47] Bump org.apache.maven.plugins:maven-compiler-plugin (#817) Bumps [org.apache.maven.plugins:maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.12.0 to 3.12.1. - [Release notes](https://github.com/apache/maven-compiler-plugin/releases) - [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.12.0...maven-compiler-plugin-3.12.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-compiler-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> From e2549fea3ee975e39ac5890afeefca0dbdcd8934 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 19 Jan 2024 21:45:21 +0100 Subject: [PATCH 05/47] Update actions/cache action to v4 (#828) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index e0698e77..df3f7691 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -25,7 +25,7 @@ jobs: with: distribution: 'temurin' java-version: 11 - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-v2-${{ hashFiles('**/pom.xml') }} From 670b19596400998e85ee5cc9207732fcc716ac9a Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 19 Jan 2024 21:45:32 +0100 Subject: [PATCH 06/47] Update dependency com.diffplug.spotless:spotless-maven-plugin to v2.42.0 (#827) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d11bf930..ba7a7d56 100644 --- a/pom.xml +++ b/pom.xml @@ -43,7 +43,7 @@ 5.3.2 1.15.3 2.16.1 - 2.41.1 + 2.42.0 From 95f07c8a1f612e608f478aec4f188c108d99acd5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 19 Jan 2024 21:45:41 +0100 Subject: [PATCH 07/47] Bump org.apache.maven.plugins:maven-surefire-plugin from 3.2.3 to 3.2.5 (#826) Bumps [org.apache.maven.plugins:maven-surefire-plugin](https://github.com/apache/maven-surefire) from 3.2.3 to 3.2.5. - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](https://github.com/apache/maven-surefire/compare/surefire-3.2.3...surefire-3.2.5) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ba7a7d56..f6f9f5c9 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ 1.9.1 0.8.11 1.6.13 - 3.2.3 + 3.2.5 3.3.0 3.6.3 2.5.3 From a7f20694fabb8d6adba6fd0f4dada2a5c2729589 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 19 Jan 2024 21:45:58 +0100 Subject: [PATCH 08/47] Update dependency org.mockito:mockito-core to v5.9.0 (#823) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f6f9f5c9..0c022627 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ ${java.version} 3.6.1 - 5.8.0 + 5.9.0 11.1.0 1.2.0 From 406eb78651bd4e41e4059a4809c973b926fe813f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 29 Jan 2024 22:04:15 +0100 Subject: [PATCH 09/47] Update dependency org.mockito:mockito-core to v5.10.0 (#834) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0c022627..8a765aaa 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ ${java.version} 3.6.1 - 5.9.0 + 5.10.0 11.1.0 1.2.0 From b096709d3a06cef325c2e9aa11829761730cdaf8 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 29 Jan 2024 22:04:24 +0100 Subject: [PATCH 10/47] Update dependency org.pitest:pitest-maven to v1.15.6 (#829) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8a765aaa..708f6ebc 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ 1.8.2 3.25.0 5.3.2 - 1.15.3 + 1.15.6 2.16.1 2.42.0 From 429b59f78895edac4a4e71d326a0aee33f90de8e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Jan 2024 22:04:35 +0100 Subject: [PATCH 11/47] Bump org.assertj:assertj-core from 3.25.0 to 3.25.2 (#838) Bumps [org.assertj:assertj-core](https://github.com/assertj/assertj) from 3.25.0 to 3.25.2. - [Release notes](https://github.com/assertj/assertj/releases) - [Commits](https://github.com/assertj/assertj/compare/assertj-build-3.25.0...assertj-build-3.25.2) --- updated-dependencies: - dependency-name: org.assertj:assertj-core dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 708f6ebc..3b5796e0 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ 3.12.1 3.5.1 1.8.2 - 3.25.0 + 3.25.2 5.3.2 1.15.6 2.16.1 From b0585a109e4715edb7238237141724466c52a1e6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Jan 2024 22:04:44 +0100 Subject: [PATCH 12/47] Bump com.diffplug.spotless:spotless-maven-plugin from 2.42.0 to 2.43.0 (#837) Bumps [com.diffplug.spotless:spotless-maven-plugin](https://github.com/diffplug/spotless) from 2.42.0 to 2.43.0. - [Changelog](https://github.com/diffplug/spotless/blob/main/CHANGES.md) - [Commits](https://github.com/diffplug/spotless/compare/lib/2.42.0...lib/2.43.0) --- updated-dependencies: - dependency-name: com.diffplug.spotless:spotless-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3b5796e0..10a75f4a 100644 --- a/pom.xml +++ b/pom.xml @@ -43,7 +43,7 @@ 5.3.2 1.15.6 2.16.1 - 2.42.0 + 2.43.0 From 3533687d170333fc25e205ab6211567f70768747 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Jan 2024 22:04:54 +0100 Subject: [PATCH 13/47] Bump org.mockito:mockito-core from 5.9.0 to 5.10.0 (#836) Bumps [org.mockito:mockito-core](https://github.com/mockito/mockito) from 5.9.0 to 5.10.0. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](https://github.com/mockito/mockito/compare/v5.9.0...v5.10.0) --- updated-dependencies: - dependency-name: org.mockito:mockito-core dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> From d5d6e34a42e9b6877ef4aa4bb989a2c01f506ddc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Jan 2024 22:05:05 +0100 Subject: [PATCH 14/47] Bump google-truth.version from 1.2.0 to 1.3.0 (#831) Bumps `google-truth.version` from 1.2.0 to 1.3.0. Updates `com.google.truth:truth` from 1.2.0 to 1.3.0 - [Release notes](https://github.com/google/truth/releases) - [Commits](https://github.com/google/truth/compare/v1.2.0...v1.3.0) Updates `com.google.truth.extensions:truth-java8-extension` from 1.2.0 to 1.3.0 --- updated-dependencies: - dependency-name: com.google.truth:truth dependency-type: direct:production update-type: version-update:semver-minor - dependency-name: com.google.truth.extensions:truth-java8-extension dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 10a75f4a..240fb52d 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ 5.10.0 11.1.0 - 1.2.0 + 1.3.0 1.0 5.10.1 1.37 From a565f1635667143ebc7b28aa66125db92c99aa84 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 29 Jan 2024 22:05:17 +0100 Subject: [PATCH 15/47] Update dependency org.assertj:assertj-core to v3.25.2 (#819) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> From 8357b18e59913770c49c4fb2e38ee90a64623ae2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 29 Jan 2024 22:05:42 +0100 Subject: [PATCH 16/47] Update dependency org.jacoco:jacoco-maven-plugin to v0.8.11 (#773) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 240fb52d..d0f573a4 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ 2.5.3 3.1.0 2.10 - 0.8.10 + 0.8.11 3.12.1 3.5.1 1.8.2 From 771285781edbad666335c16e0eed7a68a1335935 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 29 Jan 2024 22:06:13 +0100 Subject: [PATCH 17/47] Update google-truth.version to v1.3.0 (#830) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> From f1cf0390b558df9b39a296d3070b94f3e929b842 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 30 Jan 2024 00:34:02 +0100 Subject: [PATCH 18/47] Bump org.pitest:pitest-maven from 1.15.3 to 1.15.6 (#835) Bumps [org.pitest:pitest-maven](https://github.com/hcoles/pitest) from 1.15.3 to 1.15.6. - [Release notes](https://github.com/hcoles/pitest/releases) - [Commits](https://github.com/hcoles/pitest/compare/1.15.3...1.15.6) --- updated-dependencies: - dependency-name: org.pitest:pitest-maven dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> From 36989ec9897d8dc04dc420e654e6b4abd89c355a Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 3 Feb 2024 19:35:02 +0100 Subject: [PATCH 19/47] Update google-truth.version to v1.4.0 (#840) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d0f573a4..968a1a8d 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ 5.10.0 11.1.0 - 1.3.0 + 1.4.0 1.0 5.10.1 1.37 From 462288cf04d8c4e99dc20df0cffb86f8f2fe9aab Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 3 Mar 2024 23:57:36 +0100 Subject: [PATCH 20/47] Update dependency org.mockito:mockito-core to v5.11.0 (#854) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 968a1a8d..86b8d4c5 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ ${java.version} 3.6.1 - 5.10.0 + 5.11.0 11.1.0 1.4.0 From 6d790b5c7137102490bde8d1e49ce17d799e16a0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 3 Mar 2024 23:57:52 +0100 Subject: [PATCH 21/47] Bump google-truth.version from 1.4.0 to 1.4.1 (#849) Bumps `google-truth.version` from 1.4.0 to 1.4.1. Updates `com.google.truth:truth` from 1.4.0 to 1.4.1 - [Release notes](https://github.com/google/truth/releases) - [Commits](https://github.com/google/truth/compare/v1.4.0...v1.4.1) Updates `com.google.truth.extensions:truth-java8-extension` from 1.4.0 to 1.4.1 --- updated-dependencies: - dependency-name: com.google.truth:truth dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: com.google.truth.extensions:truth-java8-extension dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 86b8d4c5..88a5dd30 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ 5.11.0 11.1.0 - 1.4.0 + 1.4.1 1.0 5.10.1 1.37 From c9903d3975009f9c588adea563b0ec849a315806 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 3 Mar 2024 23:58:01 +0100 Subject: [PATCH 22/47] Update dependency org.assertj:assertj-core to v3.25.3 (#842) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 88a5dd30..3f449b14 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ 3.12.1 3.5.1 1.8.2 - 3.25.2 + 3.25.3 5.3.2 1.15.6 2.16.1 From 3a1327af97f643d19d69d526b84388c70779cba9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Mar 2024 18:33:01 +0100 Subject: [PATCH 23/47] Bump com.fasterxml.jackson.core:jackson-databind from 2.16.1 to 2.17.0 (#861) Bumps [com.fasterxml.jackson.core:jackson-databind](https://github.com/FasterXML/jackson) from 2.16.1 to 2.17.0. - [Commits](https://github.com/FasterXML/jackson/commits) --- updated-dependencies: - dependency-name: com.fasterxml.jackson.core:jackson-databind dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3f449b14..fb25f699 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ 3.25.3 5.3.2 1.15.6 - 2.16.1 + 2.17.0 2.43.0 From 22b949c6f22a70d27cdb8951558d9fcd2b1cb8f3 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 27 Mar 2024 18:33:10 +0100 Subject: [PATCH 24/47] Update dependency org.apache.maven.plugins:maven-gpg-plugin to v3.2.2 (#858) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fb25f699..813a272b 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,7 @@ 3.3.0 3.6.3 2.5.3 - 3.1.0 + 3.2.2 2.10 0.8.11 3.12.1 From f608b511f01115b5b334bf34a300bfe4c65d2196 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Mar 2024 18:33:19 +0100 Subject: [PATCH 25/47] Bump org.moditect:moditect-maven-plugin from 1.1.0 to 1.2.0.Final (#862) Bumps [org.moditect:moditect-maven-plugin](https://github.com/moditect/moditect) from 1.1.0 to 1.2.0.Final. - [Release notes](https://github.com/moditect/moditect/releases) - [Commits](https://github.com/moditect/moditect/compare/1.1.0...1.2.0.Final) --- updated-dependencies: - dependency-name: org.moditect:moditect-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 813a272b..16829ab9 100644 --- a/pom.xml +++ b/pom.xml @@ -406,7 +406,7 @@ org.moditect moditect-maven-plugin - 1.1.0 + 1.2.0.Final add-module-infos From 95e1f7328865fdb5e84f565377c13f4429d37fed Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 27 Mar 2024 18:33:33 +0100 Subject: [PATCH 26/47] Update dependency org.apache.maven.plugins:maven-shade-plugin to v3.5.2 (#850) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 16829ab9..569777ef 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ 2.10 0.8.11 3.12.1 - 3.5.1 + 3.5.2 1.8.2 3.25.3 5.3.2 From 491ee7be08c0da4f2cf1832ef94d36bfeff23642 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 27 Mar 2024 18:34:11 +0100 Subject: [PATCH 27/47] Update google-truth.version to v1.4.2 (#847) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 569777ef..3bc4b813 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ 5.11.0 11.1.0 - 1.4.1 + 1.4.2 1.0 5.10.1 1.37 From bc23f29dff1ea2a1b628299007c68a931db355a5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Mar 2024 18:34:21 +0100 Subject: [PATCH 28/47] Bump org.assertj:assertj-core from 3.25.2 to 3.25.3 (#844) Bumps [org.assertj:assertj-core](https://github.com/assertj/assertj) from 3.25.2 to 3.25.3. - [Release notes](https://github.com/assertj/assertj/releases) - [Commits](https://github.com/assertj/assertj/compare/assertj-build-3.25.2...assertj-build-3.25.3) --- updated-dependencies: - dependency-name: org.assertj:assertj-core dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> From 2ee4598eeb8458ac5c195de7eaeb904ff62c8748 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 27 Mar 2024 18:35:13 +0100 Subject: [PATCH 29/47] Bump google-truth.version from 1.4.1 to 1.4.2 (#855) Bumps `google-truth.version` from 1.4.1 to 1.4.2. Updates `com.google.truth:truth` from 1.4.1 to 1.4.2 - [Release notes](https://github.com/google/truth/releases) - [Commits](https://github.com/google/truth/compare/v1.4.1...v1.4.2) Updates `com.google.truth.extensions:truth-java8-extension` from 1.4.1 to 1.4.2 --- updated-dependencies: - dependency-name: com.google.truth:truth dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: com.google.truth.extensions:truth-java8-extension dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> From ff9370ce3d0b9eaff88fc13db62aa046f75b1b64 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 00:02:48 +0100 Subject: [PATCH 30/47] Update dependency net.jqwik:jqwik to v1.8.4 (#851) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3bc4b813..9f1e4816 100644 --- a/pom.xml +++ b/pom.xml @@ -38,7 +38,7 @@ 0.8.11 3.12.1 3.5.2 - 1.8.2 + 1.8.4 3.25.3 5.3.2 1.15.6 From 066297aaacd4e170c70a88bd00e73e75d4a11dd0 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 00:02:57 +0100 Subject: [PATCH 31/47] Update dependency org.apache.maven.plugins:maven-compiler-plugin to v3.13.0 (#867) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9f1e4816..0d09ba63 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ 3.2.2 2.10 0.8.11 - 3.12.1 + 3.13.0 3.5.2 1.8.4 3.25.3 From 4fe098e4d960842bfa6fd8621055836c8c11a2dd Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 28 Mar 2024 00:03:16 +0100 Subject: [PATCH 32/47] Update dependency org.sonarsource.scanner.maven:sonar-maven-plugin to v3.11.0.3922 (#868) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0d09ba63..d7d54424 100644 --- a/pom.xml +++ b/pom.xml @@ -427,7 +427,7 @@ org.sonarsource.scanner.maven sonar-maven-plugin - 3.10.0.2594 + 3.11.0.3922 org.pitest From 72041d71118c3392791d0635d61b92d9da78dfc7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 5 Apr 2024 00:07:34 +0200 Subject: [PATCH 33/47] Bump org.moditect:moditect-maven-plugin from 1.2.0.Final to 1.2.1.Final (#871) Bumps [org.moditect:moditect-maven-plugin](https://github.com/moditect/moditect) from 1.2.0.Final to 1.2.1.Final. - [Release notes](https://github.com/moditect/moditect/releases) - [Commits](https://github.com/moditect/moditect/compare/1.2.0.Final...1.2.1.Final) --- updated-dependencies: - dependency-name: org.moditect:moditect-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d7d54424..e4c9e6a6 100644 --- a/pom.xml +++ b/pom.xml @@ -406,7 +406,7 @@ org.moditect moditect-maven-plugin - 1.2.0.Final + 1.2.1.Final add-module-infos From e07c550ba1cbc865d93482e0a5befc3de07708a2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 7 Apr 2024 00:49:39 +0200 Subject: [PATCH 34/47] Update dependency commons-io:commons-io to v2.16.0 (#869) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e4c9e6a6..765ba5d7 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ 1.0 5.10.1 1.37 - 2.15.1 + 2.16.0 1.9.1 From 03d7734a34b6f96492ed8babb4e367884fdbaf9b Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 7 Apr 2024 00:49:47 +0200 Subject: [PATCH 35/47] Update dependency org.apache.maven.plugins:maven-source-plugin to v3.3.1 (#874) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 765ba5d7..a42be3cc 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ 0.8.11 1.6.13 3.2.5 - 3.3.0 + 3.3.1 3.6.3 2.5.3 3.2.2 From 211a7028879c4085558a6144e57df649f44869c0 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 7 Apr 2024 00:49:56 +0200 Subject: [PATCH 36/47] Update dependency org.jacoco:jacoco-maven-plugin to v0.8.12 (#872) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a42be3cc..d448dfff 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ 2.5.3 3.2.2 2.10 - 0.8.11 + 0.8.12 3.13.0 3.5.2 1.8.4 From bbd6dbe4d6cf1debd6932d6f406fb336b5870c0b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 7 Apr 2024 00:50:06 +0200 Subject: [PATCH 37/47] Bump net.jqwik:jqwik from 1.8.2 to 1.8.4 (#864) Bumps [net.jqwik:jqwik](https://github.com/jqwik-team/jqwik) from 1.8.2 to 1.8.4. - [Release notes](https://github.com/jqwik-team/jqwik/releases) - [Commits](https://github.com/jqwik-team/jqwik/compare/1.8.2...1.8.4) --- updated-dependencies: - dependency-name: net.jqwik:jqwik dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> From c63b4db1ab45ed034ce26f5f35edc150f64e0f0c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 13 Apr 2024 11:33:15 +0200 Subject: [PATCH 38/47] Update dependency commons-io:commons-io to v2.16.1 (#876) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d448dfff..13731dc1 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ 1.0 5.10.1 1.37 - 2.16.0 + 2.16.1 1.9.1 From 8296641768eb6a8f67799835697887dbd36ad258 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 13 Apr 2024 11:33:25 +0200 Subject: [PATCH 39/47] Bump org.jacoco:jacoco-maven-plugin from 0.8.11 to 0.8.12 (#875) Bumps [org.jacoco:jacoco-maven-plugin](https://github.com/jacoco/jacoco) from 0.8.11 to 0.8.12. - [Release notes](https://github.com/jacoco/jacoco/releases) - [Commits](https://github.com/jacoco/jacoco/compare/v0.8.11...v0.8.12) --- updated-dependencies: - dependency-name: org.jacoco:jacoco-maven-plugin dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 13731dc1..50399e04 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ 1.9.1 - 0.8.11 + 0.8.12 1.6.13 3.2.5 3.3.1 From 01e09ee1424be08ec70f3787874118d6638cc63d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Skj=C3=B8lberg?= Date: Sat, 13 Apr 2024 11:38:20 +0200 Subject: [PATCH 40/47] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 8d0eae8a..7b462c4a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +![Build Status](https://github.com/skjolber/3d-bin-container-packing/actions/workflows/maven.yml/badge.svg) +[![Maven Central](https://img.shields.io/maven-central/v/com.github.skjolber.3d-bin-container-packing/parent.svg)](https://mvnrepository.com/artifact/com.github.skjolber.3d-bin-container-packing) + # 3d-bin-container-packing This library does 3D rectangular bin packing; it attempts to match a set of 3D items to one or more in a set of 3D containers. The result can be constrained to a maximum number of containers. From f5582c4e1bb80e3535fca01e64721bc96cd09755 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 11 May 2024 16:47:44 +0200 Subject: [PATCH 41/47] Update dependency org.mockito:mockito-core to v5.12.0 (#887) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 50399e04..a981721a 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ ${java.version} 3.6.1 - 5.11.0 + 5.12.0 11.1.0 1.4.2 From 139327321bb52c0ff298d80daadf73a282885408 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 26 Jun 2024 23:17:17 +0200 Subject: [PATCH 42/47] Bump org.sonatype.plugins:nexus-staging-maven-plugin (#895) Bumps org.sonatype.plugins:nexus-staging-maven-plugin from 1.6.13 to 1.7.0. --- updated-dependencies: - dependency-name: org.sonatype.plugins:nexus-staging-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a981721a..92bb863c 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ 1.9.1 0.8.12 - 1.6.13 + 1.7.0 3.2.5 3.3.1 3.6.3 From 6a31884a17d0084f7054a48cbd3f2eaa2a7b5052 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 29 Jun 2024 11:14:38 +0200 Subject: [PATCH 43/47] Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.6.3 to 3.7.0 (#894) Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.6.3 to 3.7.0. - [Release notes](https://github.com/apache/maven-javadoc-plugin/releases) - [Commits](https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.6.3...maven-javadoc-plugin-3.7.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-javadoc-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 92bb863c..cc13f20f 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ 1.7.0 3.2.5 3.3.1 - 3.6.3 + 3.7.0 2.5.3 3.2.2 2.10 From a3157b257ee49d624924deb28cb9084bcbb24c03 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 29 Jun 2024 11:14:47 +0200 Subject: [PATCH 44/47] Update dependency net.jqwik:jqwik to v1.9.0 (#889) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cc13f20f..6bd7eb23 100644 --- a/pom.xml +++ b/pom.xml @@ -38,7 +38,7 @@ 0.8.12 3.13.0 3.5.2 - 1.8.4 + 1.9.0 3.25.3 5.3.2 1.15.6 From 3568e8729fc8e217f4ea4a0054aba721dc1c7262 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 29 Jun 2024 11:37:21 +0200 Subject: [PATCH 45/47] Update google-truth.version to v1.4.3 (#896) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6bd7eb23..442a17f5 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ 5.12.0 11.1.0 - 1.4.2 + 1.4.3 1.0 5.10.1 1.37 From 8d6ad0dfd74c3bb74ec8065766abd4610761eae0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 29 Jun 2024 11:37:31 +0200 Subject: [PATCH 46/47] Bump com.fasterxml.jackson.core:jackson-databind from 2.17.0 to 2.17.1 (#886) Bumps [com.fasterxml.jackson.core:jackson-databind](https://github.com/FasterXML/jackson) from 2.17.0 to 2.17.1. - [Commits](https://github.com/FasterXML/jackson/commits) --- updated-dependencies: - dependency-name: com.fasterxml.jackson.core:jackson-databind dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 442a17f5..9dd777ff 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ 3.25.3 5.3.2 1.15.6 - 2.17.0 + 2.17.1 2.43.0 From b6625e97fe73a21373944dc99d9b96d19e53dea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Skj=C3=B8lberg?= Date: Tue, 23 Jul 2024 19:39:51 +0200 Subject: [PATCH 47/47] Add scheduled executor to enforce deadlines, make packager closable (#907) * Add scheduled executor to enforce deadlines, make packager closable * Add fool-proofed duration check --- .../github/skjolber/packing/api/Packager.java | 4 +- ...eadlineCheckPackagerInterruptSupplier.java | 29 +- ...eadlineCheckPackagerInterruptSupplier.java | 29 +- ...eadlineCheckPackagerInterruptSupplier.java | 34 -- ...eadlineCheckPackagerInterruptSupplier.java | 29 -- .../NthPackagerInterruptSupplier.java | 31 -- .../deadline/PackagerInterruptSupplier.java | 7 +- .../PackagerInterruptSupplierBuilder.java | 45 +- .../PositivePackagerInterruptSupplier.java | 10 + .../iterator/PermutationRotationIterator.java | 6 +- .../packing/packer/AbstractPackager.java | 20 +- .../packer/AbstractPackagerBuilder.java | 6 - .../AbstractBruteForcePackager.java | 11 +- .../packer/bruteforce/BruteForcePackager.java | 6 +- .../BruteForcePackagerResultBuilder.java | 25 +- .../bruteforce/FastBruteForcePackager.java | 13 +- .../FastBruteForcePackagerResultBuilder.java | 29 +- .../ParallelBruteForcePackager.java | 6 +- .../AbstractLargestAreaFitFirstPackager.java | 9 +- .../laff/FastLargestAreaFitFirstPackager.java | 8 +- .../laff/LargestAreaFitFirstPackager.java | 8 +- ...gestAreaFitFirstPackagerResultBuilder.java | 26 +- .../packer/plain/AbstractPlainPackager.java | 9 +- .../packing/packer/plain/PlainPackager.java | 8 +- .../plain/PlainPackagerResultBuilder.java | 25 +- .../AbstractBruteForcePackagerTest.java | 96 ++-- .../bruteforce/BruteForcePackagerTest.java | 428 ++++++++++-------- .../FastBruteForcePackagerTest.java | 230 +++++----- .../ParallelBruteForcePackagerTest.java | 246 +++++----- .../FastLargestAreaFitFirstPackagerTest.java | 200 ++++---- .../laff/LargestAreaFitFirstPackagerTest.java | 373 ++++++++------- .../packer/plain/PlainPackagerTest.java | 283 +++++++----- .../BouwkampCodeBruteForcePackagerState.java | 44 +- .../packing/jmh/DeadlineBenchmark.java | 10 - .../packing/jmh/EgyPackagerState.java | 41 +- .../packing/jmh/TychoPackagerState.java | 41 +- .../packaging/BruteForcePackagerTest.java | 2 +- .../ParallelBruteForcePackagerTest.java | 2 +- 38 files changed, 1278 insertions(+), 1151 deletions(-) delete mode 100644 core/src/main/java/com/github/skjolber/packing/deadline/DelegateNthDeadlineCheckPackagerInterruptSupplier.java delete mode 100644 core/src/main/java/com/github/skjolber/packing/deadline/NthDeadlineCheckPackagerInterruptSupplier.java delete mode 100644 core/src/main/java/com/github/skjolber/packing/deadline/NthPackagerInterruptSupplier.java create mode 100644 core/src/main/java/com/github/skjolber/packing/deadline/PositivePackagerInterruptSupplier.java diff --git a/api/src/main/java/com/github/skjolber/packing/api/Packager.java b/api/src/main/java/com/github/skjolber/packing/api/Packager.java index beb029c6..1c79e32e 100644 --- a/api/src/main/java/com/github/skjolber/packing/api/Packager.java +++ b/api/src/main/java/com/github/skjolber/packing/api/Packager.java @@ -1,12 +1,14 @@ package com.github.skjolber.packing.api; +import java.io.Closeable; + /** * Fit boxes into container, i.e. perform bin packing to a single container. * * Thread-safe implementation. */ -public interface Packager> { +public interface Packager> extends Closeable { B newResultBuilder(); diff --git a/core/src/main/java/com/github/skjolber/packing/deadline/DeadlineCheckPackagerInterruptSupplier.java b/core/src/main/java/com/github/skjolber/packing/deadline/DeadlineCheckPackagerInterruptSupplier.java index 43d7b900..9d7bf7c6 100644 --- a/core/src/main/java/com/github/skjolber/packing/deadline/DeadlineCheckPackagerInterruptSupplier.java +++ b/core/src/main/java/com/github/skjolber/packing/deadline/DeadlineCheckPackagerInterruptSupplier.java @@ -1,17 +1,34 @@ package com.github.skjolber.packing.deadline; -public class DeadlineCheckPackagerInterruptSupplier implements PackagerInterruptSupplier { +import java.io.Closeable; +import java.util.concurrent.ScheduledFuture; - protected final long deadline; +public class DeadlineCheckPackagerInterruptSupplier implements PackagerInterruptSupplier, Runnable, Closeable { - public DeadlineCheckPackagerInterruptSupplier(long deadline) { - super(); - this.deadline = deadline; + // this is not entirely accurate for multi-threading, but close enough + // (should have been volatile) + protected boolean expired = false; + protected ScheduledFuture future; + + public DeadlineCheckPackagerInterruptSupplier() { } @Override public boolean getAsBoolean() { - return System.currentTimeMillis() > deadline; + return expired; + } + + @Override + public void run() { + this.expired = true; + } + + public void close() { + future.cancel(true); + } + + public void setFuture(ScheduledFuture future) { + this.future = future; } } \ No newline at end of file diff --git a/core/src/main/java/com/github/skjolber/packing/deadline/DelegateDeadlineCheckPackagerInterruptSupplier.java b/core/src/main/java/com/github/skjolber/packing/deadline/DelegateDeadlineCheckPackagerInterruptSupplier.java index ca5d19f5..5120a6fa 100644 --- a/core/src/main/java/com/github/skjolber/packing/deadline/DelegateDeadlineCheckPackagerInterruptSupplier.java +++ b/core/src/main/java/com/github/skjolber/packing/deadline/DelegateDeadlineCheckPackagerInterruptSupplier.java @@ -1,21 +1,38 @@ package com.github.skjolber.packing.deadline; +import java.io.Closeable; +import java.util.concurrent.ScheduledFuture; import java.util.function.BooleanSupplier; -public class DelegateDeadlineCheckPackagerInterruptSupplier implements PackagerInterruptSupplier { +public class DelegateDeadlineCheckPackagerInterruptSupplier implements PackagerInterruptSupplier, Runnable, Closeable { + // this is not entirely accurate for multi-threading, but close enough + // (should have been volatile) + protected boolean expired = false; + protected ScheduledFuture future; protected final BooleanSupplier delegate; - protected final long deadline; - - public DelegateDeadlineCheckPackagerInterruptSupplier(long deadline, BooleanSupplier delegate) { + + public DelegateDeadlineCheckPackagerInterruptSupplier(BooleanSupplier delegate) { super(); - this.deadline = deadline; this.delegate = delegate; } @Override public boolean getAsBoolean() { - return delegate.getAsBoolean() || System.currentTimeMillis() > deadline; + return expired || delegate.getAsBoolean(); + } + + @Override + public void run() { + this.expired = true; + } + + public void close() { + future.cancel(true); + } + + public void setFuture(ScheduledFuture future) { + this.future = future; } } \ No newline at end of file diff --git a/core/src/main/java/com/github/skjolber/packing/deadline/DelegateNthDeadlineCheckPackagerInterruptSupplier.java b/core/src/main/java/com/github/skjolber/packing/deadline/DelegateNthDeadlineCheckPackagerInterruptSupplier.java deleted file mode 100644 index 69de9877..00000000 --- a/core/src/main/java/com/github/skjolber/packing/deadline/DelegateNthDeadlineCheckPackagerInterruptSupplier.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.github.skjolber.packing.deadline; - -import java.util.function.BooleanSupplier; - -public class DelegateNthDeadlineCheckPackagerInterruptSupplier implements ClonablePackagerInterruptSupplier { - - protected final BooleanSupplier delegate; - protected final int checkpointsPerDeadlineCheck; - protected final long deadline; - protected int count = 0; - public long t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16 = 1L; - - public DelegateNthDeadlineCheckPackagerInterruptSupplier(long deadline, int checkpointsPerDeadlineCheck, BooleanSupplier delegate) { - super(); - this.deadline = deadline; - this.checkpointsPerDeadlineCheck = checkpointsPerDeadlineCheck; - this.delegate = delegate; - } - - @Override - public boolean getAsBoolean() { - return delegate.getAsBoolean() || (--count % checkpointsPerDeadlineCheck == 0 && System.currentTimeMillis() > deadline); - } - - @Override - public ClonablePackagerInterruptSupplier clone() { - return new DelegateNthDeadlineCheckPackagerInterruptSupplier(deadline, checkpointsPerDeadlineCheck, delegate); - } - - public long preventOptmisation() { - return t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 + t10 + t11 + t12 + t13 + t14 + t15 + t16; - } - -} \ No newline at end of file diff --git a/core/src/main/java/com/github/skjolber/packing/deadline/NthDeadlineCheckPackagerInterruptSupplier.java b/core/src/main/java/com/github/skjolber/packing/deadline/NthDeadlineCheckPackagerInterruptSupplier.java deleted file mode 100644 index 70224424..00000000 --- a/core/src/main/java/com/github/skjolber/packing/deadline/NthDeadlineCheckPackagerInterruptSupplier.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.github.skjolber.packing.deadline; - -public class NthDeadlineCheckPackagerInterruptSupplier implements ClonablePackagerInterruptSupplier { - - protected final int checkpointsPerDeadlineCheck; - protected final long deadline; - protected int count = 0; - public long t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16 = 1L; - - public NthDeadlineCheckPackagerInterruptSupplier(long deadline, int checkpointsPerDeadlineCheck) { - super(); - this.deadline = deadline; - this.checkpointsPerDeadlineCheck = checkpointsPerDeadlineCheck; - } - - @Override - public boolean getAsBoolean() { - return --count % checkpointsPerDeadlineCheck == 0 && System.currentTimeMillis() > deadline; - } - - @Override - public ClonablePackagerInterruptSupplier clone() { - return new NthDeadlineCheckPackagerInterruptSupplier(deadline, checkpointsPerDeadlineCheck); - } - - public long preventOptmisation() { - return t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 + t10 + t11 + t12 + t13 + t14 + t15 + t16; - } -} \ No newline at end of file diff --git a/core/src/main/java/com/github/skjolber/packing/deadline/NthPackagerInterruptSupplier.java b/core/src/main/java/com/github/skjolber/packing/deadline/NthPackagerInterruptSupplier.java deleted file mode 100644 index 59d4ba36..00000000 --- a/core/src/main/java/com/github/skjolber/packing/deadline/NthPackagerInterruptSupplier.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.github.skjolber.packing.deadline; - -import java.util.concurrent.atomic.AtomicBoolean; - -public class NthPackagerInterruptSupplier implements ClonablePackagerInterruptSupplier { - - protected final int checkpointsPerDeadlineCheck; - protected int count = 0; - public long t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15, t16 = 1L; - protected AtomicBoolean atomicBoolean; - - public NthPackagerInterruptSupplier(AtomicBoolean atomicBoolean, int checkpointsPerDeadlineCheck) { - super(); - this.atomicBoolean = atomicBoolean; - this.checkpointsPerDeadlineCheck = checkpointsPerDeadlineCheck; - } - - @Override - public boolean getAsBoolean() { - return --count % checkpointsPerDeadlineCheck == 0 && atomicBoolean.get(); - } - - @Override - public ClonablePackagerInterruptSupplier clone() { - return new NthPackagerInterruptSupplier(atomicBoolean, checkpointsPerDeadlineCheck); - } - - public long preventOptmisation() { - return t1 + t2 + t3 + t4 + t5 + t6 + t7 + t8 + t9 + t10 + t11 + t12 + t13 + t14 + t15 + t16; - } -} \ No newline at end of file diff --git a/core/src/main/java/com/github/skjolber/packing/deadline/PackagerInterruptSupplier.java b/core/src/main/java/com/github/skjolber/packing/deadline/PackagerInterruptSupplier.java index 94fa1623..145de14c 100644 --- a/core/src/main/java/com/github/skjolber/packing/deadline/PackagerInterruptSupplier.java +++ b/core/src/main/java/com/github/skjolber/packing/deadline/PackagerInterruptSupplier.java @@ -1,7 +1,9 @@ package com.github.skjolber.packing.deadline; +import java.io.Closeable; + @FunctionalInterface -public interface PackagerInterruptSupplier { +public interface PackagerInterruptSupplier extends Closeable { /** * Gets a result. @@ -9,4 +11,7 @@ public interface PackagerInterruptSupplier { * @return a result */ boolean getAsBoolean(); + + default void close() { + } } diff --git a/core/src/main/java/com/github/skjolber/packing/deadline/PackagerInterruptSupplierBuilder.java b/core/src/main/java/com/github/skjolber/packing/deadline/PackagerInterruptSupplierBuilder.java index 9d95cc2a..053022be 100644 --- a/core/src/main/java/com/github/skjolber/packing/deadline/PackagerInterruptSupplierBuilder.java +++ b/core/src/main/java/com/github/skjolber/packing/deadline/PackagerInterruptSupplierBuilder.java @@ -1,22 +1,25 @@ package com.github.skjolber.packing.deadline; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import java.util.function.BooleanSupplier; public class PackagerInterruptSupplierBuilder { - public static final NegativePackagerInterruptSupplier NOOP = new NegativePackagerInterruptSupplier(); + public static final NegativePackagerInterruptSupplier NEGATIVE = new NegativePackagerInterruptSupplier(); + public static final PositivePackagerInterruptSupplier POSITIVE = new PositivePackagerInterruptSupplier(); private long deadline = Long.MAX_VALUE; - private int checkpointsPerDeadlineCheck = 1; private BooleanSupplier interrupt = null; + private ScheduledThreadPoolExecutor scheduledThreadPoolExecutor; public static PackagerInterruptSupplierBuilder builder() { return new PackagerInterruptSupplierBuilder(); } - public PackagerInterruptSupplierBuilder withDeadline(long deadline, int checkpointsPerDeadlineCheck) { + public PackagerInterruptSupplierBuilder withDeadline(long deadline) { this.deadline = deadline; - this.checkpointsPerDeadlineCheck = checkpointsPerDeadlineCheck; return this; } @@ -24,26 +27,42 @@ public PackagerInterruptSupplierBuilder withInterrupt(BooleanSupplier interrupt) this.interrupt = interrupt; return this; } + + public PackagerInterruptSupplierBuilder withScheduledThreadPoolExecutor(ScheduledThreadPoolExecutor executor) { + this.scheduledThreadPoolExecutor = executor; + return this; + } public PackagerInterruptSupplier build() { - if(checkpointsPerDeadlineCheck == Integer.MAX_VALUE || checkpointsPerDeadlineCheck == -1 || deadline == Long.MAX_VALUE || deadline == -1L) { + + if(deadline == Long.MAX_VALUE || deadline == -1L) { // no deadline if(interrupt != null) { return new DefaultPackagerInterrupt(interrupt); } - return NOOP; + return NEGATIVE; } - if(checkpointsPerDeadlineCheck == 1) { - if(interrupt == null) { - return new DeadlineCheckPackagerInterruptSupplier(deadline); - } - return new DelegateDeadlineCheckPackagerInterruptSupplier(deadline, interrupt); + long delay = deadline - System.currentTimeMillis(); + if(delay <= 0) { + return POSITIVE; // i.e. time is already up + } + + if(scheduledThreadPoolExecutor == null) { + throw new IllegalStateException("Expected scheduler"); } + if(interrupt == null) { - return new NthDeadlineCheckPackagerInterruptSupplier(deadline, checkpointsPerDeadlineCheck); + DeadlineCheckPackagerInterruptSupplier supplier = new DeadlineCheckPackagerInterruptSupplier(); + ScheduledFuture schedule = scheduledThreadPoolExecutor.schedule(supplier, delay, TimeUnit.MILLISECONDS); + supplier.setFuture(schedule); + return supplier; } - return new DelegateNthDeadlineCheckPackagerInterruptSupplier(deadline, checkpointsPerDeadlineCheck, interrupt); + + DelegateDeadlineCheckPackagerInterruptSupplier supplier = new DelegateDeadlineCheckPackagerInterruptSupplier(interrupt); + ScheduledFuture schedule = scheduledThreadPoolExecutor.schedule(supplier, delay, TimeUnit.MILLISECONDS); + supplier.setFuture(schedule); + return supplier; } } diff --git a/core/src/main/java/com/github/skjolber/packing/deadline/PositivePackagerInterruptSupplier.java b/core/src/main/java/com/github/skjolber/packing/deadline/PositivePackagerInterruptSupplier.java new file mode 100644 index 00000000..a522da34 --- /dev/null +++ b/core/src/main/java/com/github/skjolber/packing/deadline/PositivePackagerInterruptSupplier.java @@ -0,0 +1,10 @@ +package com.github.skjolber.packing.deadline; + +public class PositivePackagerInterruptSupplier implements PackagerInterruptSupplier { + + @Override + public boolean getAsBoolean() { + return true; + } + +} diff --git a/core/src/main/java/com/github/skjolber/packing/iterator/PermutationRotationIterator.java b/core/src/main/java/com/github/skjolber/packing/iterator/PermutationRotationIterator.java index ea05bc07..2a6948b6 100644 --- a/core/src/main/java/com/github/skjolber/packing/iterator/PermutationRotationIterator.java +++ b/core/src/main/java/com/github/skjolber/packing/iterator/PermutationRotationIterator.java @@ -40,7 +40,7 @@ public interface PermutationRotationIterator { /** * Get current permutations * - * @return + * @return current permutations array */ int[] getPermutations(); @@ -49,7 +49,7 @@ public interface PermutationRotationIterator { * * Get current length * - * @return + * @return current length of permutations array */ int length(); @@ -112,7 +112,7 @@ public interface PermutationRotationIterator { * * @param state previously saved state * @param length number of items - * @return + * @return current permutations + rotations */ List get(PermutationRotationState state, int length); diff --git a/core/src/main/java/com/github/skjolber/packing/packer/AbstractPackager.java b/core/src/main/java/com/github/skjolber/packing/packer/AbstractPackager.java index 536844df..a563aa5c 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/AbstractPackager.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/AbstractPackager.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.concurrent.ScheduledThreadPoolExecutor; import com.github.skjolber.packing.api.Container; import com.github.skjolber.packing.api.ContainerItem; @@ -27,18 +28,16 @@ public abstract class AbstractPackager

containerItemIndexes, PackagerAdapter

ad } public List packList(List products, List containers, int limit) { - return pack(products, containers, limit, PackagerInterruptSupplierBuilder.NOOP); + return pack(products, containers, limit, PackagerInterruptSupplierBuilder.NEGATIVE); } /** * Return a list of containers which holds all the boxes in the argument * * @param boxes list of boxes to fit in a container + * @param containerItems list of containers available for use in this operation * @param limit maximum number of containers * @param interrupt When true, the computation is interrupted as soon as possible. * @return list of containers, or null if the deadline was reached, or empty list if the packages could not be packaged within the available containers and/or limit. @@ -283,5 +283,9 @@ protected long getMinStackableArea(List stackables) { } return minArea; } - + + public void close() { + scheduledThreadPoolExecutor.shutdownNow(); + } + } diff --git a/core/src/main/java/com/github/skjolber/packing/packer/AbstractPackagerBuilder.java b/core/src/main/java/com/github/skjolber/packing/packer/AbstractPackagerBuilder.java index 5cf4b1a8..ea01b6a3 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/AbstractPackagerBuilder.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/AbstractPackagerBuilder.java @@ -11,7 +11,6 @@ @SuppressWarnings({ "rawtypes", "unchecked" }) public abstract class AbstractPackagerBuilder

> { - protected int checkpointsPerDeadlineCheck = 1; protected PackResultComparator packResultComparator; public B withPackResultComparator(PackResultComparator packResultComparator) { @@ -20,11 +19,6 @@ public B withPackResultComparator(PackResultComparator packResultComparator) { return (B)this; } - public B withCheckpointsPerDeadlineCheck(int n) { - this.checkpointsPerDeadlineCheck = n; - return (B)this; - } - public abstract P build(); } diff --git a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/AbstractBruteForcePackager.java b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/AbstractBruteForcePackager.java index 03289860..853c50b4 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/AbstractBruteForcePackager.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/AbstractBruteForcePackager.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.logging.Logger; import com.github.skjolber.packing.api.Container; @@ -36,13 +37,13 @@ public abstract class AbstractBruteForcePackager extends AbstractPackager getPlacements(int size) { @@ -250,4 +251,8 @@ private List> packStackPlacement(ExtremePoints3DStack ex return best; } + protected ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor() { + return scheduledThreadPoolExecutor; + } + } diff --git a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackager.java b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackager.java index 07039bab..a0e7bfaa 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackager.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackager.java @@ -44,7 +44,7 @@ public BruteForcePackager build() { if(packResultComparator == null) { packResultComparator = new DefaultPackResultComparator(); } - return new BruteForcePackager(checkpointsPerDeadlineCheck, packResultComparator); + return new BruteForcePackager(packResultComparator); } } @@ -125,8 +125,8 @@ public Container accept(BruteForcePackagerResult bruteForceResult) { } - public BruteForcePackager(int checkpointsPerDeadlineCheck, PackResultComparator packResultComparator) { - super(checkpointsPerDeadlineCheck, packResultComparator); + public BruteForcePackager(PackResultComparator packResultComparator) { + super(packResultComparator); } @Override diff --git a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackagerResultBuilder.java b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackagerResultBuilder.java index 8c0e82c1..4c70fb53 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackagerResultBuilder.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackagerResultBuilder.java @@ -13,18 +13,11 @@ public class BruteForcePackagerResultBuilder extends PackagerResultBuilder packList = packager.pack(items, containers, maxContainerCount, build); - long duration = System.currentTimeMillis() - start; - if(packList == null) { - return new PackagerResult(Collections.emptyList(), duration, true); + try { + List packList = packager.pack(items, containers, maxContainerCount, build); + long duration = System.currentTimeMillis() - start; + if(packList == null) { + return new PackagerResult(Collections.emptyList(), duration, true); + } + return new PackagerResult(packList, duration, false); + } finally { + build.close(); } - return new PackagerResult(packList, duration, false); } } diff --git a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/FastBruteForcePackager.java b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/FastBruteForcePackager.java index 6ced168c..9d577a7f 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/FastBruteForcePackager.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/FastBruteForcePackager.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.concurrent.ScheduledThreadPoolExecutor; import com.github.skjolber.packing.api.Container; import com.github.skjolber.packing.api.ContainerItem; @@ -50,7 +51,7 @@ public FastBruteForcePackager build() { if(packResultComparator == null) { packResultComparator = new DefaultPackResultComparator(); } - return new FastBruteForcePackager(checkpointsPerDeadlineCheck, packResultComparator); + return new FastBruteForcePackager(packResultComparator); } } @@ -140,13 +141,13 @@ public Container accept(BruteForcePackagerResult bruteForceResult) { } - public FastBruteForcePackager(int checkpointsPerDeadlineCheck, PackResultComparator packResultComparator) { - super(checkpointsPerDeadlineCheck, packResultComparator); + public FastBruteForcePackager(PackResultComparator packResultComparator) { + super(packResultComparator); } @Override public FastBruteForcePackagerResultBuilder newResultBuilder() { - return new FastBruteForcePackagerResultBuilder().withCheckpointsPerDeadlineCheck(checkpointsPerDeadlineCheck).withPackager(this); + return new FastBruteForcePackagerResultBuilder().withPackager(this); } @Override @@ -398,5 +399,9 @@ public int packStackPlacement(FastExtremePoints3DStack extremePoints3D, List packList = packager.pack(items, containers, maxContainerCount, build); - long duration = System.currentTimeMillis() - start; - if(packList == null) { - return new PackagerResult(Collections.emptyList(), duration, true); + try { + List packList = packager.pack(items, containers, maxContainerCount, build); + long duration = System.currentTimeMillis() - start; + if(packList == null) { + return new PackagerResult(Collections.emptyList(), duration, true); + } + return new PackagerResult(packList, duration, false); + } finally { + build.close(); } - return new PackagerResult(packList, duration, false); } - + + } diff --git a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/ParallelBruteForcePackager.java b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/ParallelBruteForcePackager.java index 123f6069..6509a02d 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/ParallelBruteForcePackager.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/ParallelBruteForcePackager.java @@ -113,7 +113,7 @@ public ParallelBruteForcePackager build() { } } - return new ParallelBruteForcePackager(executorService, parallelizationCount, checkpointsPerDeadlineCheck, packResultComparator); + return new ParallelBruteForcePackager(executorService, parallelizationCount, packResultComparator); } } @@ -121,9 +121,9 @@ public ParallelBruteForcePackager build() { private final int parallelizationCount; private final ExecutorService executorService; - public ParallelBruteForcePackager(ExecutorService executorService, int parallelizationCount, int checkpointsPerDeadlineCheck, + public ParallelBruteForcePackager(ExecutorService executorService, int parallelizationCount, PackResultComparator packResultComparator) { - super(checkpointsPerDeadlineCheck, packResultComparator); + super(packResultComparator); this.parallelizationCount = parallelizationCount; this.executorService = executorService; diff --git a/core/src/main/java/com/github/skjolber/packing/packer/laff/AbstractLargestAreaFitFirstPackager.java b/core/src/main/java/com/github/skjolber/packing/packer/laff/AbstractLargestAreaFitFirstPackager.java index eef199d3..54268a87 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/laff/AbstractLargestAreaFitFirstPackager.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/laff/AbstractLargestAreaFitFirstPackager.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.stream.Collectors; import com.github.skjolber.packing.api.Container; @@ -68,8 +69,8 @@ public abstract class AbstractLargestAreaFitFirstPackager

stackables, Container targetContainer, int index, PackagerInterruptSupplier interrupt); @@ -127,4 +128,8 @@ protected LAFFAdapter adapter(List boxes, List con return new LAFFAdapter(boxes, containers, interrupt); } + protected ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor() { + return scheduledThreadPoolExecutor; + } + } diff --git a/core/src/main/java/com/github/skjolber/packing/packer/laff/FastLargestAreaFitFirstPackager.java b/core/src/main/java/com/github/skjolber/packing/packer/laff/FastLargestAreaFitFirstPackager.java index ffc44ba8..e36635c3 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/laff/FastLargestAreaFitFirstPackager.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/laff/FastLargestAreaFitFirstPackager.java @@ -41,12 +41,12 @@ public FastLargestAreaFitFirstPackager build() { if(packResultComparator == null) { packResultComparator = new DefaultPackResultComparator(); } - return new FastLargestAreaFitFirstPackager(checkpointsPerDeadlineCheck, packResultComparator); + return new FastLargestAreaFitFirstPackager(packResultComparator); } } - public FastLargestAreaFitFirstPackager(int checkpointsPerDeadlineCheck, PackResultComparator packResultComparator) { - super(checkpointsPerDeadlineCheck, packResultComparator); + public FastLargestAreaFitFirstPackager(PackResultComparator packResultComparator) { + super(packResultComparator); } public DefaultPackResult pack(List stackables, Container targetContainer, int containerIndex, PackagerInterruptSupplier interrupt) { @@ -244,7 +244,7 @@ public DefaultPackResult pack(List stackables, Container targetContai @Override public LargestAreaFitFirstPackagerResultBuilder newResultBuilder() { - return new LargestAreaFitFirstPackagerResultBuilder().withCheckpointsPerDeadlineCheck(checkpointsPerDeadlineCheck).withPackager(this); + return new LargestAreaFitFirstPackagerResultBuilder().withPackager(this); } } diff --git a/core/src/main/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackager.java b/core/src/main/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackager.java index f99b1aa5..fa39ec3d 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackager.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackager.java @@ -41,12 +41,12 @@ public LargestAreaFitFirstPackager build() { if(packResultComparator == null) { packResultComparator = new DefaultPackResultComparator(); } - return new LargestAreaFitFirstPackager(checkpointsPerDeadlineCheck, packResultComparator); + return new LargestAreaFitFirstPackager(packResultComparator); } } - public LargestAreaFitFirstPackager(int checkpointsPerDeadlineCheck, PackResultComparator packResultComparator) { - super(checkpointsPerDeadlineCheck, packResultComparator); + public LargestAreaFitFirstPackager(PackResultComparator packResultComparator) { + super(packResultComparator); } public DefaultPackResult pack(List stackables, Container targetContainer, int index, PackagerInterruptSupplier interrupt) { @@ -234,6 +234,6 @@ public DefaultPackResult pack(List stackables, Container targetContai @Override public LargestAreaFitFirstPackagerResultBuilder newResultBuilder() { - return new LargestAreaFitFirstPackagerResultBuilder().withCheckpointsPerDeadlineCheck(checkpointsPerDeadlineCheck).withPackager(this); + return new LargestAreaFitFirstPackagerResultBuilder().withPackager(this); } } diff --git a/core/src/main/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackagerResultBuilder.java b/core/src/main/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackagerResultBuilder.java index 951cb980..b1a34559 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackagerResultBuilder.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackagerResultBuilder.java @@ -13,18 +13,11 @@ public class LargestAreaFitFirstPackagerResultBuilder extends PackagerResultBuil private AbstractLargestAreaFitFirstPackager packager; - private int checkpointsPerDeadlineCheck = 1; - public LargestAreaFitFirstPackagerResultBuilder withPackager(AbstractLargestAreaFitFirstPackager packager) { this.packager = packager; return this; } - public LargestAreaFitFirstPackagerResultBuilder withCheckpointsPerDeadlineCheck(int n) { - this.checkpointsPerDeadlineCheck = n; - return this; - } - public PackagerResult build() { if(maxContainerCount <= 0) { throw new IllegalStateException(); @@ -39,20 +32,25 @@ public PackagerResult build() { PackagerInterruptSupplierBuilder booleanSupplierBuilder = PackagerInterruptSupplierBuilder.builder(); if(deadline != -1L) { - booleanSupplierBuilder.withDeadline(deadline, checkpointsPerDeadlineCheck); + booleanSupplierBuilder.withDeadline(deadline); } if(interrupt != null) { booleanSupplierBuilder.withInterrupt(interrupt); } - PackagerInterruptSupplier build = booleanSupplierBuilder.build(); + booleanSupplierBuilder.withScheduledThreadPoolExecutor(packager.getScheduledThreadPoolExecutor()); - List packList = packager.pack(items, containers, maxContainerCount, build); - long duration = System.currentTimeMillis() - start; - if(packList == null) { - return new PackagerResult(Collections.emptyList(), duration, true); + PackagerInterruptSupplier build = booleanSupplierBuilder.build(); + try { + List packList = packager.pack(items, containers, maxContainerCount, build); + long duration = System.currentTimeMillis() - start; + if(packList == null) { + return new PackagerResult(Collections.emptyList(), duration, true); + } + return new PackagerResult(packList, duration, false); + } finally { + build.close(); } - return new PackagerResult(packList, duration, false); } } diff --git a/core/src/main/java/com/github/skjolber/packing/packer/plain/AbstractPlainPackager.java b/core/src/main/java/com/github/skjolber/packing/packer/plain/AbstractPlainPackager.java index 65d04471..e5cc5a43 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/plain/AbstractPlainPackager.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/plain/AbstractPlainPackager.java @@ -2,6 +2,7 @@ import java.util.LinkedList; import java.util.List; +import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.stream.Collectors; import com.github.skjolber.packing.api.Container; @@ -25,8 +26,8 @@ */ public abstract class AbstractPlainPackager

> extends AbstractPackager { - public AbstractPlainPackager(int checkpointsPerDeadlineCheck, PackResultComparator packResultComparator) { - super(checkpointsPerDeadlineCheck, packResultComparator); + public AbstractPlainPackager(PackResultComparator packResultComparator) { + super(packResultComparator); } public abstract DefaultPackResult pack(List stackables, Container targetContainer, int containerIndex, PackagerInterruptSupplier interrupt); @@ -84,4 +85,8 @@ protected PlainAdapter adapter(List boxes, List co return new PlainAdapter(boxes, containers, interrupt); } + protected ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor() { + return scheduledThreadPoolExecutor; + } + } diff --git a/core/src/main/java/com/github/skjolber/packing/packer/plain/PlainPackager.java b/core/src/main/java/com/github/skjolber/packing/packer/plain/PlainPackager.java index cb783747..2479b893 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/plain/PlainPackager.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/plain/PlainPackager.java @@ -40,12 +40,12 @@ public PlainPackager build() { if(packResultComparator == null) { packResultComparator = new DefaultPackResultComparator(); } - return new PlainPackager(checkpointsPerDeadlineCheck, packResultComparator); + return new PlainPackager(packResultComparator); } } - public PlainPackager(int checkpointsPerDeadlineCheck, PackResultComparator packResultComparator) { - super(checkpointsPerDeadlineCheck, packResultComparator); + public PlainPackager(PackResultComparator packResultComparator) { + super(packResultComparator); } public DefaultPackResult pack(List stackables, Container targetContainer, int index, PackagerInterruptSupplier interrupt) { @@ -271,6 +271,6 @@ protected boolean isBetter(Stackable referenceStackable, Stackable potentiallyBe @Override public PlainPackagerResultBuilder newResultBuilder() { - return new PlainPackagerResultBuilder().withCheckpointsPerDeadlineCheck(checkpointsPerDeadlineCheck).withPackager(this); + return new PlainPackagerResultBuilder().withPackager(this); } } diff --git a/core/src/main/java/com/github/skjolber/packing/packer/plain/PlainPackagerResultBuilder.java b/core/src/main/java/com/github/skjolber/packing/packer/plain/PlainPackagerResultBuilder.java index 164fb542..0dd89a2b 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/plain/PlainPackagerResultBuilder.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/plain/PlainPackagerResultBuilder.java @@ -13,18 +13,11 @@ public class PlainPackagerResultBuilder extends PackagerResultBuilder packager; - private int checkpointsPerDeadlineCheck = 1; - public PlainPackagerResultBuilder withPackager(AbstractPlainPackager packager) { this.packager = packager; return this; } - public PlainPackagerResultBuilder withCheckpointsPerDeadlineCheck(int n) { - this.checkpointsPerDeadlineCheck = n; - return this; - } - public PackagerResult build() { if(maxContainerCount <= 0) { throw new IllegalStateException(); @@ -39,19 +32,25 @@ public PackagerResult build() { PackagerInterruptSupplierBuilder booleanSupplierBuilder = PackagerInterruptSupplierBuilder.builder(); if(deadline != -1L) { - booleanSupplierBuilder.withDeadline(deadline, checkpointsPerDeadlineCheck); + booleanSupplierBuilder.withDeadline(deadline); } if(interrupt != null) { booleanSupplierBuilder.withInterrupt(interrupt); } + booleanSupplierBuilder.withScheduledThreadPoolExecutor(packager.getScheduledThreadPoolExecutor()); + PackagerInterruptSupplier build = booleanSupplierBuilder.build(); - List packList = packager.pack(items, containers, maxContainerCount, build); - long duration = System.currentTimeMillis() - start; - if(packList == null) { - return new PackagerResult(Collections.emptyList(), duration, true); + try { + List packList = packager.pack(items, containers, maxContainerCount, build); + long duration = System.currentTimeMillis() - start; + if(packList == null) { + return new PackagerResult(Collections.emptyList(), duration, true); + } + return new PackagerResult(packList, duration, false); + } finally { + build.close(); } - return new PackagerResult(packList, duration, false); } } diff --git a/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/AbstractBruteForcePackagerTest.java b/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/AbstractBruteForcePackagerTest.java index 82de0b54..87376d06 100644 --- a/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/AbstractBruteForcePackagerTest.java +++ b/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/AbstractBruteForcePackagerTest.java @@ -41,15 +41,18 @@ public void testImpossible1() throws Exception { ); AbstractPackager packager = createPackager(); - - PackagerResult build = packager.newResultBuilder() - .withContainers(ContainerItem.newListBuilder() - .withContainer(container) - .build()) - .withStackables(b1) - .build(); - - assertFalse(build.isSuccess()); + try { + PackagerResult build = packager.newResultBuilder() + .withContainers(ContainerItem.newListBuilder() + .withContainer(container) + .build()) + .withStackables(b1) + .build(); + + assertFalse(build.isSuccess()); + } finally { + packager.close(); + } } @Test @@ -62,17 +65,20 @@ public void testImpossible2() { .build(); AbstractPackager packager = createPackager(); - - List products = Arrays.asList( - box(3,7,35,1)); - - PackagerResult build = packager - .newResultBuilder() - .withContainers(containerItems) - .withStackables(products) - .build(); - - assertFalse(build.isSuccess()); + try { + List products = Arrays.asList( + box(3,7,35,1)); + + PackagerResult build = packager + .newResultBuilder() + .withContainers(containerItems) + .withStackables(products) + .build(); + + assertFalse(build.isSuccess()); + } finally { + packager.close(); + } } @Test @@ -84,18 +90,21 @@ public void testImpossible3() { .build(); AbstractPackager packager = createPackager(); - - List products = Arrays.asList( - box(1,1,1,1), box(3,7,35,1)); - - PackagerResult build = packager - .newResultBuilder() - .withContainers(containerItems) - .withStackables(products) - .withMaxContainerCount(3) - .build(); - - assertFalse(build.isSuccess()); + try { + List products = Arrays.asList( + box(1,1,1,1), box(3,7,35,1)); + + PackagerResult build = packager + .newResultBuilder() + .withContainers(containerItems) + .withStackables(products) + .withMaxContainerCount(3) + .build(); + + assertFalse(build.isSuccess()); + } finally { + packager.close(); + } } @@ -138,16 +147,19 @@ public void testMutuallyExclusiveBoxesAndContainersForMultiContainerResult() thr ); AbstractPackager packager = createPackager(); - - PackagerResult build = packager.newResultBuilder() - .withContainers(ContainerItem.newListBuilder() - .withContainers(thin, thick) - .build()) - .withStackables(thinBox, thickBox) - .withMaxContainerCount(2) - .build(); - - assertTrue(build.isSuccess()); + try { + PackagerResult build = packager.newResultBuilder() + .withContainers(ContainerItem.newListBuilder() + .withContainers(thin, thick) + .build()) + .withStackables(thinBox, thickBox) + .withMaxContainerCount(2) + .build(); + + assertTrue(build.isSuccess()); + } finally { + packager.close(); + } } protected abstract AbstractPackager createPackager(); diff --git a/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackagerTest.java b/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackagerTest.java index 01ca1f21..4c374006 100644 --- a/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackagerTest.java +++ b/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackagerTest.java @@ -47,26 +47,29 @@ void testStackingSquaresOnSquare() { .build(); BruteForcePackager packager = BruteForcePackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - List containers = build.getContainers(); - assertValid(containers); - - List placements = containers.get(0).getStack().getPlacements(); - - assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); - assertThat(placements.get(1)).isAt(1, 0, 0).hasStackableName("B"); - assertThat(placements.get(2)).isAt(2, 0, 0).hasStackableName("C"); - - assertThat(placements.get(0)).isAlongsideX(placements.get(1)); - assertThat(placements.get(2)).followsAlongsideX(placements.get(1)); - assertThat(placements.get(1)).preceedsAlongsideX(placements.get(2)); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + List containers = build.getContainers(); + assertValid(containers); + + List placements = containers.get(0).getStack().getPlacements(); + + assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); + assertThat(placements.get(1)).isAt(1, 0, 0).hasStackableName("B"); + assertThat(placements.get(2)).isAt(2, 0, 0).hasStackableName("C"); + + assertThat(placements.get(0)).isAlongsideX(placements.get(1)); + assertThat(placements.get(2)).followsAlongsideX(placements.get(1)); + assertThat(placements.get(1)).preceedsAlongsideX(placements.get(2)); + } finally { + packager.close(); + } } @Test @@ -78,31 +81,34 @@ void testStackMultipleContainers() { .build(); BruteForcePackager packager = BruteForcePackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); - - PackagerResult build = packager.newResultBuilder().withContainers(containers).withStackables(products).withMaxContainerCount(5).build(); - - List packList = build.getContainers(); - - assertValid(packList); - assertThat(packList).hasSize(2); - - Container fits = packList.get(0); - - List placements = fits.getStack().getPlacements(); - - assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); - assertThat(placements.get(1)).isAt(1, 0, 0).hasStackableName("A"); - assertThat(placements.get(2)).isAt(2, 0, 0).hasStackableName("B"); - - assertThat(placements.get(0)).isAlongsideX(placements.get(1)); - assertThat(placements.get(2)).followsAlongsideX(placements.get(1)); - assertThat(placements.get(1)).preceedsAlongsideX(placements.get(2)); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); + + PackagerResult build = packager.newResultBuilder().withContainers(containers).withStackables(products).withMaxContainerCount(5).build(); + + List packList = build.getContainers(); + + assertValid(packList); + assertThat(packList).hasSize(2); + + Container fits = packList.get(0); + + List placements = fits.getStack().getPlacements(); + + assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); + assertThat(placements.get(1)).isAt(1, 0, 0).hasStackableName("A"); + assertThat(placements.get(2)).isAt(2, 0, 0).hasStackableName("B"); + + assertThat(placements.get(0)).isAlongsideX(placements.get(1)); + assertThat(placements.get(2)).followsAlongsideX(placements.get(1)); + assertThat(placements.get(1)).preceedsAlongsideX(placements.get(2)); + } finally { + packager.close(); + } } @Test @@ -114,22 +120,25 @@ void testStackingBinary1() { .build(); BruteForcePackager packager = BruteForcePackager.newBuilder().build(); - - List products = new ArrayList<>(); - products.add(new StackableItem(Box.newBuilder().withDescription("J").withRotate3D().withSize(4, 4, 1).withWeight(1).build(), 1)); - - for (int i = 0; i < 4; i++) { - products.add(new StackableItem(Box.newBuilder().withDescription("K").withRotate3D().withSize(2, 2, 1).withWeight(1).build(), 1)); - } - for (int i = 0; i < 16; i++) { - products.add(new StackableItem(Box.newBuilder().withDescription("K").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + try { + List products = new ArrayList<>(); + products.add(new StackableItem(Box.newBuilder().withDescription("J").withRotate3D().withSize(4, 4, 1).withWeight(1).build(), 1)); + + for (int i = 0; i < 4; i++) { + products.add(new StackableItem(Box.newBuilder().withDescription("K").withRotate3D().withSize(2, 2, 1).withWeight(1).build(), 1)); + } + for (int i = 0; i < 16; i++) { + products.add(new StackableItem(Box.newBuilder().withDescription("K").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + } + + PackagerResult build = packager.newResultBuilder().withContainers(containers).withStackables(products).build(); + + Container fits = build.getContainers().get(0); + assertValid(fits); + assertEquals(products.size(), fits.getStack().getPlacements().size()); + } finally { + packager.close(); } - - PackagerResult build = packager.newResultBuilder().withContainers(containers).withStackables(products).build(); - - Container fits = build.getContainers().get(0); - assertValid(fits); - assertEquals(products.size(), fits.getStack().getPlacements().size()); } @Test @@ -141,18 +150,21 @@ public void testStackingRectanglesOnSquareRectangleVolumeFirst() { .build(); BruteForcePackager packager = BruteForcePackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("J").withRotate3D().withSize(5, 10, 4).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("L").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("J").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("M").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("N").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - - assertValid(build); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("J").withRotate3D().withSize(5, 10, 4).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("L").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("J").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("M").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("N").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + + assertValid(build); + } finally { + packager.close(); + } } @Test @@ -164,16 +176,19 @@ public void testStackingBox() { .build(); BruteForcePackager packager = BruteForcePackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withSize(3, 2, 1).withRotate3D().withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withSize(3, 2, 1).withRotate3D().withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withSize(3, 2, 1).withRotate3D().withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("D").withSize(3, 2, 1).withRotate3D().withWeight(1).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containers).withStackables(products).build(); - assertValid(build); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withSize(3, 2, 1).withRotate3D().withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withSize(3, 2, 1).withRotate3D().withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withSize(3, 2, 1).withRotate3D().withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("D").withSize(3, 2, 1).withRotate3D().withWeight(1).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containers).withStackables(products).build(); + assertValid(build); + } finally { + packager.close(); + } } @Test @@ -217,32 +232,35 @@ protected void pack(BouwkampCode bouwkampCode) { .build(); BruteForcePackager packager = BruteForcePackager.newBuilder().build(); - - List products = new ArrayList<>(); - - List squares = new ArrayList<>(); - for (BouwkampCodeLine bouwkampCodeLine : bouwkampCode.getLines()) { - squares.addAll(bouwkampCodeLine.getSquares()); - } - - // map similar items to the same stack item - this actually helps a lot - Map frequencyMap = new TreeMap<>(); - squares.forEach(word -> frequencyMap.merge(word, 1, (v, newV) -> v + newV)); - - for (Entry entry : frequencyMap.entrySet()) { - int square = entry.getKey(); - int count = entry.getValue(); - products.add(new StackableItem(Box.newBuilder().withDescription(Integer.toString(square)).withSize(square, square, 1).withRotate3D().withWeight(1).build(), count)); + try { + List products = new ArrayList<>(); + + List squares = new ArrayList<>(); + for (BouwkampCodeLine bouwkampCodeLine : bouwkampCode.getLines()) { + squares.addAll(bouwkampCodeLine.getSquares()); + } + + // map similar items to the same stack item - this actually helps a lot + Map frequencyMap = new TreeMap<>(); + squares.forEach(word -> frequencyMap.merge(word, 1, (v, newV) -> v + newV)); + + for (Entry entry : frequencyMap.entrySet()) { + int square = entry.getKey(); + int count = entry.getValue(); + products.add(new StackableItem(Box.newBuilder().withDescription(Integer.toString(square)).withSize(square, square, 1).withRotate3D().withWeight(1).build(), count)); + } + + Collections.shuffle(products); + + PackagerResult build = packager.newResultBuilder().withContainers(containers).withStackables(products).build(); + + Container fits = build.getContainers().get(0); + assertNotNull(bouwkampCode.getName(), fits); + assertValid(fits); + assertEquals(bouwkampCode.getName(), fits.getStack().getSize(), squares.size()); + } finally { + packager.close(); } - - Collections.shuffle(products); - - PackagerResult build = packager.newResultBuilder().withContainers(containers).withStackables(products).build(); - - Container fits = build.getContainers().get(0); - assertNotNull(bouwkampCode.getName(), fits); - assertValid(fits); - assertEquals(bouwkampCode.getName(), fits.getStack().getSize(), squares.size()); } @Test @@ -264,20 +282,24 @@ public void issueNew() { .newBuilder() .build(); - List products = Arrays.asList( - new StackableItem(Box.newBuilder().withId("1").withSize(200, 2, 50).withRotate3D().withWeight(0).build(), 4), - new StackableItem(Box.newBuilder().withId("2").withSize(1, 1, 1).withRotate3D().withWeight(0).build(), 1), - new StackableItem(Box.newBuilder().withId("3").withSize(53, 11, 21).withRotate3D().withWeight(0).build(), 1), - new StackableItem(Box.newBuilder().withId("4").withSize(38, 7, 19).withRotate3D().withWeight(0).build(), 1), - new StackableItem(Box.newBuilder().withId("5").withSize(15, 3, 7).withRotate3D().withWeight(0).build(), 1), - new StackableItem(Box.newBuilder().withId("6").withSize(95, 5, 3).withRotate3D().withWeight(0).build(), 1), - new StackableItem(Box.newBuilder().withId("7").withSize(48, 15, 42).withRotate3D().withWeight(0).build(), 1), - new StackableItem(Box.newBuilder().withId("8").withSize(140, 10, 10).withRotate3D().withWeight(0).build(), 2), - new StackableItem(Box.newBuilder().withId("9").withSize(150, 4, 65).withRotate3D().withWeight(0).build(), 2), - new StackableItem(Box.newBuilder().withId("10").withSize(75, 17, 60).withRotate3D().withWeight(0).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containers).withStackables(products).build(); - assertValid(build); + try { + List products = Arrays.asList( + new StackableItem(Box.newBuilder().withId("1").withSize(200, 2, 50).withRotate3D().withWeight(0).build(), 4), + new StackableItem(Box.newBuilder().withId("2").withSize(1, 1, 1).withRotate3D().withWeight(0).build(), 1), + new StackableItem(Box.newBuilder().withId("3").withSize(53, 11, 21).withRotate3D().withWeight(0).build(), 1), + new StackableItem(Box.newBuilder().withId("4").withSize(38, 7, 19).withRotate3D().withWeight(0).build(), 1), + new StackableItem(Box.newBuilder().withId("5").withSize(15, 3, 7).withRotate3D().withWeight(0).build(), 1), + new StackableItem(Box.newBuilder().withId("6").withSize(95, 5, 3).withRotate3D().withWeight(0).build(), 1), + new StackableItem(Box.newBuilder().withId("7").withSize(48, 15, 42).withRotate3D().withWeight(0).build(), 1), + new StackableItem(Box.newBuilder().withId("8").withSize(140, 10, 10).withRotate3D().withWeight(0).build(), 2), + new StackableItem(Box.newBuilder().withId("9").withSize(150, 4, 65).withRotate3D().withWeight(0).build(), 2), + new StackableItem(Box.newBuilder().withId("10").withSize(75, 17, 60).withRotate3D().withWeight(0).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containers).withStackables(products).build(); + assertValid(build); + } finally { + packager.close(); + } } @Test @@ -307,15 +329,18 @@ public void testImpossible1() throws Exception { ); Packager packager = BruteForcePackager.newBuilder().build(); - - PackagerResult build = packager.newResultBuilder() - .withContainers(ContainerItem.newListBuilder() - .withContainer(container) - .build()) - .withStackables(b1) - .build(); - - assertFalse(build.isSuccess()); + try { + PackagerResult build = packager.newResultBuilder() + .withContainers(ContainerItem.newListBuilder() + .withContainer(container) + .build()) + .withStackables(b1) + .build(); + + assertFalse(build.isSuccess()); + } finally { + packager.close(); + } } @Test @@ -327,18 +352,21 @@ public void testImpossible2() { .withMaxLoadWeight(100).withStack(new ValidatingStack()).build(), 1) .build(); - Packager packager = BruteForcePackager.newBuilder().build(); - - List products = Arrays.asList( - box(3,7,35,1)); - - PackagerResult build = packager - .newResultBuilder() - .withContainers(containerItems) - .withStackables(products) - .build(); - - assertFalse(build.isSuccess()); + BruteForcePackager packager = BruteForcePackager.newBuilder().build(); + try { + List products = Arrays.asList( + box(3,7,35,1)); + + PackagerResult build = packager + .newResultBuilder() + .withContainers(containerItems) + .withStackables(products) + .build(); + + assertFalse(build.isSuccess()); + } finally { + packager.close(); + } } @Test @@ -349,19 +377,22 @@ public void testImpossible3() { .withMaxLoadWeight(100).withStack(new ValidatingStack()).build(), 1) .build(); - Packager packager = BruteForcePackager.newBuilder().build(); - - List products = Arrays.asList( - box(1,1,1,1), box(3,7,35,1)); - - PackagerResult build = packager - .newResultBuilder() - .withContainers(containerItems) - .withStackables(products) - .withMaxContainerCount(3) - .build(); - - assertFalse(build.isSuccess()); + BruteForcePackager packager = BruteForcePackager.newBuilder().build(); + try { + List products = Arrays.asList( + box(1,1,1,1), box(3,7,35,1)); + + PackagerResult build = packager + .newResultBuilder() + .withContainers(containerItems) + .withStackables(products) + .withMaxContainerCount(3) + .build(); + + assertFalse(build.isSuccess()); + } finally { + packager.close(); + } } @@ -404,16 +435,19 @@ public void testMutuallyExclusiveBoxesAndContainersForMultiContainerResult() thr ); BruteForcePackager packager = BruteForcePackager.newBuilder().build(); - - PackagerResult build = packager.newResultBuilder() - .withContainers(ContainerItem.newListBuilder() - .withContainers(thin, thick) - .build()) - .withStackables(thinBox, thickBox) - .withMaxContainerCount(2) - .build(); - - assertTrue(build.isSuccess()); + try { + PackagerResult build = packager.newResultBuilder() + .withContainers(ContainerItem.newListBuilder() + .withContainers(thin, thick) + .build()) + .withStackables(thinBox, thickBox) + .withMaxContainerCount(2) + .build(); + + assertTrue(build.isSuccess()); + } finally { + packager.close(); + } } @Test @@ -466,16 +500,19 @@ public void testMutuallyExclusiveBoxesAndContainersForMultiContainerResult2() th ); BruteForcePackager packager = BruteForcePackager.newBuilder().build(); - - PackagerResult build = packager.newResultBuilder() - .withContainers(ContainerItem.newListBuilder() - .withContainers(thin, thick) - .build()) - .withStackables(thinBox1, thickBox, thinBox2) - .withMaxContainerCount(2) - .build(); - - assertTrue(build.isSuccess()); + try { + PackagerResult build = packager.newResultBuilder() + .withContainers(ContainerItem.newListBuilder() + .withContainers(thin, thick) + .build()) + .withStackables(thinBox1, thickBox, thinBox2) + .withMaxContainerCount(2) + .build(); + + assertTrue(build.isSuccess()); + } finally { + packager.close(); + } } @Override @@ -493,25 +530,28 @@ public void test752() throws Exception { .build(); Packager packager = BruteForcePackager.newBuilder().build(); - - List products = Arrays.asList( - new StackableItem(Box.newBuilder().withRotate3D().withSize(3350, 510, 3350).withWeight(250).build(), 1), - new StackableItem(Box.newBuilder().withRotate3D().withSize(2600, 20500, 3600).withWeight(1200).build(), 1), - new StackableItem(Box.newBuilder().withRotate3D().withSize(2600, 25600, 4200).withWeight(1520).build(), 1), - new StackableItem(Box.newBuilder().withRotate3D().withSize(2600, 25600, 4200).withWeight(1900).build(), 1), - new StackableItem(Box.newBuilder().withRotate3D().withSize(2600, 25600, 4200).withWeight(1500).build(), 1), - new StackableItem(Box.newBuilder().withRotate3D().withSize(2600, 25600, 4200).withWeight(1420).build(), 1) - ); - - PackagerResult result = packager - .newResultBuilder() - .withContainers(containerItems) - .withStackables(products) - .withMaxContainerCount(1) - .build(); - - List packList = result.getContainers(); - assertThat(packList).hasSize(0); + try { + List products = Arrays.asList( + new StackableItem(Box.newBuilder().withRotate3D().withSize(3350, 510, 3350).withWeight(250).build(), 1), + new StackableItem(Box.newBuilder().withRotate3D().withSize(2600, 20500, 3600).withWeight(1200).build(), 1), + new StackableItem(Box.newBuilder().withRotate3D().withSize(2600, 25600, 4200).withWeight(1520).build(), 1), + new StackableItem(Box.newBuilder().withRotate3D().withSize(2600, 25600, 4200).withWeight(1900).build(), 1), + new StackableItem(Box.newBuilder().withRotate3D().withSize(2600, 25600, 4200).withWeight(1500).build(), 1), + new StackableItem(Box.newBuilder().withRotate3D().withSize(2600, 25600, 4200).withWeight(1420).build(), 1) + ); + + PackagerResult result = packager + .newResultBuilder() + .withContainers(containerItems) + .withStackables(products) + .withMaxContainerCount(1) + .build(); + + List packList = result.getContainers(); + assertThat(packList).hasSize(0); + } finally { + packager.close(); + } } diff --git a/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/FastBruteForcePackagerTest.java b/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/FastBruteForcePackagerTest.java index 6ef98db9..94fc7e8e 100644 --- a/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/FastBruteForcePackagerTest.java +++ b/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/FastBruteForcePackagerTest.java @@ -41,27 +41,30 @@ void testStackingSquaresOnSquare() { .build(); FastBruteForcePackager packager = FastBruteForcePackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - assertValid(build); - - Container fits = build.getContainers().get(0); - - List placements = fits.getStack().getPlacements(); - - assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); - assertThat(placements.get(1)).isAt(1, 0, 0).hasStackableName("B"); - assertThat(placements.get(2)).isAt(2, 0, 0).hasStackableName("C"); - - assertThat(placements.get(0)).isAlongsideX(placements.get(1)); - assertThat(placements.get(2)).followsAlongsideX(placements.get(1)); - assertThat(placements.get(1)).preceedsAlongsideX(placements.get(2)); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + assertValid(build); + + Container fits = build.getContainers().get(0); + + List placements = fits.getStack().getPlacements(); + + assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); + assertThat(placements.get(1)).isAt(1, 0, 0).hasStackableName("B"); + assertThat(placements.get(2)).isAt(2, 0, 0).hasStackableName("C"); + + assertThat(placements.get(0)).isAlongsideX(placements.get(1)); + assertThat(placements.get(2)).followsAlongsideX(placements.get(1)); + assertThat(placements.get(1)).preceedsAlongsideX(placements.get(2)); + } finally { + packager.close(); + } } @Test @@ -77,31 +80,34 @@ void testStackMultipleContainers() { .build(); FastBruteForcePackager packager = FastBruteForcePackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).withMaxContainerCount(5).build(); - assertValid(build); - - List packList = build.getContainers(); - - assertThat(packList).hasSize(2); - - Container fits = packList.get(0); - - List placements = fits.getStack().getPlacements(); - - assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); - assertThat(placements.get(1)).isAt(1, 0, 0).hasStackableName("A"); - assertThat(placements.get(2)).isAt(2, 0, 0).hasStackableName("B"); - - assertThat(placements.get(0)).isAlongsideX(placements.get(1)); - assertThat(placements.get(2)).followsAlongsideX(placements.get(1)); - assertThat(placements.get(1)).preceedsAlongsideX(placements.get(2)); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).withMaxContainerCount(5).build(); + assertValid(build); + + List packList = build.getContainers(); + + assertThat(packList).hasSize(2); + + Container fits = packList.get(0); + + List placements = fits.getStack().getPlacements(); + + assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); + assertThat(placements.get(1)).isAt(1, 0, 0).hasStackableName("A"); + assertThat(placements.get(2)).isAt(2, 0, 0).hasStackableName("B"); + + assertThat(placements.get(0)).isAlongsideX(placements.get(1)); + assertThat(placements.get(2)).followsAlongsideX(placements.get(1)); + assertThat(placements.get(1)).preceedsAlongsideX(placements.get(2)); + } finally { + packager.close(); + } } @Test @@ -145,36 +151,39 @@ protected void pack(BouwkampCode bouwkampCode) { .build(); FastBruteForcePackager packager = FastBruteForcePackager.newBuilder().build(); - - List products = new ArrayList<>(); - - List squares = new ArrayList<>(); - for (BouwkampCodeLine bouwkampCodeLine : bouwkampCode.getLines()) { - squares.addAll(bouwkampCodeLine.getSquares()); - } - - // map similar items to the same stack item - this actually helps a lot - Map frequencyMap = new HashMap<>(); - squares.forEach(word -> frequencyMap.merge(word, 1, (v, newV) -> v + newV)); - - for (Entry entry : frequencyMap.entrySet()) { - int square = entry.getKey(); - int count = entry.getValue(); - products.add(new StackableItem(Box.newBuilder().withDescription(Integer.toString(square)).withSize(square, square, 1).withRotate3D().withWeight(1).build(), count)); + try { + List products = new ArrayList<>(); + + List squares = new ArrayList<>(); + for (BouwkampCodeLine bouwkampCodeLine : bouwkampCode.getLines()) { + squares.addAll(bouwkampCodeLine.getSquares()); + } + + // map similar items to the same stack item - this actually helps a lot + Map frequencyMap = new HashMap<>(); + squares.forEach(word -> frequencyMap.merge(word, 1, (v, newV) -> v + newV)); + + for (Entry entry : frequencyMap.entrySet()) { + int square = entry.getKey(); + int count = entry.getValue(); + products.add(new StackableItem(Box.newBuilder().withDescription(Integer.toString(square)).withSize(square, square, 1).withRotate3D().withWeight(1).build(), count)); + } + + Collections.shuffle(products); + + PackagerResult build = packager + .newResultBuilder() + .withContainers(containerItems) + .withStackables(products).build(); + + Container fits = build.get(0); + + assertNotNull(bouwkampCode.getName(), fits); + assertValid(fits); + assertEquals(bouwkampCode.getName(), fits.getStack().getSize(), squares.size()); + } finally { + packager.close(); } - - Collections.shuffle(products); - - PackagerResult build = packager - .newResultBuilder() - .withContainers(containerItems) - .withStackables(products).build(); - - Container fits = build.get(0); - - assertNotNull(bouwkampCode.getName(), fits); - assertValid(fits); - assertEquals(bouwkampCode.getName(), fits.getStack().getSize(), squares.size()); } @Test @@ -189,39 +198,44 @@ void testAnotherLargeProblemShouldRespectDeadline() { FastBruteForcePackager packager = FastBruteForcePackager.newBuilder().build(); - List products = Arrays.asList( - box(1000, 1000, 1000, 1), - box(1000, 1000, 1000, 4), - box(100, 1050, 750, 1), - box(100, 650, 750, 1), - box(16, 2500, 11, 1), - box(250, 150, 80, 1), - box(280, 800, 480, 1), - box(30, 620, 10, 1), - box(40, 1000, 1000, 1), - box(40, 100, 165, 1), - box(44, 575, 534, 1), - box(475, 530, 150, 1), - box(47, 3160, 660, 1), - box(530, 120, 570, 1), - box(55, 500, 745, 1), - box(670, 25, 15, 1), - box(700, 300, 30, 1), - box(700, 400, 30, 1), - box(75, 400, 720, 1), - box(77, 360, 750, 1), - box(80, 450, 760, 1), - box(90, 210, 680, 1)); - - PackagerResult build = packager - .newResultBuilder() - .withContainers(containerItems) - .withStackables(products) - .build(); - - // strangely when the timeout is set to now + 200ms it properly returns null - Container fits = build.get(0); - assertNull(fits); + try { + List products = Arrays.asList( + box(1000, 1000, 1000, 1), + box(1000, 1000, 1000, 4), + box(100, 1050, 750, 1), + box(100, 650, 750, 1), + box(16, 2500, 11, 1), + box(250, 150, 80, 1), + box(280, 800, 480, 1), + box(30, 620, 10, 1), + box(40, 1000, 1000, 1), + box(40, 100, 165, 1), + box(44, 575, 534, 1), + box(475, 530, 150, 1), + box(47, 3160, 660, 1), + box(530, 120, 570, 1), + box(55, 500, 745, 1), + box(670, 25, 15, 1), + box(700, 300, 30, 1), + box(700, 400, 30, 1), + box(75, 400, 720, 1), + box(77, 360, 750, 1), + box(80, 450, 760, 1), + box(90, 210, 680, 1)); + + PackagerResult build = packager + .newResultBuilder() + .withContainers(containerItems) + .withStackables(products) + .build(); + + // strangely when the timeout is set to now + 200ms it properly returns null + Container fits = build.get(0); + assertNull(fits); + } finally { + packager.close(); + } + } @Test diff --git a/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/ParallelBruteForcePackagerTest.java b/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/ParallelBruteForcePackagerTest.java index fd816302..38c78ed8 100644 --- a/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/ParallelBruteForcePackagerTest.java +++ b/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/ParallelBruteForcePackagerTest.java @@ -43,29 +43,32 @@ void testStackingSquaresOnSquare() { .build(); ParallelBruteForcePackager packager = ParallelBruteForcePackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - assertValid(build); - - Container fits = build.get(0); - assertValid(fits); - assertEquals(fits.getStack().getSize(), products.size()); - - List placements = fits.getStack().getPlacements(); - - assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); - assertThat(placements.get(1)).isAt(1, 0, 0).hasStackableName("B"); - assertThat(placements.get(2)).isAt(2, 0, 0).hasStackableName("C"); - - assertThat(placements.get(0)).isAlongsideX(placements.get(1)); - assertThat(placements.get(2)).followsAlongsideX(placements.get(1)); - assertThat(placements.get(1)).preceedsAlongsideX(placements.get(2)); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + assertValid(build); + + Container fits = build.get(0); + assertValid(fits); + assertEquals(fits.getStack().getSize(), products.size()); + + List placements = fits.getStack().getPlacements(); + + assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); + assertThat(placements.get(1)).isAt(1, 0, 0).hasStackableName("B"); + assertThat(placements.get(2)).isAt(2, 0, 0).hasStackableName("C"); + + assertThat(placements.get(0)).isAlongsideX(placements.get(1)); + assertThat(placements.get(2)).followsAlongsideX(placements.get(1)); + assertThat(placements.get(1)).preceedsAlongsideX(placements.get(2)); + } finally { + packager.close(); + } } @Test @@ -77,31 +80,34 @@ void testStackMultipleContainers() { .build(); ParallelBruteForcePackager packager = ParallelBruteForcePackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).withMaxContainerCount(5).build(); - assertValid(build); - - List packList = build.getContainers(); - assertValid(packList); - assertThat(packList).hasSize(2); - - Container fits = packList.get(0); - - List placements = fits.getStack().getPlacements(); - - assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); - assertThat(placements.get(1)).isAt(1, 0, 0).hasStackableName("A"); - assertThat(placements.get(2)).isAt(2, 0, 0).hasStackableName("B"); - - assertThat(placements.get(0)).isAlongsideX(placements.get(1)); - assertThat(placements.get(2)).followsAlongsideX(placements.get(1)); - assertThat(placements.get(1)).preceedsAlongsideX(placements.get(2)); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).withMaxContainerCount(5).build(); + assertValid(build); + + List packList = build.getContainers(); + assertValid(packList); + assertThat(packList).hasSize(2); + + Container fits = packList.get(0); + + List placements = fits.getStack().getPlacements(); + + assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); + assertThat(placements.get(1)).isAt(1, 0, 0).hasStackableName("A"); + assertThat(placements.get(2)).isAt(2, 0, 0).hasStackableName("B"); + + assertThat(placements.get(0)).isAlongsideX(placements.get(1)); + assertThat(placements.get(2)).followsAlongsideX(placements.get(1)); + assertThat(placements.get(1)).preceedsAlongsideX(placements.get(2)); + } finally { + packager.close(); + } } @Test @@ -114,17 +120,21 @@ void testStackingBinary1() { ParallelBruteForcePackager packager = ParallelBruteForcePackager.newBuilder().build(); - List products = new ArrayList<>(); - products.add(new StackableItem(Box.newBuilder().withDescription("J").withSize(4, 4, 1).withRotate3D().withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("K").withRotate3D().withSize(2, 2, 1).withWeight(1).build(), 4)); - products.add(new StackableItem(Box.newBuilder().withDescription("K").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 16)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - assertValid(build); - - Container fits = build.get(0); - assertValid(fits); - assertEquals(21, fits.getStack().getPlacements().size()); + try { + List products = new ArrayList<>(); + products.add(new StackableItem(Box.newBuilder().withDescription("J").withSize(4, 4, 1).withRotate3D().withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("K").withRotate3D().withSize(2, 2, 1).withWeight(1).build(), 4)); + products.add(new StackableItem(Box.newBuilder().withDescription("K").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 16)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + assertValid(build); + + Container fits = build.get(0); + assertValid(fits); + assertEquals(21, fits.getStack().getPlacements().size()); + } finally { + packager.close(); + } } @Test @@ -136,20 +146,23 @@ public void testStackingRectanglesOnSquareRectangleVolumeFirst() { .build(); ParallelBruteForcePackager packager = ParallelBruteForcePackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("J").withRotate3D().withSize(5, 10, 4).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("L").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("J").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("M").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("N").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - assertValid(build); - - Container fits = build.get(0); - assertEquals(fits.getStack().getSize(), products.size()); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("J").withRotate3D().withSize(5, 10, 4).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("L").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("J").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("M").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("N").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + assertValid(build); + + Container fits = build.get(0); + assertEquals(fits.getStack().getSize(), products.size()); + } finally { + packager.close(); + } } @Test @@ -161,19 +174,22 @@ public void testStackingBox() { .build(); ParallelBruteForcePackager packager = ParallelBruteForcePackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(3, 2, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(3, 2, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(3, 2, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("D").withRotate3D().withSize(3, 2, 1).withWeight(1).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - assertValid(build); - Container fits = build.get(0); - - assertEquals(fits.getStack().getSize(), products.size()); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(3, 2, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(3, 2, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(3, 2, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("D").withRotate3D().withSize(3, 2, 1).withWeight(1).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + assertValid(build); + Container fits = build.get(0); + + assertEquals(fits.getStack().getSize(), products.size()); + } finally { + packager.close(); + } } @Test @@ -214,34 +230,38 @@ protected void pack(BouwkampCode bouwkampCode) { .withStack(new ValidatingStack()).build(), 1) .build(); - ParallelBruteForcePackager packager = ParallelBruteForcePackager.newBuilder().withExecutorService(executorService).withParallelizationCount(256).withCheckpointsPerDeadlineCheck(1024).build(); + ParallelBruteForcePackager packager = ParallelBruteForcePackager.newBuilder().withExecutorService(executorService).withParallelizationCount(256).build(); - List products = new ArrayList<>(); - - List squares = new ArrayList<>(); - for (BouwkampCodeLine bouwkampCodeLine : bouwkampCode.getLines()) { - squares.addAll(bouwkampCodeLine.getSquares()); - } - - // map similar items to the same stack item - this actually helps a lot - Map frequencyMap = new HashMap<>(); - squares.forEach(word -> frequencyMap.merge(word, 1, (v, newV) -> v + newV)); - - for (Entry entry : frequencyMap.entrySet()) { - int square = entry.getKey(); - int count = entry.getValue(); - products.add(new StackableItem(Box.newBuilder().withDescription(Integer.toString(square)).withRotate3D().withSize(square, square, 1).withWeight(1).build(), count)); + try { + List products = new ArrayList<>(); + + List squares = new ArrayList<>(); + for (BouwkampCodeLine bouwkampCodeLine : bouwkampCode.getLines()) { + squares.addAll(bouwkampCodeLine.getSquares()); + } + + // map similar items to the same stack item - this actually helps a lot + Map frequencyMap = new HashMap<>(); + squares.forEach(word -> frequencyMap.merge(word, 1, (v, newV) -> v + newV)); + + for (Entry entry : frequencyMap.entrySet()) { + int square = entry.getKey(); + int count = entry.getValue(); + products.add(new StackableItem(Box.newBuilder().withDescription(Integer.toString(square)).withRotate3D().withSize(square, square, 1).withWeight(1).build(), count)); + } + + Collections.shuffle(products); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + assertValid(build); + Container fits = build.get(0); + + assertNotNull(bouwkampCode.getName(), fits); + assertValid(fits); + assertEquals(bouwkampCode.getName(), fits.getStack().getSize(), squares.size()); + } finally { + packager.close(); } - - Collections.shuffle(products); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - assertValid(build); - Container fits = build.get(0); - - assertNotNull(bouwkampCode.getName(), fits); - assertValid(fits); - assertEquals(bouwkampCode.getName(), fits.getStack().getSize(), squares.size()); } @Disabled // TODO @@ -252,6 +272,6 @@ public void testAHugeProblemShouldRespectDeadline() { @Override protected AbstractPackager createPackager() { - return ParallelBruteForcePackager.newBuilder().withExecutorService(executorService).withParallelizationCount(256).withCheckpointsPerDeadlineCheck(1024).build(); + return ParallelBruteForcePackager.newBuilder().withExecutorService(executorService).withParallelizationCount(256).build(); } } diff --git a/core/src/test/java/com/github/skjolber/packing/packer/laff/FastLargestAreaFitFirstPackagerTest.java b/core/src/test/java/com/github/skjolber/packing/packer/laff/FastLargestAreaFitFirstPackagerTest.java index aa5aae08..ef937b69 100644 --- a/core/src/test/java/com/github/skjolber/packing/packer/laff/FastLargestAreaFitFirstPackagerTest.java +++ b/core/src/test/java/com/github/skjolber/packing/packer/laff/FastLargestAreaFitFirstPackagerTest.java @@ -29,16 +29,19 @@ void testStackingSquaresOnSquare() { .build(); FastLargestAreaFitFirstPackager packager = FastLargestAreaFitFirstPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - List containers = build.getContainers(); - assertValid(containers); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + List containers = build.getContainers(); + assertValid(containers); + } finally { + packager.close(); + } } @Test @@ -50,16 +53,19 @@ void testStackingRectangles() { .build(); FastLargestAreaFitFirstPackager packager = FastLargestAreaFitFirstPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - List containers = build.getContainers(); - assertValid(containers); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + List containers = build.getContainers(); + assertValid(containers); + } finally { + packager.close(); + } } @Test @@ -71,16 +77,19 @@ void testStackingSquaresAndRectangle() { .build(); FastLargestAreaFitFirstPackager packager = FastLargestAreaFitFirstPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(5, 5, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(5, 5, 1).withWeight(1).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - List containers = build.getContainers(); - assertValid(containers); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(5, 5, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(5, 5, 1).withWeight(1).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + List containers = build.getContainers(); + assertValid(containers); + } finally { + packager.close(); + } } @Test @@ -92,16 +101,19 @@ void testStackingDecreasingRectangles() { .build(); FastLargestAreaFitFirstPackager packager = FastLargestAreaFitFirstPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(3, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - List containers = build.getContainers(); - assertValid(containers); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(3, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + List containers = build.getContainers(); + assertValid(containers); + } finally { + packager.close(); + } } @Test @@ -113,21 +125,24 @@ void testStackingRectanglesTwoLevels() { .build(); FastLargestAreaFitFirstPackager packager = FastLargestAreaFitFirstPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 2)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 2)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 2)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - List containers = build.getContainers(); - assertValid(containers); - - Container fits = containers.get(0); - - LevelStack levelStack = (LevelStack)fits.getStack(); - assertEquals(2, levelStack.getLevels().size()); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 2)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 2)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 2)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + List containers = build.getContainers(); + assertValid(containers); + + Container fits = containers.get(0); + + LevelStack levelStack = (LevelStack)fits.getStack(); + assertEquals(2, levelStack.getLevels().size()); + } finally { + packager.close(); + } } @Test @@ -139,19 +154,22 @@ void testStackingRectanglesThreeLevels() { .build(); FastLargestAreaFitFirstPackager packager = FastLargestAreaFitFirstPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(2, 2, 1).withWeight(1).build(), 3)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - List containers = build.getContainers(); - assertValid(containers); - - Container fits = containers.get(0); - - LevelStack levelStack = (LevelStack)fits.getStack(); - assertEquals(3, levelStack.getLevels().size()); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(2, 2, 1).withWeight(1).build(), 3)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + List containers = build.getContainers(); + assertValid(containers); + + Container fits = containers.get(0); + + LevelStack levelStack = (LevelStack)fits.getStack(); + assertEquals(3, levelStack.getLevels().size()); + } finally { + packager.close(); + } } @Test @@ -164,15 +182,18 @@ void testStackingNotPossible() { .build(); FastLargestAreaFitFirstPackager packager = FastLargestAreaFitFirstPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 2, 1).withWeight(1).build(), 18)); // 12 - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); // 1 - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - List containers = build.getContainers(); - assertThat(containers).isEmpty(); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 2, 1).withWeight(1).build(), 18)); // 12 + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); // 1 + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + List containers = build.getContainers(); + assertThat(containers).isEmpty(); + } finally { + packager.close(); + } } @Test @@ -194,17 +215,20 @@ void issue453BoxesShouldNotFit() { FastLargestAreaFitFirstPackager packager = FastLargestAreaFitFirstPackager .newBuilder() .build(); - - List products = Arrays.asList( - new StackableItem(Box.newBuilder().withId("1").withSize(32, 19, 24).withRotate3D().withWeight(0).build(), 1), - new StackableItem(Box.newBuilder().withId("2").withSize(32, 21, 27).withRotate3D().withWeight(0).build(), 1), - new StackableItem(Box.newBuilder().withId("3").withSize(34, 21, 24).withRotate3D().withWeight(0).build(), 1), - new StackableItem(Box.newBuilder().withId("4").withSize(30, 19, 23).withRotate3D().withWeight(0).build(), 1), - new StackableItem(Box.newBuilder().withId("5").withSize(30, 21, 25).withRotate3D().withWeight(0).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - - assertEquals(0, build.size()); + try { + List products = Arrays.asList( + new StackableItem(Box.newBuilder().withId("1").withSize(32, 19, 24).withRotate3D().withWeight(0).build(), 1), + new StackableItem(Box.newBuilder().withId("2").withSize(32, 21, 27).withRotate3D().withWeight(0).build(), 1), + new StackableItem(Box.newBuilder().withId("3").withSize(34, 21, 24).withRotate3D().withWeight(0).build(), 1), + new StackableItem(Box.newBuilder().withId("4").withSize(30, 19, 23).withRotate3D().withWeight(0).build(), 1), + new StackableItem(Box.newBuilder().withId("5").withSize(30, 21, 25).withRotate3D().withWeight(0).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + + assertEquals(0, build.size()); + } finally { + packager.close(); + } } @Test diff --git a/core/src/test/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackagerTest.java b/core/src/test/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackagerTest.java index b4a15a9b..c2e386ee 100644 --- a/core/src/test/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackagerTest.java +++ b/core/src/test/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackagerTest.java @@ -38,28 +38,31 @@ void testStackingSquaresOnSquare() { .build(); LargestAreaFitFirstPackager packager = LargestAreaFitFirstPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - - PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - Container fits = result.get(0); - - assertNotNull(fits); - validate(fits); - - List placements = fits.getStack().getPlacements(); - - assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); - assertThat(placements.get(1)).isAt(1, 0, 0).hasStackableName("B"); - assertThat(placements.get(2)).isAt(2, 0, 0).hasStackableName("C"); - - assertThat(placements.get(0)).isAlongsideX(placements.get(1)); - assertThat(placements.get(2)).followsAlongsideX(placements.get(1)); - assertThat(placements.get(1)).preceedsAlongsideX(placements.get(2)); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + + PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + Container fits = result.get(0); + + assertNotNull(fits); + validate(fits); + + List placements = fits.getStack().getPlacements(); + + assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); + assertThat(placements.get(1)).isAt(1, 0, 0).hasStackableName("B"); + assertThat(placements.get(2)).isAt(2, 0, 0).hasStackableName("C"); + + assertThat(placements.get(0)).isAlongsideX(placements.get(1)); + assertThat(placements.get(2)).followsAlongsideX(placements.get(1)); + assertThat(placements.get(1)).preceedsAlongsideX(placements.get(2)); + } finally { + packager.close(); + } } @Test @@ -71,24 +74,27 @@ void testStackingRectangles() { .build(); LargestAreaFitFirstPackager packager = LargestAreaFitFirstPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); - - PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - Container fits = result.get(0); - - assertNotNull(fits); - validate(fits); - - List placements = fits.getStack().getPlacements(); - - assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); - assertThat(placements.get(1)).isAt(1, 0, 0).hasStackableName("B"); - assertThat(placements.get(2)).isAt(1, 1, 0).hasStackableName("C"); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); + + PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + Container fits = result.get(0); + + assertNotNull(fits); + validate(fits); + + List placements = fits.getStack().getPlacements(); + + assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); + assertThat(placements.get(1)).isAt(1, 0, 0).hasStackableName("B"); + assertThat(placements.get(2)).isAt(1, 1, 0).hasStackableName("C"); + } finally { + packager.close(); + } } @@ -101,18 +107,21 @@ void testStackingSquaresAndRectangle() { .build(); LargestAreaFitFirstPackager packager = LargestAreaFitFirstPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(5, 5, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(5, 5, 1).withWeight(1).build(), 1)); - - PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - Container fits = result.get(0); - - assertNotNull(fits); - validate(fits); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(5, 5, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(5, 5, 1).withWeight(1).build(), 1)); + + PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + Container fits = result.get(0); + + assertNotNull(fits); + validate(fits); + } finally { + packager.close(); + } } @Test @@ -124,24 +133,27 @@ void testStackingDecreasingRectangles() { .build(); LargestAreaFitFirstPackager packager = LargestAreaFitFirstPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(3, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - - PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - Container fits = result.get(0); - - assertNotNull(fits); - validate(fits); - - List placements = fits.getStack().getPlacements(); - - assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); - assertThat(placements.get(1)).isAt(3, 0, 0).hasStackableName("B"); // point with lowest x is selected first - assertThat(placements.get(2)).isAt(5, 0, 0).hasStackableName("C"); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(3, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + + PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + Container fits = result.get(0); + + assertNotNull(fits); + validate(fits); + + List placements = fits.getStack().getPlacements(); + + assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); + assertThat(placements.get(1)).isAt(3, 0, 0).hasStackableName("B"); // point with lowest x is selected first + assertThat(placements.get(2)).isAt(5, 0, 0).hasStackableName("C"); + } finally { + packager.close(); + } } @@ -154,31 +166,34 @@ void testStackingRectanglesTwoLevels() { .build(); LargestAreaFitFirstPackager packager = LargestAreaFitFirstPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 2)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 2)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 2)); - - PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - Container fits = result.get(0); - - assertNotNull(fits); - validate(fits); - - LevelStack levelStack = (LevelStack)fits.getStack(); - assertEquals(2, levelStack.getLevels().size()); - - List placements = fits.getStack().getPlacements(); - - assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); - assertThat(placements.get(1)).isAt(1, 0, 0).hasStackableName("A"); - assertThat(placements.get(2)).isAt(1, 1, 0).hasStackableName("B"); - - assertThat(placements.get(3)).isAt(0, 0, 1).hasStackableName("B"); - assertThat(placements.get(4)).isAt(1, 0, 1).hasStackableName("C"); - assertThat(placements.get(5)).isAt(1, 1, 1).hasStackableName("C"); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 2)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 2)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 2)); + + PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + Container fits = result.get(0); + + assertNotNull(fits); + validate(fits); + + LevelStack levelStack = (LevelStack)fits.getStack(); + assertEquals(2, levelStack.getLevels().size()); + + List placements = fits.getStack().getPlacements(); + + assertThat(placements.get(0)).isAt(0, 0, 0).hasStackableName("A"); + assertThat(placements.get(1)).isAt(1, 0, 0).hasStackableName("A"); + assertThat(placements.get(2)).isAt(1, 1, 0).hasStackableName("B"); + + assertThat(placements.get(3)).isAt(0, 0, 1).hasStackableName("B"); + assertThat(placements.get(4)).isAt(1, 0, 1).hasStackableName("C"); + assertThat(placements.get(5)).isAt(1, 1, 1).hasStackableName("C"); + } finally { + packager.close(); + } } @Test @@ -190,22 +205,25 @@ void testStackingRectanglesThreeLevels() { .build(); LargestAreaFitFirstPackager packager = LargestAreaFitFirstPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(2, 2, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 2, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(2, 2, 1).withWeight(1).build(), 1)); - - PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - - Container fits = result.get(0); - - assertNotNull(fits); - validate(fits); - - LevelStack levelStack = (LevelStack)fits.getStack(); - assertEquals(3, levelStack.getLevels().size()); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(2, 2, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 2, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(2, 2, 1).withWeight(1).build(), 1)); + + PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + + Container fits = result.get(0); + + assertNotNull(fits); + validate(fits); + + LevelStack levelStack = (LevelStack)fits.getStack(); + assertEquals(3, levelStack.getLevels().size()); + } finally { + packager.close(); + } } @Test @@ -222,14 +240,17 @@ void testStackingNotPossible() { containers.add(Container.newBuilder().withDescription("1").withEmptyWeight(1).withSize(3, 2, 3).withMaxLoadWeight(100).withStack(new ValidatingStack()).build()); LargestAreaFitFirstPackager packager = LargestAreaFitFirstPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 2, 1).withWeight(1).build(), 18)); // 12 - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); // 1 - - PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - assertEquals(result.size(), 0); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 2, 1).withWeight(1).build(), 18)); // 12 + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); // 1 + + PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + assertEquals(result.size(), 0); + } finally { + packager.close(); + } } @Test @@ -251,12 +272,16 @@ void issue433() { .newBuilder() .build(); - List products = Arrays.asList( - new StackableItem(Box.newBuilder().withId("Foot").withSize(7, 37, 39).withRotate3D().withWeight(0).build(), 20)); - - PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - Container pack = result.get(0); - assertNotNull(pack); + try { + List products = Arrays.asList( + new StackableItem(Box.newBuilder().withId("Foot").withSize(7, 37, 39).withRotate3D().withWeight(0).build(), 20)); + + PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + Container pack = result.get(0); + assertNotNull(pack); + } finally { + packager.close(); + } } @@ -277,27 +302,31 @@ void issue440() { LargestAreaFitFirstPackager packager = LargestAreaFitFirstPackager.newBuilder() .build(); - for (int i = 1; i <= 10; i++) { - int boxCountPerStackableItem = i; - - List products = Arrays.asList( - createStackableItem("1", 1200, 750, 2280, 285, boxCountPerStackableItem), - createStackableItem("2", 1200, 450, 2280, 155, boxCountPerStackableItem), - createStackableItem("3", 360, 360, 570, 20, boxCountPerStackableItem), - createStackableItem("4", 2250, 1200, 2250, 900, boxCountPerStackableItem), - createStackableItem("5", 1140, 750, 1450, 395, boxCountPerStackableItem), - createStackableItem("6", 1130, 1500, 3100, 800, boxCountPerStackableItem), - createStackableItem("7", 800, 490, 1140, 156, boxCountPerStackableItem), - createStackableItem("8", 800, 2100, 1200, 135, boxCountPerStackableItem), - createStackableItem("9", 1120, 1700, 2120, 160, boxCountPerStackableItem), - createStackableItem("10", 1200, 1050, 2280, 390, boxCountPerStackableItem)); - - PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - List packList = result.getContainers(); - - assertNotNull(packList); - assertTrue(i >= packList.size()); - validate(packList); + try { + for (int i = 1; i <= 10; i++) { + int boxCountPerStackableItem = i; + + List products = Arrays.asList( + createStackableItem("1", 1200, 750, 2280, 285, boxCountPerStackableItem), + createStackableItem("2", 1200, 450, 2280, 155, boxCountPerStackableItem), + createStackableItem("3", 360, 360, 570, 20, boxCountPerStackableItem), + createStackableItem("4", 2250, 1200, 2250, 900, boxCountPerStackableItem), + createStackableItem("5", 1140, 750, 1450, 395, boxCountPerStackableItem), + createStackableItem("6", 1130, 1500, 3100, 800, boxCountPerStackableItem), + createStackableItem("7", 800, 490, 1140, 156, boxCountPerStackableItem), + createStackableItem("8", 800, 2100, 1200, 135, boxCountPerStackableItem), + createStackableItem("9", 1120, 1700, 2120, 160, boxCountPerStackableItem), + createStackableItem("10", 1200, 1050, 2280, 390, boxCountPerStackableItem)); + + PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + List packList = result.getContainers(); + + assertNotNull(packList); + assertTrue(i >= packList.size()); + validate(packList); + } + } finally { + packager.close(); } } @@ -319,20 +348,24 @@ void testCorrectLevelZOffsetAdjustments() { // issue 450 LargestAreaFitFirstPackager packager = LargestAreaFitFirstPackager.newBuilder() .build(); - int boxCountPerStackableItem = 1; - - List products = Arrays.asList( - createStackableItem("1", 1200, 750, 2280, 285, boxCountPerStackableItem), - createStackableItem("2", 1200, 450, 2280, 155, boxCountPerStackableItem), - createStackableItem("3", 360, 360, 570, 20, boxCountPerStackableItem), - createStackableItem("4", 2250, 1200, 2250, 900, boxCountPerStackableItem), - createStackableItem("5", 1140, 750, 1450, 395, boxCountPerStackableItem), - createStackableItem("6", 1130, 1500, 3100, 800, boxCountPerStackableItem), - createStackableItem("7", 800, 490, 1140, 156, boxCountPerStackableItem)); - - PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - List packList = result.getContainers(); - validate(packList); + try { + int boxCountPerStackableItem = 1; + + List products = Arrays.asList( + createStackableItem("1", 1200, 750, 2280, 285, boxCountPerStackableItem), + createStackableItem("2", 1200, 450, 2280, 155, boxCountPerStackableItem), + createStackableItem("3", 360, 360, 570, 20, boxCountPerStackableItem), + createStackableItem("4", 2250, 1200, 2250, 900, boxCountPerStackableItem), + createStackableItem("5", 1140, 750, 1450, 395, boxCountPerStackableItem), + createStackableItem("6", 1130, 1500, 3100, 800, boxCountPerStackableItem), + createStackableItem("7", 800, 490, 1140, 156, boxCountPerStackableItem)); + + PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + List packList = result.getContainers(); + validate(packList); + } finally { + packager.close(); + } } private StackableItem createStackableItem(String id, int width, int height, int depth, int weight, int boxCountPerStackableItem) { @@ -447,14 +480,18 @@ public void testIssue698() { FastLargestAreaFitFirstPackager packager = FastLargestAreaFitFirstPackager .newBuilder() .build(); - PackagerResult result = packager - .newResultBuilder() - .withMaxContainerCount(20) - .withContainers(containerItems) - .withStackables(stackableItems) - .build(); - - assertEquals(true, result.isSuccess()); + try { + PackagerResult result = packager + .newResultBuilder() + .withMaxContainerCount(20) + .withContainers(containerItems) + .withStackables(stackableItems) + .build(); + + assertEquals(true, result.isSuccess()); + } finally { + packager.close(); + } } diff --git a/core/src/test/java/com/github/skjolber/packing/packer/plain/PlainPackagerTest.java b/core/src/test/java/com/github/skjolber/packing/packer/plain/PlainPackagerTest.java index 298d283b..a55a5364 100644 --- a/core/src/test/java/com/github/skjolber/packing/packer/plain/PlainPackagerTest.java +++ b/core/src/test/java/com/github/skjolber/packing/packer/plain/PlainPackagerTest.java @@ -29,15 +29,18 @@ void testStackingSquaresOnSquare() { .build(); PlainPackager packager = PlainPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - assertValid(build); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + assertValid(build); + } finally { + packager.close(); + } } @@ -49,15 +52,18 @@ void testStackingRectangles() { .build(); PlainPackager packager = PlainPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - assertValid(build); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + assertValid(build); + } finally { + packager.close(); + } } @@ -69,16 +75,18 @@ void testStackingSquaresAndRectangle() { .build(); PlainPackager packager = PlainPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(5, 5, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(5, 5, 1).withWeight(1).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - assertValid(build); - + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(5, 10, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(5, 5, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(5, 5, 1).withWeight(1).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + assertValid(build); + } finally { + packager.close(); + } } @Test @@ -89,16 +97,18 @@ void testStackingDecreasingRectangles() { .build(); PlainPackager packager = PlainPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(3, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - assertValid(build); - + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(3, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + assertValid(build); + } finally { + packager.close(); + } } @Test @@ -110,15 +120,18 @@ void testStackingRectanglesTwoLevels() { .build(); PlainPackager packager = PlainPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 2)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 2)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 2)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - assertValid(build); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 2)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 2)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(2, 1, 1).withWeight(1).build(), 2)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + assertValid(build); + } finally { + packager.close(); + } } @@ -131,13 +144,16 @@ void testStackingRectanglesThreeLevels() { .build(); PlainPackager packager = PlainPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(2, 2, 1).withWeight(1).build(), 3)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - assertValid(build); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(2, 2, 1).withWeight(1).build(), 3)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + assertValid(build); + } finally { + packager.close(); + } } @Test @@ -150,14 +166,17 @@ void testStackingNotPossible() { .build(); PlainPackager packager = PlainPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 2, 1).withWeight(1).build(), 18)); // 12 - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); // 1 - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - assertThat(build.getContainers()).isEmpty(); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 2, 1).withWeight(1).build(), 18)); // 12 + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); // 1 + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + assertThat(build.getContainers()).isEmpty(); + } finally { + packager.close(); + } } @Test @@ -175,17 +194,21 @@ void testStackingMultipleContainersSingleContainerResult() { PlainPackager packager = PlainPackager.newBuilder().build(); - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); - assertValid(build); - - Container fits = build.get(0); - assertEquals(fits.getVolume(), containers.get(2).getVolume()); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withStackables(products).build(); + assertValid(build); + + Container fits = build.get(0); + assertEquals(fits.getVolume(), containers.get(2).getVolume()); + } finally { + packager.close(); + } } @Test @@ -205,20 +228,23 @@ void testStackingMultipleContainersMultiContainerResult() { .build(); PlainPackager packager = PlainPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 3)); - products.add(new StackableItem(Box.newBuilder().withDescription("D").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 4)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withMaxContainerCount(5).withStackables(products).build(); - assertValid(build); - - assertEquals(build.size(), 2); - assertEquals(build.get(0).getVolume(), 7); - assertEquals(build.get(1).getVolume(), 3); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 2)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 3)); + products.add(new StackableItem(Box.newBuilder().withDescription("D").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 4)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withMaxContainerCount(5).withStackables(products).build(); + assertValid(build); + + assertEquals(build.size(), 2); + assertEquals(build.get(0).getVolume(), 7); + assertEquals(build.get(1).getVolume(), 3); + } finally { + packager.close(); + } } @Test @@ -233,31 +259,35 @@ void issue440() { PlainPackager packager = PlainPackager.newBuilder() .build(); - for (int i = 1; i <= 10; i++) { - int boxCountPerStackableItem = i; - - List containerItems = ContainerItem - .newListBuilder() - .withContainer(build, i + 2) - .build(); - - List stackableItems = Arrays.asList( - createStackableItem("1", 1200, 750, 2280, 285, boxCountPerStackableItem), - createStackableItem("2", 1200, 450, 2280, 155, boxCountPerStackableItem), - createStackableItem("3", 360, 360, 570, 20, boxCountPerStackableItem), - createStackableItem("4", 2250, 1200, 2250, 900, boxCountPerStackableItem), - createStackableItem("5", 1140, 750, 1450, 395, boxCountPerStackableItem), - createStackableItem("6", 1130, 1500, 3100, 800, boxCountPerStackableItem), - createStackableItem("7", 800, 490, 1140, 156, boxCountPerStackableItem), - createStackableItem("8", 800, 2100, 1200, 135, boxCountPerStackableItem), - createStackableItem("9", 1120, 1700, 2120, 160, boxCountPerStackableItem), - createStackableItem("10", 1200, 1050, 2280, 390, boxCountPerStackableItem)); - - PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(stackableItems).build(); - List packList = result.getContainers(); - - assertNotNull(packList); - assertTrue(i >= packList.size()); + try { + for (int i = 1; i <= 10; i++) { + int boxCountPerStackableItem = i; + + List containerItems = ContainerItem + .newListBuilder() + .withContainer(build, i + 2) + .build(); + + List stackableItems = Arrays.asList( + createStackableItem("1", 1200, 750, 2280, 285, boxCountPerStackableItem), + createStackableItem("2", 1200, 450, 2280, 155, boxCountPerStackableItem), + createStackableItem("3", 360, 360, 570, 20, boxCountPerStackableItem), + createStackableItem("4", 2250, 1200, 2250, 900, boxCountPerStackableItem), + createStackableItem("5", 1140, 750, 1450, 395, boxCountPerStackableItem), + createStackableItem("6", 1130, 1500, 3100, 800, boxCountPerStackableItem), + createStackableItem("7", 800, 490, 1140, 156, boxCountPerStackableItem), + createStackableItem("8", 800, 2100, 1200, 135, boxCountPerStackableItem), + createStackableItem("9", 1120, 1700, 2120, 160, boxCountPerStackableItem), + createStackableItem("10", 1200, 1050, 2280, 390, boxCountPerStackableItem)); + + PackagerResult result = packager.newResultBuilder().withContainers(containerItems).withStackables(stackableItems).build(); + List packList = result.getContainers(); + + assertNotNull(packList); + assertTrue(i >= packList.size()); + } + } finally { + packager.close(); } } @@ -288,19 +318,22 @@ void testStackingSpecificMultipleContainers() { .build(); PlainPackager packager = PlainPackager.newBuilder().build(); - - List products = new ArrayList<>(); - - products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 4)); - products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); - - PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withMaxContainerCount(5).withStackables(products).build(); - assertValid(build); - - assertEquals(build.get(0).getDescription(), "big"); - assertEquals(build.get(1).getDescription(), "small"); - assertEquals(build.get(2).getDescription(), "small"); + try { + List products = new ArrayList<>(); + + products.add(new StackableItem(Box.newBuilder().withDescription("A").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 4)); + products.add(new StackableItem(Box.newBuilder().withDescription("B").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + products.add(new StackableItem(Box.newBuilder().withDescription("C").withRotate3D().withSize(1, 1, 1).withWeight(1).build(), 1)); + + PackagerResult build = packager.newResultBuilder().withContainers(containerItems).withMaxContainerCount(5).withStackables(products).build(); + assertValid(build); + + assertEquals(build.get(0).getDescription(), "big"); + assertEquals(build.get(1).getDescription(), "small"); + assertEquals(build.get(2).getDescription(), "small"); + } finally { + packager.close(); + } } } diff --git a/jmh/src/main/java/com/github/skjolber/packing/jmh/BouwkampCodeBruteForcePackagerState.java b/jmh/src/main/java/com/github/skjolber/packing/jmh/BouwkampCodeBruteForcePackagerState.java index 9941aae0..47a2997b 100644 --- a/jmh/src/main/java/com/github/skjolber/packing/jmh/BouwkampCodeBruteForcePackagerState.java +++ b/jmh/src/main/java/com/github/skjolber/packing/jmh/BouwkampCodeBruteForcePackagerState.java @@ -32,31 +32,26 @@ public class BouwkampCodeBruteForcePackagerState { private final int threadPoolSize; - private final int nth; private ExecutorService pool1; private ExecutorService pool2; private List parallelBruteForcePackager = new ArrayList<>(); - private List parallelBruteForcePackagerNth = new ArrayList<>(); private List bruteForcePackager = new ArrayList<>(); - private List bruteForcePackagerNth = new ArrayList<>(); private List plainPackager = new ArrayList<>(); - private List plainPackagerNth = new ArrayList<>(); private List fastBruteForcePackager = new ArrayList<>(); public BouwkampCodeBruteForcePackagerState() { - this(8, 20000); + this(8); } - public BouwkampCodeBruteForcePackagerState(int threadPoolSize, int nth) { + public BouwkampCodeBruteForcePackagerState(int threadPoolSize) { this.threadPoolSize = threadPoolSize; - this.nth = nth; this.pool1 = Executors.newFixedThreadPool(threadPoolSize, new DefaultThreadFactory()); this.pool2 = Executors.newFixedThreadPool(threadPoolSize, new DefaultThreadFactory()); } - + @Setup(Level.Trial) public void init() { // these does not really result in successful stacking, but still should run as expected @@ -78,29 +73,22 @@ public void init() { List stackableItems3D = BouwkampConverter.getStackableItems3D(bkpLine); ParallelBruteForcePackager parallelPackager = ParallelBruteForcePackager.newBuilder().withExecutorService(pool2).withParallelizationCount(threadPoolSize * 16).build(); - ParallelBruteForcePackager parallelPackagerNth = ParallelBruteForcePackager.newBuilder().withExecutorService(pool1).withParallelizationCount(threadPoolSize * 16) - .withCheckpointsPerDeadlineCheck(nth).build(); BruteForcePackager packager = BruteForcePackager.newBuilder().build(); - BruteForcePackager packagerNth = BruteForcePackager.newBuilder().withCheckpointsPerDeadlineCheck(nth).build(); PlainPackager plainPackager = PlainPackager.newBuilder().build(); - PlainPackager plainPackagerNth = PlainPackager.newBuilder().withCheckpointsPerDeadlineCheck(nth).build(); FastBruteForcePackager fastPackager = FastBruteForcePackager.newBuilder().build(); // single-threaded this.bruteForcePackager.add(new BenchmarkSet(packager, stackableItems3D, containers)); - this.bruteForcePackagerNth.add(new BenchmarkSet(packagerNth, stackableItems3D, containers)); this.plainPackager.add(new BenchmarkSet(plainPackager, stackableItems3D, containers)); - this.plainPackagerNth.add(new BenchmarkSet(plainPackagerNth, stackableItems3D, containers)); this.fastBruteForcePackager.add(new BenchmarkSet(fastPackager, stackableItems3D, containers)); // multi-threaded this.parallelBruteForcePackager.add(new BenchmarkSet(parallelPackager, stackableItems3D, containers)); - this.parallelBruteForcePackagerNth.add(new BenchmarkSet(parallelPackagerNth, stackableItems3D, containers)); } } } @@ -110,6 +98,20 @@ public void shutdown() throws InterruptedException { pool1.shutdown(); pool2.shutdown(); + + for (BenchmarkSet benchmarkSet : parallelBruteForcePackager) { + benchmarkSet.getPackager().close(); + } + for (BenchmarkSet benchmarkSet : bruteForcePackager) { + benchmarkSet.getPackager().close(); + } + for (BenchmarkSet benchmarkSet : plainPackager) { + benchmarkSet.getPackager().close(); + } + for (BenchmarkSet benchmarkSet : fastBruteForcePackager) { + benchmarkSet.getPackager().close(); + } + try { Thread.sleep(500); } catch (Exception e) { @@ -121,26 +123,14 @@ public List getBruteForcePackager() { return bruteForcePackager; } - public List getBruteForcePackagerNth() { - return bruteForcePackagerNth; - } - public List getParallelBruteForcePackager() { return parallelBruteForcePackager; } - public List getParallelBruteForcePackagerNth() { - return parallelBruteForcePackagerNth; - } - public List getPlainPackager() { return plainPackager; } - public List getPlainPackagerNth() { - return plainPackagerNth; - } - public List getFastBruteForcePackager() { return fastBruteForcePackager; } diff --git a/jmh/src/main/java/com/github/skjolber/packing/jmh/DeadlineBenchmark.java b/jmh/src/main/java/com/github/skjolber/packing/jmh/DeadlineBenchmark.java index d54515a6..040164d3 100644 --- a/jmh/src/main/java/com/github/skjolber/packing/jmh/DeadlineBenchmark.java +++ b/jmh/src/main/java/com/github/skjolber/packing/jmh/DeadlineBenchmark.java @@ -44,11 +44,6 @@ public Object parallelPackagerDeadline(BouwkampCodeBruteForcePackagerState state return process(state.getParallelBruteForcePackager(), System.currentTimeMillis() + 10000); } - @Benchmark - public Object parallelPackagerDeadlineNth(BouwkampCodeBruteForcePackagerState state) throws Exception { - return process(state.getParallelBruteForcePackagerNth(), System.currentTimeMillis() + 10000); - } - @Benchmark public Object packagerNoDeadline(BouwkampCodeBruteForcePackagerState state) throws Exception { return process(state.getBruteForcePackager(), -1L); @@ -59,11 +54,6 @@ public Object packagerDeadline(BouwkampCodeBruteForcePackagerState state) throws return process(state.getBruteForcePackager(), System.currentTimeMillis() + 30000); } - @Benchmark - public Object packagerDeadlineNth(BouwkampCodeBruteForcePackagerState state) throws Exception { - return process(state.getBruteForcePackagerNth(), System.currentTimeMillis() + 30000); - } - public int process(List sets, long deadline) { int i = 0; for (BenchmarkSet set : sets) { diff --git a/jmh/src/main/java/com/github/skjolber/packing/jmh/EgyPackagerState.java b/jmh/src/main/java/com/github/skjolber/packing/jmh/EgyPackagerState.java index 126d3c59..27be007a 100644 --- a/jmh/src/main/java/com/github/skjolber/packing/jmh/EgyPackagerState.java +++ b/jmh/src/main/java/com/github/skjolber/packing/jmh/EgyPackagerState.java @@ -39,17 +39,13 @@ public class EgyPackagerState { private final int threadPoolSize; - private final int nth; private ExecutorService pool1; private ExecutorService pool2; private List parallelBruteForcePackager = new ArrayList<>(); - private List parallelBruteForcePackagerNth = new ArrayList<>(); private List bruteForcePackager = new ArrayList<>(); - private List bruteForcePackagerNth = new ArrayList<>(); private List plainPackager = new ArrayList<>(); - private List plainPackagerNth = new ArrayList<>(); private List fastBruteForcePackager = new ArrayList<>(); private static List stackableItems3D; @@ -74,12 +70,11 @@ public class EgyPackagerState { } public EgyPackagerState() { - this(8, 20000); + this(8); } - public EgyPackagerState(int threadPoolSize, int nth) { + public EgyPackagerState(int threadPoolSize) { this.threadPoolSize = threadPoolSize; - this.nth = nth; this.pool1 = Executors.newFixedThreadPool(threadPoolSize, new DefaultThreadFactory()); this.pool2 = Executors.newFixedThreadPool(threadPoolSize, new DefaultThreadFactory()); @@ -89,29 +84,22 @@ public EgyPackagerState(int threadPoolSize, int nth) { public void init() { ParallelBruteForcePackager parallelPackager = ParallelBruteForcePackager.newBuilder().withExecutorService(pool2).withParallelizationCount(threadPoolSize * 16) .build(); - ParallelBruteForcePackager parallelPackagerNth = ParallelBruteForcePackager.newBuilder().withExecutorService(pool1).withParallelizationCount(threadPoolSize * 16) - .withCheckpointsPerDeadlineCheck(nth).build(); BruteForcePackager packager = BruteForcePackager.newBuilder().build(); - BruteForcePackager packagerNth = BruteForcePackager.newBuilder().withCheckpointsPerDeadlineCheck(nth).build(); PlainPackager plainPackager = PlainPackager.newBuilder().build(); - PlainPackager plainPackagerNth = PlainPackager.newBuilder().withCheckpointsPerDeadlineCheck(nth).build(); FastBruteForcePackager fastPackager = FastBruteForcePackager.newBuilder().build(); // single-threaded this.bruteForcePackager.add(new BenchmarkSet(packager, stackableItems3D, containers)); - this.bruteForcePackagerNth.add(new BenchmarkSet(packagerNth, stackableItems3D, containers)); this.plainPackager.add(new BenchmarkSet(plainPackager, stackableItems3D, containers)); - this.plainPackagerNth.add(new BenchmarkSet(plainPackagerNth, stackableItems3D, containers)); this.fastBruteForcePackager.add(new BenchmarkSet(fastPackager, stackableItems3D, containers)); // multi-threaded this.parallelBruteForcePackager.add(new BenchmarkSet(parallelPackager, stackableItems3D, containers)); - this.parallelBruteForcePackagerNth.add(new BenchmarkSet(parallelPackagerNth, stackableItems3D, containers)); } public static Container getContainer(List items) { @@ -171,6 +159,19 @@ public void shutdown() throws InterruptedException { pool1.shutdown(); pool2.shutdown(); + for (BenchmarkSet benchmarkSet : parallelBruteForcePackager) { + benchmarkSet.getPackager().close(); + } + for (BenchmarkSet benchmarkSet : bruteForcePackager) { + benchmarkSet.getPackager().close(); + } + for (BenchmarkSet benchmarkSet : plainPackager) { + benchmarkSet.getPackager().close(); + } + for (BenchmarkSet benchmarkSet : fastBruteForcePackager) { + benchmarkSet.getPackager().close(); + } + try { Thread.sleep(500); } catch (Exception e) { @@ -182,26 +183,14 @@ public List getBruteForcePackager() { return bruteForcePackager; } - public List getBruteForcePackagerNth() { - return bruteForcePackagerNth; - } - public List getParallelBruteForcePackager() { return parallelBruteForcePackager; } - public List getParallelBruteForcePackagerNth() { - return parallelBruteForcePackagerNth; - } - public List getPlainPackager() { return plainPackager; } - public List getPlainPackagerNth() { - return plainPackagerNth; - } - public List getFastBruteForcePackager() { return fastBruteForcePackager; } diff --git a/jmh/src/main/java/com/github/skjolber/packing/jmh/TychoPackagerState.java b/jmh/src/main/java/com/github/skjolber/packing/jmh/TychoPackagerState.java index 30796ded..e016549d 100644 --- a/jmh/src/main/java/com/github/skjolber/packing/jmh/TychoPackagerState.java +++ b/jmh/src/main/java/com/github/skjolber/packing/jmh/TychoPackagerState.java @@ -30,17 +30,13 @@ public class TychoPackagerState { private final int threadPoolSize; - private final int nth; private ExecutorService pool1; private ExecutorService pool2; private List parallelBruteForcePackager = new ArrayList<>(); - private List parallelBruteForcePackagerNth = new ArrayList<>(); private List bruteForcePackager = new ArrayList<>(); - private List bruteForcePackagerNth = new ArrayList<>(); private List plainPackager = new ArrayList<>(); - private List plainPackagerNth = new ArrayList<>(); private List fastBruteForcePackager = new ArrayList<>(); private List stackableItems3D; @@ -49,12 +45,11 @@ public class TychoPackagerState { .withContainer(Container.newBuilder().withDescription("1").withEmptyWeight(1).withSize(1500, 1900, 4000).withMaxLoadWeight(100).build()).build(); public TychoPackagerState() { - this(8, 20000); + this(8); } - public TychoPackagerState(int threadPoolSize, int nth) { + public TychoPackagerState(int threadPoolSize) { this.threadPoolSize = threadPoolSize; - this.nth = nth; this.pool1 = Executors.newFixedThreadPool(threadPoolSize, new DefaultThreadFactory()); this.pool2 = Executors.newFixedThreadPool(threadPoolSize, new DefaultThreadFactory()); @@ -64,29 +59,21 @@ public TychoPackagerState(int threadPoolSize, int nth) { public void init() { ParallelBruteForcePackager parallelPackager = ParallelBruteForcePackager.newBuilder().withExecutorService(pool2).withParallelizationCount(threadPoolSize * 16) .build(); - ParallelBruteForcePackager parallelPackagerNth = ParallelBruteForcePackager.newBuilder().withExecutorService(pool1).withParallelizationCount(threadPoolSize * 16) - .withCheckpointsPerDeadlineCheck(nth).build(); BruteForcePackager packager = BruteForcePackager.newBuilder().build(); - BruteForcePackager packagerNth = BruteForcePackager.newBuilder().withCheckpointsPerDeadlineCheck(nth).build(); PlainPackager plainPackager = PlainPackager.newBuilder().build(); - PlainPackager plainPackagerNth = PlainPackager.newBuilder().withCheckpointsPerDeadlineCheck(nth).build(); FastBruteForcePackager fastPackager = FastBruteForcePackager.newBuilder().build(); // single-threaded this.bruteForcePackager.add(new BenchmarkSet(packager, stackableItems3D, containers)); - this.bruteForcePackagerNth.add(new BenchmarkSet(packagerNth, stackableItems3D, containers)); this.plainPackager.add(new BenchmarkSet(plainPackager, stackableItems3D, containers)); - this.plainPackagerNth.add(new BenchmarkSet(plainPackagerNth, stackableItems3D, containers)); - this.fastBruteForcePackager.add(new BenchmarkSet(fastPackager, stackableItems3D, containers)); // multi-threaded this.parallelBruteForcePackager.add(new BenchmarkSet(parallelPackager, stackableItems3D, containers)); - this.parallelBruteForcePackagerNth.add(new BenchmarkSet(parallelPackagerNth, stackableItems3D, containers)); } @TearDown(Level.Trial) @@ -94,6 +81,19 @@ public void shutdown() throws InterruptedException { pool1.shutdown(); pool2.shutdown(); + for (BenchmarkSet benchmarkSet : parallelBruteForcePackager) { + benchmarkSet.getPackager().close(); + } + for (BenchmarkSet benchmarkSet : bruteForcePackager) { + benchmarkSet.getPackager().close(); + } + for (BenchmarkSet benchmarkSet : plainPackager) { + benchmarkSet.getPackager().close(); + } + for (BenchmarkSet benchmarkSet : fastBruteForcePackager) { + benchmarkSet.getPackager().close(); + } + try { Thread.sleep(500); } catch (Exception e) { @@ -105,25 +105,14 @@ public List getBruteForcePackager() { return bruteForcePackager; } - public List getBruteForcePackagerNth() { - return bruteForcePackagerNth; - } - public List getParallelBruteForcePackager() { return parallelBruteForcePackager; } - public List getParallelBruteForcePackagerNth() { - return parallelBruteForcePackagerNth; - } - public List getPlainPackager() { return plainPackager; } - public List getPlainPackagerNth() { - return plainPackagerNth; - } public List getFastBruteForcePackager() { return fastBruteForcePackager; diff --git a/visualizer/packaging/src/test/java/com/github/skjolber/packing/visualizer/packaging/BruteForcePackagerTest.java b/visualizer/packaging/src/test/java/com/github/skjolber/packing/visualizer/packaging/BruteForcePackagerTest.java index 5ff9b959..5218f5b2 100644 --- a/visualizer/packaging/src/test/java/com/github/skjolber/packing/visualizer/packaging/BruteForcePackagerTest.java +++ b/visualizer/packaging/src/test/java/com/github/skjolber/packing/visualizer/packaging/BruteForcePackagerTest.java @@ -24,7 +24,7 @@ public class BruteForcePackagerTest extends AbstractPackagerTest { public void testSimpleImperfectSquaredRectangles() throws Exception { // this will take quite some time - BruteForcePackager packager = BruteForcePackager.newBuilder().withCheckpointsPerDeadlineCheck(1024).build(); + BruteForcePackager packager = BruteForcePackager.newBuilder().build(); BouwkampCodeDirectory directory = BouwkampCodeDirectory.getInstance(); diff --git a/visualizer/packaging/src/test/java/com/github/skjolber/packing/visualizer/packaging/ParallelBruteForcePackagerTest.java b/visualizer/packaging/src/test/java/com/github/skjolber/packing/visualizer/packaging/ParallelBruteForcePackagerTest.java index d24cb6f1..c2dbca8d 100644 --- a/visualizer/packaging/src/test/java/com/github/skjolber/packing/visualizer/packaging/ParallelBruteForcePackagerTest.java +++ b/visualizer/packaging/src/test/java/com/github/skjolber/packing/visualizer/packaging/ParallelBruteForcePackagerTest.java @@ -26,7 +26,7 @@ public class ParallelBruteForcePackagerTest extends AbstractPackagerTest { public void testSimpleImperfectSquaredRectangles() throws Exception { // if you do not have a lot of CPU cores, this will take quite some time - ParallelBruteForcePackager packager = ParallelBruteForcePackager.newBuilder().withExecutorService(executorService).withParallelizationCount(256).withCheckpointsPerDeadlineCheck(1024).build(); + ParallelBruteForcePackager packager = ParallelBruteForcePackager.newBuilder().withExecutorService(executorService).withParallelizationCount(256).build(); BouwkampCodeDirectory directory = BouwkampCodeDirectory.getInstance();