Search in sources :

Example 1 with RealExpr

use of jkind.lustre.RealExpr in project AGREE by loonwerks.

the class Main method testReal.

private static void testReal() throws IOException {
    System.out.println("=============Real Test=============");
    final Evaluator baseEvaluator = createEvaluator(INPUT_DIRECTORY + "symb_test_real.lus");
    final Evaluator evaluator = new Evaluator(baseEvaluator, Arrays.asList(new BinaryExpr(new IdExpr("__SIM_PE___ASSUME0"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("__SIM_PE___ASSUME1"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("__SIM_PE__TOP__ss__TILDE__0__DOT____GUARANTEE0"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("__SIM_PE__TOP__ss__TILDE__0__DOT____GUARANTEE1"), BinaryOp.EQUAL, new BoolExpr(true)), new BinaryExpr(new IdExpr("in1"), BinaryOp.EQUAL, new RealExpr(BigDecimal.valueOf(60))), new BinaryExpr(new IdExpr("in2"), BinaryOp.EQUAL, new RealExpr(BigDecimal.valueOf(10)))));
    testValue("in1", evaluator, new RealValue(BigFraction.valueOf(BigDecimal.valueOf(60))));
    testValue("in2", evaluator, new RealValue(BigFraction.valueOf(BigDecimal.valueOf(10))));
    testValue("out1", evaluator, new RealValue(BigFraction.valueOf(BigDecimal.valueOf(30))));
    testValue("out2", evaluator, new RealValue(BigFraction.valueOf(BigDecimal.valueOf(20))));
}
Also used : RealValue(jkind.lustre.values.RealValue) BoolExpr(jkind.lustre.BoolExpr) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) Evaluator(edu.uah.rsesc.aadlsimulator.agree.eval.Evaluator) RealExpr(jkind.lustre.RealExpr)

Example 2 with RealExpr

use of jkind.lustre.RealExpr in project AGREE by loonwerks.

the class AgreeASTBuilder method caseGetPropertyExpr.

@Override
public Expr caseGetPropertyExpr(GetPropertyExpr expr) {
    NamedElement propName = expr.getProp();
    PropertyExpression propVal;
    if (propName instanceof Property) {
        ComponentRef cr = expr.getComponentRef();
        NamedElement compName = null;
        if (cr instanceof DoubleDotRef) {
            compName = ((DoubleDotRef) cr).getElm();
        } else if (cr instanceof ThisRef) {
            compName = curInst;
        }
        Property prop = (Property) propName;
        propVal = AgreeUtils.getPropExpression(compName, prop);
        if (propVal == null) {
            if (Activator.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_UNSPECIFIED_AADL_PROPERTIES)) {
                String propInputName = unspecifiedAadlPropertyPrefix + compName.getName() + dotChar + prop.getName();
                unspecifiedAadlProperties.put(propInputName, expr);
                return new IdExpr(propInputName);
            } else {
                throw new AgreeException("Could not locate property value '" + prop.getQualifiedName() + "' in component '" + compName.getName() + "'.  Is it possible " + "that a 'this' statement is used in a context in which it wasn't supposed to?" + "  Analysis of unspecified AADL properties as inputs may be enabled in the AGREE preferences.");
            }
        }
    } else {
        propVal = AgreeUtils.getPropExpression((PropertyConstant) propName);
        if (propVal == null) {
            throw new AgreeException("Could not locate property value '" + propName.getQualifiedName());
        }
    }
    Expr res = null;
    if (propVal != null) {
        if (propVal instanceof StringLiteral) {
            // nodeStr += value.getValue() + ")";
            throw new AgreeException("Property value for '" + propName.getQualifiedName() + "' cannot be of string type");
        } else if (propVal instanceof NamedValue) {
            // EnumerationLiteral enVal = (EnumerationLiteral) absVal;
            throw new AgreeException("Property value for '" + propName.getQualifiedName() + "' cannot be of enumeration type");
        } else if (propVal instanceof BooleanLiteral) {
            BooleanLiteral value = (BooleanLiteral) propVal;
            res = new BoolExpr(value.getValue());
        } else if (propVal instanceof IntegerLiteral) {
            IntegerLiteral value = (IntegerLiteral) propVal;
            res = new IntExpr(BigInteger.valueOf((long) value.getScaledValue()));
        } else {
            assert (propVal instanceof RealLiteral);
            RealLiteral value = (RealLiteral) propVal;
            res = new RealExpr(BigDecimal.valueOf(value.getValue()));
        }
    }
    assert (res != null);
    return res;
}
Also used : BoolExpr(jkind.lustre.BoolExpr) IdExpr(jkind.lustre.IdExpr) BooleanLiteral(org.osate.aadl2.BooleanLiteral) NamedValue(org.osate.aadl2.NamedValue) PropertyConstant(org.osate.aadl2.PropertyConstant) RealLiteral(org.osate.aadl2.RealLiteral) 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) StringLiteral(org.osate.aadl2.StringLiteral) ThisRef(com.rockwellcollins.atc.agree.agree.ThisRef) DoubleDotRef(com.rockwellcollins.atc.agree.agree.DoubleDotRef) PropertyExpression(org.osate.aadl2.PropertyExpression) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) IntExpr(jkind.lustre.IntExpr) ComponentRef(com.rockwellcollins.atc.agree.agree.ComponentRef) NamedElement(org.osate.aadl2.NamedElement) Property(org.osate.aadl2.Property) RealExpr(jkind.lustre.RealExpr) IntegerLiteral(org.osate.aadl2.IntegerLiteral)

