Search in sources :

Example 6 with AgreeEquation

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

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

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation in project AMASE by loonwerks.

the class AddFaultsToNodeVisitor method addNodeCall.

/**
 * Method adds fault node call and nested trigger expression to the node
 * builder. Ex fault node call: Sender__fault_1__node__val_out =
 * Common_Faults__fail_to_real(__fault__nominal__sender_out, 1.0,
 * fault__trigger__Sender__fault_1);
 *
 * Ex nested trigger expr: agree_node_output = if fault__trigger_1 then
 * fault__node_1__val_out else if fault__trigger_2 then fault__node_2__val_out
 * ... else __fault__nominal__output)
 *
 * @param nb NodeBuilder has these expressions added in assert stmts.
 * @param f  Fault that holds this fault node call information.
 */
private void addNodeCall(AgreeNodeBuilder nb, Fault f, Map<Fault, Expr> localFaultTriggerMap) {
    List<IdExpr> lhsOfNodeCall = new ArrayList<IdExpr>();
    // populate outputParamToActualMap
    for (VarDecl v : f.faultNode.outputs) {
        String lhsId = this.createFaultNodeEqId(f.id, v.id);
        AgreeVar actual = new AgreeVar(lhsId, v.type, f.faultStatement);
        nb.addLocal(actual);
        lhsOfNodeCall.add(new IdExpr(lhsId));
        f.outputParamToActualMap.put(v.id, actual);
    }
    // Call fault node and put this into lustre node as local equation.
    AgreeEquation eq = new AgreeEquation(lhsOfNodeCall, new NodeCallExpr(f.faultNode.id, constructNodeInputs(f, localFaultTriggerMap)), f.faultStatement);
    nb.addLocalEquation(eq);
}
Also used : IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) NodeCallExpr(jkind.lustre.NodeCallExpr) ArrayList(java.util.ArrayList) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 9 with AgreeEquation

use of com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation in project AMASE by loonwerks.

the class AddFaultsToNodeVisitor method buildNonFaultCombinationAssertions.

/**
 * Method builds combinations of faults that cannot occur together based on
 * probability values.
 *
 * Uses macros to shrink the size of the entire formula in case the number of
 * fault combinations is too large for the Lustre parser to handle.
 *
 * @param topNode                         AgreeNode, top of program
 * @param builder                         Node builder will have assertions
 *                                        added.
 * @param elementProbabilities            Prob of elements
 * @param faultCombinationsAboveThreshold Which FaultSetProbabilities are above
 *                                        threshold given in top level annex.
 */
private void buildNonFaultCombinationAssertions(AgreeNode topNode, AgreeNodeBuilder builder, ArrayList<FaultProbability> elementProbabilities, ArrayList<FaultSetProbability> faultCombinationsAboveThreshold) {
    // With the valid fault combinations including dependent faults, and
    // noFaultExpr has the default (no-fault) case. Let's construct a proposition.
    Set<FaultProbability> elementProbabilitySet = new HashSet<>(elementProbabilities);
    // the default (no-fault) case
    Expr faultHypothesis = getNoFaultProposition(elementProbabilitySet);
    // Vars for macros
    List<BinaryExpr> macroList = new ArrayList<BinaryExpr>();
    List<String> macroNames = new ArrayList<String>();
    int noGoodEls = 0;
    int unique = 0;
    for (FaultSetProbability fsp : faultCombinationsAboveThreshold) {
        Set<FaultProbability> goodElements = new HashSet<>(elementProbabilities);
        goodElements.removeAll(fsp.elements);
        // add the assertion that the rest of the faults are not to happen
        if (!goodElements.isEmpty()) {
            noGoodEls = noGoodEls + goodElements.size();
            Expr local = getNoFaultProposition(goodElements);
            faultHypothesis = new BinaryExpr(local, BinaryOp.OR, faultHypothesis);
            // Macros
            if (noGoodEls > SAFE_NUM_ELEMENTS) {
                IdExpr macro = new IdExpr("GOODELS_" + noGoodEls + unique);
                macroNames.add("GOODELS_" + noGoodEls + unique);
                noGoodEls = 0;
                unique++;
                BinaryExpr binMacro = new BinaryExpr(macro, BinaryOp.EQUAL, faultHypothesis);
                macroList.add(binMacro);
                faultHypothesis = macro;
            }
        } else // if there are all faults in the current combination
        // add the assertion that all faults are allowed to happen
        // which will be ORed with the default no fault case
        {
            Expr local = getAllFaultProposition(fsp.elements);
            faultHypothesis = new BinaryExpr(local, BinaryOp.OR, faultHypothesis);
        }
    }
    // Add this fault hypothesis as an assertion if not null.
    if (faultHypothesis == null) {
        new SafetyException("There is a problem with fault hypothesis for component: " + topNode.id + ". A possible problem is that single layer analysis" + " is being run with no faults defined in lower layer." + " Check hypothesis statements and fault defs in this analysis.");
    }
    for (String s : macroNames) {
        builder.addLocal(new AgreeVar(s, NamedType.BOOL, topNode.reference));
    }
    for (BinaryExpr b : macroList) {
        builder.addLocalEquation(new AgreeEquation((IdExpr) b.left, b.right, topNode.reference));
        builder.addAssertion(new AgreeStatement("", b, topNode.reference));
    // builder.addGuarantee(new AgreeStatement("", b, topNode.reference));
    }
    builder.addAssertion(new AgreeStatement("", faultHypothesis, topNode.reference));
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayList(java.util.ArrayList) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) TransientConstraint(edu.umn.cs.crisys.safety.safety.TransientConstraint) PermanentConstraint(edu.umn.cs.crisys.safety.safety.PermanentConstraint) TemporalConstraint(edu.umn.cs.crisys.safety.safety.TemporalConstraint) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) RecordAccessExpr(jkind.lustre.RecordAccessExpr) UnaryExpr(jkind.lustre.UnaryExpr) Expr(jkind.lustre.Expr) IntExpr(jkind.lustre.IntExpr) NodeCallExpr(jkind.lustre.NodeCallExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) ArrayAccessExpr(jkind.lustre.ArrayAccessExpr) IdExpr(jkind.lustre.IdExpr) IfThenElseExpr(jkind.lustre.IfThenElseExpr) HashSet(java.util.HashSet)

