diff options
Diffstat (limited to 'Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft')
9 files changed, 749 insertions, 2 deletions
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/.Cft2FtTransformation.xtendbin b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/.Cft2FtTransformation.xtendbin index 3e751774..20f1f4a7 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/.Cft2FtTransformation.xtendbin +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/.Cft2FtTransformation.xtendbin | |||
Binary files differ | |||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/.EventCollection.xtendbin b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/.EventCollection.xtendbin new file mode 100644 index 00000000..54ba3d09 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/.EventCollection.xtendbin | |||
Binary files differ | |||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/.EventMaterializer.xtendbin b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/.EventMaterializer.xtendbin new file mode 100644 index 00000000..271c9cc0 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/.EventMaterializer.xtendbin | |||
Binary files differ | |||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/.FaultTreeBuilder.xtendbin b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/.FaultTreeBuilder.xtendbin new file mode 100644 index 00000000..db3a7e73 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/.FaultTreeBuilder.xtendbin | |||
Binary files differ | |||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/.gitignore b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/.gitignore index 70156b02..75154a4c 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/.gitignore +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/.gitignore | |||
@@ -1 +1,8 @@ | |||
1 | /.Cft2FtTransformation.java._trace | 1 | /.Cft2FtTransformation.java._trace |
2 | /.EventMaterializer.java._trace | ||
3 | /.MaterializedEvent.java._trace | ||
4 | /.CollectedInputs.java._trace | ||
5 | /.MaterializedEventCollection.java._trace | ||
6 | /.FaultTreeBuilder.java._trace | ||
7 | /.FaultModelBuilder.java._trace | ||
8 | /.EventCollection.java._trace | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/Cft2FtTransformation.java b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/Cft2FtTransformation.java index ae750806..e87b8865 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/Cft2FtTransformation.java +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/Cft2FtTransformation.java | |||
@@ -1,10 +1,49 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.cft2ft; | 1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.cft2ft; |
2 | 2 | ||
3 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.ComponentFaultTree; | 3 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.ComponentFaultTree; |
4 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ConstantEvent; | ||
5 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ConstantModel; | ||
6 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Event; | ||
7 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.FaultTree; | ||
8 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.FtFactory; | ||
9 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.RandomEvent; | ||
10 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ReliabilityModel; | ||
11 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.cft2ft.EventMaterializer; | ||
12 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.cft2ft.FaultTreeBuilder; | ||
13 | import org.eclipse.xtext.xbase.lib.ObjectExtensions; | ||
14 | import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; | ||
4 | 15 | ||
5 | @SuppressWarnings("all") | 16 | @SuppressWarnings("all") |
6 | public class Cft2FtTransformation { | 17 | public class Cft2FtTransformation { |
7 | public void createFaultTree(final ComponentFaultTree componentFaultTree) { | 18 | public ReliabilityModel createFaultTree(final ComponentFaultTree componentFaultTree) { |
8 | throw new UnsupportedOperationException(); | 19 | ReliabilityModel _xblockexpression = null; |
20 | { | ||
21 | final EventMaterializer materializer = new EventMaterializer(); | ||
22 | final Event topEvent = materializer.getOrMaterialize(componentFaultTree.getTopEvent()); | ||
23 | ReliabilityModel _switchResult = null; | ||
24 | boolean _matched = false; | ||
25 | if (topEvent instanceof ConstantEvent) { | ||
26 | _matched=true; | ||
27 | ConstantModel _createConstantModel = FtFactory.eINSTANCE.createConstantModel(); | ||
28 | final Procedure1<ConstantModel> _function = (ConstantModel it) -> { | ||
29 | it.setFailed(((ConstantEvent)topEvent).isFailed()); | ||
30 | }; | ||
31 | _switchResult = ObjectExtensions.<ConstantModel>operator_doubleArrow(_createConstantModel, _function); | ||
32 | } | ||
33 | if (!_matched) { | ||
34 | if (topEvent instanceof RandomEvent) { | ||
35 | _matched=true; | ||
36 | FaultTree _xblockexpression_1 = null; | ||
37 | { | ||
38 | final FaultTreeBuilder builder = new FaultTreeBuilder(); | ||
39 | builder.addTopLevel(((RandomEvent)topEvent)); | ||
40 | _xblockexpression_1 = builder.getFaultTree(); | ||
41 | } | ||
42 | _switchResult = _xblockexpression_1; | ||
43 | } | ||
44 | } | ||
45 | _xblockexpression = _switchResult; | ||
46 | } | ||
47 | return _xblockexpression; | ||
9 | } | 48 | } |
10 | } | 49 | } |
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventCollection.java b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventCollection.java new file mode 100644 index 00000000..dceef9f8 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventCollection.java | |||
@@ -0,0 +1,188 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.cft2ft; | ||
2 | |||
3 | import com.google.common.collect.ImmutableSet; | ||
4 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ConstantEvent; | ||
5 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Event; | ||
6 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.RandomEvent; | ||
7 | import java.util.Set; | ||
8 | import org.eclipse.xtend.lib.annotations.Data; | ||
9 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
10 | import org.eclipse.xtext.xbase.lib.Pure; | ||
11 | import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; | ||
12 | |||
13 | @Data | ||
14 | @SuppressWarnings("all") | ||
15 | public class EventCollection { | ||
16 | public static class Builder { | ||
17 | private int falseEventCount = 0; | ||
18 | |||
19 | private int trueEventCount = 0; | ||
20 | |||
21 | private final ImmutableSet.Builder<RandomEvent> randomEventsBuilder = ImmutableSet.<RandomEvent>builder(); | ||
22 | |||
23 | private Builder() { | ||
24 | } | ||
25 | |||
26 | public EventCollection.Builder add(final Event event) { | ||
27 | EventCollection.Builder _xblockexpression = null; | ||
28 | { | ||
29 | boolean _matched = false; | ||
30 | if (event instanceof ConstantEvent) { | ||
31 | _matched=true; | ||
32 | boolean _isFailed = ((ConstantEvent)event).isFailed(); | ||
33 | if (_isFailed) { | ||
34 | this.trueEventCount++; | ||
35 | } else { | ||
36 | this.falseEventCount++; | ||
37 | } | ||
38 | } | ||
39 | if (!_matched) { | ||
40 | if (event instanceof RandomEvent) { | ||
41 | _matched=true; | ||
42 | this.randomEventsBuilder.add(((RandomEvent)event)); | ||
43 | } | ||
44 | } | ||
45 | if (!_matched) { | ||
46 | throw new IllegalArgumentException(("Unknown event: " + event)); | ||
47 | } | ||
48 | _xblockexpression = this; | ||
49 | } | ||
50 | return _xblockexpression; | ||
51 | } | ||
52 | |||
53 | public EventCollection.Builder addAll(final EventCollection materializedEvens) { | ||
54 | EventCollection.Builder _xblockexpression = null; | ||
55 | { | ||
56 | int _falseEventCount = this.falseEventCount; | ||
57 | this.falseEventCount = (_falseEventCount + materializedEvens.falseEventCount); | ||
58 | int _trueEventCount = this.trueEventCount; | ||
59 | this.trueEventCount = (_trueEventCount + materializedEvens.trueEventCount); | ||
60 | this.randomEventsBuilder.addAll(materializedEvens.randomEvents); | ||
61 | _xblockexpression = this; | ||
62 | } | ||
63 | return _xblockexpression; | ||
64 | } | ||
65 | |||
66 | public EventCollection build() { | ||
67 | ImmutableSet<RandomEvent> _build = this.randomEventsBuilder.build(); | ||
68 | return new EventCollection(this.falseEventCount, this.trueEventCount, _build); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | private final int falseEventCount; | ||
73 | |||
74 | private final int trueEventCount; | ||
75 | |||
76 | private final Set<RandomEvent> randomEvents; | ||
77 | |||
78 | public boolean containsFalseEvent() { | ||
79 | return (this.falseEventCount >= 1); | ||
80 | } | ||
81 | |||
82 | public boolean containsTrueEvent() { | ||
83 | return (this.trueEventCount >= 1); | ||
84 | } | ||
85 | |||
86 | public int getVariableEventCount() { | ||
87 | return this.randomEvents.size(); | ||
88 | } | ||
89 | |||
90 | public boolean containsRandomEvent() { | ||
91 | int _variableEventCount = this.getVariableEventCount(); | ||
92 | return (_variableEventCount >= 1); | ||
93 | } | ||
94 | |||
95 | public int getCount() { | ||
96 | int _variableEventCount = this.getVariableEventCount(); | ||
97 | return ((this.falseEventCount + this.trueEventCount) + _variableEventCount); | ||
98 | } | ||
99 | |||
100 | public boolean isEmpty() { | ||
101 | return (((!this.containsFalseEvent()) && (!this.containsTrueEvent())) && (!this.containsRandomEvent())); | ||
102 | } | ||
103 | |||
104 | public boolean containsExactlyOneRandomEvent() { | ||
105 | return (((!this.containsFalseEvent()) && (!this.containsTrueEvent())) && (this.getVariableEventCount() == 1)); | ||
106 | } | ||
107 | |||
108 | public RandomEvent toSingleRandomEvent() { | ||
109 | RandomEvent _xblockexpression = null; | ||
110 | { | ||
111 | boolean _containsExactlyOneRandomEvent = this.containsExactlyOneRandomEvent(); | ||
112 | boolean _not = (!_containsExactlyOneRandomEvent); | ||
113 | if (_not) { | ||
114 | throw new IllegalStateException("Input collection is not a single random event"); | ||
115 | } | ||
116 | _xblockexpression = IterableExtensions.<RandomEvent>head(this.randomEvents); | ||
117 | } | ||
118 | return _xblockexpression; | ||
119 | } | ||
120 | |||
121 | public static EventCollection.Builder builder() { | ||
122 | return new EventCollection.Builder(); | ||
123 | } | ||
124 | |||
125 | public EventCollection(final int falseEventCount, final int trueEventCount, final Set<RandomEvent> randomEvents) { | ||
126 | super(); | ||
127 | this.falseEventCount = falseEventCount; | ||
128 | this.trueEventCount = trueEventCount; | ||
129 | this.randomEvents = randomEvents; | ||
130 | } | ||
131 | |||
132 | @Override | ||
133 | @Pure | ||
134 | public int hashCode() { | ||
135 | final int prime = 31; | ||
136 | int result = 1; | ||
137 | result = prime * result + this.falseEventCount; | ||
138 | result = prime * result + this.trueEventCount; | ||
139 | return prime * result + ((this.randomEvents== null) ? 0 : this.randomEvents.hashCode()); | ||
140 | } | ||
141 | |||
142 | @Override | ||
143 | @Pure | ||
144 | public boolean equals(final Object obj) { | ||
145 | if (this == obj) | ||
146 | return true; | ||
147 | if (obj == null) | ||
148 | return false; | ||
149 | if (getClass() != obj.getClass()) | ||
150 | return false; | ||
151 | EventCollection other = (EventCollection) obj; | ||
152 | if (other.falseEventCount != this.falseEventCount) | ||
153 | return false; | ||
154 | if (other.trueEventCount != this.trueEventCount) | ||
155 | return false; | ||
156 | if (this.randomEvents == null) { | ||
157 | if (other.randomEvents != null) | ||
158 | return false; | ||
159 | } else if (!this.randomEvents.equals(other.randomEvents)) | ||
160 | return false; | ||
161 | return true; | ||
162 | } | ||
163 | |||
164 | @Override | ||
165 | @Pure | ||
166 | public String toString() { | ||
167 | ToStringBuilder b = new ToStringBuilder(this); | ||
168 | b.add("falseEventCount", this.falseEventCount); | ||
169 | b.add("trueEventCount", this.trueEventCount); | ||
170 | b.add("randomEvents", this.randomEvents); | ||
171 | return b.toString(); | ||
172 | } | ||
173 | |||
174 | @Pure | ||
175 | public int getFalseEventCount() { | ||
176 | return this.falseEventCount; | ||
177 | } | ||
178 | |||
179 | @Pure | ||
180 | public int getTrueEventCount() { | ||
181 | return this.trueEventCount; | ||
182 | } | ||
183 | |||
184 | @Pure | ||
185 | public Set<RandomEvent> getRandomEvents() { | ||
186 | return this.randomEvents; | ||
187 | } | ||
188 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventMaterializer.java b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventMaterializer.java new file mode 100644 index 00000000..70481341 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventMaterializer.java | |||
@@ -0,0 +1,456 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.cft2ft; | ||
2 | |||
3 | import com.google.common.base.Objects; | ||
4 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.AndGateDefinition; | ||
5 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.BasicEventDefinition; | ||
6 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.Component; | ||
7 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.Connection; | ||
8 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.EventDeclaration; | ||
9 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.GateDefinition; | ||
10 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.Input; | ||
11 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.InputEvent; | ||
12 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.KOfMGateDefinition; | ||
13 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.OrGateDefinition; | ||
14 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.Output; | ||
15 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.AndGate; | ||
16 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.BasicEvent; | ||
17 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ConstantEvent; | ||
18 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Distribution; | ||
19 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Event; | ||
20 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.FtFactory; | ||
21 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Gate; | ||
22 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.KOfMGate; | ||
23 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.OrGate; | ||
24 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.RandomEvent; | ||
25 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.cft2ft.EventCollection; | ||
26 | import java.util.LinkedHashSet; | ||
27 | import java.util.Map; | ||
28 | import java.util.function.Function; | ||
29 | import org.eclipse.emf.common.util.EList; | ||
30 | import org.eclipse.emf.ecore.util.EcoreUtil; | ||
31 | import org.eclipse.xtend.lib.annotations.Data; | ||
32 | import org.eclipse.xtend2.lib.StringConcatenation; | ||
33 | import org.eclipse.xtext.xbase.lib.CollectionLiterals; | ||
34 | import org.eclipse.xtext.xbase.lib.Extension; | ||
35 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
36 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
37 | import org.eclipse.xtext.xbase.lib.ObjectExtensions; | ||
38 | import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; | ||
39 | import org.eclipse.xtext.xbase.lib.Pure; | ||
40 | |||
41 | @SuppressWarnings("all") | ||
42 | public class EventMaterializer { | ||
43 | @Data | ||
44 | protected static class EventKey<T extends EventDeclaration> { | ||
45 | private final Component component; | ||
46 | |||
47 | private final T event; | ||
48 | |||
49 | @Override | ||
50 | public String toString() { | ||
51 | StringConcatenation _builder = new StringConcatenation(); | ||
52 | String _name = this.component.getName(); | ||
53 | _builder.append(_name); | ||
54 | _builder.append("_"); | ||
55 | String _name_1 = this.event.getName(); | ||
56 | _builder.append(_name_1); | ||
57 | return _builder.toString(); | ||
58 | } | ||
59 | |||
60 | public EventKey(final Component component, final T event) { | ||
61 | super(); | ||
62 | this.component = component; | ||
63 | this.event = event; | ||
64 | } | ||
65 | |||
66 | @Override | ||
67 | @Pure | ||
68 | public int hashCode() { | ||
69 | final int prime = 31; | ||
70 | int result = 1; | ||
71 | result = prime * result + ((this.component== null) ? 0 : this.component.hashCode()); | ||
72 | return prime * result + ((this.event== null) ? 0 : this.event.hashCode()); | ||
73 | } | ||
74 | |||
75 | @Override | ||
76 | @Pure | ||
77 | public boolean equals(final Object obj) { | ||
78 | if (this == obj) | ||
79 | return true; | ||
80 | if (obj == null) | ||
81 | return false; | ||
82 | if (getClass() != obj.getClass()) | ||
83 | return false; | ||
84 | EventMaterializer.EventKey<?> other = (EventMaterializer.EventKey<?>) obj; | ||
85 | if (this.component == null) { | ||
86 | if (other.component != null) | ||
87 | return false; | ||
88 | } else if (!this.component.equals(other.component)) | ||
89 | return false; | ||
90 | if (this.event == null) { | ||
91 | if (other.event != null) | ||
92 | return false; | ||
93 | } else if (!this.event.equals(other.event)) | ||
94 | return false; | ||
95 | return true; | ||
96 | } | ||
97 | |||
98 | @Pure | ||
99 | public Component getComponent() { | ||
100 | return this.component; | ||
101 | } | ||
102 | |||
103 | @Pure | ||
104 | public T getEvent() { | ||
105 | return this.event; | ||
106 | } | ||
107 | } | ||
108 | |||
109 | @Extension | ||
110 | private final FtFactory _ftFactory = FtFactory.eINSTANCE; | ||
111 | |||
112 | private final Map<EventMaterializer.EventKey<EventDeclaration>, Event> materializationCache = CollectionLiterals.<EventMaterializer.EventKey<EventDeclaration>, Event>newHashMap(); | ||
113 | |||
114 | private final Map<EventMaterializer.EventKey<InputEvent>, EventCollection> multipleInputCache = CollectionLiterals.<EventMaterializer.EventKey<InputEvent>, EventCollection>newHashMap(); | ||
115 | |||
116 | private final ConstantEvent falseEvent; | ||
117 | |||
118 | private final ConstantEvent trueEvent; | ||
119 | |||
120 | private final LinkedHashSet<EventMaterializer.EventKey<? extends EventDeclaration>> path = new LinkedHashSet<EventMaterializer.EventKey<? extends EventDeclaration>>(); | ||
121 | |||
122 | public EventMaterializer() { | ||
123 | ConstantEvent _createConstantEvent = this._ftFactory.createConstantEvent(); | ||
124 | final Procedure1<ConstantEvent> _function = (ConstantEvent it) -> { | ||
125 | it.setFailed(false); | ||
126 | }; | ||
127 | ConstantEvent _doubleArrow = ObjectExtensions.<ConstantEvent>operator_doubleArrow(_createConstantEvent, _function); | ||
128 | this.falseEvent = _doubleArrow; | ||
129 | ConstantEvent _createConstantEvent_1 = this._ftFactory.createConstantEvent(); | ||
130 | final Procedure1<ConstantEvent> _function_1 = (ConstantEvent it) -> { | ||
131 | it.setFailed(true); | ||
132 | }; | ||
133 | ConstantEvent _doubleArrow_1 = ObjectExtensions.<ConstantEvent>operator_doubleArrow(_createConstantEvent_1, _function_1); | ||
134 | this.trueEvent = _doubleArrow_1; | ||
135 | } | ||
136 | |||
137 | public Event getOrMaterialize(final Output output) { | ||
138 | return this.getOrMaterialize(output.getComponent(), output.getEventDeclaration()); | ||
139 | } | ||
140 | |||
141 | public Event getOrMaterialize(final Component component, final EventDeclaration eventDeclaration) { | ||
142 | Event _xblockexpression = null; | ||
143 | { | ||
144 | final EventMaterializer.EventKey<EventDeclaration> eventKey = new EventMaterializer.EventKey<EventDeclaration>(component, eventDeclaration); | ||
145 | this.pushEventKey(eventKey); | ||
146 | Event _xtrycatchfinallyexpression = null; | ||
147 | try { | ||
148 | final Function<EventMaterializer.EventKey<EventDeclaration>, Event> _function = (EventMaterializer.EventKey<EventDeclaration> it) -> { | ||
149 | return this.materialize(it.component, it.event); | ||
150 | }; | ||
151 | _xtrycatchfinallyexpression = this.materializationCache.computeIfAbsent(eventKey, _function); | ||
152 | } finally { | ||
153 | this.popEventKey(eventKey); | ||
154 | } | ||
155 | _xblockexpression = _xtrycatchfinallyexpression; | ||
156 | } | ||
157 | return _xblockexpression; | ||
158 | } | ||
159 | |||
160 | protected Event materialize(final Component component, final EventDeclaration eventDeclaration) { | ||
161 | RandomEvent _xblockexpression = null; | ||
162 | { | ||
163 | String _name = component.getName(); | ||
164 | String _plus = (_name + "_"); | ||
165 | String _name_1 = eventDeclaration.getName(); | ||
166 | final String eventName = (_plus + _name_1); | ||
167 | RandomEvent _switchResult = null; | ||
168 | boolean _matched = false; | ||
169 | if (eventDeclaration instanceof InputEvent) { | ||
170 | _matched=true; | ||
171 | return this.materializeConnectedEvent(component, ((InputEvent)eventDeclaration)); | ||
172 | } | ||
173 | if (!_matched) { | ||
174 | if (eventDeclaration instanceof BasicEventDefinition) { | ||
175 | _matched=true; | ||
176 | BasicEvent _xblockexpression_1 = null; | ||
177 | { | ||
178 | final BasicEvent basicEvent = this._ftFactory.createBasicEvent(); | ||
179 | basicEvent.setDistribution(EcoreUtil.<Distribution>copy(((BasicEventDefinition)eventDeclaration).getDistribution())); | ||
180 | _xblockexpression_1 = basicEvent; | ||
181 | } | ||
182 | _switchResult = _xblockexpression_1; | ||
183 | } | ||
184 | } | ||
185 | if (!_matched) { | ||
186 | if (eventDeclaration instanceof GateDefinition) { | ||
187 | _matched=true; | ||
188 | Gate _xblockexpression_1 = null; | ||
189 | { | ||
190 | final EventCollection inputs = this.collectInputs(component, ((GateDefinition)eventDeclaration)); | ||
191 | Gate _switchResult_1 = null; | ||
192 | boolean _matched_1 = false; | ||
193 | if (eventDeclaration instanceof AndGateDefinition) { | ||
194 | _matched_1=true; | ||
195 | AndGate _xifexpression = null; | ||
196 | boolean _containsFalseEvent = inputs.containsFalseEvent(); | ||
197 | if (_containsFalseEvent) { | ||
198 | return this.falseEvent; | ||
199 | } else { | ||
200 | AndGate _xifexpression_1 = null; | ||
201 | boolean _isEmpty = inputs.isEmpty(); | ||
202 | if (_isEmpty) { | ||
203 | return this.trueEvent; | ||
204 | } else { | ||
205 | AndGate _xifexpression_2 = null; | ||
206 | boolean _containsExactlyOneRandomEvent = inputs.containsExactlyOneRandomEvent(); | ||
207 | if (_containsExactlyOneRandomEvent) { | ||
208 | return inputs.toSingleRandomEvent(); | ||
209 | } else { | ||
210 | _xifexpression_2 = this._ftFactory.createAndGate(); | ||
211 | } | ||
212 | _xifexpression_1 = _xifexpression_2; | ||
213 | } | ||
214 | _xifexpression = _xifexpression_1; | ||
215 | } | ||
216 | _switchResult_1 = _xifexpression; | ||
217 | } | ||
218 | if (!_matched_1) { | ||
219 | if (eventDeclaration instanceof OrGateDefinition) { | ||
220 | _matched_1=true; | ||
221 | OrGate _xifexpression = null; | ||
222 | boolean _containsTrueEvent = inputs.containsTrueEvent(); | ||
223 | if (_containsTrueEvent) { | ||
224 | return this.trueEvent; | ||
225 | } else { | ||
226 | OrGate _xifexpression_1 = null; | ||
227 | boolean _isEmpty = inputs.isEmpty(); | ||
228 | if (_isEmpty) { | ||
229 | return this.falseEvent; | ||
230 | } else { | ||
231 | OrGate _xifexpression_2 = null; | ||
232 | boolean _containsExactlyOneRandomEvent = inputs.containsExactlyOneRandomEvent(); | ||
233 | if (_containsExactlyOneRandomEvent) { | ||
234 | return inputs.toSingleRandomEvent(); | ||
235 | } else { | ||
236 | _xifexpression_2 = this._ftFactory.createOrGate(); | ||
237 | } | ||
238 | _xifexpression_1 = _xifexpression_2; | ||
239 | } | ||
240 | _xifexpression = _xifexpression_1; | ||
241 | } | ||
242 | _switchResult_1 = _xifexpression; | ||
243 | } | ||
244 | } | ||
245 | if (!_matched_1) { | ||
246 | if (eventDeclaration instanceof KOfMGateDefinition) { | ||
247 | _matched_1=true; | ||
248 | Gate _xblockexpression_2 = null; | ||
249 | { | ||
250 | int _count = inputs.getCount(); | ||
251 | int _k = ((KOfMGateDefinition)eventDeclaration).getK(); | ||
252 | int _multiply = (_count * _k); | ||
253 | int _m = ((KOfMGateDefinition)eventDeclaration).getM(); | ||
254 | final int requiredTrueInputs = (_multiply / _m); | ||
255 | int _trueEventCount = inputs.getTrueEventCount(); | ||
256 | final int k = (requiredTrueInputs - _trueEventCount); | ||
257 | final int m = inputs.getVariableEventCount(); | ||
258 | Gate _xifexpression = null; | ||
259 | if ((k == 0)) { | ||
260 | return this.trueEvent; | ||
261 | } else { | ||
262 | Gate _xifexpression_1 = null; | ||
263 | if ((k > m)) { | ||
264 | return this.falseEvent; | ||
265 | } else { | ||
266 | Gate _xifexpression_2 = null; | ||
267 | boolean _containsExactlyOneRandomEvent = inputs.containsExactlyOneRandomEvent(); | ||
268 | if (_containsExactlyOneRandomEvent) { | ||
269 | return inputs.toSingleRandomEvent(); | ||
270 | } else { | ||
271 | Gate _xifexpression_3 = null; | ||
272 | if ((k == 1)) { | ||
273 | _xifexpression_3 = this._ftFactory.createOrGate(); | ||
274 | } else { | ||
275 | Gate _xifexpression_4 = null; | ||
276 | if ((k == m)) { | ||
277 | _xifexpression_4 = this._ftFactory.createAndGate(); | ||
278 | } else { | ||
279 | KOfMGate _xblockexpression_3 = null; | ||
280 | { | ||
281 | final KOfMGate kOfMGate = this._ftFactory.createKOfMGate(); | ||
282 | kOfMGate.setK(k); | ||
283 | _xblockexpression_3 = kOfMGate; | ||
284 | } | ||
285 | _xifexpression_4 = _xblockexpression_3; | ||
286 | } | ||
287 | _xifexpression_3 = _xifexpression_4; | ||
288 | } | ||
289 | _xifexpression_2 = _xifexpression_3; | ||
290 | } | ||
291 | _xifexpression_1 = _xifexpression_2; | ||
292 | } | ||
293 | _xifexpression = _xifexpression_1; | ||
294 | } | ||
295 | _xblockexpression_2 = _xifexpression; | ||
296 | } | ||
297 | _switchResult_1 = _xblockexpression_2; | ||
298 | } | ||
299 | } | ||
300 | if (!_matched_1) { | ||
301 | throw new IllegalArgumentException(("Unknown gate definition: " + eventDeclaration)); | ||
302 | } | ||
303 | final Gate gate = _switchResult_1; | ||
304 | gate.getInputEvents().addAll(inputs.getRandomEvents()); | ||
305 | _xblockexpression_1 = gate; | ||
306 | } | ||
307 | _switchResult = _xblockexpression_1; | ||
308 | } | ||
309 | } | ||
310 | if (!_matched) { | ||
311 | throw new IllegalArgumentException(("Unknown event declaration: " + eventDeclaration)); | ||
312 | } | ||
313 | final RandomEvent event = _switchResult; | ||
314 | event.setName(eventName); | ||
315 | _xblockexpression = event; | ||
316 | } | ||
317 | return _xblockexpression; | ||
318 | } | ||
319 | |||
320 | protected Event materializeConnectedEvent(final Component component, final InputEvent inputEvent) { | ||
321 | Event _xblockexpression = null; | ||
322 | { | ||
323 | boolean _isMultiple = inputEvent.isMultiple(); | ||
324 | if (_isMultiple) { | ||
325 | StringConcatenation _builder = new StringConcatenation(); | ||
326 | _builder.append("Cannot materialize multiple nput "); | ||
327 | String _name = component.getName(); | ||
328 | _builder.append(_name); | ||
329 | _builder.append("_"); | ||
330 | String _name_1 = inputEvent.getName(); | ||
331 | _builder.append(_name_1); | ||
332 | throw new IllegalArgumentException(_builder.toString()); | ||
333 | } | ||
334 | final Input input = this.findInput(component, inputEvent); | ||
335 | final EList<Connection> incomingConnections = input.getIncomingConnections(); | ||
336 | int _size = incomingConnections.size(); | ||
337 | boolean _notEquals = (_size != 1); | ||
338 | if (_notEquals) { | ||
339 | StringConcatenation _builder_1 = new StringConcatenation(); | ||
340 | _builder_1.append("Input "); | ||
341 | String _name_2 = component.getName(); | ||
342 | _builder_1.append(_name_2); | ||
343 | _builder_1.append("_"); | ||
344 | String _name_3 = inputEvent.getName(); | ||
345 | _builder_1.append(_name_3); | ||
346 | _builder_1.append(" has "); | ||
347 | int _size_1 = incomingConnections.size(); | ||
348 | _builder_1.append(_size_1); | ||
349 | _builder_1.append(" connections instead of 1"); | ||
350 | throw new IllegalArgumentException(_builder_1.toString()); | ||
351 | } | ||
352 | final Output output = IterableExtensions.<Connection>head(incomingConnections).getOutput(); | ||
353 | _xblockexpression = this.getOrMaterialize(output.getComponent(), output.getEventDeclaration()); | ||
354 | } | ||
355 | return _xblockexpression; | ||
356 | } | ||
357 | |||
358 | protected EventCollection collectInputs(final Component component, final GateDefinition gateDefinition) { | ||
359 | EventCollection _xblockexpression = null; | ||
360 | { | ||
361 | final EventCollection.Builder builder = EventCollection.builder(); | ||
362 | EList<EventDeclaration> _inputEvents = gateDefinition.getInputEvents(); | ||
363 | for (final EventDeclaration inputEventDeclaration : _inputEvents) { | ||
364 | boolean _matched = false; | ||
365 | if (inputEventDeclaration instanceof InputEvent) { | ||
366 | boolean _isMultiple = ((InputEvent)inputEventDeclaration).isMultiple(); | ||
367 | if (_isMultiple) { | ||
368 | _matched=true; | ||
369 | final EventCollection materializedEvents = this.getOrMaterializeConnectedEvents(component, ((InputEvent)inputEventDeclaration)); | ||
370 | builder.addAll(materializedEvents); | ||
371 | } | ||
372 | } | ||
373 | if (!_matched) { | ||
374 | builder.add(this.getOrMaterialize(component, inputEventDeclaration)); | ||
375 | } | ||
376 | } | ||
377 | _xblockexpression = builder.build(); | ||
378 | } | ||
379 | return _xblockexpression; | ||
380 | } | ||
381 | |||
382 | protected EventCollection getOrMaterializeConnectedEvents(final Component component, final InputEvent inputEvent) { | ||
383 | EventCollection _xblockexpression = null; | ||
384 | { | ||
385 | final EventMaterializer.EventKey<InputEvent> inputKey = new EventMaterializer.EventKey<InputEvent>(component, inputEvent); | ||
386 | this.pushEventKey(inputKey); | ||
387 | EventCollection _xtrycatchfinallyexpression = null; | ||
388 | try { | ||
389 | final Function<EventMaterializer.EventKey<InputEvent>, EventCollection> _function = (EventMaterializer.EventKey<InputEvent> it) -> { | ||
390 | return this.materializeConnectedEvents(it.component, it.event); | ||
391 | }; | ||
392 | _xtrycatchfinallyexpression = this.multipleInputCache.computeIfAbsent(inputKey, _function); | ||
393 | } finally { | ||
394 | this.popEventKey(inputKey); | ||
395 | } | ||
396 | _xblockexpression = _xtrycatchfinallyexpression; | ||
397 | } | ||
398 | return _xblockexpression; | ||
399 | } | ||
400 | |||
401 | protected EventCollection materializeConnectedEvents(final Component component, final InputEvent inputEvent) { | ||
402 | EventCollection _xblockexpression = null; | ||
403 | { | ||
404 | final Input input = this.findInput(component, inputEvent); | ||
405 | final EventCollection.Builder builder = EventCollection.builder(); | ||
406 | EList<Connection> _incomingConnections = input.getIncomingConnections(); | ||
407 | for (final Connection connection : _incomingConnections) { | ||
408 | { | ||
409 | final Event materializedEvent = this.getOrMaterialize(connection.getOutput()); | ||
410 | builder.add(materializedEvent); | ||
411 | } | ||
412 | } | ||
413 | _xblockexpression = builder.build(); | ||
414 | } | ||
415 | return _xblockexpression; | ||
416 | } | ||
417 | |||
418 | protected Input findInput(final Component component, final InputEvent inputEvent) { | ||
419 | final Function1<Input, Boolean> _function = (Input it) -> { | ||
420 | InputEvent _inputEvent = it.getInputEvent(); | ||
421 | return Boolean.valueOf(Objects.equal(_inputEvent, inputEvent)); | ||
422 | }; | ||
423 | final Input input = IterableExtensions.<Input>findFirst(component.getInputs(), _function); | ||
424 | if ((input == null)) { | ||
425 | StringConcatenation _builder = new StringConcatenation(); | ||
426 | _builder.append("No input "); | ||
427 | _builder.append(inputEvent); | ||
428 | _builder.append(" in component "); | ||
429 | _builder.append(component); | ||
430 | throw new IllegalArgumentException(_builder.toString()); | ||
431 | } | ||
432 | return input; | ||
433 | } | ||
434 | |||
435 | private void pushEventKey(final EventMaterializer.EventKey<? extends EventDeclaration> eventKey) { | ||
436 | boolean _add = this.path.add(eventKey); | ||
437 | boolean _not = (!_add); | ||
438 | if (_not) { | ||
439 | StringConcatenation _builder = new StringConcatenation(); | ||
440 | _builder.append("Circular dependency ["); | ||
441 | { | ||
442 | for(final EventMaterializer.EventKey<? extends EventDeclaration> ancestor : this.path) { | ||
443 | _builder.append(ancestor); | ||
444 | _builder.append(", "); | ||
445 | } | ||
446 | } | ||
447 | _builder.append(eventKey); | ||
448 | _builder.append("] detected"); | ||
449 | throw new IllegalStateException(_builder.toString()); | ||
450 | } | ||
451 | } | ||
452 | |||
453 | private boolean popEventKey(final EventMaterializer.EventKey<? extends EventDeclaration> eventKey) { | ||
454 | return this.path.remove(eventKey); | ||
455 | } | ||
456 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/FaultTreeBuilder.java b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/FaultTreeBuilder.java new file mode 100644 index 00000000..9b2dfd76 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/FaultTreeBuilder.java | |||
@@ -0,0 +1,57 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.cft2ft; | ||
2 | |||
3 | import com.google.common.base.Objects; | ||
4 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.FaultTree; | ||
5 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.FtFactory; | ||
6 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Gate; | ||
7 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.RandomEvent; | ||
8 | import java.util.Collection; | ||
9 | import org.eclipse.emf.common.util.EList; | ||
10 | import org.eclipse.emf.ecore.EObject; | ||
11 | import org.eclipse.xtend.lib.annotations.Accessors; | ||
12 | import org.eclipse.xtext.xbase.lib.Pure; | ||
13 | |||
14 | @SuppressWarnings("all") | ||
15 | public class FaultTreeBuilder { | ||
16 | @Accessors | ||
17 | private final FaultTree faultTree = FtFactory.eINSTANCE.createFaultTree(); | ||
18 | |||
19 | public void addTopLevel(final RandomEvent event) { | ||
20 | RandomEvent _topEvent = this.faultTree.getTopEvent(); | ||
21 | boolean _tripleNotEquals = (_topEvent != null); | ||
22 | if (_tripleNotEquals) { | ||
23 | throw new IllegalStateException("Top event was already set"); | ||
24 | } | ||
25 | this.add(event); | ||
26 | this.faultTree.setTopEvent(event); | ||
27 | } | ||
28 | |||
29 | protected void add(final RandomEvent event) { | ||
30 | EObject _eContainer = this.faultTree.eContainer(); | ||
31 | boolean _equals = Objects.equal(_eContainer, this.faultTree); | ||
32 | if (_equals) { | ||
33 | return; | ||
34 | } | ||
35 | EObject _eContainer_1 = this.faultTree.eContainer(); | ||
36 | boolean _tripleNotEquals = (_eContainer_1 != null); | ||
37 | if (_tripleNotEquals) { | ||
38 | throw new IllegalStateException("Event is already in a different fault tree"); | ||
39 | } | ||
40 | EList<RandomEvent> _events = this.faultTree.getEvents(); | ||
41 | _events.add(event); | ||
42 | if ((event instanceof Gate)) { | ||
43 | this.addAll(((Gate)event).getInputEvents()); | ||
44 | } | ||
45 | } | ||
46 | |||
47 | protected void addAll(final Collection<RandomEvent> events) { | ||
48 | for (final RandomEvent event : events) { | ||
49 | this.add(event); | ||
50 | } | ||
51 | } | ||
52 | |||
53 | @Pure | ||
54 | public FaultTree getFaultTree() { | ||
55 | return this.faultTree; | ||
56 | } | ||
57 | } | ||