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