From 7ae360376fab5d77798c1d7868c2ee38ca69dac8 Mon Sep 17 00:00:00 2001 From: Slashgear Date: Sun, 26 Apr 2015 14:53:13 +0200 Subject: [PATCH] ACN:Add new Packing Algorithm. Bins are sorted to optimize bin choosing.' --- .../packing/GuillotineSortBFFSortBin.java | 54 +++++++++++++++++++ .../core/resolution/Resolution.java | 6 +-- .../packing/GuillotineSortBFFSortBinTest.java | 30 +++++++++++ 3 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 Core/src/main/java/com/polytech4A/cuttingstock/core/packing/GuillotineSortBFFSortBin.java create mode 100644 Core/src/test/java/com/polytech4A/cuttingstock/core/packing/GuillotineSortBFFSortBinTest.java diff --git a/Core/src/main/java/com/polytech4A/cuttingstock/core/packing/GuillotineSortBFFSortBin.java b/Core/src/main/java/com/polytech4A/cuttingstock/core/packing/GuillotineSortBFFSortBin.java new file mode 100644 index 0000000..d4e19bb --- /dev/null +++ b/Core/src/main/java/com/polytech4A/cuttingstock/core/packing/GuillotineSortBFFSortBin.java @@ -0,0 +1,54 @@ +/* + * + * * Project to resolve 2D cutting stock problem for Discreet Optimizations course at Polytech Lyon + * * Copyright (C) 2015. CARON Antoine and CHAUSSENDE Adrien + * * + * * This program is free software: you can redistribute it and/or modify + * * it under the terms of the GNU Affero General Public License as + * * published by the Free Software Foundation, either version 3 of the + * * License, or (at your option) any later version. + * * + * * This program is distributed in the hope that it will be useful, + * * but WITHOUT ANY WARRANTY; without even the implied warranty of + * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * * GNU Affero General Public License for more details. + * * + * * You should have received a copy of the GNU Affero General Public License + * * along with this program. If not, see . + * + */ + +package com.polytech4A.cuttingstock.core.packing; + +import com.polytech4A.cuttingstock.core.model.Box; +import com.polytech4A.cuttingstock.core.model.PlacedBox; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; + +/** + * Created by Antoine CARON on 26/04/2015. + * + * @author Antoine CARON + * @version 1.0 + */ +public class GuillotineSortBFFSortBin extends GuillotineSortBFF { + + public GuillotineSortBFFSortBin(ArrayList> boxComparators) { + super(boxComparators); + } + + /** + * Place the box on the pattern. + * + * @param bins List of bins that will be generated. + * @param box Box to be placed. + * @return The box that is now placed. Return null if it can't be placed. + */ + @Override + public PlacedBox generatePlacedBox(ArrayList bins, Box box) { + Collections.sort(bins); + return super.generatePlacedBox(bins, box); + } +} diff --git a/Core/src/main/java/com/polytech4A/cuttingstock/core/resolution/Resolution.java b/Core/src/main/java/com/polytech4A/cuttingstock/core/resolution/Resolution.java index edbb346..ba3f71f 100644 --- a/Core/src/main/java/com/polytech4A/cuttingstock/core/resolution/Resolution.java +++ b/Core/src/main/java/com/polytech4A/cuttingstock/core/resolution/Resolution.java @@ -24,7 +24,7 @@ import com.polytech4A.cuttingstock.core.model.Box; import com.polytech4A.cuttingstock.core.model.Pattern; import com.polytech4A.cuttingstock.core.model.Solution; -import com.polytech4A.cuttingstock.core.packing.GuillotineSortBFF; +import com.polytech4A.cuttingstock.core.packing.GuillotineSortBFFSortBin; import com.polytech4A.cuttingstock.core.resolution.util.context.Context; import com.polytech4A.cuttingstock.core.resolution.util.context.ContextLoaderUtils; import com.polytech4A.cuttingstock.core.resolution.util.context.IllogicalContextException; @@ -144,7 +144,7 @@ public void solve(Integer nbofIterations) { } generators.add(new RemovePatternNeighbour()); solver = new SimulatedAnnealing( - new GuillotineSortBFF(boxComparators), + new GuillotineSortBFFSortBin(boxComparators), new LinearResolutionMethod(context), generators, nbofIterations @@ -167,7 +167,7 @@ private Solution getStartingSolution() { generators.add(new MoveNeighbour()); generators.add(new RemovePatternNeighbour()); SimulatedAnnealing realSolutionGenerator = new SimulatedAnnealing( - new GuillotineSortBFF(boxComparators), + new GuillotineSortBFFSortBin(boxComparators), new LinearResolutionMethod(context), generators, 10000); diff --git a/Core/src/test/java/com/polytech4A/cuttingstock/core/packing/GuillotineSortBFFSortBinTest.java b/Core/src/test/java/com/polytech4A/cuttingstock/core/packing/GuillotineSortBFFSortBinTest.java new file mode 100644 index 0000000..f242e37 --- /dev/null +++ b/Core/src/test/java/com/polytech4A/cuttingstock/core/packing/GuillotineSortBFFSortBinTest.java @@ -0,0 +1,30 @@ +/* + * + * * Project to resolve 2D cutting stock problem for Discreet Optimizations course at Polytech Lyon + * * Copyright (C) 2015. CARON Antoine and CHAUSSENDE Adrien + * * + * * This program is free software: you can redistribute it and/or modify + * * it under the terms of the GNU Affero General Public License as + * * published by the Free Software Foundation, either version 3 of the + * * License, or (at your option) any later version. + * * + * * This program is distributed in the hope that it will be useful, + * * but WITHOUT ANY WARRANTY; without even the implied warranty of + * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * * GNU Affero General Public License for more details. + * * + * * You should have received a copy of the GNU Affero General Public License + * * along with this program. If not, see . + * + */ + +package com.polytech4A.cuttingstock.core.packing; + +/** + * Created by Antoine CARON on 26/04/2015. + * + * @author Antoine CARON + * @version 1.0 + */ +public class GuillotineSortBFFSortBinTest extends GuillotineSortBFFTest { +} \ No newline at end of file