Search in sources :

Example 11 with UnaryExpr

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

the class AgreePatternTranslator method translatePatternConstraint.

private Expr translatePatternConstraint(AgreeSporadicPattern pattern, AgreeNodeBuilder builder, EObject varReference) {
    AgreeVar jitterVar = new AgreeVar(JITTER_PREFIX + patternIndex, NamedType.REAL, varReference);
    AgreeVar periodVar = new AgreeVar(PERIOD_PREFIX + patternIndex, NamedType.REAL, varReference);
    AgreeVar timeoutVar = new AgreeVar(TIMEOUT_PREFIX + patternIndex, NamedType.REAL, varReference);
    builder.addOutput(jitterVar);
    builder.addOutput(periodVar);
    builder.addOutput(timeoutVar);
    IdExpr jitterId = new IdExpr(jitterVar.id);
    IdExpr periodId = new IdExpr(periodVar.id);
    IdExpr timeoutId = new IdExpr(timeoutVar.id);
    builder.addEventTime(timeoutVar);
    // -j <= jitter <= j
    Expr jitterLow = new BinaryExpr(new UnaryExpr(UnaryOp.NEGATIVE, pattern.jitter), BinaryOp.LESSEQUAL, jitterId);
    Expr jitterHigh = new BinaryExpr(jitterId, BinaryOp.LESSEQUAL, pattern.jitter);
    builder.addAssertion(new AgreeStatement(null, new BinaryExpr(jitterLow, BinaryOp.AND, jitterHigh), pattern.reference));
    // pnext >= 0 -> if pre ((pnext + jitter) = t) then pnext >= p +
    // pre(pnext) else pre(pnext)
    Expr prePNext = new UnaryExpr(UnaryOp.PRE, periodId);
    Expr pNextInit = new BinaryExpr(periodId, BinaryOp.GREATEREQUAL, new RealExpr(BigDecimal.ZERO));
    Expr pNextCond = new BinaryExpr(periodId, BinaryOp.PLUS, jitterId);
    pNextCond = new BinaryExpr(pNextCond, BinaryOp.EQUAL, timeExpr);
    pNextCond = new UnaryExpr(UnaryOp.PRE, pNextCond);
    Expr pNextThen = new BinaryExpr(pattern.period, BinaryOp.PLUS, prePNext);
    pNextThen = new BinaryExpr(periodId, BinaryOp.GREATEREQUAL, pNextThen);
    Expr pNextHold = new BinaryExpr(periodId, BinaryOp.EQUAL, prePNext);
    Expr pNextIf = new IfThenElseExpr(pNextCond, pNextThen, pNextHold);
    Expr pNext = new BinaryExpr(pNextInit, BinaryOp.ARROW, pNextIf);
    builder.addAssertion(new AgreeStatement(null, pNext, pattern.reference));
    // timeout = pnext + jitter
    Expr timeoutExpr = new BinaryExpr(periodId, BinaryOp.PLUS, jitterId);
    timeoutExpr = new BinaryExpr(timeoutId, BinaryOp.EQUAL, timeoutExpr);
    builder.addAssertion(new AgreeStatement(null, timeoutExpr, pattern.reference));
    // event = (t = timeout)
    Expr eventExpr = new BinaryExpr(timeExpr, BinaryOp.EQUAL, timeoutId);
    eventExpr = new BinaryExpr(pattern.event, BinaryOp.EQUAL, eventExpr);
    return eventExpr;
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) RealExpr(jkind.lustre.RealExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) IfThenElseExpr(jkind.lustre.IfThenElseExpr)

Example 12 with UnaryExpr

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

the class AgreeRealtimeCalendarBuilder method getTimeConstraint.

public static Expr getTimeConstraint(Set<AgreeVar> events) {
    IdExpr timeId = AgreePatternTranslator.timeExpr;
    Expr preTime = new UnaryExpr(UnaryOp.PRE, timeId);
    Expr nodeCall = new BinaryExpr(timeId, BinaryOp.MINUS, preTime);
    for (AgreeVar eventVar : events) {
        Expr event = new IdExpr(eventVar.id);
        BinaryExpr timeChange = new BinaryExpr(event, BinaryOp.MINUS, timeId);
        Expr preTimeChange = new UnaryExpr(UnaryOp.PRE, timeChange);
        nodeCall = new NodeCallExpr(MIN_POS_NODE_NAME, preTimeChange, nodeCall);
    }
    nodeCall = new BinaryExpr(preTime, BinaryOp.PLUS, nodeCall);
    Expr timeExpr = new BinaryExpr(timeId, BinaryOp.EQUAL, nodeCall);
    timeExpr = new BinaryExpr(new BoolExpr(true), BinaryOp.ARROW, timeExpr);
    Expr timeGrtPreTime = new BinaryExpr(timeId, BinaryOp.GREATER, preTime);
    Expr timeInitZero = new BinaryExpr(timeId, BinaryOp.EQUAL, new RealExpr(BigDecimal.ZERO));
    timeInitZero = new BinaryExpr(timeInitZero, BinaryOp.ARROW, timeGrtPreTime);
    return new BinaryExpr(timeInitZero, BinaryOp.AND, timeExpr);
}
Also used : BoolExpr(jkind.lustre.BoolExpr) IdExpr(jkind.lustre.IdExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) Expr(jkind.lustre.Expr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) RealExpr(jkind.lustre.RealExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 13 with UnaryExpr

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

the class AgreeRealtimeCalendarBuilder method getFallNode.

private static Node getFallNode() {
    NodeBuilder builder = new NodeBuilder(FALL_NODE_NAME);
    builder.addInput(new VarDecl("input", NamedType.BOOL));
    builder.addOutput(new VarDecl("output", NamedType.BOOL));
    IdExpr inputId = new IdExpr("input");
    IdExpr outputId = new IdExpr("output");
    Expr outputExpr = new UnaryExpr(UnaryOp.PRE, inputId);
    Expr notInput = new UnaryExpr(UnaryOp.NOT, inputId);
    outputExpr = new BinaryExpr(outputExpr, BinaryOp.AND, notInput);
    outputExpr = new BinaryExpr(notInput, BinaryOp.ARROW, outputExpr);
    builder.addEquation(new Equation(outputId, outputExpr));
    return builder.build();
}
Also used : IdExpr(jkind.lustre.IdExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) Expr(jkind.lustre.Expr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) BinaryExpr(jkind.lustre.BinaryExpr) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder) UnaryExpr(jkind.lustre.UnaryExpr)

