本文整理汇总了Java中org.apache.commons.math.util.MathUtils.compareTo方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.compareTo方法的具体用法?Java MathUtils.compareTo怎么用?Java MathUtils.compareTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math.util.MathUtils
的用法示例。
在下文中一共展示了MathUtils.compareTo方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPivotRow
import org.apache.commons.math.util.MathUtils; //导入方法依赖的package包/类
/**
* Returns the row with the minimum ratio as given by the minimum ratio test (MRT).
* @param tableau simple tableau for the problem
* @param col the column to test the ratio of. See {@link #getPivotColumn()}
* @return row with the minimum ratio
*/
private Integer getPivotRow(final int col, final SimplexTableau tableau) {
double minRatio = Double.MAX_VALUE;
Integer minRatioPos = null;
for (int i = tableau.getNumObjectiveFunctions(); i < tableau.getHeight(); i++) {
double rhs = tableau.getEntry(i, tableau.getWidth() - 1);
if (MathUtils.compareTo(tableau.getEntry(i, col), 0, epsilon) >= 0) {
double ratio = rhs / tableau.getEntry(i, col);
if (ratio < minRatio) {
minRatio = ratio;
minRatioPos = i;
}
}
}
return minRatioPos;
}
示例2: getPivotColumn
import org.apache.commons.math.util.MathUtils; //导入方法依赖的package包/类
/**
* Returns the column with the most negative coefficient in the objective function row.
* @param tableau simple tableau for the problem
* @return column with the most negative coefficient
*/
private Integer getPivotColumn(SimplexTableau tableau) {
double minValue = 0;
Integer minPos = null;
for (int i = tableau.getNumObjectiveFunctions(); i < tableau.getWidth() - 1; i++) {
if (MathUtils.compareTo(tableau.getEntry(0, i), minValue, epsilon) < 0) {
minValue = tableau.getEntry(0, i);
minPos = i;
}
}
return minPos;
}
示例3: getPivotRow
import org.apache.commons.math.util.MathUtils; //导入方法依赖的package包/类
/**
* Returns the row with the minimum ratio as given by the minimum ratio test (MRT).
* @param tableau simple tableau for the problem
* @param col the column to test the ratio of. See {@link #getPivotColumn(SimplexTableau)}
* @return row with the minimum ratio
*/
private Integer getPivotRow(SimplexTableau tableau, final int col) {
// create a list of all the rows that tie for the lowest score in the minimum ratio test
List<Integer> minRatioPositions = new ArrayList<Integer>();
double minRatio = Double.MAX_VALUE;
for (int i = tableau.getNumObjectiveFunctions(); i < tableau.getHeight(); i++) {
final double rhs = tableau.getEntry(i, tableau.getWidth() - 1);
final double entry = tableau.getEntry(i, col);
if (MathUtils.compareTo(entry, 0, epsilon) > 0) {
final double ratio = rhs / entry;
if (MathUtils.equals(ratio, minRatio, epsilon)) {
minRatioPositions.add(i);
} else if (ratio < minRatio) {
minRatio = ratio;
minRatioPositions = new ArrayList<Integer>();
minRatioPositions.add(i);
}
}
}
if (minRatioPositions.size() == 0) {
return null;
} else if (minRatioPositions.size() > 1) {
// there's a degeneracy as indicated by a tie in the minimum ratio test
// check if there's an artificial variable that can be forced out of the basis
for (Integer row : minRatioPositions) {
for (int i = 0; i < tableau.getNumArtificialVariables(); i++) {
int column = i + tableau.getArtificialVariableOffset();
if (MathUtils.equals(tableau.getEntry(row, column), 1, epsilon) &&
row.equals(tableau.getBasicRow(column))) {
return row;
}
}
}
}
return minRatioPositions.get(0);
}
示例4: isOptimal
import org.apache.commons.math.util.MathUtils; //导入方法依赖的package包/类
/**
* Returns whether the problem is at an optimal state.
* @return whether the model has been solved
*/
boolean isOptimal() {
for (int i = getNumObjectiveFunctions(); i < getWidth() - 1; i++) {
if (MathUtils.compareTo(tableau.getEntry(0, i), 0, epsilon) < 0) {
return false;
}
}
return true;
}
示例5: getPivotColumn
import org.apache.commons.math.util.MathUtils; //导入方法依赖的package包/类
/**
* Returns the column with the most negative coefficient in the objective function row.
* @param tableau simple tableau for the problem
* @return column with the most negative coefficient
*/
private Integer getPivotColumn(SimplexTableau tableau) {
double minValue = 0;
Integer minPos = null;
for (int i = tableau.getNumObjectiveFunctions(); i < tableau.getWidth() - 1; i++) {
//if((org.apache.commons.math.util.MathUtils.compareTo(tableau.getEntry(0, i), 0, epsilon)) < 0){
if (MathUtils.compareTo(tableau.getEntry(0, i), minValue, epsilon) < 0) {
minValue = tableau.getEntry(0, i);
minPos = i;
}
}
return minPos;
}
示例6: getPivotColumn
import org.apache.commons.math.util.MathUtils; //导入方法依赖的package包/类
/**
* Returns the column with the most negative coefficient in the objective function row.
* @param tableau simple tableau for the problem
* @return column with the most negative coefficient
*/
private Integer getPivotColumn(SimplexTableau tableau) {
double minValue = 0;
Integer minPos = null;
for (int i = tableau.getNumObjectiveFunctions(); i < tableau.getWidth() - 1; i++) {
final double entry = tableau.getEntry(0, i);
if (MathUtils.compareTo(entry, minValue, maxUlps) < 0) {
minValue = entry;
minPos = i;
}
}
return minPos;
}
示例7: isOptimal
import org.apache.commons.math.util.MathUtils; //导入方法依赖的package包/类
/**
* Returns whether the problem is at an optimal state.
* @return whether the model has been solved
*/
boolean isOptimal() {
for (int i = getNumObjectiveFunctions(); i < getWidth() - 1; i++) {
final double entry = tableau.getEntry(0, i);
if (MathUtils.compareTo(entry, 0d, epsilon) < 0) {
return false;
}
}
return true;
}
示例8: isOptimal
import org.apache.commons.math.util.MathUtils; //导入方法依赖的package包/类
/**
* Returns whether the problem is at an optimal state.
* @param tableau simple tableau for the problem
* @return whether the model has been solved
*/
public boolean isOptimal(final SimplexTableau tableau) {
if (tableau.getNumArtificialVariables() > 0) {
return false;
}
for (int i = tableau.getNumObjectiveFunctions(); i < tableau.getWidth() - 1; i++) {
if (MathUtils.compareTo(tableau.getEntry(0, i), 0, epsilon) < 0) {
return false;
}
}
return true;
}
示例9: isPhase1Solved
import org.apache.commons.math.util.MathUtils; //导入方法依赖的package包/类
/**
* Checks whether Phase 1 is solved.
* @param tableau simple tableau for the problem
* @return whether Phase 1 is solved
*/
private boolean isPhase1Solved(final SimplexTableau tableau) {
if (tableau.getNumArtificialVariables() == 0) {
return true;
}
for (int i = tableau.getNumObjectiveFunctions(); i < tableau.getWidth() - 1; i++) {
if (MathUtils.compareTo(tableau.getEntry(0, i), 0, epsilon) < 0) {
return false;
}
}
return true;
}