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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations