Search in sources :

Example 6 with RealConstraint

use of org.evosuite.symbolic.expr.RealConstraint in project evosuite by EvoSuite.

the class TestRealSearch method testEvosuiteExample2.

@Test
public void testEvosuiteExample2() {
    double var1 = 355.80758027529504;
    // var3__SYM(355.80758027529504) >= 0.0 dist: 177.90379013764752
    // var3__SYM(355.80758027529504) == 0.0 dist: 177.90379013764752
    RealVariable realVar = new RealVariable("test1", var1, -1000000, 1000000);
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new RealConstraint(realVar, Comparator.GE, new RealConstant(0.0)));
    constraints.add(new RealConstraint(realVar, Comparator.EQ, new RealConstant(0.0)));
    EvoSuiteSolver skr = new EvoSuiteSolver();
    Map<String, Object> result;
    try {
        result = solve(skr, constraints);
        assertNotNull(result);
        if (result.containsKey("test1"))
            var1 = ((Number) result.get("test1")).doubleValue();
        assertEquals(0, var1, 0.0001);
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) Constraint(org.evosuite.symbolic.expr.Constraint) RealConstraint(org.evosuite.symbolic.expr.RealConstraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) RealVariable(org.evosuite.symbolic.expr.fp.RealVariable) RealConstant(org.evosuite.symbolic.expr.fp.RealConstant) RealConstraint(org.evosuite.symbolic.expr.RealConstraint) Test(org.junit.Test)

Example 7 with RealConstraint

use of org.evosuite.symbolic.expr.RealConstraint in project evosuite by EvoSuite.

the class TestRealConstraint method buildConstraintSystem.

private static Collection<Constraint<?>> buildConstraintSystem() {
    RealVariable var0 = new RealVariable("var0", INIT_DOUBLE, Double.MIN_VALUE, Double.MAX_VALUE);
    RealConstant constPi = new RealConstant(Math.PI);
    RealConstraint constr1 = new RealConstraint(var0, Comparator.EQ, constPi);
    return Arrays.<Constraint<?>>asList(constr1);
}
Also used : RealConstant(org.evosuite.symbolic.expr.fp.RealConstant) Constraint(org.evosuite.symbolic.expr.Constraint) RealConstraint(org.evosuite.symbolic.expr.RealConstraint) RealVariable(org.evosuite.symbolic.expr.fp.RealVariable) RealConstraint(org.evosuite.symbolic.expr.RealConstraint)

Example 8 with RealConstraint

use of org.evosuite.symbolic.expr.RealConstraint 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;
    }
}
Also used : DistanceCalculator(org.evosuite.symbolic.expr.DistanceCalculator) IntegerConstraint(org.evosuite.symbolic.expr.IntegerConstraint) StringConstraint(org.evosuite.symbolic.expr.StringConstraint) RealConstraint(org.evosuite.symbolic.expr.RealConstraint)

Example 9 with RealConstraint

use of org.evosuite.symbolic.expr.RealConstraint in project evosuite by EvoSuite.

the class TestRealSearch method testLTVariable.

@Test
public void testLTVariable() {
    double var1 = 2.6576;
    double var2 = 1.434;
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new RealConstraint(new RealVariable("test1", var1, -1000000.0, 1000000.0), Comparator.LT, new RealVariable("test2", var2, -1000000.0, 1000000.0)));
    EvoSuiteSolver skr = new EvoSuiteSolver();
    Map<String, Object> result;
    try {
        result = solve(skr, constraints);
        assertNotNull(result);
        if (result.containsKey("test1"))
            var1 = ((Number) result.get("test1")).doubleValue();
        if (result.containsKey("test2"))
            var2 = ((Number) result.get("test2")).doubleValue();
        assertTrue(var1 < var2);
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) Constraint(org.evosuite.symbolic.expr.Constraint) RealConstraint(org.evosuite.symbolic.expr.RealConstraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) RealVariable(org.evosuite.symbolic.expr.fp.RealVariable) RealConstraint(org.evosuite.symbolic.expr.RealConstraint) Test(org.junit.Test)

Example 10 with RealConstraint

use of org.evosuite.symbolic.expr.RealConstraint in project evosuite by EvoSuite.

the class TestRealSearch method testEvosuiteExample3.

// @Test
public void testEvosuiteExample3() {
    // ((1102.5 + var22__SYM(12.220999717712402)) *
    // var19__SYM(-45.633541107177734)) == 2.772399987618165E32
    double var1 = 12.220999717712402;
    double var2 = -45.633541107177734;
    RealVariable realVar1 = new RealVariable("test1", var1, -1000000, 1000000);
    RealVariable realVar2 = new RealVariable("test2", var2, -1000000, 1000000);
    List<Constraint<?>> constraints = new ArrayList<Constraint<?>>();
    constraints.add(new RealConstraint(new RealBinaryExpression(new RealBinaryExpression(new RealConstant(1102.5), Operator.PLUS, realVar1, 1.22209997177135E16), Operator.MUL, realVar2, -5.57687492989087E32), Comparator.EQ, new RealConstant(2.772399987618165E32)));
    assert (DistanceEstimator.getDistance(constraints) > 0);
    EvoSuiteSolver skr = new EvoSuiteSolver();
    Map<String, Object> result;
    try {
        result = solve(skr, constraints);
        assertNotNull(result);
        if (result.containsKey("test1"))
            var1 = ((Number) result.get("test1")).doubleValue();
        if (result.containsKey("test2"))
            var2 = ((Number) result.get("test2")).doubleValue();
        assertEquals(var1, var2, 0.0001);
    } catch (SolverTimeoutException e) {
        fail();
    }
}
Also used : SolverTimeoutException(org.evosuite.symbolic.solver.SolverTimeoutException) Constraint(org.evosuite.symbolic.expr.Constraint) RealConstraint(org.evosuite.symbolic.expr.RealConstraint) EvoSuiteSolver(org.evosuite.symbolic.solver.avm.EvoSuiteSolver) ArrayList(java.util.ArrayList) RealVariable(org.evosuite.symbolic.expr.fp.RealVariable) RealConstant(org.evosuite.symbolic.expr.fp.RealConstant) RealBinaryExpression(org.evosuite.symbolic.expr.fp.RealBinaryExpression) RealConstraint(org.evosuite.symbolic.expr.RealConstraint)

Aggregations

RealConstraint (org.evosuite.symbolic.expr.RealConstraint)23 Constraint (org.evosuite.symbolic.expr.Constraint)22 RealVariable (org.evosuite.symbolic.expr.fp.RealVariable)22 ArrayList (java.util.ArrayList)21 SolverTimeoutException (org.evosuite.symbolic.solver.SolverTimeoutException)21 EvoSuiteSolver (org.evosuite.symbolic.solver.avm.EvoSuiteSolver)21 Test (org.junit.Test)20 RealConstant (org.evosuite.symbolic.expr.fp.RealConstant)16 RealBinaryExpression (org.evosuite.symbolic.expr.fp.RealBinaryExpression)2 DistanceCalculator (org.evosuite.symbolic.expr.DistanceCalculator)1 IntegerConstraint (org.evosuite.symbolic.expr.IntegerConstraint)1 StringConstraint (org.evosuite.symbolic.expr.StringConstraint)1