Example #1
0
  /**
   * Apply AVM on variable
   *
   * @param delta
   * @param factor
   */
  private void iterateVar(double delta, double factor) throws SolverTimeoutException {

    log.debug("[Loop] Trying increment " + delta + " of " + realVar.toString());

    incrementVar(delta);
    double newDist = DistanceEstimator.getDistance(cnstr);
    log.debug("[Loop] Old distance: " + this.checkpointedDistance + ", new distance: " + newDist);
    while (distImpr(newDist)) {
      if (isFinished()) {
        throw new SolverTimeoutException();
      }

      checkpointVar(newDist);
      if (newDist == 0.0) {
        // solution found
        return;
      }
      delta = factor * delta;
      log.debug("[Loop] Trying increment " + delta + " of " + realVar);
      incrementVar(delta);
      newDist = DistanceEstimator.getDistance(cnstr);
    }
    log.debug("No improvement on " + realVar);
    restoreVar();

    log.debug("Final value of this iteration: " + realVar);
  }
Example #2
0
  private boolean doRealSearch(double delta, double factor) throws SolverTimeoutException {

    boolean improvement = false;

    final double initial_distance = DistanceEstimator.getDistance(cnstr);
    checkpointVar(initial_distance);
    if (initial_distance == 0.0) {
      // already solved, no improvement found
      return false;
    }

    while (true) {
      if (isFinished()) {
        throw new SolverTimeoutException();
      }

      // Try increment
      log.debug("Trying to increment " + realVar + " with: " + delta);
      incrementVar(delta);
      double newDist = DistanceEstimator.getDistance(cnstr);
      log.debug("Old distance: " + this.checkpointedDistance + ", new distance: " + newDist);
      if (distImpr(newDist)) {
        improvement = true;
        checkpointVar(newDist);
        if (newDist == 0.0) {
          // solution found
          break;
        }
        iterateVar(factor * delta, factor);
      } else {
        // restore
        restoreVar();
        // Try decrement
        log.debug("Trying to decrement " + realVar + " with: " + delta);
        incrementVar(-delta);
        newDist = DistanceEstimator.getDistance(cnstr);
        if (distImpr(newDist)) {
          improvement = true;
          checkpointVar(newDist);
          if (newDist == 0.0) {
            // solution found
            break;
          }
          iterateVar(-factor * delta, factor);
        } else {
          restoreVar();
          break;
        }
      }
    }

    return improvement;
  }
Example #3
0
  /**
   * Cut off digits after comma.
   *
   * @param precision
   * @param isFloat
   */
  private void chopOffPrecision(int precision, boolean isFloat) {

    double value = realVar.getConcreteValue();
    BigDecimal bd = new BigDecimal(value).setScale(precision, RoundingMode.HALF_EVEN);
    double newValue = bd.doubleValue();
    if (newValue == value) {
      return; // false;
    }
    realVar.setConcreteValue(newValue);

    log.debug("Trying to chop precision " + precision + ": " + value + " -> " + newValue);
    double dist = DistanceEstimator.getDistance(cnstr);
    if (!distWrsn(dist)) {
      checkpointVar(dist);
      return; // true;
    } else {
      restoreVar();
      return; // false;
    }
  }