use of jkind.lustre.NodeCallExpr in project AGREE by loonwerks.
the class AgreePatternTranslator method getTimeFall.
private AgreeVar getTimeFall(String varName, AgreeNodeBuilder builder, EObject reference) {
Map<String, AgreeVar> timeFallMap = builder.build().timeFallMap;
if (timeFallMap.containsKey(varName)) {
return timeFallMap.get(varName);
}
AgreeVar timeFall = new AgreeVar(varName + FALL_SUFFIX, NamedType.REAL, reference);
builder.addOutput(timeFall);
Expr Fall = new NodeCallExpr(AgreeRealtimeCalendarBuilder.FALL_NODE_NAME, new IdExpr(varName));
Expr timeVarExpr = expr("timeFall = (if Fall then time else (-1.0 -> pre timeFall))", to("timeFall", timeFall), to("Fall", Fall), to("time", timeExpr));
builder.addAssertion(new AgreeStatement(null, timeVarExpr, reference));
Expr lemmaExpr = expr("timeFall <= time and timeFall >= -1.0", to("timeFall", timeFall), to("time", timeExpr));
// add this assertion to help with proofs (it should always be true)
builder.addAssertion(new AgreeStatement("", lemmaExpr, reference));
builder.addTimeFall(varName, timeFall);
return timeFall;
}
use of jkind.lustre.NodeCallExpr 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);
}
use of jkind.lustre.NodeCallExpr in project AGREE by loonwerks.
the class LustreCondactNodeVisitor method visit.
@Override
public Expr visit(NodeCallExpr e) {
if (globalLustreNodeNames.contains(e.node)) {
List<Expr> newArgs = new ArrayList<>();
newArgs.add(new IdExpr(clockVarName));
newArgs.add(new IdExpr(initVarName));
newArgs.addAll(acceptList(e.args));
return new NodeCallExpr(AgreeMakeClockedLustreNodes.clockedNodePrefix + e.node, newArgs);
} else {
return new NodeCallExpr(e.node, acceptList(e.args));
}
}
use of jkind.lustre.NodeCallExpr in project AGREE by loonwerks.
the class LinearizationAgreeASTVisitor method visit.
@Override
public Expr visit(NodeCallExpr e) {
// If the call is to a linearization, generate ephemeral
// var and constraint then substitute an id expr to the ephemeral
// var for the fn call.
String linCallDef = linearizationMap.get(e.node);
if (linCallDef != null) {
AgreeVar ephemeral = new AgreeVar(ephemeralBaseName + Integer.toString(ephemeralIndex), jkind.lustre.NamedType.REAL, null, contextStack.peek().componentInstance, null);
++ephemeralIndex;
List<Expr> args = visitExprs(e.args);
args.add(new jkind.lustre.IdExpr(ephemeral.id));
jkind.lustre.NodeCallExpr constraintExpr = new jkind.lustre.NodeCallExpr(linCallDef, args);
contextStack.peek().addedVars.add(ephemeral);
contextStack.peek().liftedConstraintExprs.add(constraintExpr);
return new jkind.lustre.IdExpr(ephemeral.id);
}
return new NodeCallExpr(e.location, e.node, visitExprs(e.args));
}
use of jkind.lustre.NodeCallExpr in project AMASE by loonwerks.
the class AddFaultsToNodeVisitor method addNodeCall.
/**
* Method adds fault node call and nested trigger expression to the node
* builder. Ex fault node call: Sender__fault_1__node__val_out =
* Common_Faults__fail_to_real(__fault__nominal__sender_out, 1.0,
* fault__trigger__Sender__fault_1);
*
* Ex nested trigger expr: agree_node_output = if fault__trigger_1 then
* fault__node_1__val_out else if fault__trigger_2 then fault__node_2__val_out
* ... else __fault__nominal__output)
*
* @param nb NodeBuilder has these expressions added in assert stmts.
* @param f Fault that holds this fault node call information.
*/
private void addNodeCall(AgreeNodeBuilder nb, Fault f, Map<Fault, Expr> localFaultTriggerMap) {
List<IdExpr> lhsOfNodeCall = new ArrayList<IdExpr>();
// populate outputParamToActualMap
for (VarDecl v : f.faultNode.outputs) {
String lhsId = this.createFaultNodeEqId(f.id, v.id);
AgreeVar actual = new AgreeVar(lhsId, v.type, f.faultStatement);
nb.addLocal(actual);
lhsOfNodeCall.add(new IdExpr(lhsId));
f.outputParamToActualMap.put(v.id, actual);
}
// Call fault node and put this into lustre node as local equation.
AgreeEquation eq = new AgreeEquation(lhsOfNodeCall, new NodeCallExpr(f.faultNode.id, constructNodeInputs(f, localFaultTriggerMap)), f.faultStatement);
nb.addLocalEquation(eq);
}
Aggregations