本文整理汇总了Java中org.apache.commons.math3.util.MathUtils.equals方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.equals方法的具体用法?Java MathUtils.equals怎么用?Java MathUtils.equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.util.MathUtils
的用法示例。
在下文中一共展示了MathUtils.equals方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapVMsToHost
import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/**
* It maps VMs from hosts with lower score (interest in distribute some of its VMs) to hosts
* with
* higher score (interesting to allocate more VMs). This methods simulates three different
* mappings methods; the simulation that give the best standard deviation on the hosts workload
* will be the chosen one. Each simulation is done by calling the {@link simulateVmsMigrations}
* method with a different standard deviation ({@link #standardDeviationVmsConfiguration},
* {@link #standardDeviationHostsUsage}, {@link #standardDeviationAverage}).
* The standard deviation is used to give a maximum load in each host (host average load +
* standard deviation) and the minimum load (host average load - standard deviation).
*/
@Override
public Map<Long, HostResources> mapVMsToHost(List<HostResources> rankedHosts) {
if (MathUtils.equals(standardDeviationHostsUsage, 0)) {
return new HashMap<>();
}
List<HostResources> rankedHostsStdVms = cloneListOfHosts(rankedHosts);
List<HostResources> rankedHostsStdHosts = cloneListOfHosts(rankedHosts);
List<HostResources> rankedHostsStdAverage = cloneListOfHosts(rankedHosts);
logger.debug("Simulating migration mapping with VMs resource standard deviation");
Map<Long, HostResources> vmsToHostStdVms = simulateVmsMigrations(rankedHostsStdVms, standardDeviationVmsConfiguration);
logger.debug("Simulating migration mapping with hosts resource standard deviation");
Map<Long, HostResources> vmsToHostStdHosts = simulateVmsMigrations(rankedHostsStdHosts, standardDeviationHostsUsage);
logger.debug("Simulating migration mapping with the average of hosts resource and VMs resource standard deviation");
Map<Long, HostResources> vmsToHostStdAverage = simulateVmsMigrations(rankedHostsStdAverage, standardDeviationAverage);
double usedMemoryHostsWithStdVms[] = new double[rankedHosts.size()];
for (int i = 0; i < rankedHostsStdVms.size(); i++) {
usedMemoryHostsWithStdVms[i] = rankedHostsStdVms.get(i).getUsedMemoryInMegaBytes();
}
double stdWithStdVms = std.evaluate(usedMemoryHostsWithStdVms);
logger.debug(String.format("The Std. achieved using the VMs resource standard deviation as parameter for the simulation was [%f]", stdWithStdVms));
double usedMemoryHostsWithStdHost[] = new double[rankedHosts.size()];
for (int i = 0; i < rankedHostsStdHosts.size(); i++) {
usedMemoryHostsWithStdHost[i] = rankedHostsStdHosts.get(i).getUsedMemoryInMegaBytes();
}
double stdWithStdHosts = std.evaluate(usedMemoryHostsWithStdHost);
logger.debug(String.format("The Std. achieved using the hosts resource standard deviation as parameter for the simulation was [%f]", stdWithStdHosts));
double usedMemoryHostsWithStdAverage[] = new double[rankedHosts.size()];
for (int i = 0; i < rankedHostsStdAverage.size(); i++) {
usedMemoryHostsWithStdAverage[i] = rankedHostsStdAverage.get(i).getUsedMemoryInMegaBytes();
}
double stdWithStdAverage = std.evaluate(usedMemoryHostsWithStdAverage);
logger.debug(String.format("The Std. achieved using the average between hosts resource and VMs resource standard deviation as parameter for the simulation was [%f]",
stdWithStdAverage));
if (stdWithStdAverage <= stdWithStdHosts && stdWithStdAverage <= stdWithStdVms) {
logger.debug("The simulation that won the competition was the one executed with alpha as the average of host resource and VMs resource standard deviation.");
logger.debug(String.format("The number of migrations that will be executed is[%d].", vmsToHostStdAverage.size()));
return vmsToHostStdAverage;
}
if (stdWithStdHosts <= stdWithStdVms) {
logger.debug("The simulation that won the competition was the one executed with alpha as the host resource standard deviation.");
logger.debug(String.format("The number of migrations that will be executed is[%d].", vmsToHostStdHosts.size()));
return vmsToHostStdHosts;
}
logger.debug("The simulation that won the competition was the one executed with alpha as the VMs resource standard deviation.");
logger.debug(String.format("The number of migrations that will be executed is[%d].", vmsToHostStdVms.size()));
return vmsToHostStdVms;
}
开发者ID:Autonomiccs,项目名称:autonomiccs-platform,代码行数:65,代码来源:VmsDispersionAlgorithmForHomogeneousEnvironment.java
示例2: equals
import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
/**
* Test for equality with another object.
* If both the real and imaginary parts of two complex numbers
* are exactly the same, and neither is {@code Double.NaN}, the two
* Complex objects are considered to be equal.
* The behavior is the same as for JDK's {@link Double#equals(Object)
* Double}:
* <ul>
* <li>All {@code NaN} values are considered to be equal,
* i.e, if either (or both) real and imaginary parts of the complex
* number are equal to {@code Double.NaN}, the complex number is equal
* to {@code NaN}.
* </li>
* <li>
* Instances constructed with different representations of zero (i.e.
* either "0" or "-0") are <em>not</em> considered to be equal.
* </li>
* </ul>
*
* @param other Object to test for equality with this instance.
* @return {@code true} if the objects are equal, {@code false} if object
* is {@code null}, not an instance of {@code Complex}, or not equal to
* this instance.
*/
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other instanceof Complex){
Complex c = (Complex) other;
if (c.isNaN) {
return isNaN;
} else {
return MathUtils.equals(real, c.real) &&
MathUtils.equals(imaginary, c.imaginary);
}
}
return false;
}
示例3: getHistory
import org.apache.commons.math3.util.MathUtils; //导入方法依赖的package包/类
@Override
public DataElementHistory getHistory( DataElement dataElement, DataElementCategoryOptionCombo optionCombo,
DataElementCategoryOptionCombo attributeOptionCombo, OrganisationUnit organisationUnit, Period lastPeriod, int historyLength )
{
if ( !dataElement.getValueType().isNumeric() )
{
return null; // TODO
}
// ---------------------------------------------------------------------
// Initialise history
// ---------------------------------------------------------------------
DataElementHistory history = new DataElementHistory();
history.setDataElement( dataElement );
history.setOptionCombo( optionCombo );
history.setAttributeOptionComboOptionCombo( attributeOptionCombo );
history.setOrganisationUnit( organisationUnit );
history.setHistoryLength( historyLength );
addMinMaxLimits( organisationUnit, dataElement, optionCombo, history );
// ---------------------------------------------------------------------
// Create history points
// ---------------------------------------------------------------------
List<Period> periods = periodService.getPeriods( lastPeriod, historyLength );
double max = 1;
double average = 0;
double total = 0;
int count = 0;
if ( history.getMaxLimit() != null )
{
max = Math.max( max, history.getMaxLimit() );
}
for ( Period period : periods )
{
DataElementHistoryPoint historyPoint = new DataElementHistoryPoint();
historyPoint.setPeriod( period );
Double value = getValue( dataElement, optionCombo, attributeOptionCombo, organisationUnit, period );
if ( value != null )
{
historyPoint.setValue( value );
}
if ( historyPoint.getValue() != null )
{
max = Math.max( max, historyPoint.getValue() );
total += historyPoint.getValue();
average = total / ++count;
average = Precision.round( average, 1 );
}
historyPoint.setAverage( average );
history.getHistoryPoints().add( historyPoint );
}
history.setMaxHistoryValue( max );
double maxValue = getMaxValue( history );
if ( !MathUtils.equals( maxValue, Double.NEGATIVE_INFINITY ) )
{
history.setMaxValue( maxValue );
double minValue = getMinValue( history );
history.setMinValue( minValue );
}
return history;
}