Search in sources :

Example 6 with BinaryOp

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

the class AgreePatternTranslator method translatePatternEventProperty.

private Expr translatePatternEventProperty(AgreeCauseEffectPattern pattern, AgreeNodeBuilder builder, IdExpr causeId, IdExpr effectId) {
    EObject varReference = pattern.reference;
    AgreeVar timerVar = new AgreeVar(TIMER_PREFIX + patternIndex, NamedType.REAL, varReference);
    AgreeVar runVar = new AgreeVar(RUNNING_PREFIX + patternIndex, NamedType.BOOL, varReference);
    AgreeVar recordVar = new AgreeVar(RECORD_PREFIX + patternIndex, NamedType.BOOL, varReference);
    builder.addLocal(timerVar);
    builder.addLocal(runVar);
    builder.addInput(recordVar);
    IdExpr timerId = new IdExpr(timerVar.id);
    IdExpr runId = new IdExpr(runVar.id);
    IdExpr recordId = new IdExpr(recordVar.id);
    // run = record -> if pre(run) and e and l <= timer <= h then
    // false
    // else
    // if record then
    // true
    // else
    // pre(run)
    Expr preRun = new UnaryExpr(UnaryOp.PRE, runId);
    {
        Expr if2 = new IfThenElseExpr(recordId, new BoolExpr(true), preRun);
        BinaryOp left = getIntervalLeftOp(pattern.effectInterval);
        BinaryOp right = getIntervalRightOp(pattern.effectInterval);
        Expr timerLow = new BinaryExpr(pattern.effectInterval.low, left, timerId);
        Expr timerHigh = new BinaryExpr(timerId, right, pattern.effectInterval.high);
        Expr cond1 = new BinaryExpr(preRun, BinaryOp.AND, effectId);
        cond1 = new BinaryExpr(cond1, BinaryOp.AND, timerLow);
        cond1 = new BinaryExpr(cond1, BinaryOp.AND, timerHigh);
        Expr if1 = new IfThenElseExpr(cond1, new BoolExpr(false), if2);
        Expr runExpr = new BinaryExpr(recordId, BinaryOp.ARROW, if1);
        builder.addLocalEquation(new AgreeEquation(runId, runExpr, varReference));
    }
    // timer = (0 -> if pre(run) then pre(timer) + (t - pre(t)) else 0)
    {
        Expr preTimer = new UnaryExpr(UnaryOp.PRE, timerId);
        Expr preT = new UnaryExpr(UnaryOp.PRE, timeExpr);
        Expr elapsed = new BinaryExpr(timeExpr, BinaryOp.MINUS, preT);
        Expr total = new BinaryExpr(preTimer, BinaryOp.PLUS, elapsed);
        Expr timerExpr = new IfThenElseExpr(preRun, total, new RealExpr(BigDecimal.ZERO));
        timerExpr = new BinaryExpr(new RealExpr(BigDecimal.ZERO), BinaryOp.ARROW, timerExpr);
        builder.addLocalEquation(new AgreeEquation(timerId, timerExpr, varReference));
    }
    // property that should be true for timer to help induction
    {
        Expr expr = new BinaryExpr(timerId, BinaryOp.GREATEREQUAL, new RealExpr(BigDecimal.ZERO));
        builder.addAssertion(new AgreeStatement(null, expr, varReference));
    }
    // record => cause and not (e and (l = 0))
    {
        Expr causeExpr;
        if (pattern.effectInterval.type == IntervalType.OPEN_LEFT || pattern.effectInterval.type == IntervalType.OPEN) {
            causeExpr = causeId;
        } else {
            Expr eAndLZero = new BinaryExpr(pattern.effectInterval.low, BinaryOp.EQUAL, new RealExpr(BigDecimal.ZERO));
            eAndLZero = new BinaryExpr(effectId, BinaryOp.AND, eAndLZero);
            Expr notEAndLZero = new UnaryExpr(UnaryOp.NOT, eAndLZero);
            causeExpr = new BinaryExpr(causeId, BinaryOp.AND, notEAndLZero);
        }
        Expr recordExpr = new BinaryExpr(recordId, BinaryOp.IMPLIES, causeExpr);
        AgreeStatement statement = new AgreeStatement(null, recordExpr, varReference);
        builder.addAssertion(statement);
    }
    // lemma to help induction
    AgreeVar timeOfCause = getTimeOf(causeId.id, builder, pattern);
    AgreeVar timeOfEffect = getTimeOf(effectId.id, builder, pattern);
    // Expr expr = expr("(timer > 0.0 => timeOfCause > 0.0) and "
    // + "(timeOfEffect < timeOfCause => timer <= time - timeOfCause) and "
    // + "(cause => timeOfCause = time) and"
    // + "(true -> ((pre (timeOfEffect - low > timeOfCause)) => timer =
    // 0.0))",
    // to("timer", timerVar),
    // to("timeOfCause", timeOfCause),
    // to("time", timeExpr),
    // to("cause", causeId),
    // to("timeOfEffect", timeOfEffect),
    // to("low", pattern.effectInterval.low));
    Expr expr = expr("(timer > 0.0 => timeOfCause >= 0.0) and " + "(timer <= time) and" + "(timeOfEffect >= timeOfCause and timer <= high and timeOfEffect >= time - timer + low => not run) and" + "(true -> (pre(timeOfEffect >= timeOfCause + low and timeOfEffect <= timeOfCause + high and timer <= high) => timer = 0.0)) and" + "(timer = 0.0 or timer >= time - timeOfCause)", to("timer", timerVar), to("timeOfCause", timeOfCause), to("timeOfEffect", timeOfEffect), to("time", timeExpr), to("low", pattern.effectInterval.low), to("high", pattern.effectInterval.high), to("run", runVar));
    builder.addPatternProp(new AgreeStatement("Timer Lemma for Pattern " + patternIndex, expr, pattern));
    // timer <= h
    BinaryOp right = getIntervalRightOp(pattern.effectInterval);
    return new BinaryExpr(timerId, right, pattern.effectInterval.high);
}
Also used : BoolExpr(jkind.lustre.BoolExpr) 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) EObject(org.eclipse.emf.ecore.EObject) BinaryExpr(jkind.lustre.BinaryExpr) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) UnaryExpr(jkind.lustre.UnaryExpr) RealExpr(jkind.lustre.RealExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) IfThenElseExpr(jkind.lustre.IfThenElseExpr) BinaryOp(jkind.lustre.BinaryOp)

