aboutsummaryrefslogtreecommitdiffstats
path: root/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventMaterializer.java
diff options
context:
space:
mode:
Diffstat (limited to 'Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventMaterializer.java')
-rw-r--r--Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventMaterializer.java469
1 files changed, 0 insertions, 469 deletions
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
deleted file mode 100644
index 98a82b7d..00000000
--- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventMaterializer.java
+++ /dev/null
@@ -1,469 +0,0 @@
1package hu.bme.mit.inf.dslreasoner.faulttree.transformation.cft2ft;
2
3import com.google.common.base.Objects;
4import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.AndGateDefinition;
5import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.BasicEventDefinition;
6import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.Component;
7import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.Connection;
8import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.EventDeclaration;
9import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.GateDefinition;
10import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.Input;
11import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.InputEvent;
12import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.KOfMGateDefinition;
13import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.OrGateDefinition;
14import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.Output;
15import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.AndGate;
16import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.BasicEvent;
17import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ConstantEvent;
18import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Distribution;
19import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Event;
20import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.FtFactory;
21import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Gate;
22import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.KOfMGate;
23import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.OrGate;
24import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.RandomEvent;
25import hu.bme.mit.inf.dslreasoner.faulttree.model.util.CftExtensions;
26import hu.bme.mit.inf.dslreasoner.faulttree.transformation.cft2ft.EventCollection;
27import java.util.LinkedHashSet;
28import java.util.Map;
29import org.eclipse.emf.common.util.EList;
30import org.eclipse.emf.ecore.util.EcoreUtil;
31import org.eclipse.xtend.lib.annotations.Data;
32import org.eclipse.xtend2.lib.StringConcatenation;
33import org.eclipse.xtext.xbase.lib.CollectionLiterals;
34import org.eclipse.xtext.xbase.lib.Extension;
35import org.eclipse.xtext.xbase.lib.Functions.Function1;
36import org.eclipse.xtext.xbase.lib.IterableExtensions;
37import org.eclipse.xtext.xbase.lib.ObjectExtensions;
38import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
39import org.eclipse.xtext.xbase.lib.Pure;
40
41@SuppressWarnings("all")
42public 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 Event _xblockexpression_1 = null;
149 {
150 Event event = this.materializationCache.get(eventKey);
151 if ((event == null)) {
152 event = this.materialize(component, eventDeclaration);
153 this.materializationCache.put(eventKey, event);
154 }
155 _xblockexpression_1 = event;
156 }
157 _xtrycatchfinallyexpression = _xblockexpression_1;
158 } finally {
159 this.popEventKey(eventKey);
160 }
161 _xblockexpression = _xtrycatchfinallyexpression;
162 }
163 return _xblockexpression;
164 }
165
166 protected Event materialize(final Component component, final EventDeclaration eventDeclaration) {
167 RandomEvent _xblockexpression = null;
168 {
169 String _name = component.getName();
170 String _plus = (_name + "_");
171 String _name_1 = eventDeclaration.getName();
172 final String eventName = (_plus + _name_1);
173 RandomEvent _switchResult = null;
174 boolean _matched = false;
175 if (eventDeclaration instanceof InputEvent) {
176 _matched=true;
177 return this.materializeConnectedEvent(component, ((InputEvent)eventDeclaration));
178 }
179 if (!_matched) {
180 if (eventDeclaration instanceof BasicEventDefinition) {
181 _matched=true;
182 BasicEvent _xblockexpression_1 = null;
183 {
184 final BasicEvent basicEvent = this._ftFactory.createBasicEvent();
185 basicEvent.setDistribution(EcoreUtil.<Distribution>copy(((BasicEventDefinition)eventDeclaration).getDistribution()));
186 _xblockexpression_1 = basicEvent;
187 }
188 _switchResult = _xblockexpression_1;
189 }
190 }
191 if (!_matched) {
192 if (eventDeclaration instanceof GateDefinition) {
193 _matched=true;
194 Gate _xblockexpression_1 = null;
195 {
196 final EventCollection inputs = this.collectInputs(component, ((GateDefinition)eventDeclaration));
197 Gate _switchResult_1 = null;
198 boolean _matched_1 = false;
199 if (eventDeclaration instanceof AndGateDefinition) {
200 _matched_1=true;
201 AndGate _xifexpression = null;
202 boolean _containsFalseEvent = inputs.containsFalseEvent();
203 if (_containsFalseEvent) {
204 return this.falseEvent;
205 } else {
206 AndGate _xifexpression_1 = null;
207 boolean _isEmpty = inputs.isEmpty();
208 if (_isEmpty) {
209 return this.trueEvent;
210 } else {
211 AndGate _xifexpression_2 = null;
212 boolean _containsExactlyOneRandomEvent = inputs.containsExactlyOneRandomEvent();
213 if (_containsExactlyOneRandomEvent) {
214 return inputs.toSingleRandomEvent();
215 } else {
216 _xifexpression_2 = this._ftFactory.createAndGate();
217 }
218 _xifexpression_1 = _xifexpression_2;
219 }
220 _xifexpression = _xifexpression_1;
221 }
222 _switchResult_1 = _xifexpression;
223 }
224 if (!_matched_1) {
225 if (eventDeclaration instanceof OrGateDefinition) {
226 _matched_1=true;
227 OrGate _xifexpression = null;
228 boolean _containsTrueEvent = inputs.containsTrueEvent();
229 if (_containsTrueEvent) {
230 return this.trueEvent;
231 } else {
232 OrGate _xifexpression_1 = null;
233 boolean _isEmpty = inputs.isEmpty();
234 if (_isEmpty) {
235 return this.falseEvent;
236 } else {
237 OrGate _xifexpression_2 = null;
238 boolean _containsExactlyOneRandomEvent = inputs.containsExactlyOneRandomEvent();
239 if (_containsExactlyOneRandomEvent) {
240 return inputs.toSingleRandomEvent();
241 } else {
242 _xifexpression_2 = this._ftFactory.createOrGate();
243 }
244 _xifexpression_1 = _xifexpression_2;
245 }
246 _xifexpression = _xifexpression_1;
247 }
248 _switchResult_1 = _xifexpression;
249 }
250 }
251 if (!_matched_1) {
252 if (eventDeclaration instanceof KOfMGateDefinition) {
253 _matched_1=true;
254 Gate _xblockexpression_2 = null;
255 {
256 int _count = inputs.getCount();
257 int _k = ((KOfMGateDefinition)eventDeclaration).getK();
258 int _multiply = (_count * _k);
259 int _m = ((KOfMGateDefinition)eventDeclaration).getM();
260 final int requiredTrueInputs = (_multiply / _m);
261 int _trueEventCount = inputs.getTrueEventCount();
262 final int k = (requiredTrueInputs - _trueEventCount);
263 final int m = inputs.getVariableEventCount();
264 Gate _xifexpression = null;
265 if ((k == 0)) {
266 return this.trueEvent;
267 } else {
268 Gate _xifexpression_1 = null;
269 if ((k > m)) {
270 return this.falseEvent;
271 } else {
272 Gate _xifexpression_2 = null;
273 boolean _containsExactlyOneRandomEvent = inputs.containsExactlyOneRandomEvent();
274 if (_containsExactlyOneRandomEvent) {
275 return inputs.toSingleRandomEvent();
276 } else {
277 Gate _xifexpression_3 = null;
278 if ((k == 1)) {
279 _xifexpression_3 = this._ftFactory.createOrGate();
280 } else {
281 Gate _xifexpression_4 = null;
282 if ((k == m)) {
283 _xifexpression_4 = this._ftFactory.createAndGate();
284 } else {
285 KOfMGate _xblockexpression_3 = null;
286 {
287 final KOfMGate kOfMGate = this._ftFactory.createKOfMGate();
288 kOfMGate.setK(k);
289 _xblockexpression_3 = kOfMGate;
290 }
291 _xifexpression_4 = _xblockexpression_3;
292 }
293 _xifexpression_3 = _xifexpression_4;
294 }
295 _xifexpression_2 = _xifexpression_3;
296 }
297 _xifexpression_1 = _xifexpression_2;
298 }
299 _xifexpression = _xifexpression_1;
300 }
301 _xblockexpression_2 = _xifexpression;
302 }
303 _switchResult_1 = _xblockexpression_2;
304 }
305 }
306 if (!_matched_1) {
307 throw new IllegalArgumentException(("Unknown gate definition: " + eventDeclaration));
308 }
309 final Gate gate = _switchResult_1;
310 gate.getInputEvents().addAll(inputs.getRandomEvents());
311 _xblockexpression_1 = gate;
312 }
313 _switchResult = _xblockexpression_1;
314 }
315 }
316 if (!_matched) {
317 throw new IllegalArgumentException(("Unknown event declaration: " + eventDeclaration));
318 }
319 final RandomEvent event = _switchResult;
320 event.setName(eventName);
321 _xblockexpression = event;
322 }
323 return _xblockexpression;
324 }
325
326 protected Event materializeConnectedEvent(final Component component, final InputEvent inputEvent) {
327 Event _xblockexpression = null;
328 {
329 boolean _isMultiple = inputEvent.isMultiple();
330 if (_isMultiple) {
331 StringConcatenation _builder = new StringConcatenation();
332 _builder.append("Cannot materialize multiple nput ");
333 String _name = component.getName();
334 _builder.append(_name);
335 _builder.append("_");
336 String _name_1 = inputEvent.getName();
337 _builder.append(_name_1);
338 throw new IllegalArgumentException(_builder.toString());
339 }
340 final Input input = this.findInput(component, inputEvent);
341 final EList<Connection> incomingConnections = input.getIncomingConnections();
342 int _size = incomingConnections.size();
343 boolean _notEquals = (_size != 1);
344 if (_notEquals) {
345 StringConcatenation _builder_1 = new StringConcatenation();
346 _builder_1.append("Input ");
347 String _name_2 = component.getName();
348 _builder_1.append(_name_2);
349 _builder_1.append("_");
350 String _name_3 = inputEvent.getName();
351 _builder_1.append(_name_3);
352 _builder_1.append(" has ");
353 int _size_1 = incomingConnections.size();
354 _builder_1.append(_size_1);
355 _builder_1.append(" connections instead of 1");
356 throw new IllegalArgumentException(_builder_1.toString());
357 }
358 final Output output = IterableExtensions.<Connection>head(incomingConnections).getOutput();
359 _xblockexpression = this.getOrMaterialize(output.getComponent(), output.getEventDeclaration());
360 }
361 return _xblockexpression;
362 }
363
364 protected EventCollection collectInputs(final Component component, final GateDefinition gateDefinition) {
365 EventCollection _xblockexpression = null;
366 {
367 final EventCollection.Builder builder = EventCollection.builder();
368 EList<EventDeclaration> _inputEvents = gateDefinition.getInputEvents();
369 for (final EventDeclaration inputEventDeclaration : _inputEvents) {
370 boolean _matched = false;
371 if (inputEventDeclaration instanceof InputEvent) {
372 boolean _isMultiple = ((InputEvent)inputEventDeclaration).isMultiple();
373 if (_isMultiple) {
374 _matched=true;
375 final EventCollection materializedEvents = this.getOrMaterializeConnectedEvents(component, ((InputEvent)inputEventDeclaration));
376 builder.addAll(materializedEvents);
377 }
378 }
379 if (!_matched) {
380 builder.add(this.getOrMaterialize(component, inputEventDeclaration));
381 }
382 }
383 _xblockexpression = builder.build();
384 }
385 return _xblockexpression;
386 }
387
388 protected EventCollection getOrMaterializeConnectedEvents(final Component component, final InputEvent inputEvent) {
389 EventCollection _xblockexpression = null;
390 {
391 final EventMaterializer.EventKey<InputEvent> inputKey = new EventMaterializer.EventKey<InputEvent>(component, inputEvent);
392 this.pushEventKey(inputKey);
393 EventCollection _xtrycatchfinallyexpression = null;
394 try {
395 EventCollection _xblockexpression_1 = null;
396 {
397 EventCollection eventCollection = this.multipleInputCache.get(inputKey);
398 if ((eventCollection == null)) {
399 eventCollection = this.materializeConnectedEvents(component, inputEvent);
400 this.multipleInputCache.put(inputKey, eventCollection);
401 }
402 _xblockexpression_1 = eventCollection;
403 }
404 _xtrycatchfinallyexpression = _xblockexpression_1;
405 } finally {
406 this.popEventKey(inputKey);
407 }
408 _xblockexpression = _xtrycatchfinallyexpression;
409 }
410 return _xblockexpression;
411 }
412
413 protected EventCollection materializeConnectedEvents(final Component component, final InputEvent inputEvent) {
414 EventCollection _xblockexpression = null;
415 {
416 final Input input = this.findInput(component, inputEvent);
417 final EventCollection.Builder builder = EventCollection.builder();
418 EList<Connection> _incomingConnections = input.getIncomingConnections();
419 for (final Connection connection : _incomingConnections) {
420 boolean _isCurrentlyConnected = CftExtensions.isCurrentlyConnected(connection);
421 if (_isCurrentlyConnected) {
422 final Event materializedEvent = this.getOrMaterialize(connection.getOutput());
423 builder.add(materializedEvent);
424 }
425 }
426 _xblockexpression = builder.build();
427 }
428 return _xblockexpression;
429 }
430
431 protected Input findInput(final Component component, final InputEvent inputEvent) {
432 final Function1<Input, Boolean> _function = (Input it) -> {
433 InputEvent _inputEvent = it.getInputEvent();
434 return Boolean.valueOf(Objects.equal(_inputEvent, inputEvent));
435 };
436 final Input input = IterableExtensions.<Input>findFirst(component.getInputs(), _function);
437 if ((input == null)) {
438 StringConcatenation _builder = new StringConcatenation();
439 _builder.append("No input ");
440 _builder.append(inputEvent);
441 _builder.append(" in component ");
442 _builder.append(component);
443 throw new IllegalArgumentException(_builder.toString());
444 }
445 return input;
446 }
447
448 private void pushEventKey(final EventMaterializer.EventKey<? extends EventDeclaration> eventKey) {
449 boolean _add = this.path.add(eventKey);
450 boolean _not = (!_add);
451 if (_not) {
452 StringConcatenation _builder = new StringConcatenation();
453 _builder.append("Circular dependency [");
454 {
455 for(final EventMaterializer.EventKey<? extends EventDeclaration> ancestor : this.path) {
456 _builder.append(ancestor);
457 _builder.append(", ");
458 }
459 }
460 _builder.append(eventKey);
461 _builder.append("] detected");
462 throw new IllegalStateException(_builder.toString());
463 }
464 }
465
466 private boolean popEventKey(final EventMaterializer.EventKey<? extends EventDeclaration> eventKey) {
467 return this.path.remove(eventKey);
468 }
469}