Search in sources :

Example 16 with AgreeStatement

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AGREE by loonwerks.

the class AgreePatternTranslator method getTimeRise.

private AgreeVar getTimeRise(String varName, AgreeNodeBuilder builder, EObject reference) {
    Map<String, AgreeVar> timeRiseMap = builder.build().timeRiseMap;
    if (timeRiseMap.containsKey(varName)) {
        return timeRiseMap.get(varName);
    }
    AgreeVar timeRise = new AgreeVar(varName + RISE_SUFFIX, NamedType.REAL, reference);
    builder.addOutput(timeRise);
    Expr rise = new NodeCallExpr(AgreeRealtimeCalendarBuilder.RISE_NODE_NAME, new IdExpr(varName));
    Expr timeVarExpr = expr("timeRise = (if rise then time else (-1.0 -> pre timeRise))", to("timeRise", timeRise), to("rise", rise), to("time", timeExpr));
    builder.addAssertion(new AgreeStatement(null, timeVarExpr, reference));
    Expr lemmaExpr = expr("timeRise <= time and timeRise >= -1.0", to("timeRise", timeRise), to("time", timeExpr));
    // add this assertion to help with proofs (it should always be true)
    builder.addAssertion(new AgreeStatement("", lemmaExpr, reference));
    builder.addTimeRise(varName, timeRise);
    return timeRise;
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) 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) IdExpr(jkind.lustre.IdExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 17 with AgreeStatement

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AGREE by loonwerks.

the class AgreePatternTranslator method translateCauseCondtionPattern.

// this method registers a timeout and creates an event that is true iff the
// condition
// holds during the given interval. This is meant to essentially translate a
// condition
// pattern to a purely event based pattern. it returns an IdExpr
// corresponding to the
// event that triggers when the condition is held for the interval
private IdExpr translateCauseCondtionPattern(AgreeCauseEffectPattern pattern, IdExpr causeId, AgreeNodeBuilder builder) {
    AgreeVar causeRiseTimeVar = getTimeRise(causeId.id, builder, pattern);
    AgreeVar causeFallTimeVar = getTimeFall(causeId.id, builder, pattern);
    AgreeVar causeHeldVar = new AgreeVar(CAUSE_CONDITION_HELD_PREFIX + causeId.id, NamedType.BOOL, pattern);
    AgreeVar causeHeldTimeoutVar = new AgreeVar(CAUSE_CONDITION_TIMEOUT_PREFIX + causeId.id, NamedType.REAL, pattern);
    builder.addLocal(causeHeldVar);
    builder.addInput(causeHeldTimeoutVar);
    IdExpr causeFallTimeId = new IdExpr(causeFallTimeVar.id);
    IdExpr causeHeldId = new IdExpr(causeHeldVar.id);
    IdExpr causeRiseTimeId = new IdExpr(causeRiseTimeVar.id);
    IdExpr causeHeldTimeoutId = new IdExpr(causeHeldTimeoutVar.id);
    {
        // timeout = if causeRiseTime > -1 and causeRiseTime > causeFallTime
        // then
        // causeRiseTime + h
        // else
        // -1
        Expr posRise = new BinaryExpr(causeRiseTimeId, BinaryOp.GREATER, NEG_ONE);
        Expr gtFall = new BinaryExpr(causeRiseTimeId, BinaryOp.GREATER, causeFallTimeId);
        Expr cond = new BinaryExpr(posRise, BinaryOp.AND, gtFall);
        Expr heldTime = new BinaryExpr(causeRiseTimeId, BinaryOp.PLUS, pattern.causeInterval.high);
        Expr ifExpr = new IfThenElseExpr(cond, heldTime, NEG_ONE);
        // builder.addLocalEquation(new AgreeEquation(causeHeldTimeoutId,
        // ifExpr, pattern));
        builder.addAssertion(new AgreeStatement(null, new BinaryExpr(causeHeldTimeoutId, BinaryOp.EQUAL, ifExpr), pattern));
        builder.addEventTime(causeHeldTimeoutVar);
    }
    {
        // causeHeld = (t = causeHeldTimeout)
        Expr causeHeldExpr = new BinaryExpr(timeExpr, BinaryOp.EQUAL, causeHeldTimeoutId);
        builder.addLocalEquation(new AgreeEquation(causeHeldId, causeHeldExpr, pattern));
    }
    return causeHeldId;
}
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) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) IfThenElseExpr(jkind.lustre.IfThenElseExpr)

Example 18 with AgreeStatement

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement in project AGREE by loonwerks.

the class AgreePatternTranslator method translatePatternEffectHoldConstraint.

private Expr translatePatternEffectHoldConstraint(AgreeCauseEffectPattern pattern, AgreeNodeBuilder builder, IdExpr causeId, IdExpr effectId) {
    AgreeVar timeCauseVar = getTimeOf(causeId.id, builder, pattern);
    AgreeVar timeoutVar = new AgreeVar(TIMEOUT_PREFIX + patternIndex, NamedType.REAL, pattern);
    builder.addOutput(timeoutVar);
    Expr timeoutExpr = expr("timeout = if timeCause >= 0.0 then (timeCause + l) else -1.0", to("timeout", timeoutVar), to("timeCause", timeCauseVar), to("l", pattern.effectInterval.low));
    builder.addAssertion(new AgreeStatement(null, timeoutExpr, pattern.reference));
    builder.addEventTime(timeoutVar);
    BinaryOp left = getIntervalLeftOp(pattern.effectInterval);
    BinaryOp right = getIntervalRightOp(pattern.effectInterval);
    Expr intervalLeft = expr("timeCause + l", to("timeCause", timeCauseVar), to("l", pattern.effectInterval.low));
    Expr intervalRight = expr("timeCause + h", to("timeCause", timeCauseVar), to("h", pattern.effectInterval.high));
    intervalLeft = new BinaryExpr(intervalLeft, left, timeExpr);
    intervalRight = new BinaryExpr(timeExpr, right, intervalRight);
    Expr inInterval = new BinaryExpr(intervalLeft, BinaryOp.AND, intervalRight);
    String constrString;
    if (pattern.effectIsExclusive) {
        constrString = "if timeCause > -1.0 and inInterval then effectTrue else not effectTrue";
    } else {
        constrString = "timeCause > -1.0 => inInterval => effectTrue";
    }
    Expr expr = expr(constrString, to("timeCause", timeCauseVar), to("inInterval", inInterval), to("effectTrue", effectId));
    return expr;
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) 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) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) BinaryOp(jkind.lustre.BinaryOp)

Example 19 with AgreeStatement

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

Example 20 with AgreeStatement

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement 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)

Aggregations

AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)56 IdExpr (jkind.lustre.IdExpr)50 Expr (jkind.lustre.Expr)49 BinaryExpr (jkind.lustre.BinaryExpr)47 NodeCallExpr (jkind.lustre.NodeCallExpr)45 BoolExpr (jkind.lustre.BoolExpr)44 UnaryExpr (jkind.lustre.UnaryExpr)40 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)39 IfThenElseExpr (jkind.lustre.IfThenElseExpr)28 ArrayList (java.util.ArrayList)25 IntExpr (jkind.lustre.IntExpr)23 RecordAccessExpr (jkind.lustre.RecordAccessExpr)19 ArrayAccessExpr (jkind.lustre.ArrayAccessExpr)15 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)13 RealExpr (jkind.lustre.RealExpr)13 VarDecl (jkind.lustre.VarDecl)13 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)12 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)11 Equation (jkind.lustre.Equation)11 TupleExpr (jkind.lustre.TupleExpr)11