本文整理汇总了Java中com.google.common.math.DoubleMath.fuzzyEquals方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleMath.fuzzyEquals方法的具体用法?Java DoubleMath.fuzzyEquals怎么用?Java DoubleMath.fuzzyEquals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.math.DoubleMath
的用法示例。
在下文中一共展示了DoubleMath.fuzzyEquals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: adaptMIPResult
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
protected XORAllocation<T> adaptMIPResult(IMIPResult mipResult) {
Map<Bidder<T>, BidderAllocation<T>> trades = new HashMap<>();
for (Bidder<T> bidder : auction.getBidders()) {
double totalValue = 0;
Builder<Good> goodsBuilder = ImmutableSet.<Good>builder();
Builder<XORValue<T>> bundleBids = ImmutableSet.<XORValue<T>>builder();
for (XORValue<T> bundleBid : auction.getBid(bidder).getValues()) {
if (DoubleMath.fuzzyEquals(mipResult.getValue(getBidVariable(bundleBid)), 1, 1e-3)) {
goodsBuilder.addAll(bundleBid.getLicenses());
bundleBids.add(bundleBid);
totalValue += bundleBid.value().doubleValue();
}
}
Set<Good> goods = goodsBuilder.build();
if (!goods.isEmpty()) {
trades.put(bidder, new BidderAllocation<>(totalValue, new Bundle<>(goods), bundleBids.build()));
}
}
return new XORAllocation<>(trades);
}
示例2: pack
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
@Override
public List<WorkUnit> pack(Map<String, List<WorkUnit>> workUnitsByTopic, int numContainers) {
setWorkUnitEstSizes(workUnitsByTopic);
List<WorkUnit> workUnits = Lists.newArrayList();
for (List<WorkUnit> workUnitsForTopic : workUnitsByTopic.values()) {
// For each topic, merge all empty workunits into a single workunit, so that a single
// empty task will be created instead of many.
MultiWorkUnit zeroSizeWorkUnit = new MultiWorkUnit();
for (WorkUnit workUnit : workUnitsForTopic) {
if (DoubleMath.fuzzyEquals(getWorkUnitEstSize(workUnit), 0.0, EPS)) {
addWorkUnitToMultiWorkUnit(workUnit, zeroSizeWorkUnit);
} else {
workUnit.setWatermarkInterval(getWatermarkIntervalFromWorkUnit(workUnit));
workUnits.add(workUnit);
}
}
if (!zeroSizeWorkUnit.getWorkUnits().isEmpty()) {
workUnits.add(squeezeMultiWorkUnit(zeroSizeWorkUnit, state));
}
}
return worstFitDecreasingBinPacking(workUnits, numContainers);
}
示例3: matches
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
* Ignores 'default' indicator
*
* @param other
* @return
*/
public boolean matches(
final ConstraintData other ) {
if (this == other) {
return true;
}
if (range == null) {
if (other.range != null) {
return false;
}
}
else if (!DoubleMath.fuzzyEquals(
range.getMin(),
other.range.getMin(),
DOUBLE_TOLERANCE) || !DoubleMath.fuzzyEquals(
range.getMax(),
other.range.getMax(),
DOUBLE_TOLERANCE)) {
return false;
}
return true;
}
示例4: equals
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
* Check the two input points for equality. This method does not take the
* point number into account.
*
* @param p1 First point to compare
* @param p2 Second point to compare
* @param tolerance The tolerance used for the comparison
* @param altitude Set to true if you want to consider the altitude for the
* comparison
* @return True if they are the same, false otherwise.
*/
public static boolean equals(Point p1, Point p2, double tolerance, boolean altitude) {
if ((p1 == null) || (p2 == null)) {
return false;
}
if (DoubleMath.fuzzyEquals(p1.getEast(), p2.getEast(), tolerance)
&& DoubleMath.fuzzyEquals(p1.getNorth(), p2.getNorth(), tolerance)) {
if (altitude && !MathUtils.isIgnorable(p1.getAltitude())
&& !MathUtils.isIgnorable(p2.getAltitude())) {
if (!DoubleMath.fuzzyEquals(p1.getAltitude(), p2.getAltitude(), tolerance)) {
return false;
}
}
return true;
}
return false;
}
示例5: pack
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
@Override
public List<WorkUnit> pack(Map<String, List<WorkUnit>> workUnitsByTopic, int numContainers) {
setWorkUnitEstSizes(workUnitsByTopic);
List<WorkUnit> workUnits = Lists.newArrayList();
for (List<WorkUnit> workUnitsForTopic : workUnitsByTopic.values()) {
// For each topic, merge all empty workunits into a single workunit, so that a single
// empty task will be created instead of many.
MultiWorkUnit zeroSizeWorkUnit = MultiWorkUnit.createEmpty();
for (WorkUnit workUnit : workUnitsForTopic) {
if (DoubleMath.fuzzyEquals(getWorkUnitEstSize(workUnit), 0.0, EPS)) {
addWorkUnitToMultiWorkUnit(workUnit, zeroSizeWorkUnit);
} else {
workUnit.setWatermarkInterval(getWatermarkIntervalFromWorkUnit(workUnit));
workUnits.add(workUnit);
}
}
if (!zeroSizeWorkUnit.getWorkUnits().isEmpty()) {
workUnits.add(squeezeMultiWorkUnit(zeroSizeWorkUnit));
}
}
return worstFitDecreasingBinPacking(workUnits, numContainers);
}
示例6: checkCoverage
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
* Tool can be used custom index strategies to check if the tiles actual
* intersect with the provided bounding box.
*
* @param boxRangeData
* @param innerTile
* @return
*/
private boolean checkCoverage(
final MultiDimensionalNumericData boxRangeData,
final MultiDimensionalNumericData innerTile ) {
for (int i = 0; i < boxRangeData.getDimensionCount(); i++) {
final double i1 = innerTile.getDataPerDimension()[i].getMin();
final double i2 = innerTile.getDataPerDimension()[i].getMax();
final double j1 = boxRangeData.getDataPerDimension()[i].getMin();
final double j2 = boxRangeData.getDataPerDimension()[i].getMax();
final boolean overlaps = ((i1 < j2) || DoubleMath.fuzzyEquals(
i1,
j2,
DOUBLE_TOLERANCE)) && ((i2 > j1) || DoubleMath.fuzzyEquals(
i2,
j1,
DOUBLE_TOLERANCE));
if (!overlaps) {
return false;
}
}
return true;
}
示例7: merge
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
private List<Range> merge(List<Range> ranges) {
List<Range> result = Lists.newArrayList();
for(int i =0;i<ranges.size();i++) {
Range range = ranges.get(i);
if((i+1)<ranges.size()) {
Range next = ranges.get(i+1);
if(range.intersects(next) || DoubleMath.fuzzyEquals(
range.getUpperBound(),next.getLowerBound(), 0.0000001)) {
Range merged = Range.combine(range, next);
result.add(merged);
for(int j=i+2;j<ranges.size();j++) {
result.add(ranges.get(j));
}
result = merge(result);
break;
} else {
result.add(range);
}
} else {
result.add(range);
}
}
return result;
}
示例8: almostEquals
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
* Compare two double values for almost equality
* @param a
* @param b
* @return
*/
public static boolean almostEquals(final double a, final double b, final double delta) {
if(a == b) {
return true;
}
return DoubleMath.fuzzyEquals(a, b, a / delta);
}
示例9: bucketsNearlyEquals
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
private static boolean bucketsNearlyEquals(ExplicitBuckets a, ExplicitBuckets b) {
if (a.getBoundsCount() != b.getBoundsCount()) {
return false;
}
for (int i = 0; i < b.getBoundsCount(); i++) {
if (!DoubleMath.fuzzyEquals(a.getBounds(i), b.getBounds(i), TOLERANCE)) {
return false;
}
}
return true;
}
示例10: fuzzyEquals
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
public boolean fuzzyEquals(Writable o, double tolerance) {
double other;
if (o instanceof IntWritable){
other = ((IntWritable) o).toDouble();
} else if (o instanceof LongWritable) {
other = ((LongWritable) o).toDouble();
} else if (o instanceof ByteWritable) {
other = ((ByteWritable) o).toDouble();
} else if (o instanceof DoubleWritable) {
other = ((DoubleWritable) o).toDouble();
} else if (o instanceof FloatWritable) {
other = ((FloatWritable) o).toDouble();
} else { return false; }
return DoubleMath.fuzzyEquals(this.value, other, tolerance);
}
示例11: next
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
public void next(double val) {
if (val > 0) {
if (DoubleMath.fuzzyEquals(min, -1d, 0.01) || val < min) {
min = val;
}
if (DoubleMath.fuzzyEquals(min, -1d, 0.01) || val > max) {
max = val;
}
sum += val;
count++;
}
}
示例12: equals
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
@SuppressWarnings("ReferenceEquality")
public final boolean equals(AbstractMatrix m, double epsilon) {
if (this == m) {
return true;
}
return DoubleMath.fuzzyEquals(m00, m.m00, epsilon)
&& DoubleMath.fuzzyEquals(m01, m.m01, epsilon)
&& DoubleMath.fuzzyEquals(m02, m.m02, epsilon)
&& DoubleMath.fuzzyEquals(m10, m.m10, epsilon)
&& DoubleMath.fuzzyEquals(m11, m.m11, epsilon)
&& DoubleMath.fuzzyEquals(m12, m.m12, epsilon);
}
示例13: equals
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
/**
* Fuzzy compares this vector with another factor. Differences no greater than {@code epsilon} are treated as equal.
*/
public boolean equals(Vec2 v, double epsilon) {
if (epsilon != 0.0) {
return DoubleMath.fuzzyEquals(x, v.x, epsilon)
&& DoubleMath.fuzzyEquals(y, v.y, epsilon);
}
return x == v.x && y == v.y;
}
示例14: stateEquals
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
public static boolean stateEquals(
Object thisStateObj, Object thatStateObj, double epsilon, EqualsReporter reporter) {
if (thisStateObj == thatStateObj) {
return true;
}
if (thisStateObj == null || thatStateObj == null) {
return false;
}
if (!State.class.isAssignableFrom(thisStateObj.getClass()) || !State.class.isAssignableFrom(thatStateObj.getClass())) {
return false;
}
State thisState = (State) thisStateObj;
State thatState = (State) thatStateObj;
if (thisState.getId() != thatState.getId()) {
reporter.report("state.id", thisState.getId(), thatState.getId());
return false;
}
if (!DoubleMath.fuzzyEquals(thatState.getFinalWeight(), thisState.getFinalWeight(), epsilon)) {
reporter.report("state.finalWeight", thisState.getFinalWeight(), thatState.getFinalWeight());
return false;
}
if (thisState.getArcs().size() != thatState.getArcs().size()) {
reporter.report("state.arcCount", thisState.getArcCount(), thatState.getArcCount());
return false;
}
for (int i = 0; i < thisState.getArcs().size(); i++) {
Arc thisArc = thisState.getArc(i);
Arc thatArc = thatState.getArc(i);
if (!arcEquals(thisArc, thatArc, epsilon)) {
reporter.report("state.arc", thisArc, thatArc);
return false;
}
}
return true;
}
示例15: matchesSafely
import com.google.common.math.DoubleMath; //导入方法依赖的package包/类
@Override
protected boolean matchesSafely(AvailabilityBucketPoint item) {
return item.getStart() == expected.getStart()
&& item.getEnd() == expected.getEnd()
&& item.getNotUpCount() == expected.getNotUpCount()
&& item.getDurationMap().equals(expected.getDurationMap())
&& item.getLastNotUptime() == expected.getLastNotUptime()
&& DoubleMath.fuzzyEquals(item.getUptimeRatio(), expected.getUptimeRatio(), 0.001);
}