diff --git a/jsprit-core/src/main/java/jsprit/core/problem/Capacity.java b/jsprit-core/src/main/java/jsprit/core/problem/Capacity.java new file mode 100644 index 00000000..a0ec0d4e --- /dev/null +++ b/jsprit-core/src/main/java/jsprit/core/problem/Capacity.java @@ -0,0 +1,71 @@ +package jsprit.core.problem; + + +public class Capacity { + + public static class Builder { + + /** + * default is 1 dimension with size of zero + */ + private int[] dimensions = new int[1]; + + public static Builder newInstance(){ + return new Builder(); + } + + Builder(){} + + /** + * add capacity dimension + * + *

if automatically resizes dimensions according to index, i.e. if index=7 there are 8 dimensions. + * + * @throw IllegalStateException if dimValue < 0 + * @param index + * @param dimValue + * @return + */ + public Builder addDimension(int index, int dimValue){ + if(dimValue<0) throw new IllegalStateException("dimValue can never be negative"); + if(index < dimensions.length){ + dimensions[index] = dimValue; + } + else{ + int requiredSize = index + 1; + int[] newDimensions = new int[requiredSize]; + copy(dimensions,newDimensions); + newDimensions[index]=dimValue; + this.dimensions=newDimensions; + } + return this; + } + + private void copy(int[] from, int[] to) { + for(int i=0;i