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 15 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class AbstractContainerBuilder<B extends AbstractContainerBuilder<B>> {
protected int loadDy = -1; // y
protected int loadDz = -1; // z

protected StackConstraint stackConstraint;
protected StackValueConstraint stackConstraint;

protected List<Surface> surfaces;

Expand All @@ -48,7 +48,7 @@ public B withLoadSize(int dx, int dy, int dz) {
return (B)this;
}

public B withStackConstraint(StackConstraint stackConstraint) {
public B withStackConstraint(StackValueConstraint stackConstraint) {
this.stackConstraint = stackConstraint;
return (B)this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@SuppressWarnings("unchecked")
public class AbstractPhysicsBuilder<B extends AbstractPhysicsBuilder<B>> {

protected StackConstraint constraint;
protected StackValueConstraint constraint;
protected Dimension size;
protected StackableSurface stackableSurface;

Expand All @@ -34,7 +34,7 @@ public B withStackableSurface(StackableSurface stackableSurface) {
return (B)this;
}

public B withConstraint(StackConstraint stackConstraint) {
public B withConstraint(StackValueConstraint stackConstraint) {
this.constraint = stackConstraint;
return (B)this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,24 @@ protected <T> T[] getStackValues() {
// z y
// | /
// | /
// | /-------/|
// | / xy / |
// | / / |
// | |-------| |
// | | | |
// | | | y |
// | | xz | z |
// | | | |
// | | | |
// | | | /
// | | | /
// | |-------|/
// | /---------/|
// | / xy / |
// | / / |
// | |---------| |
// | | | |
// | | | y |
// | | xz | z |
// | | | |
// | | | |
// | | | /
// | | | /
// | |---------|/
// | /
// |/
// |------------------ x
//

// two square sides, the other 4 sides are equal (but can be rotated)
// add xz/yz and xy

if(stackableSurface.isXY()) {
Expand Down Expand Up @@ -134,6 +135,7 @@ protected <T> T[] getStackValues() {
// |----------------------------------- x
//

// two square sides, the other 4 sides are equal (but can be rotated)
// add xz/xy and yz

if(stackableSurface.isYZ()) {
Expand All @@ -154,8 +156,6 @@ protected <T> T[] getStackValues() {

} else if(dx == dz) {

// add xy/zy and xz

//
// z y
// | /
Expand All @@ -175,6 +175,8 @@ protected <T> T[] getStackValues() {
// |/
// |------------------ x
//
// two square sides, the other 4 sides are equal (but can be rotated)
// add xy/zy and xz

if(stackableSurface.isXZ()) {
list.add(newStackValue(dx, dx, dy, constraint, stackableSurface.getXZSurfaces()));
Expand Down Expand Up @@ -291,6 +293,6 @@ protected <T> T[] getStackValues() {

protected abstract <T> T[] newStackValueArray(int size);

protected abstract BoxStackValue newStackValue(int dx, int dy, int dz, StackConstraint constraint, List<Surface> surfaces);
protected abstract BoxStackValue newStackValue(int dx, int dy, int dz, StackValueConstraint constraint, List<Surface> surfaces);

}
25 changes: 22 additions & 3 deletions api/src/main/java/com/github/skjolber/packing/api/Box.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected <T> T[] newStackValueArray(int size) {
return (T[])new BoxStackValue[size];
}

protected BoxStackValue newStackValue(int dx, int dy, int dz, StackConstraint constraint, List<Surface> surfaces) {
protected BoxStackValue newStackValue(int dx, int dy, int dz, StackValueConstraint constraint, List<Surface> surfaces) {
return new BoxStackValue(dx, dy, dz, constraint, surfaces);
}
}
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class BoxStackValue extends StackValue {

private Box stackable;

public BoxStackValue(int dx, int dy, int dz, StackConstraint constraint, List<Surface> surfaces) {
public BoxStackValue(int dx, int dy, int dz, StackValueConstraint constraint, List<Surface> surfaces) {
super(dx, dy, dz, constraint, surfaces);
}

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

public class ConstrainedStackPlacement extends StackPlacement {



public ConstrainedStackPlacement() {
super();
}

public ConstrainedStackPlacement(Stackable stackable, StackValue value, int x, int y, int z) {
super(stackable, value, x, y, z);
}



}
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.ContainerLoadInputsFilterBuilder;

/**
*
* Interface for handling which {@linkplain StackableItem}, or combinations of {@linkplain StackableItem} go into a Container.
*
*/

public interface ContainerConstraint {

ContainerLoadInputsFilterBuilder<?> newStackableItemsFilterBuilder();

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class ContainerStackValue extends StackValue {

public ContainerStackValue(
int dx, int dy, int dz,
StackConstraint constraint,
StackValueConstraint constraint,
int loadDx, int loadDy, int loadDz, int maxLoadWeight, List<Surface> surfaces) {
super(dx, dy, dz, constraint, surfaces);

Expand Down
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
Expand Up @@ -8,7 +8,7 @@ public class DefaultContainerStackValue extends ContainerStackValue {

public DefaultContainerStackValue(
int dx, int dy, int dz,
StackConstraint constraint,
StackValueConstraint constraint,
int loadDx, int loadDy, int loadDz,
int maxLoadWeight, List<Surface> sides) {
super(dx, dy, dz, constraint, loadDx, loadDy, loadDz, maxLoadWeight, sides);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class FixedContainerStackValue extends ContainerStackValue {

public FixedContainerStackValue(
int dx, int dy, int dz,
StackConstraint constraint,
StackValueConstraint constraint,
int stackWeight, int emptyWeight,
int loadDx, int loadDy, int loadDz, int maxLoadWeight, List<Surface> surfaces) {
super(dx, dy, dz, constraint, loadDx, loadDy, loadDz, maxLoadWeight, surfaces);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.github.skjolber.packing.api;

import java.util.List;

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

/**
*
* Constraint for load (weight) on a {@linkplain StackValue};
*
*/

public interface LoadBearingConstraint {

List<BoundedStackable> filter(List<BoundedStackable> stackables);

boolean canAdd(StackValue value, int x, int y, int z, int weight);

void add(StackPlacement stackPlacement, int weight);

void append(StackValue value, int weight);

void canAppend(StackValue value, int weight);

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

/**
*
* Load bearing constraint for a stacked {@linkplain Stackable}.
*
*/

@SuppressWarnings("unchecked")
public abstract class LoadBearingConstraintBuilder<B extends LoadBearingConstraintBuilder<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 B withStackPlacement(StackPlacement stackPlacement) {
this.stackPlacement = stackPlacement;
return (B)this;
}

public abstract LoadBearingConstraint build();



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

public enum LoadBearingConstraintType {

NONE, // no weight bearing
WEIGHT, // total weight limit
PRESSURE, // weight per area limit
COUNT // specific kind of stackable (i.e. the same type)

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

public enum LoadBearingStackableConstraintType {

ALL, // no restrictions
SET, // set of stackable
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.github.skjolber.packing.api;

public class PressureLoadBearingConstraint implements LoadBearingConstraint {


private int maximumPressure;

@Override
public boolean canLoad(StackValue value, int x, int y, int z, int weight) {
return weight / ;
}

@Override
public void loaded(StackValue value, int x, int y, int z, int weight) {
currentWeight += weight;
}

}
Loading
Loading