private boolean doCharacterAVM(int position) throws SolverTimeoutException {
  checkpointVar(DistanceEstimator.getDistance(cnstr));
  boolean done=false;
  boolean hasImproved=false;
  while (!done) {
    if (isFinished()) {
      throw new SolverTimeoutException();
    }
    done=true;
    String origString=strVar.getConcreteValue();
    char oldChar=origString.charAt(position);
    char[] characters=origString.toCharArray();
    char replacement=oldChar;
    replacement=nextChar(replacement,1);
    characters[position]=replacement;
    String newString=new String(characters);
    strVar.setConcreteValue(newString);
    double newDist=DistanceEstimator.getDistance(cnstr);
    log.debug("Probing increment " + position + ": "+ newString+ ": "+ newDist+ " replacement = "+ (int)replacement);
    if (distImpr(newDist)) {
      checkpointVar(newDist);
      if (newDist == 0.0)       return true;
      done=false;
      hasImproved=true;
      iterateCharacterAVM(position,2);
    }
 else {
      replacement=nextChar(replacement,-2);
      characters[position]=replacement;
      newString=new String(characters);
      strVar.setConcreteValue(newString);
      newDist=DistanceEstimator.getDistance(cnstr);
      log.debug("Probing decrement " + position + ": "+ newString+ ": "+ newDist+ " replacement = "+ (int)replacement);
      if (distImpr(newDist)) {
        checkpointVar(newDist);
        if (newDist == 0.0)         return true;
        done=false;
        hasImproved=true;
        iterateCharacterAVM(position,-2);
      }
 else {
        replacement=(char)(oldChar + 32);
        characters[position]=replacement;
        newString=new String(characters);
        strVar.setConcreteValue(newString);
        newDist=DistanceEstimator.getDistance(cnstr);
        log.debug("Probing increment [32] " + position + ": "+ newString+ ": "+ newDist+ " replacement = "+ (int)replacement);
        if (distImpr(newDist)) {
          checkpointVar(newDist);
          done=false;
          hasImproved=true;
          break;
        }
 else {
          replacement=(char)(oldChar + 32);
          characters[position]=replacement;
          newString=new String(characters);
          strVar.setConcreteValue(newString);
          newDist=DistanceEstimator.getDistance(cnstr);
          log.debug("Probing increment [32] " + position + ": "+ newString+ ": "+ newDist+ " replacement = "+ (int)replacement);
          if (distImpr(newDist)) {
            checkpointVar(newDist);
            done=false;
            hasImproved=true;
          }
 else {
            restoreVar();
          }
        }
        if (done)         log.debug("Search finished " + position + ": "+ newString+ ": "+ newDist);
 else         log.debug("Going for another iteration at position " + position);
      }
    }
  }
  return hasImproved;
}

private boolean doCharacterAVM ( int position ) throws SolverTimeoutException { checkpointVar ( DistanceEstimator . getDistance ( cnstr ) ) ; boolean done = false ; boolean hasImproved = false ; while ( ! done ) { if ( isFinished ( ) ) { throw new SolverTimeoutException ( ) ; } done = true ; String origString = strVar . getConcreteValue ( ) ; char oldChar = origString . charAt ( position ) ; char [ ] characters = origString . toCharArray ( ) ; char replacement = oldChar ; replacement = nextChar ( replacement , 1 ) ; characters [ position ] = replacement ; String newString = new String ( characters ) ; strVar . setConcreteValue ( newString ) ; double newDist = DistanceEstimator . getDistance ( cnstr ) ; log . debug ( "Probing increment " + position + ": " + newString + ": " + newDist + " replacement = " + ( int ) replacement ) ; if ( distImpr ( newDist ) ) { checkpointVar ( newDist ) ; if ( newDist == 0.0 ) return true ; done = false ; hasImproved = true ; iterateCharacterAVM ( position , 2 ) ; } else { replacement = nextChar ( replacement , - 2 ) ; characters [ position ] = replacement ; newString = new String ( characters ) ; strVar . setConcreteValue ( newString ) ; newDist = DistanceEstimator . getDistance ( cnstr ) ; log . debug ( "Probing decrement " + position + ": " + newString + ": " + newDist + " replacement = " + ( int ) replacement ) ; if ( distImpr ( newDist ) ) { checkpointVar ( newDist ) ; if ( newDist == 0.0 ) return true ; done = false ; hasImproved = true ; iterateCharacterAVM ( position , - 2 ) ; } else { replacement = ( char ) ( oldChar + 32 ) ; characters [ position ] = replacement ; newString = new String ( characters ) ; strVar . setConcreteValue ( newString ) ; newDist = DistanceEstimator . getDistance ( cnstr ) ; log . debug ( "Probing increment [32] " + position + ": " + newString + ": " + newDist + " replacement = " + ( int ) replacement ) ; if ( distImpr ( newDist ) ) { checkpointVar ( newDist ) ; done = false ; hasImproved = true ; break ; } else { replacement = ( char ) ( oldChar + 32 ) ; characters [ position ] = replacement ; newString = new String ( characters ) ; strVar . setConcreteValue ( newString ) ; newDist = DistanceEstimator . getDistance ( cnstr ) ; log . debug ( "Probing increment [32] " + position + ": " + newString + ": " + newDist + " replacement = " + ( int ) replacement ) ; if ( distImpr ( newDist ) ) { checkpointVar ( newDist ) ; done = false ; hasImproved = true ; } else { restoreVar ( ) ; } } if ( done ) log . debug ( "Search finished " + position + ": " + newString + ": " + newDist ) ; else log . debug ( "Going for another iteration at position " + position ) ; } } } return hasImproved ; }
apply avm to an individual character within a string
