Esempio n. 1
0
  /**
   * Return true if this equation is satisfied.
   *
   * @return True if this equation is satisfied.
   */
  public boolean isSatisfied() {
    UnitExpr lhsReduced = getLhs().reduce();
    UnitExpr rhsReduced = getRhs().reduce();
    Unit lhsUnit = lhsReduced.getSingleUnit();
    Unit rhsUnit = rhsReduced.getSingleUnit();

    if ((lhsUnit == null) || (rhsUnit == null)) {
      return false;
    }

    if (lhsUnit.hasSameType(rhsUnit)) {
      return true;
    } else {
      return false;
    }
  }
Esempio n. 2
0
  /**
   * Transform to the canonical form of the equation. The canonical form of an equation is <b> Ex1,
   * Ex2, ..., Exn = A <b> where each Exi is a Unit term containing only one variable, and A is a
   * Unit term containing one Unit and no variables.
   *
   * @return unitEquation The UnitEquation in canonical form.
   */
  public UnitEquation canonicalize() {
    UnitExpr lhsUExpr = getLhs();
    UnitExpr rhsUExpr = getRhs();
    UnitExpr newLeftUExpr = new UnitExpr();
    UnitExpr newRightUExpr = new UnitExpr();
    Vector leftUTerms = lhsUExpr.getUTerms();

    for (int i = 0; i < leftUTerms.size(); i++) {
      UnitTerm uTerm = ((UnitTerm) (leftUTerms.elementAt(i)));

      if (uTerm.isUnit()) {
        newRightUExpr.addUnitTerm(uTerm.invert());
      } else if (uTerm.isVariable()) {
        newLeftUExpr.addUnitTerm(uTerm);
      }
    }

    Vector rightUTerms = rhsUExpr.getUTerms();

    for (int i = 0; i < rightUTerms.size(); i++) {
      UnitTerm uTerm = ((UnitTerm) (rightUTerms.elementAt(i)));

      if (uTerm.isUnit()) {
        newRightUExpr.addUnitTerm(uTerm);
      } else if (uTerm.isVariable()) {
        newLeftUExpr.addUnitTerm(uTerm.invert());
      }
    }

    if (newRightUExpr.getUTerms().isEmpty()) {
      UnitTerm x = new UnitTerm();
      x.setUnit(UnitLibrary.Identity);
      newRightUExpr.addUnitTerm(x);
    }

    newRightUExpr = newRightUExpr.reduce();
    return new UnitEquation(newLeftUExpr, newRightUExpr);
  }