Search in sources :

Example 1 with Segment

use of com.rockwellcollins.atc.agree.analysis.linearization.Linearize.Segment in project AGREE by loonwerks.

the class LinearizationRewriter method generateLustreConstraintForm.

@SuppressWarnings("unused")
private static jkind.lustre.Node generateLustreConstraintForm(LinearizationDef linDef, BoundingSegments segs) {
    String nodeName = getConstraintFormName(AgreeUtils.getNodeName(linDef));
    List<VarDecl> inputs = new ArrayList<>();
    inputs.add(new jkind.lustre.VarDecl(inputId, jkind.lustre.NamedType.REAL));
    inputs.add(new jkind.lustre.VarDecl(outputId, jkind.lustre.NamedType.REAL));
    List<VarDecl> outputs = new ArrayList<>();
    inputs.add(new jkind.lustre.VarDecl(constraintId, jkind.lustre.NamedType.BOOL));
    List<VarDecl> locals = new ArrayList<>();
    locals.add(new jkind.lustre.VarDecl(domainCheckLemmaId, jkind.lustre.NamedType.BOOL));
    jkind.lustre.BinaryExpr domainCheckLowerExpr = new jkind.lustre.BinaryExpr(new jkind.lustre.RealExpr(BigDecimal.valueOf(segs.lower.getFirst().startX)), jkind.lustre.BinaryOp.LESSEQUAL, new jkind.lustre.IdExpr(inputId));
    jkind.lustre.BinaryExpr domainCheckUpperExpr = new jkind.lustre.BinaryExpr(new jkind.lustre.IdExpr(inputId), jkind.lustre.BinaryOp.LESSEQUAL, new jkind.lustre.RealExpr(BigDecimal.valueOf(segs.lower.getLast().stopX)));
    jkind.lustre.BinaryExpr domainCheckExpr = new jkind.lustre.BinaryExpr(domainCheckLowerExpr, jkind.lustre.BinaryOp.AND, domainCheckUpperExpr);
    jkind.lustre.Expr upperBoundExpr = new jkind.lustre.BoolExpr(true);
    for (Segment seg : segs.upper) {
        upperBoundExpr = new jkind.lustre.BinaryExpr(upperBoundExpr, jkind.lustre.BinaryOp.AND, generateLustreLinearBoundImplicationExpr(jkind.lustre.BinaryOp.LESSEQUAL, seg));
    }
    jkind.lustre.Expr lowerBoundExpr = new jkind.lustre.BoolExpr(true);
    for (Segment seg : segs.upper) {
        lowerBoundExpr = new jkind.lustre.BinaryExpr(lowerBoundExpr, jkind.lustre.BinaryOp.AND, generateLustreLinearBoundImplicationExpr(jkind.lustre.BinaryOp.GREATEREQUAL, seg));
    }
    jkind.lustre.Expr constraintExpr = new jkind.lustre.BinaryExpr(domainCheckExpr, jkind.lustre.BinaryOp.AND, new jkind.lustre.BinaryExpr(upperBoundExpr, jkind.lustre.BinaryOp.AND, lowerBoundExpr));
    List<Equation> equations = new ArrayList<>();
    equations.add(new jkind.lustre.Equation(new jkind.lustre.IdExpr(constraintId), constraintExpr));
    equations.add(new jkind.lustre.Equation(new jkind.lustre.IdExpr(domainCheckLemmaId), domainCheckExpr));
    List<String> properties = new ArrayList<>();
    properties.add(domainCheckLemmaId);
    NodeBuilder builder = new NodeBuilder(nodeName);
    builder.addInputs(inputs);
    builder.addOutputs(outputs);
    builder.addLocals(locals);
    builder.addEquations(equations);
    builder.addProperties(properties);
    return builder.build();
}
Also used : BinaryExpr(com.rockwellcollins.atc.agree.agree.BinaryExpr) ArrayList(java.util.ArrayList) Equation(jkind.lustre.Equation) Equation(jkind.lustre.Equation) NodeBuilder(jkind.lustre.builders.NodeBuilder) Segment(com.rockwellcollins.atc.agree.analysis.linearization.Linearize.Segment) VarDecl(jkind.lustre.VarDecl) VarDecl(jkind.lustre.VarDecl)

Example 2 with Segment

use of com.rockwellcollins.atc.agree.analysis.linearization.Linearize.Segment 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

BinaryExpr (com.rockwellcollins.atc.agree.agree.BinaryExpr)2 Segment (com.rockwellcollins.atc.agree.analysis.linearization.Linearize.Segment)2 Arg (com.rockwellcollins.atc.agree.agree.Arg)1 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)1 Expr (com.rockwellcollins.atc.agree.agree.Expr)1 NamedElmExpr (com.rockwellcollins.atc.agree.agree.NamedElmExpr)1 NodeBodyExpr (com.rockwellcollins.atc.agree.agree.NodeBodyExpr)1 NodeDef (com.rockwellcollins.atc.agree.agree.NodeDef)1 NodeEq (com.rockwellcollins.atc.agree.agree.NodeEq)1 NodeLemma (com.rockwellcollins.atc.agree.agree.NodeLemma)1 PrimType (com.rockwellcollins.atc.agree.agree.PrimType)1 RealLitExpr (com.rockwellcollins.atc.agree.agree.RealLitExpr)1 ArrayList (java.util.ArrayList)1 Equation (jkind.lustre.Equation)1 VarDecl (jkind.lustre.VarDecl)1 NodeBuilder (jkind.lustre.builders.NodeBuilder)1 BooleanLiteral (org.osate.aadl2.BooleanLiteral)1