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