Search in sources :

Example 16 with AgreeVar

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

the class AgreePatternTranslator method getTimeOf.

private AgreeVar getTimeOf(String varName, AgreeNodeBuilder builder, EObject reference) {
    Map<String, AgreeVar> timeOfMap = builder.build().timeOfMap;
    if (timeOfMap.containsKey(varName)) {
        return timeOfMap.get(varName);
    }
    AgreeVar timeCause = new AgreeVar(varName + TIME_SUFFIX, NamedType.REAL, reference);
    builder.addOutput(timeCause);
    Expr timeVarExpr = expr("timeCause = (if cause then time else (-1.0 -> pre timeCause))", to("timeCause", timeCause), to("cause", varName), to("time", timeExpr));
    builder.addAssertion(new AgreeStatement(null, timeVarExpr, reference));
    Expr lemmaExpr = expr("timeCause <= time and timeCause >= -1.0", to("timeCause", timeCause), to("time", timeExpr));
    // add this assertion to help with proofs (it should always be true)
    builder.addAssertion(new AgreeStatement("", lemmaExpr, reference));
    builder.addTimeOf(varName, timeCause);
    return timeCause;
}
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) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 17 with AgreeVar

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar 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 18 with AgreeVar

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

the class AgreePatternTranslator method translatePatternProperty.

private Expr translatePatternProperty(AgreePeriodicPattern pattern, AgreeNodeBuilder builder, EObject varReference) {
    AgreeVar periodVar = new AgreeVar(PERIOD_PREFIX + patternIndex, NamedType.REAL, null);
    builder.addLocal(periodVar);
    AgreeEquation eq = new AgreeEquation(equation("period = if event then (if time <= P then time  else (0.0 -> pre period)) + P else (P -> pre period);", to("event", pattern.event), to("period", periodVar), to("P", pattern.period)), varReference);
    builder.addLocalEquation(eq);
    Expr prop = expr("true -> (time >= P + j => event => (pre period) - j <= time and time <= (pre period) + j)", to("time", timeExpr), to("period", periodVar), to("P", pattern.period), to("j", pattern.jitter), to("event", pattern.event));
    return prop;
}
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) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 19 with AgreeVar

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeVar 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 20 with AgreeVar

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

Aggregations

AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)69 IdExpr (jkind.lustre.IdExpr)49 Expr (jkind.lustre.Expr)45 NodeCallExpr (jkind.lustre.NodeCallExpr)42 BinaryExpr (jkind.lustre.BinaryExpr)41 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)39 BoolExpr (jkind.lustre.BoolExpr)38 UnaryExpr (jkind.lustre.UnaryExpr)37 ArrayList (java.util.ArrayList)28 IfThenElseExpr (jkind.lustre.IfThenElseExpr)25 VarDecl (jkind.lustre.VarDecl)19 Equation (jkind.lustre.Equation)15 RealExpr (jkind.lustre.RealExpr)15 AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)14 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)13 IntExpr (jkind.lustre.IntExpr)13 AgreeException (com.rockwellcollins.atc.agree.analysis.AgreeException)12 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)12 NodeBuilder (jkind.lustre.builders.NodeBuilder)11 SafetyException (edu.umn.cs.crisys.safety.analysis.SafetyException)9