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))));
}
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));
}
}
}
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;
}
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;
}
}
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));
}
}
}
Aggregations