Search in sources :

Example 1 with CarryVariable

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();
}
Also used : Program(jkind.lustre.Program) SimulationProgram(edu.uah.rsesc.aadlsimulator.agree.SimulationProgram) IdExpr(jkind.lustre.IdExpr) ProgramBuilder(jkind.lustre.builders.ProgramBuilder) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) CarryVariable(edu.uah.rsesc.aadlsimulator.agree.CarryVariable) NodeBuilder(jkind.lustre.builders.NodeBuilder) BinaryExpr(jkind.lustre.BinaryExpr) Expr(jkind.lustre.Expr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) IntExpr(jkind.lustre.IntExpr) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) SimulationProgramBuilder(edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder) IntExpr(jkind.lustre.IntExpr)

Example 2 with CarryVariable

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

Aggregations

CarryVariable (edu.uah.rsesc.aadlsimulator.agree.CarryVariable)2 BinaryExpr (jkind.lustre.BinaryExpr)2 Expr (jkind.lustre.Expr)2 IdExpr (jkind.lustre.IdExpr)2 IntExpr (jkind.lustre.IntExpr)2 SimulationProgram (edu.uah.rsesc.aadlsimulator.agree.SimulationProgram)1 SimulationProgramBuilder (edu.uah.rsesc.aadlsimulator.agree.SimulationProgramBuilder)1 ArrayExpr (jkind.lustre.ArrayExpr)1 BoolExpr (jkind.lustre.BoolExpr)1 Equation (jkind.lustre.Equation)1 IfThenElseExpr (jkind.lustre.IfThenElseExpr)1 Program (jkind.lustre.Program)1 RealExpr (jkind.lustre.RealExpr)1 TupleExpr (jkind.lustre.TupleExpr)1 VarDecl (jkind.lustre.VarDecl)1 NodeBuilder (jkind.lustre.builders.NodeBuilder)1 ProgramBuilder (jkind.lustre.builders.ProgramBuilder)1 ArrayValue (jkind.lustre.values.ArrayValue)1 BooleanValue (jkind.lustre.values.BooleanValue)1 EnumValue (jkind.lustre.values.EnumValue)1