use of edu.uah.rsesc.aadlsimulator.agree.CarryVariable in project AGREE by loonwerks.
the class ReplaceFollowedByOperator method transform.
public static SimulationProgram transform(final SimulationProgram program) {
final Program lustreProgram = program.getLustreProgram();
if (lustreProgram.nodes.size() != 1) {
throw new IllegalArgumentException("Only lustre programs with exactly one node are supported");
}
final ReplaceFollowedByOperator visitor = new ReplaceFollowedByOperator();
final NodeBuilder nodeBuilder = new NodeBuilder(visitor.visit(lustreProgram.getMainNode()));
// Create variable for the step number
nodeBuilder.addInput(new VarDecl(stepVariableId, NamedType.INT));
// Add an output for the next step number
nodeBuilder.addOutput(new VarDecl(nextStepVariableId, NamedType.INT));
nodeBuilder.addEquation(new Equation(new IdExpr(nextStepVariableId), new BinaryExpr(new IdExpr(stepVariableId), BinaryOp.PLUS, new IntExpr(1))));
// Create the new lustre program using the new node
final ProgramBuilder lustreProgramBuilder = new ProgramBuilder(lustreProgram);
lustreProgramBuilder.clearNodes();
lustreProgramBuilder.addNode(nodeBuilder.build());
// Create the simulation program
final SimulationProgramBuilder simulationProgramBuilder = new SimulationProgramBuilder(program);
final Expr stepVariableExpr = new IdExpr(stepVariableId);
// Ensure that the initial step is greater than the first step when simulating inductive counterexamples
final int initialStepValue = program.getType().isInductive() ? firstStepValue + 1 : firstStepValue;
simulationProgramBuilder.addInitialConstraint(new BinaryExpr(stepVariableExpr, BinaryOp.EQUAL, new IntExpr(initialStepValue)));
simulationProgramBuilder.addCarryVariable(new CarryVariable(stepVariableExpr, new IdExpr(nextStepVariableId)));
simulationProgramBuilder.setLustreProgram(lustreProgramBuilder.build());
return simulationProgramBuilder.build();
}
use of edu.uah.rsesc.aadlsimulator.agree.CarryVariable 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));
}
}
}
Aggregations