Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve constraints and order of packaging #923

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
23 changes: 21 additions & 2 deletions api/src/main/java/com/github/skjolber/packing/api/Box.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ protected BoxStackValue newStackValue(int dx, int dy, int dz, StackConstraint co
protected final long minimumArea;
protected final long maximumArea;

public Box(String id, String name, long volume, int weight, BoxStackValue[] stackValues) {
super(id, name);
protected final String id;
protected final String description;

public Box(String id, String description, long volume, int weight, BoxStackValue[] stackValues) {
this.id = id;
this.description = description;

this.volume = volume;
this.weight = weight;
this.stackValues = stackValues;
Expand All @@ -65,6 +70,16 @@ public Box(String id, String name, long volume, int weight, BoxStackValue[] stac
boxStackValue.setStackable(this);
}
}

@Override
public String getDescription() {
return description;
}

@Override
public String getId() {
return id;
}

@Override
public int getWeight() {
Expand All @@ -88,6 +103,10 @@ public Box clone() {
}
return new Box(id, description, volume, weight, stackValues);
}

public StackValue getStackValue(int index) {
return stackValues[index];
}

@Override
public long getMinimumArea() {
Expand Down
18 changes: 16 additions & 2 deletions api/src/main/java/com/github/skjolber/packing/api/Container.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,13 @@ protected ContainerStackValue[] getStackValues() {
protected final long minArea;
protected final long maxArea;

public Container(String id, String name, long volume, int emptyWeight, long maxLoadVolume, int maxLoadWeight, long minArea, long maxArea) {
super(id, name);
protected final String id;
protected final String description;

public Container(String id, String description, long volume, int emptyWeight, long maxLoadVolume, int maxLoadWeight, long minArea, long maxArea) {
this.id = id;
this.description = description;

this.emptyWeight = emptyWeight;
this.maxLoadVolume = maxLoadVolume;
this.maxLoadWeight = maxLoadWeight;
Expand All @@ -159,6 +163,16 @@ public Container(String id, String name, long volume, int emptyWeight, long maxL
this.maxArea = maxArea;
}

@Override
public String getDescription() {
return description;
}

@Override
public String getId() {
return id;
}

@Override
public int getWeight() {
return emptyWeight + getStack().getWeight();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.github.skjolber.packing.api;

import com.github.skjolber.packing.api.packager.StackableItemsFilterBuilder;

/**
*
* Interface for handling which Stackables, or combinations of Stackables go into a Container.
*
*/

public interface ContainerConstraint {

StackableItemsFilterBuilder<?> newLoadableFilterBuilder();

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public ContainerStackValue[] getStackValues() {
public Stack getStack() {
return stack;
}

public ContainerStackValue getStackValue(int index) {
return stackValues[index];
}

@Override
public DefaultContainer clone() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.skjolber.packing.api;

public interface GravitySupport {

void loaded(StackPlacement stackPlacement);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.github.skjolber.packing.api;

/**
* Builder scaffold.
*
* @see <a href=
* "https://www.sitepoint.com/self-types-with-javas-generics/">https://www.sitepoint.com/self-types-with-javas-generics/</a>
*/

@SuppressWarnings("unchecked")
public abstract class GravitySupportBuilder<B extends GravitySupportBuilder<B>> {

protected Container container;
protected ContainerStackValue stackValue;
protected Stack stack;
protected StackPlacement stackPlacement;

public B withContainer(Container container) {
this.container = container;
return (B)this;
}

public B withStack(Stack stack) {
this.stack = stack;
return (B)this;
}

public B withStackValue(ContainerStackValue stackValue) {
this.stackValue = stackValue;
return (B)this;
}

public abstract GravitySupport build();



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.github.skjolber.packing.api;

/**
* Builder scaffold.
*
* @see <a href=
* "https://www.sitepoint.com/self-types-with-javas-generics/">https://www.sitepoint.com/self-types-with-javas-generics/</a>
*/

@SuppressWarnings("unchecked")
public abstract class PlacementSupportBuilder<B extends PlacementSupportBuilder<B>> {

protected Container container;
protected ContainerStackValue stackValue;
protected Stack stack;

public B withContainer(Container container) {
this.container = container;
return (B)this;
}

public B withStack(Stack stack) {
this.stack = stack;
return (B)this;
}

public B withStackValue(ContainerStackValue stackValue) {
this.stackValue = stackValue;
return (B)this;
}

public abstract GravitySupport build();



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.skjolber.packing.api;

public interface StackValueConstraint {

GravitySupportBuilder<?> newGravitySupportBuilder();


}
19 changes: 4 additions & 15 deletions api/src/main/java/com/github/skjolber/packing/api/Stackable.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,15 @@ public abstract class Stackable implements Serializable {

private static final long serialVersionUID = 1L;

protected final String id;
protected final String description;

public Stackable(String id, String description) {
super();
this.id = id;
this.description = description;
}

public abstract long getVolume();

public abstract int getWeight();

public abstract StackValue[] getStackValues();

public String getDescription() {
return description;
}
public abstract String getDescription();

public String getId() {
return id;
}
public abstract String getId();

public List<StackValue> fitsInside(Dimension bound) {
List<StackValue> list = new ArrayList<>();
Expand All @@ -42,6 +29,8 @@ public List<StackValue> fitsInside(Dimension bound) {

return list;
}

public abstract StackValue getStackValue(int index);

@Override
public abstract Stackable clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class StackableItem implements Serializable {

private static final long serialVersionUID = 1L;

private final int count;
private final Stackable stackable;
protected int count;
protected final Stackable stackable;

public StackableItem(Stackable box) {
this(box, 1);
Expand All @@ -36,5 +36,21 @@ public Stackable getStackable() {
public String toString() {
return String.format("%dx%s", count, stackable);
}

public void decrement() {
count--;
}

public boolean isEmpty() {
return count == 0;
}

public void decrement(int value) {
this.count = this.count - value;
}

public StackableItem clone() {
return new StackableItem(stackable, count);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.github.skjolber.packing.api;

import java.util.ArrayList;
import java.util.List;

/**
*
* Items which belong together, for example different parts of a single product or order.
*
*/

public class StackableItemGroup {

private String id;

private List<StackableItem> items;

public StackableItemGroup(String id, List<StackableItem> items) {
super();
this.id = id;
this.items = items;
}

public String getId() {
return id;
}

public List<StackableItem> getItems() {
return items;
}

public void setId(String id) {
this.id = id;
}

public void setItems(List<StackableItem> items) {
this.items = items;
}

public int size() {
return items.size();
}

public StackableItem get(int i) {
return items.get(i);
}


public int stackableItemsCount() {
int count = 0;
for (StackableItem loadableItem : items) {
count += loadableItem.getCount();
}
return count;
}

public boolean isEmpty() {
for (StackableItem loadableItem : items) {
if(!loadableItem.isEmpty()) {
return false;
}
}

return true;
}

public void removeEmpty() {
for (int j = 0; j < items.size(); j++) {
StackableItem loadableItem = items.get(j);

if(loadableItem.isEmpty()) {
items.remove(j);
j--;
}
}
}

public StackableItemGroup clone() {
List<StackableItem> items = new ArrayList<>();

for (StackableItem stackableItem : this.items) {
items.add(stackableItem.clone());
}

return new StackableItemGroup(id, items);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.github.skjolber.packing.api.ep;
import java.util.List;

import com.github.skjolber.packing.api.ep.Point3D;

/**
* Constraint describing where a box can be placed within a stack.
* For example, a flammable item must be stacked by the door.
*/

public interface Point3DFilter {

List<Point3D> filter(List<Point3D> points);

}
Loading
Loading