/** * Sets the borders of the location generator such that it spans the * specified area. The min position is <code>(0,0)</code>, and max is * <code>(sqrt(area),sqrt(area))</code>. * @param area The area to use. * @return This, as per the builder pattern. */ public Builder squareByArea(double area) { return square(Math.sqrt(area)); }
.announceTimes( TimeSeries.homogenousPoisson(4 * 60 * 60 * 1000L, 10)) .locations(Locations.builder().square(5).buildUniform()) .timeWindows(TimeWindows.builder().build()) .build())
.build())) .locations(Locations.builder() .min(new Point(0, 0)) .max(new Point(10, 10)) .mean(new Point(2, 3)) .std(3) .redrawWhenOutOfBounds() .buildNormal()) .build()) .vehicles(
/** * Tests whether the fixed location generator handles the inputs correctly. */ @Test public void testFixed() { final LocationGenerator lg = Locations.builder().buildFixed( asList(new Point(0, 0), new Point(1, 1))); assertAlwaysEquals(lg); assertEquals(new Point(.5, .5), lg.getCenter()); assertEquals(new Point(0, 0), lg.getMin()); assertEquals(new Point(1, 1), lg.getMax()); final LocationGenerator lg2 = Locations.builder() .min(-6.3) .max(9.3) .mean(0.1) .buildFixed( asList(new Point(0, 0), new Point(1, 1))); assertAlwaysEquals(lg2); assertEquals(new Point(.1, .1), lg2.getCenter()); assertEquals(new Point(-6.3, -6.3), lg2.getMin()); assertEquals(new Point(9.3, 9.3), lg2.getMax()); TestUtil.testPrivateConstructor(Locations.class); }
/** * Create a uniform distributed {@link LocationGenerator}. The min and max * values set to this builder take precedence over the mean and standard * deviations. In case the boundaries were set any specified means and * standard deviations are ignored when generating the locations. However, * the mean as supplied to this builder will be returned in the * {@link LocationGenerator#getCenter()} method. * @return A uniform distributed generator. */ public LocationGenerator buildUniform() { final Point xMinMax = getUniformMinMax(xMin, xMax, xMean, xSd); final Point yMinMax = getUniformMinMax(yMin, yMax, yMean, ySd); final Point min = new Point(xMinMax.x, yMinMax.x); final Point max = new Point(xMinMax.y, yMinMax.y); final double xCenter = getUniformCenter(xMean, min.x, max.x); final double yCenter = getUniformCenter(yMean, min.y, max.y); return new SupplierLocGen( min, max, new Point(xCenter, yCenter), uniformDouble(min.x, max.x), uniformDouble(min.y, max.y)); }
/** * An error should be thrown when a wrong number of locations is requested. */ @Test(expected = IllegalArgumentException.class) public void testFixedFail() { Locations.builder().buildFixed(asList(new Point(0, 0), new Point(1, 1))) .generate(0L, 3); }
/** * @return A {@link Builder} for creating {@link LocationGenerator}s. */ public static Builder builder() { return new Builder(); }