Example 14 with UnaryExpr

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

the class GenerateUfcObligationsVisitor method constructNewNode.

/**
 * Method for constructing new programs using the UFC obligations.
 */
private Node constructNewNode(Node existing, ObligationSet obs) {
    List<VarDecl> locals = new ArrayList<>(existing.locals);
    List<Equation> equations = new ArrayList<>(existing.equations);
    // List<String> properties = new ArrayList<>(existing.properties);
    // Change: MWW 5/6: Don't really want existing properties here.
    List<String> properties = new ArrayList<>();
    /* writing the TCG obligations back as trap properties by negating them... */
    for (int i = 0; i < obs.positivePolarity.size(); i++) {
        String varName = TRAP_PROP_PREFIX + i;
        Obligation ob = obs.positivePolarity.get(i);
        locals.add(new VarDecl(varName, NamedType.BOOL));
        equations.add(new Equation(new IdExpr(varName), new UnaryExpr(UnaryOp.NOT, ob.getObligationExpr())));
        properties.add(varName);
        // renaming information
        if (renaming != null) {
            renaming.addRenaming(varName, ob.getEqAssignId(), ob.getTestedCondition().toString(), new HashSet<Obligation>(Arrays.asList(ob)));
        }
        System.out.println("Renaming: mapping " + varName + " --> " + ob.getEqAssignId());
    }
    Node newNode = new Node(existing.id, existing.inputs, existing.outputs, locals, equations, properties, existing.assertions, null, null, new ArrayList<String>());
    return newNode;
}
Also used : Obligation(com.rockwellcollins.atc.tcg.obligations.ufc.Obligation) IdExpr(jkind.lustre.IdExpr) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) UnaryExpr(jkind.lustre.UnaryExpr) VarDecl(jkind.lustre.VarDecl)

Example 15 with UnaryExpr

use of jkind.lustre.UnaryExpr in project AMASE by loonwerks.

the class AddFaultDriverGuardAssertionVisitor method visit.

@Override
public Node visit(Node node) {
    if (nodeId.equals(node.id)) {
        List<Expr> assertions = Lists.newArrayList(node.assertions);
        Expr expr = new IdExpr(faultDriverIds.get(0));
        for (int i = 1; i < faultDriverIds.size(); ++i) {
            expr = new BinaryExpr(expr, BinaryOp.AND, new IdExpr(faultDriverIds.get(i)));
        }
        assertions.add(new UnaryExpr(UnaryOp.NOT, expr));
        return new Node(node.location, node.id, node.inputs, node.outputs, node.locals, node.equations, node.properties, assertions, node.realizabilityInputs, node.contract, node.ivc);
    }
    return node;
}
Also used : BinaryExpr(jkind.lustre.BinaryExpr) Expr(jkind.lustre.Expr) UnaryExpr(jkind.lustre.UnaryExpr) IdExpr(jkind.lustre.IdExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) Node(jkind.lustre.Node) UnaryExpr(jkind.lustre.UnaryExpr)

Aggregations

UnaryExpr (jkind.lustre.UnaryExpr)36 BinaryExpr (jkind.lustre.BinaryExpr)34 IdExpr (jkind.lustre.IdExpr)34 Expr (jkind.lustre.Expr)32 BoolExpr (jkind.lustre.BoolExpr)29 NodeCallExpr (jkind.lustre.NodeCallExpr)29 IfThenElseExpr (jkind.lustre.IfThenElseExpr)24 Equation (jkind.lustre.Equation)21 IntExpr (jkind.lustre.IntExpr)18 VarDecl (jkind.lustre.VarDecl)17 NodeBuilder (jkind.lustre.builders.NodeBuilder)15 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)12 ArrayList (java.util.ArrayList)11 RealExpr (jkind.lustre.RealExpr)11 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)9 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)6 Node (jkind.lustre.Node)6 RecordAccessExpr (jkind.lustre.RecordAccessExpr)6 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)4 CondactExpr (jkind.lustre.CondactExpr)4