Example 7 with BinaryOp

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

the class AgreePatternTranslator method addPatternConstraintProperty.

private void addPatternConstraintProperty(AgreeCauseEffectPattern pattern, AgreeNodeBuilder builder, IdExpr causeId, IdExpr effectId) {
    AgreeVar newCause = new AgreeVar(NEW_CAUSE_PREFIX + causeId.id + patternIndex, NamedType.BOOL, pattern);
    builder.addLocal(newCause);
    AgreeVar timeCauseVar = getTimeOf(causeId.id, builder, pattern);
    IdExpr timeCauseId = new IdExpr(timeCauseVar.id);
    IdExpr newCauseId = new IdExpr(newCause.id);
    Expr preTimeCause = new UnaryExpr(UnaryOp.PRE, timeCauseId);
    Expr newCauseExpr = new BinaryExpr(preTimeCause, BinaryOp.NOTEQUAL, timeCauseId);
    newCauseExpr = new BinaryExpr(newCauseExpr, BinaryOp.AND, new BinaryExpr(preTimeCause, BinaryOp.GREATEREQUAL, new RealExpr(BigDecimal.ZERO)));
    builder.addLocalEquation(new AgreeEquation(newCauseId, newCauseExpr, pattern));
    if (pattern.effectType == TriggerType.EVENT) {
        AgreeVar timeEffectVar = getTimeOf(effectId.id, builder, pattern);
        IdExpr timeEffectId = new IdExpr(timeEffectVar.id);
        Expr preTimeCausePlusL = new BinaryExpr(preTimeCause, BinaryOp.PLUS, pattern.effectInterval.low);
        BinaryOp left = getIntervalLeftOp(pattern.effectInterval);
        Expr inInterval = new BinaryExpr(preTimeCausePlusL, left, timeEffectId);
        Expr propExpr = new BinaryExpr(newCauseId, BinaryOp.IMPLIES, inInterval);
        propExpr = new BinaryExpr(new BoolExpr(true), BinaryOp.ARROW, propExpr);
        AgreeStatement statement = new AgreeStatement(" pattern " + patternIndex + " in bounds", propExpr, pattern);
        builder.addPatternProp(statement);
    } else {
        AgreeVar timeEndVar = new AgreeVar(END_INTERVAL + patternIndex, NamedType.REAL, pattern);
        builder.addLocal(timeEndVar);
        Equation eq = equation("timeEnd = timeCause + h;", to("timeEnd", timeEndVar), to("timeCause", timeCauseId), to("h", pattern.effectInterval.high));
        builder.addLocalEquation(new AgreeEquation(eq, pattern));
        Expr expr = expr("true -> (newCause => pre(timeEnd) < time)", to("timeEnd", timeEndVar), to("newCause", newCauseId), to("time", timeExpr));
        AgreeStatement statement = new AgreeStatement(" pattern " + patternIndex + " in bounds", expr, pattern);
        builder.addPatternProp(statement);
    }
}
Also used : BoolExpr(jkind.lustre.BoolExpr) 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) Equation(jkind.lustre.Equation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) UnaryExpr(jkind.lustre.UnaryExpr) RealExpr(jkind.lustre.RealExpr) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) BinaryOp(jkind.lustre.BinaryOp)

