use of com.rockwellcollins.atc.agree.agree.Expr 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;
}
use of com.rockwellcollins.atc.agree.agree.Expr in project AGREE by loonwerks.
the class AgreeTypeSystem method isInLinearizationBody.
public static boolean isInLinearizationBody(Expr expr) {
boolean result = false;
EObject current = expr;
while (current != null && current instanceof Expr) {
EObject container = current.eContainer();
if (container instanceof LinearizationDef) {
result = ((LinearizationDef) container).getExprBody().equals(current);
}
current = container;
}
return result;
}
use of com.rockwellcollins.atc.agree.agree.Expr in project AGREE by loonwerks.
the class WhenStatementImpl method basicSetCondition.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetCondition(Expr newCondition, NotificationChain msgs) {
Expr oldCondition = condition;
condition = newCondition;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, AgreePackage.WHEN_STATEMENT__CONDITION, oldCondition, newCondition);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
use of com.rockwellcollins.atc.agree.agree.Expr in project AGREE by loonwerks.
the class WhenStatementImpl method basicSetEvent.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetEvent(Expr newEvent, NotificationChain msgs) {
Expr oldEvent = event;
event = newEvent;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, AgreePackage.WHEN_STATEMENT__EVENT, oldEvent, newEvent);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
use of com.rockwellcollins.atc.agree.agree.Expr in project AGREE by loonwerks.
the class WheneverBecomesTrueStatementImpl method basicSetEffect.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public NotificationChain basicSetEffect(Expr newEffect, NotificationChain msgs) {
Expr oldEffect = effect;
effect = newEffect;
if (eNotificationRequired()) {
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, AgreePackage.WHENEVER_BECOMES_TRUE_STATEMENT__EFFECT, oldEffect, newEffect);
if (msgs == null)
msgs = notification;
else
msgs.add(notification);
}
return msgs;
}
Aggregations