Search in sources :

Example 1 with NodeLemma

use of com.rockwellcollins.atc.agree.agree.NodeLemma in project AGREE by loonwerks.

the class AgreeASTBuilder method caseNodeDef.

@Override
public Expr caseNodeDef(NodeDef expr) {
    String nodeName = AgreeUtils.getNodeName(expr);
    for (Node node : globalNodes) {
        if (node.id.equals(nodeName)) {
            return null;
        }
    }
    List<VarDecl> inputs = agreeVarsFromArgs(expr.getArgs(), null);
    List<VarDecl> outputs = agreeVarsFromArgs(expr.getRets(), null);
    NodeBodyExpr body = expr.getNodeBody();
    List<VarDecl> internals = agreeVarsFromArgs(body.getLocs(), null);
    List<Equation> eqs = new ArrayList<>();
    List<String> props = new ArrayList<>();
    // TODO are node lemmas deprecated?
    String lemmaName = "__nodeLemma";
    int lemmaIndex = 0;
    for (NodeStmt stmt : body.getStmts()) {
        if (stmt instanceof NodeLemma) {
            NodeLemma nodeLemma = (NodeLemma) stmt;
            String propName = lemmaName + lemmaIndex++;
            IdExpr eqId = new IdExpr(propName);
            internals.add(new VarDecl(eqId.id, NamedType.BOOL));
            Expr eqExpr = doSwitch(nodeLemma.getExpr());
            Equation eq = new Equation(eqId, eqExpr);
            eqs.add(eq);
            props.add(eqId.id);
        } else if (stmt instanceof NodeEq) {
            eqs.add(nodeEqToEq((NodeEq) stmt));
        }
    }
    NodeBuilder builder = new NodeBuilder(nodeName);
    builder.addInputs(inputs);
    builder.addOutputs(outputs);
    builder.addLocals(internals);
    builder.addEquations(eqs);
    builder.addProperties(props);
    Node n = builder.build();
    addToNodeList(n);
    return null;
}
Also used : NodeStmt(com.rockwellcollins.atc.agree.agree.NodeStmt) IdExpr(jkind.lustre.IdExpr) NodeLemma(com.rockwellcollins.atc.agree.agree.NodeLemma) Node(jkind.lustre.Node) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) NodeEq(com.rockwellcollins.atc.agree.agree.NodeEq) NodeBuilder(jkind.lustre.builders.NodeBuilder) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) EnumLitExpr(com.rockwellcollins.atc.agree.agree.EnumLitExpr) IndicesExpr(com.rockwellcollins.atc.agree.agree.IndicesExpr) TimeRiseExpr(com.rockwellcollins.atc.agree.agree.TimeRiseExpr) RecordAccessExpr(jkind.lustre.RecordAccessExpr) FlatmapExpr(com.rockwellcollins.atc.agree.agree.FlatmapExpr) TimeFallExpr(com.rockwellcollins.atc.agree.agree.TimeFallExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) GetPropertyExpr(com.rockwellcollins.atc.agree.agree.GetPropertyExpr) Expr(jkind.lustre.Expr) CastExpr(jkind.lustre.CastExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) TimeOfExpr(com.rockwellcollins.atc.agree.agree.TimeOfExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) ArrayExpr(jkind.lustre.ArrayExpr) PrevExpr(com.rockwellcollins.atc.agree.agree.PrevExpr) IdExpr(jkind.lustre.IdExpr) TimeExpr(com.rockwellcollins.atc.agree.agree.TimeExpr) FoldRightExpr(com.rockwellcollins.atc.agree.agree.FoldRightExpr) TagExpr(com.rockwellcollins.atc.agree.agree.TagExpr) EventExpr(com.rockwellcollins.atc.agree.agree.EventExpr) LatchedExpr(com.rockwellcollins.atc.agree.agree.LatchedExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) FunctionCallExpr(jkind.lustre.FunctionCallExpr) SelectionExpr(com.rockwellcollins.atc.agree.agree.SelectionExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) TupleExpr(jkind.lustre.TupleExpr) UnaryExpr(jkind.lustre.UnaryExpr) ArraySubExpr(com.rockwellcollins.atc.agree.agree.ArraySubExpr) IntExpr(jkind.lustre.IntExpr) PreExpr(com.rockwellcollins.atc.agree.agree.PreExpr) RecordLitExpr(com.rockwellcollins.atc.agree.agree.RecordLitExpr) ExistsExpr(com.rockwellcollins.atc.agree.agree.ExistsExpr) FoldLeftExpr(com.rockwellcollins.atc.agree.agree.FoldLeftExpr) RecordUpdateExpr(com.rockwellcollins.atc.agree.agree.RecordUpdateExpr) ForallExpr(com.rockwellcollins.atc.agree.agree.ForallExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) ArrayUpdateExpr(com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) IntLitExpr(com.rockwellcollins.atc.agree.agree.IntLitExpr) CallExpr(com.rockwellcollins.atc.agree.agree.CallExpr) ArrayLiteralExpr(com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr) VarDecl(jkind.lustre.VarDecl)

