-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ACE: Add Maximum Rectangles packing algorithm implementation. Some cl…
…ean-up and refactor.
- Loading branch information
1 parent
f66ea4a
commit a8e0d82
Showing
11 changed files
with
207 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 0 additions & 166 deletions
166
Core/src/main/java/com/polytech4A/cuttingstock/core/packing/GuillotineSortBFFRM.java
This file was deleted.
Oops, something went wrong.
54 changes: 0 additions & 54 deletions
54
Core/src/main/java/com/polytech4A/cuttingstock/core/packing/GuillotineSortBFFSortBin.java
This file was deleted.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
Core/src/main/java/com/polytech4A/cuttingstock/core/packing/MaxRectsBAF.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.polytech4A.cuttingstock.core.packing; | ||
|
||
import com.polytech4A.cuttingstock.core.model.Box; | ||
import com.polytech4A.cuttingstock.core.model.Pattern; | ||
import com.polytech4A.cuttingstock.core.model.PlacedBox; | ||
import com.polytech4A.cuttingstock.core.model.Vector; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
|
||
/** | ||
* Created by Adrien CHAUSSENDE on 09/05/2015. | ||
* | ||
* @author Adrien CHAUSSENDE | ||
* @version 1.0 | ||
*/ | ||
public class MaxRectsBAF extends GuillotineSortBAF { | ||
|
||
public MaxRectsBAF(ArrayList<Comparator<Box>> boxComparators) { | ||
super(boxComparators); | ||
} | ||
|
||
@Override | ||
public void generateSubBins(Bin bin, PlacedBox placedBox, ArrayList<Bin> bins) { | ||
Vector sizeBox; | ||
Bin bintoCreate; | ||
if (placedBox.isRotation()) { | ||
sizeBox = placedBox.getSize().getInvertedVector(); | ||
} else { | ||
sizeBox = placedBox.getSize(); | ||
} | ||
//Horizontal cut | ||
Vector sizeBin = new Vector(bin.getSize().getX(), bin.getSize().getY() - sizeBox.getY()); | ||
Vector originBin = new Vector(bin.getOrigin().getX(), bin.getOrigin().getY() + sizeBox.getY()); | ||
if (!sizeBin.isDimensionNull()) { | ||
bintoCreate = new MaxRectsBin(sizeBin, bin.getPattern(), originBin); | ||
bin.getHorizontalsubBin().add(bintoCreate); | ||
bins.add(bintoCreate); | ||
} | ||
|
||
//Vertical cut | ||
sizeBin = new Vector(bin.getSize().getX() - sizeBox.getX(), bin.getSize().getY()); | ||
originBin = new Vector(bin.getOrigin().getX() + sizeBox.getX(), bin.getOrigin().getY()); | ||
if (!sizeBin.isDimensionNull()) { | ||
bintoCreate = new MaxRectsBin(sizeBin, bin.getPattern(), originBin); | ||
bin.getVerticalsubBin().add(bintoCreate); | ||
bins.add(bintoCreate); | ||
} | ||
} | ||
|
||
@Override | ||
public Pattern generatePattern(Pattern p, Comparator<Box> comparator) { | ||
ArrayList<Box> boxes = p.getBoxes(); | ||
Collections.sort(boxes, Collections.reverseOrder(comparator)); | ||
Bin bin = new MaxRectsBin(p.getSize(), p, new Vector(0, 0)); | ||
ArrayList<Bin> bins = new ArrayList<>(); | ||
bins.add(bin); | ||
ArrayList<PlacedBox> placedBoxes = generatePlacedBoxes(boxes, bins); | ||
if (placedBoxes != null) { | ||
Pattern retPattern = new Pattern(p.getSize(), p.getAmounts()); | ||
retPattern.setPlacedBoxes(placedBoxes); | ||
return retPattern; | ||
} | ||
return p; | ||
} | ||
} |
Oops, something went wrong.