Example 3 with RealExpr

use of jkind.lustre.RealExpr in project AGREE by loonwerks.

the class AgreePatternTranslator method translatePatternProperty.

private Expr translatePatternProperty(AgreeSporadicPattern pattern, AgreeNodeBuilder builder, EObject varReference) {
    if (!((RealExpr) pattern.jitter).value.equals(BigDecimal.ZERO)) {
        throw new AgreeException("We currently do not handle non-zero jitter values correctly for sporadic patterns");
    }
    AgreeVar timeofEvent = getTimeOf(pattern.event.id, builder, null);
    Expr propExpr = expr("(true -> (not ((pre laste) = -1.0) => event => time - (pre laste) >= period))", to("laste", timeofEvent), to("event", pattern.event), to("time", timeExpr), to("period", pattern.period));
    return propExpr;
}
Also used : BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) AgreeException(com.rockwellcollins.atc.agree.analysis.AgreeException) RealExpr(jkind.lustre.RealExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 4 with RealExpr

use of jkind.lustre.RealExpr in project AGREE by loonwerks.

the class AgreePatternTranslator method translatePatternConstraint.

private Expr translatePatternConstraint(AgreeSporadicPattern pattern, AgreeNodeBuilder builder, EObject varReference) {
    AgreeVar jitterVar = new AgreeVar(JITTER_PREFIX + patternIndex, NamedType.REAL, varReference);
    AgreeVar periodVar = new AgreeVar(PERIOD_PREFIX + patternIndex, NamedType.REAL, varReference);
    AgreeVar timeoutVar = new AgreeVar(TIMEOUT_PREFIX + patternIndex, NamedType.REAL, varReference);
    builder.addOutput(jitterVar);
    builder.addOutput(periodVar);
    builder.addOutput(timeoutVar);
    IdExpr jitterId = new IdExpr(jitterVar.id);
    IdExpr periodId = new IdExpr(periodVar.id);
    IdExpr timeoutId = new IdExpr(timeoutVar.id);
    builder.addEventTime(timeoutVar);
    // -j <= jitter <= j
    Expr jitterLow = new BinaryExpr(new UnaryExpr(UnaryOp.NEGATIVE, pattern.jitter), BinaryOp.LESSEQUAL, jitterId);
    Expr jitterHigh = new BinaryExpr(jitterId, BinaryOp.LESSEQUAL, pattern.jitter);
    builder.addAssertion(new AgreeStatement(null, new BinaryExpr(jitterLow, BinaryOp.AND, jitterHigh), pattern.reference));
    // pnext >= 0 -> if pre ((pnext + jitter) = t) then pnext >= p +
    // pre(pnext) else pre(pnext)
    Expr prePNext = new UnaryExpr(UnaryOp.PRE, periodId);
    Expr pNextInit = new BinaryExpr(periodId, BinaryOp.GREATEREQUAL, new RealExpr(BigDecimal.ZERO));
    Expr pNextCond = new BinaryExpr(periodId, BinaryOp.PLUS, jitterId);
    pNextCond = new BinaryExpr(pNextCond, BinaryOp.EQUAL, timeExpr);
    pNextCond = new UnaryExpr(UnaryOp.PRE, pNextCond);
    Expr pNextThen = new BinaryExpr(pattern.period, BinaryOp.PLUS, prePNext);
    pNextThen = new BinaryExpr(periodId, BinaryOp.GREATEREQUAL, pNextThen);
    Expr pNextHold = new BinaryExpr(periodId, BinaryOp.EQUAL, prePNext);
    Expr pNextIf = new IfThenElseExpr(pNextCond, pNextThen, pNextHold);
    Expr pNext = new BinaryExpr(pNextInit, BinaryOp.ARROW, pNextIf);
    builder.addAssertion(new AgreeStatement(null, pNext, pattern.reference));
    // timeout = pnext + jitter
    Expr timeoutExpr = new BinaryExpr(periodId, BinaryOp.PLUS, jitterId);
    timeoutExpr = new BinaryExpr(timeoutId, BinaryOp.EQUAL, timeoutExpr);
    builder.addAssertion(new AgreeStatement(null, timeoutExpr, pattern.reference));
    // event = (t = timeout)
    Expr eventExpr = new BinaryExpr(timeExpr, BinaryOp.EQUAL, timeoutId);
    eventExpr = new BinaryExpr(pattern.event, BinaryOp.EQUAL, eventExpr);
    return eventExpr;
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) RealExpr(jkind.lustre.RealExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) RealExpr(jkind.lustre.RealExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) IfThenElseExpr(jkind.lustre.IfThenElseExpr)

Example 5 with RealExpr

use of jkind.lustre.RealExpr 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);
}
Also used : BoolExpr(jkind.lustre.BoolExpr) 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) NodeCallExpr(jkind.lustre.NodeCallExpr) BinaryExpr(jkind.lustre.BinaryExpr) UnaryExpr(jkind.lustre.UnaryExpr) RealExpr(jkind.lustre.RealExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Aggregations

BinaryExpr (jkind.lustre.BinaryExpr)14 BoolExpr (jkind.lustre.BoolExpr)14 RealExpr (jkind.lustre.RealExpr)14 IdExpr (jkind.lustre.IdExpr)12 UnaryExpr (jkind.lustre.UnaryExpr)12 Expr (jkind.lustre.Expr)11 IfThenElseExpr (jkind.lustre.IfThenElseExpr)10 NodeCallExpr (jkind.lustre.NodeCallExpr)10 IntExpr (jkind.lustre.IntExpr)6 ArrayExpr (jkind.lustre.ArrayExpr)4 TupleExpr (jkind.lustre.TupleExpr)4 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)3 ArraySubExpr (com.rockwellcollins.atc.agree.agree.ArraySubExpr)3 ArrayUpdateExpr (com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr)3 BoolLitExpr (com.rockwellcollins.atc.agree.agree.BoolLitExpr)3 CallExpr (com.rockwellcollins.atc.agree.agree.CallExpr)3 EnumLitExpr (com.rockwellcollins.atc.agree.agree.EnumLitExpr)3 EventExpr (com.rockwellcollins.atc.agree.agree.EventExpr)3 ExistsExpr (com.rockwellcollins.atc.agree.agree.ExistsExpr)3 FlatmapExpr (com.rockwellcollins.atc.agree.agree.FlatmapExpr)3