Search in sources :

Example 36 with AgreeStatement

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

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

the class AddFaultsToNodeVisitor method mapFaultActiveToNodeInterface.

/**
 * Method maps the trigger to dep/indep active ids. Ex: assert
 * (Sender__fault__trigger__Sender__fault_2 =
 * (__fault__independently__active__Sender__Sender__fault_2 or
 * __fault__dependently__active__Sender__Sender__fault_2));
 *
 * @param hwf
 * @param path
 * @param base
 * @param builder
 */
public void mapFaultActiveToNodeInterface(HWFault hwf, List<String> path, String base, AgreeNodeBuilder builder) {
    String interfaceVarId = addPathDelimiters(path, this.createFaultNodeTriggerId(hwf.id));
    String indepentlyActiveVarId = this.createFaultIndependentActiveId(base);
    String depentlyActiveVarId = this.createFaultDependentActiveId(base);
    Expr equate = new BinaryExpr(new IdExpr(interfaceVarId), BinaryOp.EQUAL, new BinaryExpr(new IdExpr(indepentlyActiveVarId), BinaryOp.OR, new IdExpr(depentlyActiveVarId)));
    builder.addAssertion(new AgreeStatement("", equate, hwf.hwFaultStatement));
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) 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) IdExpr(jkind.lustre.IdExpr) BinaryExpr(jkind.lustre.BinaryExpr)

Example 38 with AgreeStatement

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

the class FaultASTBuilder method renameEqId.

/**
 * Make new fault with updated eq stmt ids
 * @param f fault to update
 * @param idMap map from old id to new
 * @return new updated fault
 */
private Fault renameEqId(Fault f, Map<String, String> idMap) {
    Fault newFault = new Fault(f);
    newFault.safetyEqVars.clear();
    newFault.safetyEqAsserts.clear();
    newFault.faultOutputMap.clear();
    newFault.faultInputMap.clear();
    if (!f.triggers.isEmpty()) {
        throw new SafetyException("User-defined triggers are currently unsupported.");
    }
    // update the variable declarations
    for (AgreeVar eq : f.safetyEqVars) {
        if (idMap.containsKey(eq.id)) {
            eq = new AgreeVar(idMap.get(eq.id), eq.type, eq.reference);
        }
        newFault.safetyEqVars.add(eq);
    }
    ReplaceIdVisitor visitor = new ReplaceIdVisitor(idMap);
    for (AgreeStatement s : f.safetyEqAsserts) {
        newFault.safetyEqAsserts.add(visitor.visit(s));
    }
    for (Map.Entry<Expr, String> element : f.faultOutputMap.entrySet()) {
        newFault.faultOutputMap.put(element.getKey().accept(visitor), element.getValue());
    }
    for (Map.Entry<String, Expr> element : f.faultInputMap.entrySet()) {
        newFault.faultInputMap.put(element.getKey(), element.getValue().accept(visitor));
    }
    return newFault;
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) RecordAccessExpr(jkind.lustre.RecordAccessExpr) TupleExpr(jkind.lustre.TupleExpr) Expr(jkind.lustre.Expr) NodeCallExpr(jkind.lustre.NodeCallExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) IdExpr(jkind.lustre.IdExpr) ReplaceIdVisitor(edu.umn.cs.crisys.safety.analysis.ast.visitors.ReplaceIdVisitor) SafetyException(edu.umn.cs.crisys.safety.analysis.SafetyException) Map(java.util.Map) HashMap(java.util.HashMap) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

Example 39 with AgreeStatement

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

the class FaultASTBuilder method addSafetyEqVal.

/**
 * Add safety eq statements to the safetyEqVars list for this fault
 *
 * @param fault	The fault with these associated safety eq stmts
 * @param stmt The EqValue statements to be added to the safetyEqVars list.
 */
private void addSafetyEqVal(Fault fault, EqValue stmt) {
    if (stmt.getExpr() != null) {
        Expr lhsExpr = constructEqLhsExpr(stmt);
        Expr rhsExpr = builder.doSwitch(stmt.getExpr());
        Expr expr = new BinaryExpr(lhsExpr, BinaryOp.EQUAL, rhsExpr);
        fault.safetyEqAsserts.add(new AgreeStatement("", expr, stmt));
    }
    List<VarDecl> vars = builder.agreeVarsFromArgs(stmt.getLhs(), agreeNode.compInst);
    for (VarDecl var : vars) {
        fault.safetyEqVars.add((AgreeVar) var);
    }
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) RecordAccessExpr(jkind.lustre.RecordAccessExpr) TupleExpr(jkind.lustre.TupleExpr) Expr(jkind.lustre.Expr) NodeCallExpr(jkind.lustre.NodeCallExpr) BoolExpr(jkind.lustre.BoolExpr) BinaryExpr(jkind.lustre.BinaryExpr) IdExpr(jkind.lustre.IdExpr) VarDecl(jkind.lustre.VarDecl) BinaryExpr(jkind.lustre.BinaryExpr)

Example 40 with AgreeStatement

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

the class LinearizationAgreeASTVisitor method linearizeStatement.

private LinearizationResult linearizeStatement(AgreeNode parent, AgreeStatement stmt, jkind.lustre.BinaryOp connective) {
    contextStack.push(new LinearizationContext(parent.compInst));
    List<AgreeVar> addedLocals = new ArrayList<>();
    List<AgreeStatement> addedAssertions = new ArrayList<>();
    AgreeStatement linearizedStatement = this.visit(stmt);
    // Incorporate the additions resulting from the linearization
    LinearizationContext ctx = contextStack.peek();
    addedLocals.addAll(contextStack.peek().addedVars);
    for (int index = 0; index < ctx.liftedConstraintExprs.size(); ++index) {
        AgreeVar ephemeral = ctx.addedVars.get(index);
        String statementName = stmt.string + " (linearize constraint " + ephemeral.id + ")";
        addedAssertions.add(new AgreeStatement(statementName, ctx.liftedConstraintExprs.get(index), null));
    }
    contextStack.pop();
    return new LinearizationResult(addedLocals, addedAssertions, linearizedStatement);
}
Also used : AgreeStatement(com.rockwellcollins.atc.agree.analysis.ast.AgreeStatement) ArrayList(java.util.ArrayList) AgreeVar(com.rockwellcollins.atc.agree.analysis.ast.AgreeVar)

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