Java Code Examples for org.apache.commons.math.util.MathUtils#compareTo()

The following examples show how to use org.apache.commons.math.util.MathUtils#compareTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: jMutRepair_0015_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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(final int col, final SimplexTableau tableau) {
    double minRatio = Double.MAX_VALUE;
    Integer minRatioPos = null;
    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 (ratio < minRatio) {
                minRatio = ratio;
                minRatioPos = i; 
            }
        }
    }
    return minRatioPos;
}
 
Example 2
Source File: Math_82_SimplexSolver_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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(final int col, final SimplexTableau tableau) {
    double minRatio = Double.MAX_VALUE;
    Integer minRatioPos = null;
    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 (ratio < minRatio) {
                minRatio = ratio;
                minRatioPos = i; 
            }
        }
    }
    return minRatioPos;
}
 
Example 3
Source File: Math_82_SimplexSolver_t.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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(final int col, final SimplexTableau tableau) {
    double minRatio = Double.MAX_VALUE;
    Integer minRatioPos = null;
    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 (ratio < minRatio) {
                minRatio = ratio;
                minRatioPos = i; 
            }
        }
    }
    return minRatioPos;
}
 
Example 4
Source File: Cardumen_00185_s.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: Cardumen_00232_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 6
Source File: SimplexTableau.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source File: SimplexSolver.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 8
Source File: Cardumen_0063_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 9
Source File: jMutRepair_0018_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 10
Source File: Cardumen_00232_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 11
Source File: Cardumen_00130_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 12
Source File: SimplexSolver.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 13
Source File: jMutRepair_0015_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 14
Source File: SimplexSolver.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 15
Source File: jMutRepair_0027_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 16
Source File: jKali_0015_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 17
Source File: SimplexSolver.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 18
Source File: Cardumen_00275_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 19
Source File: SimplexSolver.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 20
Source File: Cardumen_00275_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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;
}