Search in sources :

Example 21 with NodeBuilder

use of jkind.lustre.builders.NodeBuilder 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 22 with NodeBuilder

use of jkind.lustre.builders.NodeBuilder in project AMASE by loonwerks.

the class FaultASTBuilder method createCommNode.

/**
 * Create Lustre node for asymmetric fault connection nodes.
 *
 * @param node AgreeNode corresponds to the "sender" node that has the fan out connections.
 * 			   This is needed to access the type of connection for input/output of this node.
 * @param fstmt FaultStatement associated with the sender component output.
 * @param fault	Fault built from fault statement.
 * @param nodeName Name of asymmetric node.
 * @param connNumber How many connections from sender to receivers (used in naming).
 * @return Node : lustre node of this communication node.
 */
private Node createCommNode(AgreeNode node, FaultStatement fstmt, Fault fault, String nodeName, int connNumber) {
    // 1. Create unique node name
    NodeBuilder newNode = new NodeBuilder(nodeName);
    // 2. Get the output/input type from the node and the fstmt
    List<AgreeVar> nodeOutputs = node.outputs;
    AgreeVar outputOfInterest = null;
    // Assume asymmetric fault first in list.
    // Will have to display this to user somewhere.
    List<NamedElement> nomFaultConn = new ArrayList<NamedElement>();
    // Get the nominal connection
    for (FaultSubcomponent fs : fstmt.getFaultDefinitions()) {
        if (fs instanceof OutputStatement) {
            nomFaultConn = ((OutputStatement) fs).getNom_conn();
        }
    }
    // Get the agree node output that this fault is connected to
    for (AgreeVar agreeVar : nodeOutputs) {
        String temp = agreeVar.id;
        if (temp.contentEquals(nomFaultConn.get(0).getName())) {
            // This agreeVar is the sender var we want to save for the
            // later mapping to the receiver var.
            outputOfInterest = agreeVar;
        }
    }
    // Now the same type on the AgreeNode outputOfInterest
    // is the same as what we will create for the type of
    // both input and output of commNode.
    Type type = outputOfInterest.type;
    newNode = createInputForCommNode(newNode, fault, outputOfInterest.type, nodeName);
    newNode = createOutputForCommNode(newNode);
    newNode = createLocalsForCommNode(newNode, fault);
    newNode = createEquationsForCommNode(newNode, fault, type, nodeName);
    return newNode.build();
}
Also used : RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) FaultSubcomponent(edu.umn.cs.crisys.safety.safety.FaultSubcomponent) ArrayList(java.util.ArrayList) NodeBuilder(jkind.lustre.builders.NodeBuilder) NamedElement(org.osate.aadl2.NamedElement) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) OutputStatement(edu.umn.cs.crisys.safety.safety.OutputStatement)

Example 23 with NodeBuilder

use of jkind.lustre.builders.NodeBuilder in project AMASE by loonwerks.

the class AsymFaultASTBuilder method addFaultsToCommNode.

/**
 * Creates a lustre node with all fault node calls defined for a particular agree
 * node output. Returns completed Lustre node.
 *
 * @param agreeNode The AgreeNode which has the fault list associated with an output.
 * @param faults The List<Fault> that is on an output of the agree node.
 * @param senderOutput DataPortImpl is the agreeNode output that these faults are connected to.
 * @param nodeName String of the name of the node to be created.
 * @param i The unique id number associated with the node to be created.
 * @return Node to be inserted into Lustre.
 */
private Node addFaultsToCommNode(AgreeNode agreeNode, List<Fault> faults, DataPortImpl senderOutput, String nodeName, int i) {
    // Create unique node name
    NodeBuilder newNode = new NodeBuilder(nodeName);
    List<AgreeVar> nodeOutputs = agreeNode.outputs;
    AgreeVar outputOfInterest = null;
    // Get name of output according to senderOutput data port impl
    String nameOfOutput = senderOutput.getName();
    // Find the output in agree node outputs in order to access type.
    for (AgreeVar agreeVar : nodeOutputs) {
        String temp = agreeVar.id;
        if (temp.contentEquals(nameOfOutput)) {
            // This agreeVar is the sender var we want to save for the
            // later mapping to the receiver var.
            outputOfInterest = agreeVar;
        }
    }
    if (outputOfInterest == null) {
        new SafetyException("Cannot locate output for asymmetric fault in Agree: " + senderOutput.getName());
    }
    // Now the same type on the AgreeNode outputOfInterest
    // is the same as what we will create for the type of
    // both input and output of commNode.
    Type type = outputOfInterest.type;
    newNode = createInputForCommNode(agreeNode, newNode, faults, outputOfInterest.type, nodeName);
    newNode = super.createOutputForCommNode(newNode);
    newNode = createLocalsForCommNode(newNode, faults);
    newNode = createEquationsForCommNode(newNode, faults, type, nodeName);
    return newNode.build();
}
Also used : RecordType(jkind.lustre.RecordType) Type(jkind.lustre.Type) NamedType(jkind.lustre.NamedType) NodeBuilder(jkind.lustre.builders.NodeBuilder) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 24 with NodeBuilder

use of jkind.lustre.builders.NodeBuilder 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 25 with NodeBuilder

use of jkind.lustre.builders.NodeBuilder 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)

Aggregations

NodeBuilder (jkind.lustre.builders.NodeBuilder)37 Equation (jkind.lustre.Equation)30 VarDecl (jkind.lustre.VarDecl)30 IdExpr (jkind.lustre.IdExpr)29 BinaryExpr (jkind.lustre.BinaryExpr)28 Expr (jkind.lustre.Expr)26 UnaryExpr (jkind.lustre.UnaryExpr)24 BoolExpr (jkind.lustre.BoolExpr)23 NodeCallExpr (jkind.lustre.NodeCallExpr)22 ArrayList (java.util.ArrayList)18 IfThenElseExpr (jkind.lustre.IfThenElseExpr)17 IntExpr (jkind.lustre.IntExpr)15 Node (jkind.lustre.Node)11 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)10 ProgramBuilder (jkind.lustre.builders.ProgramBuilder)10 Program (jkind.lustre.Program)9 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)8 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)7 SimulationProgram (edu.uah.rsesc.aadlsimulator.agree.SimulationProgram)6 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)5