Example 8 with BinaryOp

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

the class AgreePatternTranslator method translatePatternEffectEventConstraint.

private Expr translatePatternEffectEventConstraint(AgreeCauseEffectPattern pattern, AgreeNodeBuilder builder, IdExpr causeId, IdExpr effectId) {
    AgreeVar effectTimeRangeVar = new AgreeVar(EFFECT_TIME_RANGE_PREFIX + patternIndex, NamedType.REAL, pattern);
    builder.addInput(effectTimeRangeVar);
    IdExpr effectTimeRangeId = new IdExpr(effectTimeRangeVar.id);
    AgreeVar timeEffectVar = new AgreeVar(TIME_WILL_PREFIX + patternIndex, NamedType.REAL, pattern);
    builder.addOutput(timeEffectVar);
    IdExpr timeEffectId = new IdExpr(timeEffectVar.id);
    Expr effectTimeRangeConstraint = getTimeRangeConstraint(effectTimeRangeId, pattern.effectInterval);
    builder.addAssertion(new AgreeStatement(null, effectTimeRangeConstraint, pattern.reference));
    // make a constraint that triggers when the event WILL happen
    Expr expr = expr("timeEffect = if causeId then effectTimeRangeId else (-1.0 -> pre timeEffect)", to("timeEffect", timeEffectId), to("causeId", causeId), to("effectTimeRangeId", effectTimeRangeId));
    builder.addAssertion(new AgreeStatement(null, expr, pattern));
    // a lemma that may be helpful
    Expr lemma = expr("timeEffect <= time + intHigh", to("timeEffect", timeEffectVar), to("time", timeExpr), to("intHigh", pattern.effectInterval.high));
    builder.addAssertion(new AgreeStatement(null, lemma, pattern));
    lemma = expr("timeWill <= causeTime + high and (causeTime >= 0.0 => causeTime + low <= timeWill)", to("timeWill", timeEffectVar), to("causeTime", getTimeOf(causeId.id, builder, pattern)), to("high", pattern.effectInterval.high), to("low", pattern.effectInterval.low));
    builder.addAssertion(new AgreeStatement(null, lemma, pattern));
    lemma = expr("timeWill <= time => timeWill <= timeEffect", to("timeWill", timeEffectVar), to("timeEffect", getTimeOf(effectId.id, builder, pattern)));
    builder.addAssertion((new AgreeStatement(null, lemma, pattern)));
    // Expr lemmaExpr = expr("timeEffect <= effectTimeRangeId and timeEffect
    // >= -1.0",
    // to("timeEffect", timeEffectId),
    // to("effectTimeRangeId", effectTimeRangeId));
    // 
    // //add this assertion to help with proofs (it should always be true)
    // builder.addAssertion(new AgreeStatement(null, lemmaExpr, pattern));
    // register the event time
    builder.addEventTime(timeEffectVar);
    // make the equation that triggers the event at the correct ime
    Expr timeEqualsEffectTime = new BinaryExpr(timeExpr, BinaryOp.EQUAL, timeEffectId);
    // if the event is exclusive it only occurs when scheduled
    BinaryOp effectOp = pattern.effectIsExclusive ? BinaryOp.EQUAL : BinaryOp.IMPLIES;
    Expr impliesEffect = new BinaryExpr(timeEqualsEffectTime, effectOp, effectId);
    return impliesEffect;
}
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) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) BinaryOp(jkind.lustre.BinaryOp)

Aggregations

BinaryExpr (jkind.lustre.BinaryExpr)8 BinaryOp (jkind.lustre.BinaryOp)8 BoolExpr (jkind.lustre.BoolExpr)8 Expr (jkind.lustre.Expr)8 IdExpr (jkind.lustre.IdExpr)8 NodeCallExpr (jkind.lustre.NodeCallExpr)8 IfThenElseExpr (jkind.lustre.IfThenElseExpr)7 RealExpr (jkind.lustre.RealExpr)7 UnaryExpr (jkind.lustre.UnaryExpr)7 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)6 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)6 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)3 Equation (jkind.lustre.Equation)2 RecordAccessExpr (jkind.lustre.RecordAccessExpr)2 TupleExpr (jkind.lustre.TupleExpr)2 EObject (org.eclipse.emf.ecore.EObject)2 AgreeTypeSystem (com.rockwellcollins.atc.agree.AgreeTypeSystem)1 ArrayLiteralExpr (com.rockwellcollins.atc.agree.agree.ArrayLiteralExpr)1 ArraySubExpr (com.rockwellcollins.atc.agree.agree.ArraySubExpr)1 ArrayUpdateExpr (com.rockwellcollins.atc.agree.agree.ArrayUpdateExpr)1