private void splat(PointF start, PointF end, PointF mid, float d) { Path firstPath = new Path(); if (d < 0) { d = 0; } firstPath.moveTo(start.x, start.y); firstPath.quadTo(mid.x, mid.y, end.x, end.y); fCurrentOperation.addPath(firstPath, d); float dst = dist(start.x, start.y, end.x, end.y); int quarterDrips = fDrips / 4; int nbDrips = quarterDrips + RANDOM.nextInt(fDrips); for (int i = 0; i < nbDrips; i++) { // positioning of splotch varies between ±4dd, tending towards 0 float x4 = dst * getProbability(0.5f); float y4 = dst * getProbability(0.5f); // direction of splotch varies between ±0.5 float x5 = getProbability(0.5f); float y5 = getProbability(0.5f); float dd = Math.min(d * (RANDOM.nextFloat() + 0.4f), d); Path subPath = new Path(); subPath.moveTo(start.x + x4, start.y + y4); subPath.lineTo(start.x + x4 + x5, start.y + y4 + y5); fCurrentOperation.addPath(subPath, dd); } }
private void generateAndAddOrder() { Entity order = dataDefinitionService.get(L_ORDERS_PLUGIN_IDENTIFIER, L_ORDERS_MODEL_ORDER).create(); long dateFrom = generateRandomDate(); long dateTo = generateRandomDate(dateFrom); Preconditions.checkArgument(dateTo > dateFrom, "Order was finished before it was started !"); Entity product = getRandomProduct(); Entity technology = (getDefaultTechnologyForProduct(product) == null) ? getRandomProduct() : getDefaultTechnologyForProduct(product); String number = generateString(CHARS_AND_DIGITS, RANDOM.nextInt(34) + 5); order.setField(L_NUMBER, number); order.setField(L_NAME, getNameFromNumberAndPrefix("Order-", number)); order.setField("dateFrom", new Date(dateFrom)); order.setField("dateTo", new Date(dateTo)); order.setField(STATE_L, "01pending"); order.setField(L_BASIC_MODEL_PRODUCT, product); order.setField("plannedQuantity", RANDOM.nextInt(100) + 100); order.setField("doneQuantity", RANDOM.nextInt(100) + 1); order.setField(L_TECHNOLOGY_MODEL_TECHNOLOGY, technology); order.setField("externalSynchronized", true); order.setField("typeOfProductionRecording", "01basic"); order.setField("trackingRecordTreatment", "01duringProduction"); dataDefinitionService.get(L_ORDERS_PLUGIN_IDENTIFIER, L_ORDERS_MODEL_ORDER).save(order); }
/** Tests the constructors of class MultivariatePolyaDistributionTest. */ @Override public void testConstructors() { System.out.println("Constructors"); MultivariatePolyaDistribution instance = new MultivariatePolyaDistribution(); assertEquals( MultivariatePolyaDistribution.DEFAULT_DIMENSIONALITY, instance.getInputDimensionality()); assertEquals(MultivariatePolyaDistribution.DEFAULT_NUM_TRIALS, instance.getNumTrials()); int dim = RANDOM.nextInt(100) + 10; int numTrials = RANDOM.nextInt(100) + 10; instance = new MultivariatePolyaDistribution(dim, numTrials); assertEquals(dim, instance.getInputDimensionality()); assertEquals(numTrials, instance.getNumTrials()); Vector p = VectorFactory.getDefault().createUniformRandom(dim, 0.0, 10.0, RANDOM); instance = new MultivariatePolyaDistribution(p, numTrials); assertSame(p, instance.getParameters()); assertEquals(numTrials, instance.getNumTrials()); MultivariatePolyaDistribution i2 = new MultivariatePolyaDistribution(instance); assertNotSame(i2.getParameters(), instance.getParameters()); assertEquals(i2.getParameters(), instance.getParameters()); assertEquals(i2.getNumTrials(), instance.getNumTrials()); }
private String generateWorkingHours(final String locale) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 8); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); long minHours = calendar.getTimeInMillis(); calendar.set(Calendar.HOUR_OF_DAY, 20); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); long maxHours = calendar.getTimeInMillis(); long workBeginHours = (long) (RANDOM.nextDouble() * (maxHours / 2 - minHours) + minHours); long workEndHours = (long) (RANDOM.nextDouble() * (maxHours - workBeginHours) + workBeginHours); Date workBeginDate = new Date(workBeginHours); Date workEndDate = new Date(workEndHours); StringBuilder workingHours = new StringBuilder(); SimpleDateFormat hourFormat = new SimpleDateFormat("HH:mm", LocaleUtils.toLocale(locale)); workingHours .append(hourFormat.format(workBeginDate)) .append("-") .append(hourFormat.format(workEndDate)); return workingHours.toString(); }
public void paint(GC gc) { int i = 2 * x + 1; if (values == null || i >= values.length) { return; } int value = getNextValue() * (90 + RANDOM.nextInt(20)) / 100 + RANDOM.nextInt(4) - 2; if (value > 100) { value = 100; } else if (value < -100) { value = -100; } int fx = y + value * channelHeight / 100; values[i] = fx; gc.setForeground(white); gc.setLineWidth(1); gc.drawPolyline(values); gc.setForeground(black); gc.setLineWidth(2); gc.drawRectangle(x, fx, 2, 2); if (++x >= width) { x = 0; } }
private Entity addOperationComponent( final Entity technology, final Entity parent, final Entity operation, final int productsComponentsQuantity) { Preconditions.checkNotNull(technology, "Technology entity is null"); Entity operationComponent = dataDefinitionService .get(L_TECHNOLOGIES_PLUGIN_IDENTIFIER, "technologyOperationComponent") .create(); int productInComponentQuantity = RANDOM.nextInt(productsComponentsQuantity); int productOutComponentQuantity = productsComponentsQuantity - productInComponentQuantity; operationComponent.setField( L_NAME, "operationComponent" + generateString(CHARS_AND_DIGITS, 15)); operationComponent.setField(L_NUMBER, generateString(CHARS_AND_DIGITS, 20)); operationComponent.setField(L_TECHNOLOGY_MODEL_TECHNOLOGY, technology); operationComponent.setField("parent", parent); operationComponent.setField(L_TECHNOLOGY_MODEL_OPERATION, operation); operationComponent.setField("entityType", L_TECHNOLOGY_MODEL_OPERATION); operationComponent.setField(L_TPZ, operation.getField(L_TPZ)); operationComponent.setField(L_TJ, operation.getField(L_TJ)); operationComponent.setField("machineUtilization", operation.getField("machineUtilization")); operationComponent.setField("laborUtilization", operation.getField("laborUtilization")); operationComponent.setField("productionInOneCycle", operation.getField("productionInOneCycle")); operationComponent.setField( L_NEXT_OPERATION_AFTER_PRODUCED_TYPE, operation.getField(L_NEXT_OPERATION_AFTER_PRODUCED_TYPE)); operationComponent.setField("nextOperationAfterProducedQuantity", "0"); operationComponent.setField("timeNextOperation", operation.getField("timeNextOperation")); operationComponent = operationComponent.getDataDefinition().save(operationComponent); List<Entity> listOut = new LinkedList<Entity>(); Entity productOut = null; for (int i = 0; i < productOutComponentQuantity; i++) { productOut = getRandomProduct(); while (listOut.contains(productOut)) { productOut = getRandomProduct(); } listOut.add(productOut); generateAndAddOperationProductOutComponent( operationComponent, new BigDecimal(RANDOM.nextInt(50) + 5), productOut); } List<Entity> listIn = new LinkedList<Entity>(); Entity productIn = null; for (int i = 0; i < productInComponentQuantity; i++) { productIn = getRandomProduct(); while (listIn.contains(productIn)) { productIn = getRandomProduct(); } listIn.add(productIn); generateAndAddOperationProductInComponent( operationComponent, new BigDecimal(RANDOM.nextInt(50) + 5), productIn); } return operationComponent; }
private void generateAndAddWorkPlan() { Entity workPlan = dataDefinitionService.get("workPlans", "workPlan").create(); workPlan.setField( L_NAME, getNameFromNumberAndPrefix( "WorkPlan-", 5 + generateString(CHARS_AND_DIGITS, RANDOM.nextInt(45)))); workPlan.setField("date", new Date(generateRandomDate())); workPlan.setField( "worker", getNameFromNumberAndPrefix( "Worker-", 5 + generateString(CHARS_AND_DIGITS, RANDOM.nextInt(45)))); workPlan.setField("generated", false); workPlan.setField("type", "01noDistinction"); workPlan = workPlan.getDataDefinition().save(workPlan); List<Entity> allOrders = dataDefinitionService.get("orders", L_ORDERS_MODEL_ORDER).find().list().getEntities(); int iters = RANDOM.nextInt(allOrders.size() / 30 + 1); for (int i = 0; i < iters; i++) { addWorkPlanComponent(workPlan, allOrders); } }
@Test(expectedExceptions = IllegalArgumentException.class) public void testInsufficientData() { final TimeSeries<Long, Double> subSeries = RANDOM.subSeries(RANDOM.getTimeAt(0), RANDOM.getTimeAt(3)); SAMPLE_ACF.evaluate( new FastArrayLongDoubleTimeSeries( ENCODING, subSeries.timesArray(), subSeries.valuesArray())); }
@Override public MultivariatePolyaDistribution createInstance() { final double r = 10.0; int N = 6; Vector a = VectorFactory.getDefault() .copyValues(r * RANDOM.nextDouble(), r * RANDOM.nextDouble(), r * RANDOM.nextDouble()); return new MultivariatePolyaDistribution(a, N); }
@Test // TODO if this interpolator cannot get the answer right then an exception should be thrown public void testFlat() { final double x1 = 10 * RANDOM.nextDouble(); final double x2 = 10 * RANDOM.nextDouble(); final double x3 = 10 * RANDOM.nextDouble(); // Fails utterly for flat surface since the variogram function will be zero for all r final InterpolatorND interpolator = new KrigingInterpolatorND(1.99); final InterpolatorNDDataBundle dataBundle = interpolator.getDataBundle(FLAT_DATA); assertEquals(INTERPOLATOR.interpolate(dataBundle, new double[] {x1, x2, x3}), 0, 0); }
private void generateAndAddStaff() { Entity staff = dataDefinitionService.get(L_BASIC_PLUGIN_IDENTIFIER, L_BASIC_MODEL_STAFF).create(); String number = generateString(DIGITS_ONLY, RANDOM.nextInt(40) + 5); staff.setField(L_NUMBER, number); staff.setField(L_NAME, getNameFromNumberAndPrefix("Staff-", number)); staff.setField("surname", generateString(CHARS_ONLY, RANDOM.nextInt(12))); staff.setField("post", generateString(CHARS_ONLY, RANDOM.nextInt(5))); dataDefinitionService.get(L_BASIC_PLUGIN_IDENTIFIER, L_BASIC_MODEL_STAFF).save(staff); }
@Override public void spawnServerSide( EntityPlayer player, NBTTagCompound dataFromClient, NBTTagCompound rewardData) { for (int i = 0; i < dataFromClient.getInteger(AMOUNTOFORBS_KEY); i++) { double X = player.posX, Y = player.posY, Z = player.posZ; X += (0.5 - RANDOM.nextDouble()); Z += (0.5 - RANDOM.nextDouble()); player.worldObj.spawnEntityInWorld( new EntityXPOrb(player.worldObj, X, Y, Z, RANDOM.nextInt(5) + 1)); } }
private void generateAndAddShift(final String locale) { Entity shift = dataDefinitionService.get(L_BASIC_PLUGIN_IDENTIFIER, "shift").create(); shift.setField( L_NAME, getNameFromNumberAndPrefix("Shift-", generateString(CHARS_ONLY, RANDOM.nextInt(40) + 5))); for (int i = 0; i < SHIFT_HOURS.length; i++) { shift.setField(WORK_SHIFT[i], RANDOM.nextBoolean()); shift.setField(SHIFT_HOURS[i], generateWorkingHours(locale)); } dataDefinitionService.get(L_BASIC_PLUGIN_IDENTIFIER, "shift").save(shift); }
private void addSubstituteToProduct(final Entity product) { Entity substitute = dataDefinitionService.get(L_BASIC_PLUGIN_IDENTIFIER, "substitute").create(); String number = generateString(DIGITS_ONLY, RANDOM.nextInt(34) + 5); substitute.setField(L_NUMBER, number); substitute.setField(L_NAME, getNameFromNumberAndPrefix("ProductSubstitute-", number)); substitute.setField(L_BASIC_MODEL_PRODUCT, product); substitute.setField("priority", RANDOM.nextInt(7)); substitute = dataDefinitionService.get(L_BASIC_PLUGIN_IDENTIFIER, "substitute").save(substitute); addSubstituteComponent( substitute, getRandomProduct(), RANDOM.nextInt(997) * RANDOM.nextDouble()); }
private void generateAndAddWorkstationType() { Entity machine = dataDefinitionService .get(L_BASIC_PLUGIN_IDENTIFIER, L_BASIC_MODEL_WORKSTATION_TYPE) .create(); String number = generateString(CHARS_AND_DIGITS, RANDOM.nextInt(40) + 5); machine.setField(L_NAME, getNameFromNumberAndPrefix("Workstation type-", number)); machine.setField(L_NUMBER, number); machine.setField("description", generateString(CHARS_ONLY, RANDOM.nextInt(100))); dataDefinitionService .get(L_BASIC_PLUGIN_IDENTIFIER, L_BASIC_MODEL_WORKSTATION_TYPE) .save(machine); }
@Override public void testPDFKnownValues() { System.out.println("PDF.knownValues"); for (int i = 0; i < 100; i++) { UniformDistribution.PDF instance = this.createInstance().getProbabilityFunction(); double a = instance.getMinSupport(); double b = instance.getMaxSupport(); double x = (RANDOM.nextDouble() * (b - a + 2)) + a - 1; double h = 1 / (b - a); double y; if (x < a) { y = 0; } else if (x > b) { y = 0; } else { y = h; } double yhat = instance.evaluate(x); assertEquals(y, yhat); assertEquals(h, instance.evaluate(a)); assertEquals(h, instance.evaluate(b)); } }
/** Test of getNumTrials method, of class MultivariatePolyaDistribution. */ public void testGetNumTrials() { System.out.println("getNumTrials"); int numTrials = RANDOM.nextInt(100) + 1; MultivariatePolyaDistribution instance = this.createInstance(); instance.setNumTrials(numTrials); assertEquals(numTrials, instance.getNumTrials()); }
private final float getRandomValueB() { if (this.mMinValueB == this.mMaxValueB) { return this.mMaxValueB; } else { return RANDOM.nextFloat() * (this.mMaxValueB - this.mMinValueB) + this.mMinValueB; } }
protected Vector createCopy(Vector vector) { if (RANDOM.nextBoolean()) { return DenseVectorFactoryMTJ.INSTANCE.copyVector(vector); } else { return SparseVectorFactoryMTJ.INSTANCE.copyVector(vector); } }
/** * Test of getMaxSupport method, of class * gov.sandia.cognition.learning.util.statistics.UniformDistribution. */ public void testGetMaxX() { System.out.println("getMaxX"); double a = RANDOM.nextGaussian(); double b = a + 1; UniformDistribution instance = new UniformDistribution(a, b); assertEquals(b, instance.getMaxSupport()); }
@Override public void testCDFConstructors() { System.out.println("CDF Constructor"); UniformDistribution.CDF u = new UniformDistribution.CDF(); assertEquals(UniformDistribution.DEFAULT_MIN, u.getMinSupport()); assertEquals(UniformDistribution.DEFAULT_MAX, u.getMaxSupport()); double a = RANDOM.nextGaussian(); double b = RANDOM.nextDouble() + a; u = new UniformDistribution.CDF(a, b); assertEquals(a, u.getMinSupport()); assertEquals(b, u.getMaxSupport()); UniformDistribution.CDF u2 = new UniformDistribution.CDF(u); assertEquals(u.getMinSupport(), u2.getMinSupport()); assertEquals(u.getMaxSupport(), u2.getMaxSupport()); }
protected Vector createVector(int numDim) { if (RANDOM.nextBoolean()) { return DenseVectorFactoryMTJ.INSTANCE.createVector(numDim); } else { return SparseVectorFactoryMTJ.INSTANCE.createVector(numDim); } }
private void generateAndAddTechnologyOperationComponent(final Entity technology) { List<Entity> operations = new LinkedList<Entity>(); Entity operation = null; for (int i = 0; i < 4; i++) { if (operations.isEmpty()) { operation = addOperationComponent(technology, null, getRandomOperation(), RANDOM.nextInt(3) + 3); } else { operation = addOperationComponent( technology, operations.get(RANDOM.nextInt(operations.size())), getRandomOperation(), RANDOM.nextInt(3) + 3); } operations.add(operation); } }
private Entity getRandomEntity(final String pluginIdentifier, final String modelName) { SearchCriteriaBuilder searchBuilder = dataDefinitionService.get(pluginIdentifier, modelName).find(); int totalNumberOfEntities = searchBuilder.list().getTotalNumberOfEntities(); return searchBuilder .setMaxResults(1) .setFirstResult(RANDOM.nextInt(totalNumberOfEntities)) .uniqueResult(); }
private String generateRandomEmail() { String email; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(generateString(CHARS_AND_DIGITS, RANDOM.nextInt(3) + 3)); stringBuilder.append("@").append(generateString(CHARS_AND_DIGITS, 4)).append("."); stringBuilder.append("org"); email = stringBuilder.toString(); return email; }
/** * Returns a pseudo random <code>int</code> value in the range <code>[min, max]</code> (fast and * thread-safe without synchronization). * * @param min the minimum value inclusive. * @param max the maximum value exclusive. * @return a pseudo random number in the range <code>[min, max]</code>. */ public static int random(int min, int max) { int next = RANDOM.nextInt(); if ((next >= min) && (next <= max)) return next; next += Integer.MIN_VALUE; if ((next >= min) && (next <= max)) return next; // We should not have interval overflow as the interval has to be less // or equal to Integer.MAX_VALUE (otherwise we would have exited before). final int interval = 1 + max - min; // Positive. if (interval <= 0) throw new Error("Interval [" + min + ".." + max + "] error"); // In case. return MathLib.abs(next % interval) + min; }
/** Tests what happens when the min == max */ public void testDegenerate() { System.out.println("CDF.degenerate"); for (int i = 0; i < 100; i++) { double x = RANDOM.nextGaussian(); UniformDistribution.CDF instance = new UniformDistribution.CDF(x, x); assertEquals(x, instance.getMinSupport()); assertEquals(x, instance.getMaxSupport()); assertEquals(x, instance.getMean()); assertEquals(0.0, instance.getVariance()); assertEquals(x, instance.sample(RANDOM)); } }
/** Test of setNumTrials method, of class MultivariatePolyaDistribution. */ public void testSetNumTrials() { System.out.println("setNumTrials"); int numTrials = RANDOM.nextInt(100) + 1; MultivariatePolyaDistribution instance = this.createInstance(); instance.setNumTrials(numTrials); assertEquals(numTrials, instance.getNumTrials()); try { instance.setNumTrials(0); fail("numTrials must be > 0"); } catch (Exception e) { System.out.println("Good: " + e); } }
private String generateString(final String allowedChars, final int stringLength) { int stringLen = stringLength; String generatedString; if (stringLen <= 0) { stringLen = 1; } char[] chars = new char[stringLen]; for (int i = 0; i < stringLen; i++) { chars[i] = allowedChars.charAt(RANDOM.nextInt(allowedChars.length())); } generatedString = new String(chars); return generatedString; }
private void generateAndAddTechnology(final Entity product) { Entity technology = dataDefinitionService.get(TECHNOLOGIES_PLUGIN, L_TECHNOLOGY_MODEL_TECHNOLOGY).create(); Entity defaultTechnology = getDefaultTechnologyForProduct(product); String number = generateString(DIGITS_ONLY, RANDOM.nextInt(40) + 5); technology.setField("master", defaultTechnology == null); technology.setField(L_NAME, getNameFromNumberAndPrefix("Technology-", number)); technology.setField(L_NUMBER, number); technology.setField(L_BASIC_MODEL_PRODUCT, product); technology.setField(STATE_L, "01draft"); technology.setField("batchRequired", true); technology.setField("postFeatureRequired", false); technology.setField("otherFeatureRequired", false); technology.setField("shiftFeatureRequired", false); technology.setField("minimalQuantity", RANDOM.nextInt(40) + 10); technology.setField("technologyBatchRequired", false); technology.setField("qualityControlType", "02forUnit"); technology.setField("unitSamplingNr", "123"); technology.setField("qualityControlInstruction", "asd23"); technology = dataDefinitionService .get(TECHNOLOGIES_PLUGIN, L_TECHNOLOGY_MODEL_TECHNOLOGY) .save(technology); generateAndAddTechnologyOperationComponent(technology); treeNumberingService.generateNumbersAndUpdateTree( dataDefinitionService.get(L_TECHNOLOGIES_PLUGIN_IDENTIFIER, "technologyOperationComponent"), L_TECHNOLOGY_MODEL_TECHNOLOGY, technology.getId()); technology.setField(STATE_L, "02accepted"); dataDefinitionService.get(TECHNOLOGIES_PLUGIN, L_TECHNOLOGY_MODEL_TECHNOLOGY).save(technology); }