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