Search in sources :

Example 6 with BinaryExpr

use of jkind.lustre.BinaryExpr in project AGREE by loonwerks.

the class Main method testReal.

private static void testReal() throws IOException {
    System.out.println("=============Real Test=============");
    final Evaluator baseEvaluator = createEvaluator(INPUT_DIRECTORY + "symb_test_real.lus");
    final Evaluator evaluator = new Evaluator(baseEvaluator, Arrays.asList(new BinaryExpr(new IdExpr("__SIM_PE___ASSUME0"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("__SIM_PE___ASSUME1"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("__SIM_PE__TOP__ss__TILDE__0__DOT____GUARANTEE0"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("__SIM_PE__TOP__ss__TILDE__0__DOT____GUARANTEE1"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("in1"), BinaryOp.EQUAL, new RealExpr(BigDecimal.valueOf(60))), new BinaryExpr(new IdExpr("in2"), BinaryOp.EQUAL, new RealExpr(BigDecimal.valueOf(10)))));
    testValue("in1", evaluator, new RealValue(BigFraction.valueOf(BigDecimal.valueOf(60))));
    testValue("in2", evaluator, new RealValue(BigFraction.valueOf(BigDecimal.valueOf(10))));
    testValue("out1", evaluator, new RealValue(BigFraction.valueOf(BigDecimal.valueOf(30))));
    testValue("out2", evaluator, new RealValue(BigFraction.valueOf(BigDecimal.valueOf(20))));
}
Also used : RealValue(jkind.lustre.values.RealValue) BoolExpr(jkind.lustre.BoolExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) Evaluator(edu.uah.rsesc.aadlsimulator.agree.eval.Evaluator) RealExpr(jkind.lustre.RealExpr)

Example 7 with BinaryExpr

use of jkind.lustre.BinaryExpr in project AGREE by loonwerks.

the class FrameAssertionHelper method addNextFrameAssertions.

/**
 * Adds the frame specific assertions for the next frame to an assertion collection. Does not add assertions related to property enablement.
 * @param program
 * @param lastResults
 * @param assertions is the collection to which assertions will be added.
 */
public static void addNextFrameAssertions(final SimulationProgram program, final SimulationFrameResults lastResults, final Collection<Expr> assertions) {
    if (lastResults == null) {
        for (final Expr c : program.getInitialConstraints()) {
            assertions.add(c);
        }
    } else {
        for (final CarryVariable cv : program.getCarryVariables()) {
            final Value value = lastResults.getValue(cv.getOutputVariableExpression().toString());
            if (value == null) {
                throw new RuntimeException("Unable to get value for: " + cv.getOutputVariableExpression().toString());
            }
            final Expr valueExpression = valueToExpr(value);
            assertions.add(new BinaryExpr(cv.getInputVariableExpression(), BinaryOp.EQUAL, valueExpression));
        }
    }
}
Also used : BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) TupleExpr(jkind.lustre.TupleExpr) ArrayExpr(jkind.lustre.ArrayExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealValue(jkind.lustre.values.RealValue) TupleValue(jkind.lustre.values.TupleValue) Value(jkind.lustre.values.Value) EnumValue(jkind.lustre.values.EnumValue) ArrayValue(jkind.lustre.values.ArrayValue) BooleanValue(jkind.lustre.values.BooleanValue) IntegerValue(jkind.lustre.values.IntegerValue) CarryVariable(edu.uah.rsesc.aadlsimulator.agree.CarryVariable)

Example 8 with BinaryExpr

use of jkind.lustre.BinaryExpr in project AGREE by loonwerks.

the class CreateSimulationGuarantee method addDummyGuaranteeExpressions.

/**
 * Adds expressions that guarantee the variable declarations equal themselves. This is needed to ensure that JKind provies the values in the counterexample.
 * @param guaranteePartNum
 * @param varDecls
 * @return
 */
private int addDummyGuaranteeExpressions(final int guaranteePartNum, final Collection<VarDecl> varDecls) {
    int nextGuaranteeNum = guaranteePartNum;
    for (final VarDecl varDecl : varDecls) {
        final String prevExprId = buildSimGuaranteeId(nextGuaranteeNum - 1);
        nextGuaranteeNum = createGuaranteePartExpression(nextGuaranteeNum, new BinaryExpr(new IdExpr(prevExprId), BinaryOp.AND, new BinaryExpr(new IdExpr(varDecl.id), BinaryOp.EQUAL, new IdExpr(varDecl.id))), nodeBuilder);
    }
    return nextGuaranteeNum;
}
Also used : IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) BinaryExpr(jkind.lustre.BinaryExpr)

Example 9 with BinaryExpr

use of jkind.lustre.BinaryExpr in project AGREE by loonwerks.

the class AGREESimulationState method createEvaluator.

private Evaluator createEvaluator(final Collection<Expr> constraints, final Set<SimulationProperty> disabledProperties) {
    try {
        final SimulationFrameResults lastFrameResults = frameInfos.size() == 0 ? null : frameInfos.get(frameInfos.size() - 1).getFrameResults();
        final List<Expr> assertions = new ArrayList<Expr>();
        FrameAssertionHelper.addNextFrameAssertions(simulationProgram, lastFrameResults, assertions);
        assertions.addAll(constraints);
        // Add assertions for property enablement variables
        for (final SimulationProperty simProp : simulationProgram.getSimulationProperties()) {
            if (simProp.getEnablementVariableId() != null) {
                assertions.add(new BinaryExpr(new IdExpr(simProp.getEnablementVariableId()), BinaryOp.EQUAL, new BoolExpr(disabledProperties.contains(simProp) ? false : true)));
            }
        }
        // Create the new evaluator
        return new Evaluator(baseEvaluator, assertions);
    } catch (EvaluationException ex) {
        return null;
    }
}
Also used : BoolExpr(jkind.lustre.BoolExpr) SimulationFrameResults(edu.uah.rsesc.aadlsimulator.agree.sim.SimulationFrameResults) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) Expr(jkind.lustre.Expr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) IdExpr(jkind.lustre.IdExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) SimulationProperty(edu.uah.rsesc.aadlsimulator.agree.SimulationProperty) EvaluationException(edu.uah.rsesc.aadlsimulator.agree.eval.EvaluationException) Evaluator(edu.uah.rsesc.aadlsimulator.agree.eval.Evaluator)

Example 10 with BinaryExpr

use of jkind.lustre.BinaryExpr in project AGREE by loonwerks.

the class ExpressionFlattener method flattenEqualsExpression.

private void flattenEqualsExpression(final BinaryExpr expr, final List<BinaryExpr> results) {
    // Assume that both sides of the binary expression are the same type
    final Type leftType = expr.left.accept(typeReconstructor);
    if (leftType instanceof ArrayType) {
        flattenArrayEquality(expr, (ArrayType) leftType, results);
    } else if (leftType instanceof RecordType) {
        flattenRecordEquality(expr, (RecordType) leftType, results);
    } else if (leftType instanceof NamedType) {
        // Flatten both sides of the expression
        final Expr newLeft = flattenExpression(expr.left);
        final Expr newRight = flattenExpression(expr.right);
        if (newLeft != null && newRight != null) {
            results.add(new BinaryExpr(newLeft, expr.op, newRight));
        }
    }
}
Also used : ArrayType(jkind.lustre.ArrayType) NamedType(jkind.lustre.NamedType) RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) ArrayType(jkind.lustre.ArrayType) RecordType(jkind.lustre.RecordType) BinaryExpr(jkind.lustre.BinaryExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) RecordUpdateExpr(jkind.lustre.RecordUpdateExpr) ArrayUpdateExpr(jkind.lustre.ArrayUpdateExpr) ArrayExpr(jkind.lustre.ArrayExpr) Expr(jkind.lustre.Expr) RecordExpr(jkind.lustre.RecordExpr) IntExpr(jkind.lustre.IntExpr) NamedType(jkind.lustre.NamedType) BinaryExpr(jkind.lustre.BinaryExpr)

Aggregations

BinaryExpr (jkind.lustre.BinaryExpr)86 IdExpr (jkind.lustre.IdExpr)80 Expr (jkind.lustre.Expr)74 BoolExpr (jkind.lustre.BoolExpr)71 NodeCallExpr (jkind.lustre.NodeCallExpr)62 UnaryExpr (jkind.lustre.UnaryExpr)61 IfThenElseExpr (jkind.lustre.IfThenElseExpr)48 IntExpr (jkind.lustre.IntExpr)48 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)31 ArrayList (java.util.ArrayList)29 RecordAccessExpr (jkind.lustre.RecordAccessExpr)29 RealExpr (jkind.lustre.RealExpr)27 Equation (jkind.lustre.Equation)26 VarDecl (jkind.lustre.VarDecl)26 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)25 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)23 NodeBuilder (jkind.lustre.builders.NodeBuilder)22 TupleExpr (jkind.lustre.TupleExpr)20 ArrayExpr (jkind.lustre.ArrayExpr)15 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)11