use of org.evosuite.symbolic.expr.DistanceCalculator in project evosuite by EvoSuite.
the class DistanceEstimator method getDistance.
/**
* <p>
* getDistance
* </p>
*
* @param constraints
* a {@link java.util.Collection} object.
* @return normalized distance in [0,1]
*/
public static double getDistance(Collection<Constraint<?>> constraints) {
double result = 0;
DistanceCalculator distanceCalculator = new DistanceCalculator();
try {
for (Constraint<?> c : constraints) {
if (c instanceof StringConstraint) {
StringConstraint string_constraint = (StringConstraint) c;
try {
double strD = (double) string_constraint.accept(distanceCalculator, null);
result += normalize(strD);
log.debug("S: " + string_constraint + " strDist " + strD);
} catch (Throwable t) {
log.debug("S: " + string_constraint + " strDist " + t);
result += 1.0;
}
} else if (c instanceof IntegerConstraint) {
IntegerConstraint integer_constraint = (IntegerConstraint) c;
long intD = (long) integer_constraint.accept(distanceCalculator, null);
result += normalize(intD);
log.debug("C: " + integer_constraint + " intDist " + intD);
} else if (c instanceof RealConstraint) {
RealConstraint real_constraint = (RealConstraint) c;
double realD = (double) real_constraint.accept(distanceCalculator, null);
result += normalize(realD);
log.debug("C: " + real_constraint + " realDist " + realD);
} else {
throw new IllegalArgumentException("DistanceCalculator: got an unknown constraint: " + c);
}
}
log.debug("Resulting distance: " + result);
return Math.abs(result);
} catch (Exception e) {
return Double.MAX_VALUE;
}
}
Aggregations