Skip to content

Commit

Permalink
* Implement support for OrMore in FTA generation
Browse files Browse the repository at this point in the history
	For #1837
  • Loading branch information
jjhugues committed Jul 10, 2019
1 parent c3be5a2 commit 4b22747
Show file tree
Hide file tree
Showing 4 changed files with 273 additions and 136 deletions.
Expand Up @@ -28,6 +28,7 @@
import org.osate.xtext.aadl2.errormodel.errorModel.ErrorPropagation;
import org.osate.xtext.aadl2.errormodel.errorModel.ErrorSource;
import org.osate.xtext.aadl2.errormodel.errorModel.ErrorTypes;
import org.osate.xtext.aadl2.errormodel.errorModel.OrmoreExpression;
import org.osate.xtext.aadl2.errormodel.errorModel.OutgoingPropagationCondition;

public class FTAGenerator extends PropagationGraphBackwardTraversal {
Expand Down Expand Up @@ -68,8 +69,7 @@ public FaultTree getftaModel(ComponentInstance rootComponent, NamedElement rootS
return ftaModel;
} else {
ftaRootEvent = (Event) traverseOutgoingErrorPropagation(rootComponent,
(ErrorPropagation) rootStateOrPropagation,
rootComponentTypes, BigOne);
(ErrorPropagation) rootStateOrPropagation, rootComponentTypes, BigOne);
}
}
if (ftaRootEvent == null) {
Expand Down Expand Up @@ -118,7 +118,6 @@ public FaultTree getftaModel(ComponentInstance rootComponent, NamedElement rootS
return ftaModel;
}


/**
* turn list of subevents into an specified gate.
* In the process flatten any sub gates of the same type (one level is sufficient since we flatten at each step
Expand Down Expand Up @@ -163,7 +162,33 @@ private Event finalizeAsOrEvents(ComponentInstance component, Element ne, ErrorT
combined.getSubEvents().add((Event) seobj);
}
return combined;
}

private Event finalizeAsOrMoreEvents(ComponentInstance component, Element ne, ErrorTypes type,
List<EObject> subEvents) {
if (subEvents.size() == 0) {
return null;
}
// if (subEvents.size() == 1) {
// return (Event) subEvents.get(0);
// }
Event combined = FaultTreeUtils.findSharedSubtree(ftaModel, subEvents, LogicOperation.KORMORE, component, ne,
type);
if (combined != null) {
return combined;
}

combined = FaultTreeUtils.createIntermediateEvent(ftaModel, component, ne, type);
combined.setSubEventLogic(LogicOperation.KORMORE);

// Propagate the K value from the original element
OrmoreExpression omCondition = (OrmoreExpression) ne;
combined.setK((int) omCondition.getCount()); // XXX this cast indicates discrepancy between two meta models

for (Object seobj : subEvents) {
combined.getSubEvents().add((Event) seobj);
}
return combined;
}

private Event finalizeAsAndEvents(ComponentInstance component, Element ne, ErrorTypes type,
Expand Down Expand Up @@ -300,8 +325,8 @@ private Event minimalCutSet(Event rootevent) {
List<Event> toAdd = new LinkedList<Event>();
// alternatives : collection of minimal cutsets
Event alternatives = FaultTreeUtils.createUniqueIntermediateEvent(ftaModel,
(ComponentInstance) rootevent.getRelatedInstanceObject(),
rootevent.getRelatedEMV2Object(), (ErrorTypes) rootevent.getRelatedErrorType());
(ComponentInstance) rootevent.getRelatedInstanceObject(), rootevent.getRelatedEMV2Object(),
(ErrorTypes) rootevent.getRelatedErrorType());
alternatives.setName("Alternatives");
if (rootevent.getSubEventLogic() == LogicOperation.XOR) {
alternatives.setSubEventLogic(LogicOperation.XOR);
Expand All @@ -314,8 +339,8 @@ private Event minimalCutSet(Event rootevent) {
for (Event alt : rootevent.getSubEvents()) {
// if top-level is OR, XOR, KORMORE each of the sub-events become the starting point of a cutset
Event alternative = FaultTreeUtils.createUniqueIntermediateEvent(ftaModel,
(ComponentInstance) rootevent.getRelatedInstanceObject(),
rootevent.getRelatedEMV2Object(), (ErrorTypes) rootevent.getRelatedErrorType());
(ComponentInstance) rootevent.getRelatedInstanceObject(), rootevent.getRelatedEMV2Object(),
(ErrorTypes) rootevent.getRelatedErrorType());
alternative.setSubEventLogic(LogicOperation.AND);
toAdd.add(alternative);
// normalize each of the subevents
Expand All @@ -329,8 +354,8 @@ private Event minimalCutSet(Event rootevent) {
|| rootevent.getSubEventLogic() == LogicOperation.PRIORITY_AND) {
// in case of AND or P-AND we take the root as starting point
Event alternative = FaultTreeUtils.createUniqueIntermediateEvent(ftaModel,
(ComponentInstance) rootevent.getRelatedInstanceObject(),
rootevent.getRelatedEMV2Object(), (ErrorTypes) rootevent.getRelatedErrorType());
(ComponentInstance) rootevent.getRelatedInstanceObject(), rootevent.getRelatedEMV2Object(),
(ErrorTypes) rootevent.getRelatedErrorType());
alternative.setSubEventLogic(LogicOperation.AND);
toAdd.add(alternative);
normalizeEvent(rootevent, toAdd);
Expand Down Expand Up @@ -423,7 +448,6 @@ private void addAsMinimalAndSet(Event alternatives, Event altEvent) {
existingAlternatives.add(altEvent);
}


/**
* recursively remove common events from subgates of XOR gates
* @param rootevent
Expand Down Expand Up @@ -543,7 +567,7 @@ private Event optimizeEvent(Event rootevent) {
removeZeroOneEventSubGates(res);
}
}
if (res.getSubEventLogic() == LogicOperation.AND ) {
if (res.getSubEventLogic() == LogicOperation.AND) {
res = removeSubEventsCommonWithEnclosingEvents(res, LogicOperation.AND, LogicOperation.OR);
}
if (res.getSubEventLogic() == LogicOperation.OR) {
Expand All @@ -561,7 +585,7 @@ private Event optimizeEvent(Event rootevent) {
* find common events in subgates and move them to an enclosing gate
* Currently does it if all of the gates of a given type have something in common.
* It also does it for various subsets of events with the matching gate type.
* Distributive Law 3a and 3b (se NRC Fault Tree Handbook page 80.
* Distributive Law 3a and 3b (see NRC Fault Tree Handbook page 80).
* @param topevent
* @param gt
* @return Event
Expand Down Expand Up @@ -596,8 +620,7 @@ private Event transformSubgates(Event topevent, LogicOperation gt, LogicOperatio
// all subgates are involved
// remove from lower OR and create an OR above top gate
Event newtopevent = FaultTreeUtils.createIntermediateEvent(ftaModel,
(ComponentInstance) topevent.getRelatedInstanceObject(),
topevent.getRelatedEMV2Object(),
(ComponentInstance) topevent.getRelatedInstanceObject(), topevent.getRelatedEMV2Object(),
(ErrorTypes) topevent.getRelatedErrorType());
newtopevent.setSubEventLogic(gt);
newtopevent.getSubEvents().add(topevent);
Expand All @@ -616,8 +639,7 @@ private Event transformSubgates(Event topevent, LogicOperation gt, LogicOperatio
} else {
// transformed subtree to top gate replacing subset of events involved in transformation
Event newtopevent = FaultTreeUtils.createIntermediateEvent(ftaModel,
(ComponentInstance) topevent.getRelatedInstanceObject(),
topevent.getRelatedEMV2Object(),
(ComponentInstance) topevent.getRelatedInstanceObject(), topevent.getRelatedEMV2Object(),
(ErrorTypes) topevent.getRelatedErrorType());
newtopevent.setSubEventLogic(gt);
topevent.getSubEvents().add(newtopevent);
Expand Down Expand Up @@ -895,8 +917,8 @@ protected EObject postProcessIncomingErrorPropagation(ComponentInstance componen
protected EObject processOutgoingErrorPropagationCondition(ComponentInstance component,
OutgoingPropagationCondition opc, ErrorTypes type, EObject conditionResult, EObject stateResult,
BigDecimal scale) {
Event consolidated = consolidateAsPriorityAnd((Event) stateResult, (Event) conditionResult,
component, opc, type);
Event consolidated = consolidateAsPriorityAnd((Event) stateResult, (Event) conditionResult, component, opc,
type);
return consolidated;
}

Expand All @@ -919,8 +941,8 @@ protected EObject postProcessCompositeErrorStates(ComponentInstance component, E
}

@Override
protected EObject processErrorBehaviorState(ComponentInstance component, ErrorBehaviorState state,
ErrorTypes type, BigDecimal scale) {
protected EObject processErrorBehaviorState(ComponentInstance component, ErrorBehaviorState state, ErrorTypes type,
BigDecimal scale) {
Event newEvent = FaultTreeUtils.createBasicEvent(ftaModel, component, state, type);
newEvent.setScale(scale);
return newEvent;
Expand All @@ -939,8 +961,8 @@ protected EObject postProcessErrorBehaviorState(ComponentInstance component, Err
@Override
protected EObject processTransitionCondition(ComponentInstance component, ErrorBehaviorState source,
ErrorTypes type, EObject conditionResult, EObject stateResult, BigDecimal scale) {
Event consolidated = consolidateAsPriorityAnd((Event) stateResult, (Event) conditionResult,
component, source, type);
Event consolidated = consolidateAsPriorityAnd((Event) stateResult, (Event) conditionResult, component, source,
type);
return consolidated;
}

Expand All @@ -960,8 +982,8 @@ protected EObject postProcessAnd(ComponentInstance component, Element condition,
}

@Override
protected EObject postProcessXor(ComponentInstance component, Element condition, ErrorTypes type,
BigDecimal scale, List<EObject> subResults) {
protected EObject postProcessXor(ComponentInstance component, Element condition, ErrorTypes type, BigDecimal scale,
List<EObject> subResults) {
Event ftaEvent = finalizeAsXOrEvents(component, condition, type, subResults);
return ftaEvent;
}
Expand All @@ -973,6 +995,13 @@ protected EObject postProcessOr(ComponentInstance component, Element condition,
return ftaEvent;
}

@Override
protected EObject postProcessOrMore(ComponentInstance component, Element condition, ErrorTypes type,
List<EObject> subResults, BigDecimal scale) {

Event ftaEvent = finalizeAsOrMoreEvents(component, condition, type, subResults);
return ftaEvent;
}
@Override
protected EObject processTypesetElements(ComponentInstance component, Element state, ErrorTypes type,
List<EObject> subResults, BigDecimal scale) {
Expand Down

0 comments on commit 4b22747

Please sign in to comment.