Examples of UnitConverter


Examples of javax.measure.converter.UnitConverter

        objVal += sol.objectiveValue;
      }

      // convert the objective values computed by the solver to the unit of the
      // gendreau benchmark (minutes).
      final UnitConverter converter = scenario.getTimeUnit().getConverterTo(
          NonSI.MINUTE);
      final double objValInMinutes = converter.convert(objVal);

      final GlobalStateObject solverInput = dsc.solver.getInputs().get(0);
      final ImmutableList<ImmutableList<ParcelDTO>> solverOutput = dsc.solver
          .getOutputs().get(0);
View Full Code Here

Examples of javax.measure.converter.UnitConverter

    assertArrayEquals(new int[] { 163, 45, 101, 186, 0 }, matrix2[4]);
  }

  @Test
  public void convertTWtest() {
    final UnitConverter timeConverter = MILLI(SECOND).getConverterTo(SECOND);

    final int[] tw1 = convertTW(new TimeWindow(300, 800), 5, timeConverter);
    assertEquals(0, tw1[0]);
    assertEquals(1, tw1[1]);
View Full Code Here

Examples of javax.measure.converter.UnitConverter

   * @return An {@link ArraysObject} using the specified output time unit.
   */
  public static ArraysObject toSingleVehicleArrays(GlobalStateObject state,
      Unit<Duration> outputTimeUnit) {

    final UnitConverter timeConverter = state.timeUnit
        .getConverterTo(outputTimeUnit);

    final VehicleStateObject v = state.vehicles.iterator().next();

    // we check all vehicles in case this method is used in other contexts
    final ImmutableSet.Builder<ParcelDTO> cargoBuilder = ImmutableSet.builder();
    for (final VehicleStateObject vs : state.vehicles) {
      cargoBuilder.addAll(vs.contents);
    }
    final Set<ParcelDTO> inCargo = cargoBuilder.build();

    // there are always two locations: the current vehicle location and
    // the depot
    final int numLocations = 2 + (state.availableParcels.size() * 2)
        + inCargo.size();

    final int[] releaseDates = new int[numLocations];
    final int[] dueDates = new int[numLocations];
    final int[][] servicePairs = new int[state.availableParcels.size()][2];
    final int[] serviceTimes = new int[numLocations];

    // we need to create two mappings:
    // parceldto -> pickup index / deliver index
    // index -> parceldto
    final ImmutableMap.Builder<ParcelDTO, ParcelIndexObj> parcel2indexBuilder = ImmutableMap
        .builder();
    final ImmutableMap.Builder<Integer, ParcelIndexObj> index2parcelBuilder = ImmutableMap
        .builder();

    // we wrap the points in PointWrapper to avoid problems with (possibly)
    // duplicates in the points
    final ImmutableList.Builder<Point> points = ImmutableList.builder();
    points.add(v.location);

    int index = 1;
    int spIndex = 0;
    for (final ParcelDTO p : state.availableParcels) {
      serviceTimes[index] = DoubleMath.roundToInt(
          timeConverter.convert(p.pickupDuration), RoundingMode.CEILING);
      // add pickup location and time window
      points.add(p.pickupLocation);
      final int deliveryIndex = index + state.availableParcels.size();
      final ParcelIndexObj pio = new ParcelIndexObj(p, index, deliveryIndex);
      parcel2indexBuilder.put(p, pio);
      index2parcelBuilder.put(index, pio);
      index2parcelBuilder.put(deliveryIndex, pio);

      final int[] tw = convertTW(p.pickupTimeWindow, state.time, timeConverter);
      releaseDates[index] = tw[0];
      dueDates[index] = tw[1];
      checkState(releaseDates[index] <= dueDates[index]);

      // link the pair with its delivery location (see next loop)
      servicePairs[spIndex++] = new int[] { index, deliveryIndex };

      index++;
    }
    checkState(spIndex == state.availableParcels.size(), "%s %s",
        state.availableParcels.size(), spIndex);

    final List<ParcelDTO> deliveries = new ImmutableList.Builder<ParcelDTO>()
        .addAll(state.availableParcels).addAll(inCargo).build();
    for (final ParcelDTO p : deliveries) {
      serviceTimes[index] = DoubleMath.roundToInt(
          timeConverter.convert(p.deliveryDuration), RoundingMode.CEILING);

      points.add(p.destinationLocation);
      if (inCargo.contains(p)) {
        final ParcelIndexObj pio = new ParcelIndexObj(p, -1, index);
        parcel2indexBuilder.put(p, pio);
View Full Code Here

Examples of javax.measure.converter.UnitConverter

     */
    private static <Q extends Quantity> void checkConversion(
            final double expected, final Unit<Q> unitExpected,
            final double actual,   final Unit<Q> unitActual)
    {
        UnitConverter converter = unitActual.getConverterTo(unitExpected);
        assertEquals(expected, converter.convert(actual), 1E-6);
        converter = converter.inverse();
        assertEquals(actual, converter.convert(expected), 1E-6);
    }
View Full Code Here

Examples of javax.measure.converter.UnitConverter

        }

        // ok let's try harder --> this is going to be slower
        try {
            Unit unit = (Unit) SpeedConverter.UCUM_FORMAT_INSTANCE.parseObject(uom);
            UnitConverter converter = unit.getConverterTo(NonSI.KNOT);
            return converter.convert(speed);
        } catch (Exception e) {
            throw new IllegalArgumentException("The supplied units isn't currently supported:"
                    + uom, e);
        }
    }
View Full Code Here

Examples of javax.measure.converter.UnitConverter

            }
        }
        if (units == null) {
            return new MeasurementRange<N>(type, this, targetUnits);
        }
        final UnitConverter converter = units.getConverterTo(targetUnits);
        if (converter.equals(UnitConverter.IDENTITY)) {
            return new MeasurementRange<N>(type, this, targetUnits);
        }
        boolean isMinIncluded = isMinIncluded();
        boolean isMaxIncluded = isMaxIncluded();
        Double minimum = converter.convert(getMinimum());
        Double maximum = converter.convert(getMaximum());
        if (minimum.compareTo(maximum) > 0) {
            final Double td = minimum;
            minimum = maximum;
            maximum = td;
            final boolean tb = isMinIncluded;
View Full Code Here

Examples of javax.measure.converter.UnitConverter

            MathTransform crsTransform = CRS.findMathTransform(crs, epsg4326);

            FeatureType targetFeatureType = createTargetFeatureType(featureCollection.getSchema());
            Unit fromUnit = SI.METER;
            Unit toUnit = Unit.valueOf("mi");
            UnitConverter unitConvert = fromUnit.getConverterTo(toUnit);
            Feature nearestFeature = null;
            double nearestDistance = 9e9;
            Coordinate[] nearestCoords = null;
            FeatureIterator<Feature> featureIterator = null;
            try {
View Full Code Here

Examples of javax.measure.converter.UnitConverter

            CoordinateReferenceSystem hor = CRS.getHorizontalCRS(crs);
            if (hor instanceof GeographicCRS) {
                generator = new GeographicGenerator(center, quadrantSegments, crs);
            } else {
                Unit unit = hor.getCoordinateSystem().getAxis(0).getUnit();
                UnitConverter converter = SI.METER.getConverterTo(unit);
                generator = new MetricGenerator(center, quadrantSegments, converter);
            }
        } else {
            generator = new MetricGenerator(center, quadrantSegments, UnitConverter.IDENTITY);
        }
View Full Code Here

Examples of javax.measure.converter.UnitConverter

            DefaultFeatureCollection results = new DefaultFeatureCollection();
            FeatureType targetFeatureType = createTargetFeatureType(featureCollection.getSchema());
            Unit fromUnit = SI.METER;
            Unit toUnit = Unit.valueOf("mi");
            UnitConverter unitConvert = fromUnit.getConverterTo(toUnit);
            Feature nearestFeature = null;
            double nearestDistance = 9e9;
            double nearestBearing = 0;
            double[] nearestPoint = new double[2];
            FeatureIterator featureIterator = featureCollection.features();
            try {
                while (featureIterator.hasNext()) {
                    SimpleFeature f = (SimpleFeature) featureIterator.next();
                    if (f.getDefaultGeometryProperty().getValue() == null)
                        continue;
                    DistanceOp op = new DistanceOp(point, (Geometry) f.getDefaultGeometryProperty()
                            .getValue());
                    Coordinate[] co = op.closestPoints();
                    double[] co0 = new double[] { co[0].x, co[0].y, };
                    double[] co1 = new double[] { co[1].x, co[1].y, };
                    double[] geo0 = new double[2];
                    double[] geo1 = new double[2];
                    crsTransform.transform(co0, 0, geo0, 0, 1);
                    crsTransform.transform(co1, 0, geo1, 0, 1);

                    // get distance
                    Measure m = DefaultGeographicCRS.WGS84.distance(geo0, geo1);
                    if (m.doubleValue() > nearestDistance)
                        continue;
                    nearestFeature = f;
                    nearestDistance = m.doubleValue();
                    nearestBearing = calcBearing(co);
                    nearestPoint[0] = geo1[0];
                    nearestPoint[1] = geo1[1];
                }
            } finally {
                featureIterator.close();
            }
            if (nearestFeature != null) {
                nearestDistance = unitConvert.convert(nearestDistance);
                results.add(createTargetFeature(nearestFeature,
                        (SimpleFeatureType) targetFeatureType, nearestPoint, nearestDistance,
                        nearestBearing));
            }
            return results;
View Full Code Here

Examples of javax.measure.converter.UnitConverter

            DefaultFeatureCollection results = new DefaultFeatureCollection();
            FeatureType targetFeatureType = createTargetFeatureType(featureCollection.getSchema());
            Unit fromUnit = SI.METER;
            Unit toUnit = Unit.valueOf("mi");
            UnitConverter unitConvert = fromUnit.getConverterTo(toUnit);
            Feature nearestFeature = null;
            double nearestDistance = 9e9;
            double nearestBearing = 0;
            FeatureIterator featureIterator = featureCollection.features();
            try {
                while (featureIterator.hasNext()) {
                    SimpleFeature f = (SimpleFeature) featureIterator.next();
                    if (f.getDefaultGeometryProperty().getValue() == null)
                        continue;
                    DistanceOp op = new DistanceOp(point, (Geometry) f.getDefaultGeometryProperty()
                            .getValue());
                    Coordinate[] co = op.closestPoints();
                    double[] co0 = new double[] { co[0].x, co[0].y, };
                    double[] co1 = new double[] { co[1].x, co[1].y, };
                    double[] geo0 = new double[2];
                    double[] geo1 = new double[2];
                    crsTransform.transform(co0, 0, geo0, 0, 1);
                    crsTransform.transform(co1, 0, geo1, 0, 1);

                    // get distance
                    Measure m = DefaultGeographicCRS.WGS84.distance(geo0, geo1);
                    if (m.doubleValue() > nearestDistance)
                        continue;
                    nearestFeature = f;
                    nearestDistance = m.doubleValue();
                    nearestBearing = calcBearing(co);
                }
            } finally {
                featureIterator.close();
            }
            if (nearestFeature != null) {
                nearestDistance = unitConvert.convert(nearestDistance);
                results.add(createTargetFeature(nearestFeature,
                        (SimpleFeatureType) targetFeatureType, nearestDistance, nearestBearing));
            }
            return results;
        } catch (ProcessException e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.