/** * @return true if input {@link ResourceRequirement} exceeds the hard bound long any dimension. If the parameter * orEqual is true, then matching along any dimension will also return true. */ public boolean exceedsHardBound(ResourceRequirement requirement, boolean orEqual) { return VectorAlgebra.exceedsVector(this.hardBound, requirement.getResourceVector(), orEqual); }
/** * @return true if input {@link ResourceRequirement} exceeds the soft bound long any dimension. If the parameter * orEqual is true, then matching along any dimension will also return true. */ public boolean exceedsSoftBound(ResourceRequirement requirement, boolean orEqual) { return VectorAlgebra.exceedsVector(this.softBound, requirement.getResourceVector(), orEqual); }
/** * Stringify a {@link ResourceRequirement} with the appropriate dimension labels. */ public String stringifyRequirement(ResourceRequirement requirement) { return vectorToString(requirement.getResourceVector()); }
/** * @return a new {@link ResourcePool} which is a copy of this {@link ResourcePool} except its resource vector has been * reduced by the input {@link ResourceRequirement}. */ protected ResourcePool contractPool(ResourceRequirement requirement) { return new ResourcePool(VectorAlgebra.addVector(this.softBound, requirement.getResourceVector(), -1., null), VectorAlgebra.addVector(this.hardBound, requirement.getResourceVector(), -1., null), this.defaultResourceUse, this.dimensionIndex); }
ResourceRequirement copyInto(ResourceRequirement reuse) { if (reuse == null) { return new ResourceRequirement(this.resourceVector.clone()); } else { System.arraycopy(this.resourceVector, 0, reuse.getResourceVector(), 0, this.resourceVector.length); return reuse; } }
@Override public T next() { RequestWithResourceRequirement<T> nextElement = this.underlying.next(); VectorAlgebra.addVector(this.currentRequirement, nextElement.getResourceRequirement().getResourceVector(), 1.0, this.currentRequirement); return nextElement.getT(); }
@Test public void test() { ResourcePool pool = ResourcePool.builder().maxResource(MEMORY, 1000.).maxResource(TIME, 200.).tolerance(MEMORY, 2.) .defaultRequirement(TIME, 1.).build(); Assert.assertEquals(pool.getNumDimensions(), 2); Assert.assertEquals(pool.getSoftBound(), new double[]{1000, 200}); // Default tolerance is 1.2 Assert.assertEquals(pool.getHardBound(), new double[]{2000, 240}); // Test default resource use Assert.assertEquals(pool.getResourceRequirementBuilder().build().getResourceVector(), new double[]{0, 1}); ResourceRequirement requirement = pool.getResourceRequirementBuilder().setRequirement(MEMORY, 10.).build(); Assert.assertEquals(requirement.getResourceVector(), new double[]{10, 1}); }
/** * @return true if input {@link ResourceRequirement} exceeds the soft bound long any dimension. If the parameter * orEqual is true, then matching along any dimension will also return true. */ public boolean exceedsSoftBound(ResourceRequirement requirement, boolean orEqual) { return VectorAlgebra.exceedsVector(this.softBound, requirement.getResourceVector(), orEqual); }
/** * @return true if input {@link ResourceRequirement} exceeds the hard bound long any dimension. If the parameter * orEqual is true, then matching along any dimension will also return true. */ public boolean exceedsHardBound(ResourceRequirement requirement, boolean orEqual) { return VectorAlgebra.exceedsVector(this.hardBound, requirement.getResourceVector(), orEqual); }
/** * Stringify a {@link ResourceRequirement} with the appropriate dimension labels. */ public String stringifyRequirement(ResourceRequirement requirement) { return vectorToString(requirement.getResourceVector()); }
/** * @return a new {@link ResourcePool} which is a copy of this {@link ResourcePool} except its resource vector has been * reduced by the input {@link ResourceRequirement}. */ protected ResourcePool contractPool(ResourceRequirement requirement) { return new ResourcePool(VectorAlgebra.addVector(this.softBound, requirement.getResourceVector(), -1., null), VectorAlgebra.addVector(this.hardBound, requirement.getResourceVector(), -1., null), this.defaultResourceUse, this.dimensionIndex); }
ResourceRequirement copyInto(ResourceRequirement reuse) { if (reuse == null) { return new ResourceRequirement(this.resourceVector.clone()); } else { System.arraycopy(this.resourceVector, 0, reuse.getResourceVector(), 0, this.resourceVector.length); return reuse; } }
@Override public T next() { RequestWithResourceRequirement<T> nextElement = this.underlying.next(); VectorAlgebra.addVector(this.currentRequirement, nextElement.getResourceRequirement().getResourceVector(), 1.0, this.currentRequirement); return nextElement.getT(); }