Skip to content

Commit

Permalink
Prototype constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
skjolber committed Aug 26, 2024
1 parent b2efb5c commit 58a0aa1
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.skjolber.packing.api;

public interface ContainerLoadConstraint {

boolean canLoad(Stackable stackable, Container container);

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

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 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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.github.skjolber.packing.api;

/**
*
* Interface for reporting whether it is okey to add a stackable to a stack, given the addition of another stackable.
*
* This might be used to limit the number of special packages in each container, i.e. only one battery per contaner.
*
*/

public interface StackableLoadConstraint {

boolean canLoad(Stackable stackable, Stackable loaded);

}
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);

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

public class DefaultLoadableItemScope implements LoadableItemScope {

protected final List<LoadableItem> loadableItems;

public DefaultLoadableItemScope(List<LoadableItem> loadableItems) {
this.loadableItems = loadableItems;
}

@Override
public List<LoadableItem> getLoadableItems() {
return loadableItems;
}

@Override
public boolean loaded(int index) {
LoadableItem loadableItem = loadableItems.get(index);
loadableItem.decrement();
if(loadableItem.isEmpty()) {
loadableItems.remove(index);
}
return false;
}

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

import java.util.Comparator;

import com.github.skjolber.packing.api.StackValue;
import com.github.skjolber.packing.api.Stackable;

@FunctionalInterface
public interface PlacementComparator<L> {
public interface LoadComparator<L> {

/**
* See {@linkplain Comparator#compare(Object, Object)}.<br>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.github.skjolber.packing.api.packager;

import java.util.List;

import com.github.skjolber.packing.api.StackValue;
import com.github.skjolber.packing.api.Stackable;

/**
*
* Stackable item which fit within certain bounds, i.e. load dimensions of a container.
*
*/

public class LoadableItem {

protected final List<StackValue> values;
protected final Stackable stackable;

private int count;

protected final long minVolumeLimit;
protected final long minAreaLimit;

public LoadableItem(Stackable stackable, List<StackValue> stackValues, int count) {
this.values = stackValues;
this.stackable = stackable;
this.count = count;

long minVolumeLimit = Long.MAX_VALUE;
long minAreaLimit = Long.MAX_VALUE;

for (int i = 0; i < values.size(); i++) {
StackValue stackValue = values.get(i);

if(minVolumeLimit > stackValue.getVolume()) {
minVolumeLimit = stackValue.getVolume();
}

if(minAreaLimit > stackValue.getArea()) {
minAreaLimit = stackValue.getArea();
}
}

this.minAreaLimit = minAreaLimit;
this.minVolumeLimit = minVolumeLimit;
}

public List<StackValue> getValues() {
return values;
}

public long getMinAreaLimit() {
return minAreaLimit;
}

public long getMinVolumeLimit() {
return minVolumeLimit;
}

public Stackable getStackable() {
return stackable;
}

public int getCount() {
return count;
}

public void decrement() {
count--;
}

public boolean isEmpty() {
return count == 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.github.skjolber.packing.api.packager;

import java.util.List;

/**
*
* The items which are available for load into some particular container.
*
*/

public interface LoadableItemScope {

List<LoadableItem> getLoadableItems();

/**
*
* Notify item was loaded
*
* @param index
* @return true if some loadable item was excluded due to this
*/

boolean loaded(int index);
}

0 comments on commit 58a0aa1

Please sign in to comment.