Example 2 with NodeLemma

use of com.rockwellcollins.atc.agree.agree.NodeLemma in project AGREE by loonwerks.

the class LinearizationRewriter method generateAgreeConstraintForm.

private static NodeDef generateAgreeConstraintForm(LinearizationDef linDef, BoundingSegments segs) {
    NodeDef result = af.createNodeDef();
    result.setName(getConstraintFormName(AgreeUtils.getNodeName(linDef)));
    Arg inputArg = af.createArg();
    PrimType inputArgType = af.createPrimType();
    inputArgType.setName("real");
    inputArg.setType(inputArgType);
    inputArg.setName("inp");
    result.getArgs().add(inputArg);
    Arg outputArg = af.createArg();
    PrimType outputArgType = af.createPrimType();
    outputArgType.setName("real");
    outputArg.setType(outputArgType);
    outputArg.setName("result");
    result.getArgs().add(outputArg);
    Arg constraintArg = af.createArg();
    PrimType constraintArgType = af.createPrimType();
    constraintArgType.setName("bool");
    constraintArg.setType(constraintArgType);
    constraintArg.setName("constraint");
    result.getRets().add(constraintArg);
    NamedElmExpr inputId = af.createNamedElmExpr();
    inputId.setElm(EcoreUtil.copy(inputArg));
    RealLitExpr domainCheckLowerLit = af.createRealLitExpr();
    domainCheckLowerLit.setVal(Double.toString(segs.lower.getFirst().startX));
    BinaryExpr domainCheckLowerExpr = af.createBinaryExpr();
    domainCheckLowerExpr.setOp("<=");
    domainCheckLowerExpr.setLeft(domainCheckLowerLit);
    domainCheckLowerExpr.setRight(EcoreUtil.copy(inputId));
    RealLitExpr domainCheckUpperLit = af.createRealLitExpr();
    domainCheckUpperLit.setVal(Double.toString(segs.lower.getLast().stopX));
    BinaryExpr domainCheckUpperExpr = af.createBinaryExpr();
    domainCheckUpperExpr.setOp("<=");
    domainCheckUpperExpr.setLeft(EcoreUtil.copy(inputId));
    domainCheckUpperExpr.setRight(domainCheckUpperLit);
    BinaryExpr domainCheckExpr = af.createBinaryExpr();
    domainCheckExpr.setOp("and");
    domainCheckExpr.setLeft(domainCheckLowerExpr);
    domainCheckExpr.setRight(domainCheckUpperExpr);
    BoolLitExpr trueLitExpr = af.createBoolLitExpr();
    BooleanLiteral trueLitValue = aadlF.createBooleanLiteral();
    trueLitValue.setValue(true);
    trueLitExpr.setVal(trueLitValue);
    Expr upperBoundExpr = EcoreUtil.copy(trueLitExpr);
    for (Segment seg : segs.upper) {
        BinaryExpr andExpr = af.createBinaryExpr();
        andExpr.setOp("and");
        andExpr.setLeft(upperBoundExpr);
        andExpr.setRight(generateAgreeLinearBoundImplicationExpr(inputArg, outputArg, "<=", seg));
        upperBoundExpr = andExpr;
    }
    Expr lowerBoundExpr = EcoreUtil.copy(trueLitExpr);
    for (Segment seg : segs.lower) {
        BinaryExpr andExpr = af.createBinaryExpr();
        andExpr.setOp("and");
        andExpr.setLeft(lowerBoundExpr);
        andExpr.setRight(generateAgreeLinearBoundImplicationExpr(inputArg, outputArg, ">=", seg));
        lowerBoundExpr = andExpr;
    }
    BinaryExpr boundsCheckExpr = af.createBinaryExpr();
    boundsCheckExpr.setOp("and");
    boundsCheckExpr.setLeft(upperBoundExpr);
    boundsCheckExpr.setRight(lowerBoundExpr);
    BinaryExpr constraintExpr = af.createBinaryExpr();
    constraintExpr.setOp("and");
    constraintExpr.setLeft(domainCheckExpr);
    constraintExpr.setRight(boundsCheckExpr);
    NodeEq constraintEq = af.createNodeEq();
    constraintEq.getLhs().add(constraintArg);
    constraintEq.setExpr(constraintExpr);
    NodeBodyExpr nodeBody = af.createNodeBodyExpr();
    nodeBody.getStmts().add(constraintEq);
    result.setNodeBody(nodeBody);
    NodeLemma domainCheckLemma = af.createNodeLemma();
    domainCheckLemma.setStr(result.getName() + " domain check");
    domainCheckLemma.setExpr(EcoreUtil.copy(domainCheckExpr));
    nodeBody.getStmts().add(domainCheckLemma);
    return result;
}
Also used : BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) NodeDef(com.rockwellcollins.atc.agree.agree.NodeDef) NodeLemma(com.rockwellcollins.atc.agree.agree.NodeLemma) BooleanLiteral(org.osate.aadl2.BooleanLiteral) BinaryExpr(com.rockwellcollins.atc.agree.agree.BinaryExpr) NodeEq(com.rockwellcollins.atc.agree.agree.NodeEq) Segment(com.rockwellcollins.atc.agree.analysis.linearization.Linearize.Segment) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) Expr(com.rockwellcollins.atc.agree.agree.Expr) BoolLitExpr(com.rockwellcollins.atc.agree.agree.BoolLitExpr) NodeBodyExpr(com.rockwellcollins.atc.agree.agree.NodeBodyExpr) BinaryExpr(com.rockwellcollins.atc.agree.agree.BinaryExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr) Arg(com.rockwellcollins.atc.agree.agree.Arg) PrimType(com.rockwellcollins.atc.agree.agree.PrimType) RealLitExpr(com.rockwellcollins.atc.agree.agree.RealLitExpr) NamedElmExpr(com.rockwellcollins.atc.agree.agree.NamedElmExpr)

Aggregations

BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)2 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)2 NodeBodyExpr (com.rockwellcollins.atc.agree.agree.NodeBodyExpr)2 NodeEq (com.rockwellcollins.atc.agree.agree.NodeEq)2 NodeLemma (com.rockwellcollins.atc.agree.agree.NodeLemma)2 RealLitExpr (com.rockwellcollins.atc.agree.agree.RealLitExpr)2 Arg (com.rockwellcollins.atc.agree.agree.Arg)1 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)1 ArraySubExpr (com.rockwellcollins.atc.agree.agree.ArraySubExpr)1 ArrayUpdateExpr (com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr)1 BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)1 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)1 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)1 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)1 ExistsExpr (com.rockwellcollins.atc.agree.agree.ExistsExpr)1 Expr (com.rockwellcollins.atc.agree.agree.Expr)1 FlatmapExpr (com.rockwellcollins.atc.agree.agree.FlatmapExpr)1 FoldLeftExpr (com.rockwellcollins.atc.agree.agree.FoldLeftExpr)1 FoldRightExpr (com.rockwellcollins.atc.agree.agree.FoldRightExpr)1 ForallExpr (com.rockwellcollins.atc.agree.agree.ForallExpr)1