use of org.evosuite.symbolic.expr.Variable in project evosuite by EvoSuite.
the class EvoSuiteSolver method solve.
@Override
public SolverResult solve(Collection<Constraint<?>> constraints) throws SolverTimeoutException, SolverEmptyQueryException {
long timeout = Properties.DSE_CONSTRAINT_SOLVER_TIMEOUT_MILLIS;
long startTimeMillis = System.currentTimeMillis();
Set<Variable<?>> variables = getVariables(constraints);
Map<String, Object> initialValues = getConcreteValues(variables);
double distance = DistanceEstimator.getDistance(constraints);
if (distance == 0.0) {
log.info("Initial distance already is 0.0, skipping search");
SolverResult satResult = SolverResult.newSAT(initialValues);
return satResult;
}
for (int attempt = 0; attempt <= Properties.DSE_VARIABLE_RESETS; attempt++) {
for (Variable<?> v : variables) {
long currentTimeMillis = System.currentTimeMillis();
long elapsed_solving_time = currentTimeMillis - startTimeMillis;
if (elapsed_solving_time > timeout) {
throw new SolverTimeoutException();
}
log.debug("Variable: " + v + ", " + variables);
if (v instanceof IntegerVariable) {
IntegerVariable integerVariable = (IntegerVariable) v;
IntegerAVM avm = new IntegerAVM(integerVariable, constraints, startTimeMillis, timeout);
avm.applyAVM();
} else if (v instanceof RealVariable) {
RealVariable realVariable = (RealVariable) v;
RealAVM avm = new RealAVM(realVariable, constraints, startTimeMillis, timeout);
avm.applyAVM();
} else if (v instanceof StringVariable) {
StringVariable strVariable = (StringVariable) v;
StringAVM avm = new StringAVM(strVariable, constraints, startTimeMillis, timeout);
avm.applyAVM();
} else {
throw new RuntimeException("Unknown variable type " + v.getClass().getName());
}
distance = DistanceEstimator.getDistance(constraints);
if (distance <= 0.0) {
log.info("Distance is 0, ending search");
break;
}
}
if (distance <= 0.0) {
log.info("Distance is 0, ending search");
break;
} else {
log.info("Randomizing variables");
randomizeValues(variables, getConstants(constraints));
}
}
// distance = DistanceEstimator.getDistance(constraints);
if (distance <= 0) {
log.debug("Distance is " + distance + ", found solution");
Map<String, Object> new_model = getConcreteValues(variables);
setConcreteValues(variables, initialValues);
SolverResult satResult = SolverResult.newSAT(new_model);
return satResult;
} else {
setConcreteValues(variables, initialValues);
log.debug("Returning null, search was not successful");
SolverResult unsatResult = SolverResult.newUNSAT();
return unsatResult;
}
}
use of org.evosuite.symbolic.expr.Variable in project evosuite by EvoSuite.
the class ConcolicMutation method reduce.
/**
* Apply cone of influence reduction to constraints with respect to the last
* constraint in the list
*
* @param constraints
* @return
*/
private static List<Constraint<?>> reduce(List<Constraint<?>> constraints) {
Constraint<?> target = constraints.get(constraints.size() - 1);
Set<Variable<?>> dependencies = getVariables(target);
LinkedList<Constraint<?>> coi = new LinkedList<Constraint<?>>();
coi.add(target);
for (int i = constraints.size() - 2; i >= 0; i--) {
Constraint<?> constraint = constraints.get(i);
Set<Variable<?>> variables = getVariables(constraint);
for (Variable<?> var : dependencies) {
if (variables.contains(var)) {
dependencies.addAll(variables);
coi.addFirst(constraint);
break;
}
}
}
return coi;
}
use of org.evosuite.symbolic.expr.Variable in project evosuite by EvoSuite.
the class DSETestGenerator method reduce.
/**
* Apply cone of influence reduction to constraints with respect to the last
* constraint in the list
*
* @param constraints
* @return
*/
private List<Constraint<?>> reduce(List<Constraint<?>> constraints) {
Constraint<?> target = constraints.get(constraints.size() - 1);
Set<Variable<?>> dependencies = getVariables(target);
LinkedList<Constraint<?>> coi = new LinkedList<Constraint<?>>();
if (dependencies.size() <= 0)
return coi;
coi.add(target);
for (int i = constraints.size() - 2; i >= 0; i--) {
Constraint<?> constraint = constraints.get(i);
Set<Variable<?>> variables = getVariables(constraint);
for (Variable<?> var : dependencies) {
if (variables.contains(var)) {
dependencies.addAll(variables);
coi.addFirst(constraint);
break;
}
}
}
return coi;
}
use of org.evosuite.symbolic.expr.Variable in project evosuite by EvoSuite.
the class DSETestGenerator method isRelevant.
/**
* Returns true iff the constraint has at least one variable that is
*
* @param constraint
* @param targets
* @return
*/
private boolean isRelevant(Constraint<?> constraint, Set<VariableReference> targets) {
Set<Variable<?>> variables = constraint.getVariables();
Set<String> targetNames = new HashSet<String>();
for (VariableReference v : targets) {
targetNames.add(v.getName());
}
for (Variable<?> var : variables) {
if (targetNames.contains(var.getName()))
return true;
}
return false;
}
Aggregations