Example 10 with AgreeEquation

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

the class AgreePatternTranslator method translatePatternConditionProperty.

private Expr translatePatternConditionProperty(AgreeCauseEffectPattern pattern, AgreeNodeBuilder builder, IdExpr causeId, IdExpr effectId) {
    EObject varReference = pattern.reference;
    AgreeVar recordVar = new AgreeVar(RECORD_PREFIX + patternIndex, NamedType.BOOL, varReference);
    AgreeVar windowVar = new AgreeVar(WINDOW_PREFIX + patternIndex, NamedType.BOOL, varReference);
    builder.addInput(recordVar);
    builder.addLocal(windowVar);
    AgreeVar tRecord = getTimeOf(recordVar.id, builder, pattern);
    Expr expr = expr("record => cause", to("record", recordVar), to("cause", causeId));
    builder.addAssertion(new AgreeStatement(null, expr, varReference));
    BinaryOp left = getIntervalLeftOp(pattern.effectInterval);
    BinaryOp right = getIntervalRightOp(pattern.effectInterval);
    Equation eq = equation("in_window = (trecord <> -1.0) and " + "(l + trecord " + left + " time) and (time " + right + " h + trecord);", to("in_window", windowVar), to("trecord", tRecord), to("time", timeExpr), to("l", pattern.effectInterval.low), to("h", pattern.effectInterval.high));
    builder.addLocalEquation(new AgreeEquation(eq, varReference));
    return expr("in_window => effect", to("in_window", windowVar), to("effect", effectId));
}
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) EObject(org.eclipse.emf.ecore.EObject) Equation(jkind.lustre.Equation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) AgreeEquation(com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar) BinaryOp(jkind.lustre.BinaryOp)

Aggregations

AgreeEquation (com.rockwellcollins.atc.agree.analysis.ast.AgreeEquation)14 IdExpr (jkind.lustre.IdExpr)13 AgreeVar (com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)12 Expr (jkind.lustre.Expr)12 NodeCallExpr (jkind.lustre.NodeCallExpr)10 AgreeStatement (com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement)9 BinaryExpr (jkind.lustre.BinaryExpr)9 BoolExpr (jkind.lustre.BoolExpr)9 UnaryExpr (jkind.lustre.UnaryExpr)9 ArrayList (java.util.ArrayList)7 IfThenElseExpr (jkind.lustre.IfThenElseExpr)6 Equation (jkind.lustre.Equation)5 RealExpr (jkind.lustre.RealExpr)5 EObject (org.eclipse.emf.ecore.EObject)5 AgreeNode (com.rockwellcollins.atc.agree.analysis.ast.AgreeNode)4 AgreeNodeBuilder (com.rockwellcollins.atc.agree.analysis.ast.AgreeNodeBuilder)4 IntExpr (jkind.lustre.IntExpr)4 HashSet (java.util.HashSet)3 BinaryOp (jkind.lustre.BinaryOp)3 VarDecl (jkind.lustre.VarDecl)3