-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
2,713 additions
and
9 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
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
70 changes: 70 additions & 0 deletions
70
api/src/main/java/com/github/skjolber/packing/api/packager/LoadableItemGroup.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,70 @@ | ||
package com.github.skjolber.packing.api.packager; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* | ||
* Items which belong together, for example different parts of a single product or order. | ||
* | ||
*/ | ||
|
||
public class LoadableItemGroup { | ||
|
||
private String id; | ||
private List<LoadableItem> items; | ||
|
||
public LoadableItemGroup(String id, List<LoadableItem> items) { | ||
super(); | ||
this.id = id; | ||
this.items = items; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public List<LoadableItem> getItems() { | ||
return items; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public void setItems(List<LoadableItem> items) { | ||
this.items = items; | ||
} | ||
|
||
public int size() { | ||
return items.size(); | ||
} | ||
|
||
public int loadableItemsCount() { | ||
int count = 0; | ||
for (LoadableItem loadableItem : items) { | ||
count += loadableItem.getCount(); | ||
} | ||
return count; | ||
} | ||
|
||
public boolean isEmpty() { | ||
for (LoadableItem loadableItem : items) { | ||
if(!loadableItem.isEmpty()) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public void removeEmpty() { | ||
for (int j = 0; j < items.size(); j++) { | ||
LoadableItem loadableItem = items.get(j); | ||
|
||
if(loadableItem.isEmpty()) { | ||
items.remove(j); | ||
j--; | ||
} | ||
} | ||
} | ||
} |
10 changes: 7 additions & 3 deletions
10
api/src/main/java/com/github/skjolber/packing/api/packager/LoadableItems.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 |
---|---|---|
@@ -1,13 +1,17 @@ | ||
package com.github.skjolber.packing.api.packager; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* | ||
* The items which are available for load into some particular container. | ||
* | ||
*/ | ||
|
||
public interface LoadableItems extends List<LoadableItem>{ | ||
public interface LoadableItems { | ||
|
||
int size(); | ||
|
||
LoadableItem get(int index); | ||
|
||
void remove(int index, int count); | ||
|
||
} |
110 changes: 110 additions & 0 deletions
110
...n/java/com/github/skjolber/packing/iterator/AbstractLoadableItemGroupIteratorBuilder.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,110 @@ | ||
package com.github.skjolber.packing.iterator; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import com.github.skjolber.packing.api.Dimension; | ||
import com.github.skjolber.packing.api.StackValue; | ||
import com.github.skjolber.packing.api.Stackable; | ||
import com.github.skjolber.packing.api.StackableItem; | ||
import com.github.skjolber.packing.api.StackableItemGroup; | ||
import com.github.skjolber.packing.api.packager.Loadable; | ||
import com.github.skjolber.packing.api.packager.LoadableItem; | ||
import com.github.skjolber.packing.api.packager.LoadableItemGroup; | ||
|
||
/** | ||
* Builder scaffold. | ||
* | ||
* @see <a href= | ||
* "https://www.sitepoint.com/self-types-with-javas-generics/">https://www.sitepoint.com/self-types-with-javas-generics/</a> | ||
*/ | ||
|
||
public abstract class AbstractLoadableItemGroupIteratorBuilder<B extends AbstractLoadableItemGroupIteratorBuilder<B>> { | ||
|
||
protected int maxLoadWeight = -1; | ||
protected Predicate<Stackable> filter; | ||
protected Dimension size; | ||
protected List<StackableItemGroup> stackableItemGroups; | ||
|
||
public B withSize(int dx, int dy, int dz) { | ||
this.size = new Dimension(dx, dy, dz); | ||
|
||
return (B)this; | ||
} | ||
|
||
public B withLoadSize(Dimension dimension) { | ||
this.size = dimension; | ||
|
||
return (B)this; | ||
} | ||
|
||
public B withFilter(Predicate<Stackable> filter) { | ||
this.filter = filter; | ||
|
||
return (B)this; | ||
} | ||
|
||
public B withMaxLoadWeight(int maxLoadWeight) { | ||
this.maxLoadWeight = maxLoadWeight; | ||
|
||
return (B)this; | ||
} | ||
|
||
public B withStackableItemGroups(List<StackableItemGroup> stackableItems) { | ||
this.stackableItemGroups = stackableItems; | ||
|
||
return (B)this; | ||
} | ||
|
||
protected List<LoadableItemGroup> toMatrix() { | ||
List<LoadableItemGroup> results = new ArrayList<>(stackableItemGroups.size()); | ||
|
||
int offset = 0; | ||
|
||
for (int i = 0; i < stackableItemGroups.size(); i++) { | ||
|
||
StackableItemGroup group = stackableItemGroups.get(i); | ||
|
||
List<LoadableItem> loadableItems = new ArrayList<>(group.size()); | ||
for (int k = 0; k < group.size(); k++) { | ||
StackableItem item = group.get(k); | ||
|
||
if(item.getCount() == 0) { | ||
continue; | ||
} | ||
|
||
Stackable stackable = item.getStackable(); | ||
if(stackable.getWeight() > maxLoadWeight) { | ||
continue; | ||
} | ||
|
||
if(stackable.getVolume() > size.getVolume()) { | ||
continue; | ||
} | ||
|
||
List<StackValue> boundRotations = stackable.rotations(size); | ||
if(boundRotations == null || boundRotations.isEmpty()) { | ||
continue; | ||
} | ||
|
||
if(filter != null && !filter.test(stackable)) { | ||
continue; | ||
} | ||
|
||
Loadable loadable = new Loadable(stackable, boundRotations); | ||
|
||
loadableItems.add(new LoadableItem(loadable, item.getCount(), offset)); | ||
|
||
offset++; | ||
} | ||
if(!loadableItems.isEmpty()) { | ||
results.add(new LoadableItemGroup(group.getId(), loadableItems)); | ||
} | ||
} | ||
return results; | ||
} | ||
|
||
public abstract LoadableItemPermutationRotationIterator build(); | ||
|
||
} |
95 changes: 95 additions & 0 deletions
95
core/src/main/java/com/github/skjolber/packing/iterator/AbstractLoadableIteratorBuilder.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,95 @@ | ||
package com.github.skjolber.packing.iterator; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import com.github.skjolber.packing.api.Dimension; | ||
import com.github.skjolber.packing.api.StackValue; | ||
import com.github.skjolber.packing.api.Stackable; | ||
import com.github.skjolber.packing.api.StackableItem; | ||
import com.github.skjolber.packing.api.packager.Loadable; | ||
import com.github.skjolber.packing.api.packager.LoadableItem; | ||
import com.github.skjolber.packing.api.packager.LoadableItems; | ||
|
||
/** | ||
* Builder scaffold. | ||
* | ||
* @see <a href= | ||
* "https://www.sitepoint.com/self-types-with-javas-generics/">https://www.sitepoint.com/self-types-with-javas-generics/</a> | ||
*/ | ||
|
||
public abstract class AbstractLoadableIteratorBuilder<B extends AbstractLoadableIteratorBuilder<B>> { | ||
|
||
protected int maxLoadWeight = -1; | ||
protected Predicate<Stackable> filter; | ||
protected Dimension size; | ||
protected List<StackableItem> stackableItems; | ||
|
||
public B withSize(int dx, int dy, int dz) { | ||
this.size = new Dimension(dx, dy, dz); | ||
|
||
return (B)this; | ||
} | ||
|
||
public B withLoadSize(Dimension dimension) { | ||
this.size = dimension; | ||
|
||
return (B)this; | ||
} | ||
|
||
public B withFilter(Predicate<Stackable> filter) { | ||
this.filter = filter; | ||
|
||
return (B)this; | ||
} | ||
|
||
public B withMaxLoadWeight(int maxLoadWeight) { | ||
this.maxLoadWeight = maxLoadWeight; | ||
|
||
return (B)this; | ||
} | ||
|
||
public B withStackableItems(List<StackableItem> stackableItems) { | ||
this.stackableItems = stackableItems; | ||
|
||
return (B)this; | ||
} | ||
|
||
protected LoadableItem[] toMatrix() { | ||
LoadableItem[] results = new LoadableItem[stackableItems.size()]; | ||
|
||
for (int i = 0; i < stackableItems.size(); i++) { | ||
StackableItem item = stackableItems.get(i); | ||
|
||
if(item.getCount() == 0) { | ||
continue; | ||
} | ||
|
||
Stackable stackable = item.getStackable(); | ||
if(stackable.getWeight() > maxLoadWeight) { | ||
continue; | ||
} | ||
|
||
if(stackable.getVolume() > size.getVolume()) { | ||
continue; | ||
} | ||
|
||
List<StackValue> boundRotations = stackable.rotations(size); | ||
if(boundRotations == null || boundRotations.isEmpty()) { | ||
continue; | ||
} | ||
|
||
if(filter != null && !filter.test(stackable)) { | ||
continue; | ||
} | ||
|
||
Loadable loadable = new Loadable(stackable, boundRotations); | ||
|
||
results[i] = new LoadableItem(loadable, item.getCount(), i); | ||
} | ||
return results; | ||
} | ||
|
||
public abstract LoadableItemPermutationRotationIterator build(); | ||
|
||
} |
Oops, something went wrong.