diff options
author | 2019-02-16 00:43:11 +0100 | |
---|---|---|
committer | 2019-02-19 19:18:25 +0100 | |
commit | d90bedacaafe87e06fddaa05a6ff9b7b796e97e7 (patch) | |
tree | 3631e27854b40de3bce7606f60113054c77bd391 /Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation | |
parent | Ecore2Cft transformation (diff) | |
download | VIATRA-Generator-d90bedacaafe87e06fddaa05a6ff9b7b796e97e7.tar.gz VIATRA-Generator-d90bedacaafe87e06fddaa05a6ff9b7b796e97e7.tar.zst VIATRA-Generator-d90bedacaafe87e06fddaa05a6ff9b7b796e97e7.zip |
Two-valued fault tree analyzer WIP
Diffstat (limited to 'Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation')
45 files changed, 2334 insertions, 14 deletions
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/META-INF/MANIFEST.MF b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/META-INF/MANIFEST.MF index 91eeedc5..ce704acf 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/META-INF/MANIFEST.MF +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/META-INF/MANIFEST.MF | |||
@@ -13,4 +13,11 @@ Require-Bundle: com.google.guava, | |||
13 | org.eclipse.viatra.query.runtime, | 13 | org.eclipse.viatra.query.runtime, |
14 | org.eclipse.viatra.query.runtime.rete, | 14 | org.eclipse.viatra.query.runtime.rete, |
15 | org.eclipse.viatra.query.runtime.localsearch, | 15 | org.eclipse.viatra.query.runtime.localsearch, |
16 | hu.bme.mit.inf.dslreasoner.faulttree.components | 16 | hu.bme.mit.inf.dslreasoner.faulttree.components, |
17 | hu.bme.mit.inf.dslreasoner.logic.model, | ||
18 | com.github.jnr.constants;bundle-version="0.9.8", | ||
19 | org.apache.commons.lang;bundle-version="2.6.0" | ||
20 | Export-Package: hu.bme.mit.inf.dslreasoner.faulttree.transformation.cft2ft, | ||
21 | hu.bme.mit.inf.dslreasoner.faulttree.transformation.ecore2cft, | ||
22 | hu.bme.mit.inf.dslreasoner.faulttree.transformation.ft2galileo, | ||
23 | hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/build.properties b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/build.properties index 34d2e4d2..d8e2f0e9 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/build.properties +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/build.properties | |||
@@ -1,4 +1,5 @@ | |||
1 | source.. = src/ | 1 | source.. = src/,\ |
2 | xtend-gen/ | ||
2 | output.. = bin/ | 3 | output.. = bin/ |
3 | bin.includes = META-INF/,\ | 4 | bin.includes = META-INF/,\ |
4 | . | 5 | . |
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/Cft2FtTransformation.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/Cft2FtTransformation.xtend index caaffc3c..a522654c 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/Cft2FtTransformation.xtend +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/Cft2FtTransformation.xtend | |||
@@ -1,10 +1,24 @@ | |||
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.FtFactory | ||
6 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.RandomEvent | ||
4 | 7 | ||
5 | class Cft2FtTransformation { | 8 | class Cft2FtTransformation { |
6 | def createFaultTree(ComponentFaultTree componentFaultTree) { | 9 | def createFaultTree(ComponentFaultTree componentFaultTree) { |
7 | // TODO | 10 | val materializer = new EventMaterializer |
8 | throw new UnsupportedOperationException() | 11 | val topEvent = materializer.getOrMaterialize(componentFaultTree.topEvent) |
12 | switch (topEvent) { | ||
13 | ConstantEvent: | ||
14 | FtFactory.eINSTANCE.createConstantModel => [ | ||
15 | failed = topEvent.failed | ||
16 | ] | ||
17 | RandomEvent: { | ||
18 | val builder = new FaultTreeBuilder | ||
19 | builder.addTopLevel(topEvent) | ||
20 | builder.faultTree | ||
21 | } | ||
22 | } | ||
9 | } | 23 | } |
10 | } \ No newline at end of file | 24 | } |
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventCollection.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventCollection.xtend new file mode 100644 index 00000000..102dc57e --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventCollection.xtend | |||
@@ -0,0 +1,90 @@ | |||
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 | |||
10 | @Data | ||
11 | class EventCollection { | ||
12 | val int falseEventCount | ||
13 | val int trueEventCount | ||
14 | val Set<RandomEvent> randomEvents | ||
15 | |||
16 | def containsFalseEvent() { | ||
17 | falseEventCount >= 1 | ||
18 | } | ||
19 | |||
20 | def containsTrueEvent() { | ||
21 | trueEventCount >= 1 | ||
22 | } | ||
23 | |||
24 | def getVariableEventCount() { | ||
25 | randomEvents.size | ||
26 | } | ||
27 | |||
28 | def containsRandomEvent() { | ||
29 | variableEventCount >= 1 | ||
30 | } | ||
31 | |||
32 | def getCount() { | ||
33 | falseEventCount + trueEventCount + variableEventCount | ||
34 | } | ||
35 | |||
36 | def isEmpty() { | ||
37 | !containsFalseEvent && !containsTrueEvent && !containsRandomEvent | ||
38 | } | ||
39 | |||
40 | def containsExactlyOneRandomEvent() { | ||
41 | !containsFalseEvent && !containsTrueEvent && variableEventCount == 1 | ||
42 | } | ||
43 | |||
44 | def toSingleRandomEvent() { | ||
45 | if (!containsExactlyOneRandomEvent) { | ||
46 | throw new IllegalStateException("Input collection is not a single random event") | ||
47 | } | ||
48 | randomEvents.head | ||
49 | } | ||
50 | |||
51 | static def builder() { | ||
52 | new Builder() | ||
53 | } | ||
54 | |||
55 | static class Builder { | ||
56 | var falseEventCount = 0 | ||
57 | var trueEventCount = 0 | ||
58 | val randomEventsBuilder = ImmutableSet.<RandomEvent>builder | ||
59 | |||
60 | private new() { | ||
61 | } | ||
62 | |||
63 | def add(Event event) { | ||
64 | switch (event) { | ||
65 | ConstantEvent: | ||
66 | if (event.failed) { | ||
67 | trueEventCount++ | ||
68 | } else { | ||
69 | falseEventCount++ | ||
70 | } | ||
71 | RandomEvent: | ||
72 | randomEventsBuilder.add(event) | ||
73 | default: | ||
74 | throw new IllegalArgumentException("Unknown event: " + event) | ||
75 | } | ||
76 | this | ||
77 | } | ||
78 | |||
79 | def addAll(EventCollection materializedEvens) { | ||
80 | falseEventCount += materializedEvens.falseEventCount | ||
81 | trueEventCount += materializedEvens.trueEventCount | ||
82 | randomEventsBuilder.addAll(materializedEvens.randomEvents) | ||
83 | this | ||
84 | } | ||
85 | |||
86 | def build() { | ||
87 | new EventCollection(falseEventCount, trueEventCount, randomEventsBuilder.build) | ||
88 | } | ||
89 | } | ||
90 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventMaterializer.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventMaterializer.xtend new file mode 100644 index 00000000..85396e4d --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/EventMaterializer.xtend | |||
@@ -0,0 +1,192 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.cft2ft | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.AndGateDefinition | ||
4 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.BasicEventDefinition | ||
5 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.Component | ||
6 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.EventDeclaration | ||
7 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.GateDefinition | ||
8 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.InputEvent | ||
9 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.KOfMGateDefinition | ||
10 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.OrGateDefinition | ||
11 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.Output | ||
12 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ConstantEvent | ||
13 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Event | ||
14 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.FtFactory | ||
15 | import java.util.LinkedHashSet | ||
16 | import java.util.Map | ||
17 | import org.eclipse.emf.ecore.util.EcoreUtil | ||
18 | import org.eclipse.xtend.lib.annotations.Data | ||
19 | |||
20 | class EventMaterializer { | ||
21 | extension val FtFactory = FtFactory.eINSTANCE | ||
22 | |||
23 | val Map<EventKey<EventDeclaration>, Event> materializationCache = newHashMap | ||
24 | val Map<EventKey<InputEvent>, EventCollection> multipleInputCache = newHashMap | ||
25 | val ConstantEvent falseEvent | ||
26 | val ConstantEvent trueEvent | ||
27 | val path = new LinkedHashSet<EventKey<? extends EventDeclaration>> | ||
28 | |||
29 | new() { | ||
30 | falseEvent = createConstantEvent => [ | ||
31 | failed = false | ||
32 | ] | ||
33 | trueEvent = createConstantEvent => [ | ||
34 | failed = true | ||
35 | ] | ||
36 | } | ||
37 | |||
38 | def getOrMaterialize(Output output) { | ||
39 | getOrMaterialize(output.component, output.eventDeclaration) | ||
40 | } | ||
41 | |||
42 | def Event getOrMaterialize(Component component, EventDeclaration eventDeclaration) { | ||
43 | val eventKey = new EventKey(component, eventDeclaration) | ||
44 | pushEventKey(eventKey) | ||
45 | try { | ||
46 | materializationCache.computeIfAbsent(eventKey)[materialize(it.component, it.event)] | ||
47 | } finally { | ||
48 | popEventKey(eventKey) | ||
49 | } | ||
50 | } | ||
51 | |||
52 | protected def materialize(Component component, EventDeclaration eventDeclaration) { | ||
53 | val eventName = component.name + "_" + eventDeclaration.name | ||
54 | val event = switch (eventDeclaration) { | ||
55 | InputEvent: | ||
56 | return materializeConnectedEvent(component, eventDeclaration) | ||
57 | BasicEventDefinition: { | ||
58 | val basicEvent = createBasicEvent | ||
59 | basicEvent.distribution = EcoreUtil.copy(eventDeclaration.distribution) | ||
60 | basicEvent | ||
61 | } | ||
62 | GateDefinition: { | ||
63 | val inputs = collectInputs(component, eventDeclaration) | ||
64 | val gate = switch (eventDeclaration) { | ||
65 | AndGateDefinition: | ||
66 | if (inputs.containsFalseEvent) { | ||
67 | return falseEvent | ||
68 | } else if (inputs.empty) { | ||
69 | return trueEvent | ||
70 | } else if (inputs.containsExactlyOneRandomEvent) { | ||
71 | return inputs.toSingleRandomEvent | ||
72 | } else { | ||
73 | createAndGate | ||
74 | } | ||
75 | OrGateDefinition: | ||
76 | if (inputs.containsTrueEvent) { | ||
77 | return trueEvent | ||
78 | } else if (inputs.empty) { | ||
79 | return falseEvent | ||
80 | } else if (inputs.containsExactlyOneRandomEvent) { | ||
81 | return inputs.toSingleRandomEvent | ||
82 | } else { | ||
83 | createOrGate | ||
84 | } | ||
85 | KOfMGateDefinition: { | ||
86 | val requiredTrueInputs = inputs.count * eventDeclaration.k / eventDeclaration.m | ||
87 | val k = requiredTrueInputs - inputs.getTrueEventCount | ||
88 | val m = inputs.variableEventCount | ||
89 | if (k == 0) { | ||
90 | return trueEvent | ||
91 | } else if (k > m) { | ||
92 | return falseEvent | ||
93 | } else if (inputs.containsExactlyOneRandomEvent) { | ||
94 | return inputs.toSingleRandomEvent | ||
95 | } else if (k == 1) { | ||
96 | createOrGate | ||
97 | } else if (k == m) { | ||
98 | createAndGate | ||
99 | } else { | ||
100 | val kOfMGate = createKOfMGate | ||
101 | kOfMGate.k = k | ||
102 | kOfMGate | ||
103 | } | ||
104 | } | ||
105 | default: | ||
106 | throw new IllegalArgumentException("Unknown gate definition: " + eventDeclaration) | ||
107 | } | ||
108 | gate.inputEvents.addAll(inputs.getRandomEvents) | ||
109 | gate | ||
110 | } | ||
111 | default: | ||
112 | throw new IllegalArgumentException("Unknown event declaration: " + eventDeclaration) | ||
113 | } | ||
114 | event.name = eventName | ||
115 | event | ||
116 | } | ||
117 | |||
118 | protected def materializeConnectedEvent(Component component, InputEvent inputEvent) { | ||
119 | if (inputEvent.multiple) { | ||
120 | throw new IllegalArgumentException('''Cannot materialize multiple nput «component.name»_«inputEvent.name»''') | ||
121 | } | ||
122 | val input = findInput(component, inputEvent) | ||
123 | val incomingConnections = input.incomingConnections | ||
124 | if (incomingConnections.size != 1) { | ||
125 | throw new IllegalArgumentException('''Input «component.name»_«inputEvent.name» has «incomingConnections.size» connections instead of 1''') | ||
126 | } | ||
127 | val output = incomingConnections.head.output | ||
128 | getOrMaterialize(output.component, output.eventDeclaration) | ||
129 | } | ||
130 | |||
131 | protected def collectInputs(Component component, GateDefinition gateDefinition) { | ||
132 | val builder = EventCollection.builder | ||
133 | for (inputEventDeclaration : gateDefinition.inputEvents) { | ||
134 | switch (inputEventDeclaration) { | ||
135 | InputEvent case inputEventDeclaration.multiple: { | ||
136 | val materializedEvents = getOrMaterializeConnectedEvents(component, inputEventDeclaration) | ||
137 | builder.addAll(materializedEvents) | ||
138 | } | ||
139 | default: | ||
140 | builder.add(getOrMaterialize(component, inputEventDeclaration)) | ||
141 | } | ||
142 | } | ||
143 | builder.build | ||
144 | } | ||
145 | |||
146 | protected def getOrMaterializeConnectedEvents(Component component, InputEvent inputEvent) { | ||
147 | val inputKey = new EventKey(component, inputEvent) | ||
148 | pushEventKey(inputKey) | ||
149 | try { | ||
150 | multipleInputCache.computeIfAbsent(inputKey)[materializeConnectedEvents(it.component, it.event)] | ||
151 | } finally { | ||
152 | popEventKey(inputKey) | ||
153 | } | ||
154 | } | ||
155 | |||
156 | protected def materializeConnectedEvents(Component component, InputEvent inputEvent) { | ||
157 | val input = findInput(component, inputEvent) | ||
158 | val builder = EventCollection.builder | ||
159 | for (connection : input.incomingConnections) { | ||
160 | val materializedEvent = getOrMaterialize(connection.output) | ||
161 | builder.add(materializedEvent) | ||
162 | } | ||
163 | builder.build | ||
164 | } | ||
165 | |||
166 | protected def findInput(Component component, InputEvent inputEvent) { | ||
167 | val input = component.inputs.findFirst[it.inputEvent == inputEvent] | ||
168 | if (input === null) { | ||
169 | throw new IllegalArgumentException('''No input «inputEvent» in component «component»''') | ||
170 | } | ||
171 | return input | ||
172 | } | ||
173 | |||
174 | private def pushEventKey(EventKey<? extends EventDeclaration> eventKey) { | ||
175 | if (!path.add(eventKey)) { | ||
176 | throw new IllegalStateException( | ||
177 | '''Circular dependency [«FOR ancestor : path»«ancestor», «ENDFOR»«eventKey»] detected''') | ||
178 | } | ||
179 | } | ||
180 | |||
181 | private def popEventKey(EventKey<? extends EventDeclaration> eventKey) { | ||
182 | path.remove(eventKey) | ||
183 | } | ||
184 | |||
185 | @Data | ||
186 | protected static class EventKey<T extends EventDeclaration> { | ||
187 | val Component component | ||
188 | val T event | ||
189 | |||
190 | override toString() '''«component.name»_«event.name»''' | ||
191 | } | ||
192 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/FaultTreeBuilder.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/FaultTreeBuilder.xtend new file mode 100644 index 00000000..0b0afea6 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/cft2ft/FaultTreeBuilder.xtend | |||
@@ -0,0 +1,39 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.cft2ft | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.FtFactory | ||
4 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Gate | ||
5 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.RandomEvent | ||
6 | import java.util.Collection | ||
7 | import org.eclipse.xtend.lib.annotations.Accessors | ||
8 | |||
9 | class FaultTreeBuilder { | ||
10 | @Accessors | ||
11 | val faultTree = FtFactory.eINSTANCE.createFaultTree | ||
12 | |||
13 | def addTopLevel(RandomEvent event) { | ||
14 | if (faultTree.topEvent !== null) { | ||
15 | throw new IllegalStateException("Top event was already set") | ||
16 | } | ||
17 | add(event) | ||
18 | faultTree.topEvent = event | ||
19 | } | ||
20 | |||
21 | protected def void add(RandomEvent event) { | ||
22 | if (faultTree.eContainer == faultTree) { | ||
23 | return | ||
24 | } | ||
25 | if (faultTree.eContainer !== null) { | ||
26 | throw new IllegalStateException("Event is already in a different fault tree") | ||
27 | } | ||
28 | faultTree.events += event | ||
29 | if (event instanceof Gate) { | ||
30 | addAll(event.inputEvents) | ||
31 | } | ||
32 | } | ||
33 | |||
34 | protected def addAll(Collection<RandomEvent> events) { | ||
35 | for (event : events) { | ||
36 | add(event) | ||
37 | } | ||
38 | } | ||
39 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/Ecore2CftTransformation.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/Ecore2CftTransformation.xtend index 36aac5e1..062de3df 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/Ecore2CftTransformation.xtend +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/Ecore2CftTransformation.xtend | |||
@@ -23,5 +23,6 @@ class Ecore2CftTransformation { | |||
23 | for (handler : mappingHandlers) { | 23 | for (handler : mappingHandlers) { |
24 | handler.instantiateConnections(trace) | 24 | handler.instantiateConnections(trace) |
25 | } | 25 | } |
26 | trace.componentFaultTree | ||
26 | } | 27 | } |
27 | } | 28 | } |
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ft2galileo/Ft2GalileoTransformation.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ft2galileo/Ft2GalileoTransformation.xtend new file mode 100644 index 00000000..732d9fed --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ft2galileo/Ft2GalileoTransformation.xtend | |||
@@ -0,0 +1,56 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.ft2galileo | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.AndGate | ||
4 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.BasicEvent | ||
5 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ConstantDistribution | ||
6 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Distribution | ||
7 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ExponentialDistribution | ||
8 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.FaultTree | ||
9 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Gate | ||
10 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.KOfMGate | ||
11 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.OrGate | ||
12 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.RandomEvent | ||
13 | import org.eclipse.xtend2.lib.StringConcatenationClient | ||
14 | |||
15 | class Ft2GalileoTransformation { | ||
16 | def toGalileo(FaultTree faultTree) ''' | ||
17 | toplevel «faultTree.topEvent.name»; | ||
18 | «FOR event : faultTree.events» | ||
19 | «event.name» «defineEvent(event)»; | ||
20 | «ENDFOR» | ||
21 | ''' | ||
22 | |||
23 | protected dispatch def defineEvent(BasicEvent basicEvent) { | ||
24 | defineDistribution(basicEvent.distribution) | ||
25 | } | ||
26 | |||
27 | protected dispatch def StringConcatenationClient defineDistribution(ConstantDistribution distribution) { | ||
28 | '''p=«distribution.p»''' | ||
29 | } | ||
30 | |||
31 | protected dispatch def StringConcatenationClient defineDistribution(ExponentialDistribution distribution) { | ||
32 | '''lambda=«distribution.lambda»''' | ||
33 | } | ||
34 | |||
35 | protected dispatch def StringConcatenationClient defineDistribution(Distribution distribution) { | ||
36 | throw new IllegalArgumentException("Unknown distribution: " + distribution) | ||
37 | } | ||
38 | |||
39 | protected dispatch def StringConcatenationClient defineEvent(Gate gate) { | ||
40 | '''«defineGate(gate)» «FOR input : gate.inputEvents SEPARATOR " "»«input.name»«ENDFOR»''' | ||
41 | } | ||
42 | |||
43 | protected dispatch def StringConcatenationClient defineGate(AndGate gate) '''and''' | ||
44 | |||
45 | protected dispatch def StringConcatenationClient defineGate(OrGate gate) '''or''' | ||
46 | |||
47 | protected dispatch def StringConcatenationClient defineGate(KOfMGate gate) '''«gate.k»of«gate.inputEvents.size»''' | ||
48 | |||
49 | protected dispatch def StringConcatenationClient defineGate(Gate gate) { | ||
50 | throw new IllegalArgumentException("Unknown gate: " + gate) | ||
51 | } | ||
52 | |||
53 | protected dispatch def StringConcatenationClient defineEvent(RandomEvent randomEvent) { | ||
54 | throw new IllegalArgumentException("Unknown random even: " + randomEvent) | ||
55 | } | ||
56 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/ReliabilityResult.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/ReliabilityResult.xtend new file mode 100644 index 00000000..19c3d17d --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/ReliabilityResult.xtend | |||
@@ -0,0 +1,51 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver | ||
2 | |||
3 | import org.eclipse.xtend.lib.annotations.Data | ||
4 | import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor | ||
5 | |||
6 | abstract class ReliabilityResult { | ||
7 | public static val TIMEOUT = new Unknown("Solver timed out") | ||
8 | public static val MEMOUT = new Unknown("Solver out of memory") | ||
9 | |||
10 | abstract def Solution getOrThrow() | ||
11 | |||
12 | @Data | ||
13 | static final class Solution extends ReliabilityResult { | ||
14 | val double lowerBound | ||
15 | val double upperBound | ||
16 | |||
17 | new(double value) { | ||
18 | this(value, value) | ||
19 | } | ||
20 | |||
21 | new(double lowerBound, double upperBound) { | ||
22 | if (lowerBound > upperBound) { | ||
23 | throw new IllegalArgumentException("lowerBound must not be larger than upperBound") | ||
24 | } | ||
25 | this.lowerBound = lowerBound | ||
26 | this.upperBound = upperBound | ||
27 | } | ||
28 | |||
29 | override getOrThrow() { | ||
30 | this | ||
31 | } | ||
32 | } | ||
33 | |||
34 | @Data | ||
35 | static final class Unknown extends ReliabilityResult { | ||
36 | val String message | ||
37 | val Throwable cause | ||
38 | |||
39 | @FinalFieldsConstructor | ||
40 | new() { | ||
41 | } | ||
42 | |||
43 | new(String message) { | ||
44 | this(message, null) | ||
45 | } | ||
46 | |||
47 | override getOrThrow() { | ||
48 | throw new RuntimeException(message, cause) | ||
49 | } | ||
50 | } | ||
51 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftConfiguration.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftConfiguration.xtend new file mode 100644 index 00000000..d9059bfc --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftConfiguration.xtend | |||
@@ -0,0 +1,45 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.SolverConfiguration | ||
4 | |||
5 | final class StormDftConfiguration extends SolverConfiguration { | ||
6 | public static val DEFAULT_SOLVER_PATH = "storm-dft" | ||
7 | |||
8 | public double precision = 1e-6 | ||
9 | |||
10 | public boolean bisimulation = true | ||
11 | |||
12 | public boolean symmetryReduction = true | ||
13 | |||
14 | public boolean modularization = true | ||
15 | |||
16 | public boolean dontCarePropagation = true | ||
17 | |||
18 | public double approximation = 0 | ||
19 | |||
20 | public var approximationHeuristic = ApproximationHeuristic.NONE | ||
21 | |||
22 | public FtAnalysisObjective objective | ||
23 | |||
24 | def isApproximationInUse() { | ||
25 | approximationHeuristic != ApproximationHeuristic.NONE | ||
26 | } | ||
27 | } | ||
28 | |||
29 | abstract class FtAnalysisObjective { | ||
30 | public static val MTTF = new FtAnalysisObjective { | ||
31 | } | ||
32 | |||
33 | private new() { | ||
34 | } | ||
35 | |||
36 | static final class TimeBound extends FtAnalysisObjective { | ||
37 | public double timeBound = 0 | ||
38 | } | ||
39 | } | ||
40 | |||
41 | enum ApproximationHeuristic { | ||
42 | NONE, | ||
43 | DEPTH | ||
44 | // See https://github.com/moves-rwth/storm/issues/35 for additional approximation heuristics. | ||
45 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftHandler.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftHandler.xtend new file mode 100644 index 00000000..91c6a0d0 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftHandler.xtend | |||
@@ -0,0 +1,186 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver | ||
2 | |||
3 | import com.google.common.collect.ImmutableList | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.SolverConfiguration | ||
6 | import java.io.BufferedReader | ||
7 | import java.io.IOException | ||
8 | import java.io.InputStream | ||
9 | import java.io.InputStreamReader | ||
10 | import java.util.regex.Pattern | ||
11 | import jnr.constants.platform.Signal | ||
12 | import org.apache.commons.lang.SystemUtils | ||
13 | |||
14 | class StormDftException extends RuntimeException { | ||
15 | new(String s) { | ||
16 | super(s) | ||
17 | } | ||
18 | |||
19 | new(String s, Exception e) { | ||
20 | super(s, e) | ||
21 | } | ||
22 | } | ||
23 | |||
24 | class StormDftHandler { | ||
25 | static val DOUBLE_REGEX = "[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?" | ||
26 | static val SINGLE_RESULT_GROUP = "single" | ||
27 | static val LOWER_BOUND_GROUP = "lower" | ||
28 | static val UPPER_BOUND_GROUP = "upper" | ||
29 | static val RESULT_REGEX = '''^Result:\s*\[(?:(?<«SINGLE_RESULT_GROUP»>«DOUBLE_REGEX»)|\((?<«LOWER_BOUND_GROUP»>«DOUBLE_REGEX»),\s*(?<«UPPER_BOUND_GROUP»>«DOUBLE_REGEX»)\))\]''' | ||
30 | static val RESULT_PATTERN = Pattern.compile(RESULT_REGEX) | ||
31 | |||
32 | // See http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/jdk7-b147/src/solaris/native/java/lang/UNIXProcess_md.c#l332 | ||
33 | static val SIGNAL_EXIT_VALUE_OFFSET = if(SystemUtils.IS_OS_SOLARIS) 0 else 0x80 | ||
34 | |||
35 | static val STORM_GENERAL_ERROR = (-1).bitwiseAnd(0xff) | ||
36 | static val STORM_TIMEOUT = (-2).bitwiseAnd(0xff) | ||
37 | static val STORM_MEMOUT = (-3).bitwiseAnd(0xff) | ||
38 | |||
39 | def callSolver(String dftFilePath, StormDftConfiguration configuration) { | ||
40 | val commandLine = configuration.toCommandLine(dftFilePath) | ||
41 | val documentationLevel = configuration.documentationLevel | ||
42 | val printOutput = documentationLevel == DocumentationLevel.NORMAL || | ||
43 | documentationLevel == DocumentationLevel.FULL | ||
44 | val processBuilder = new ProcessBuilder().command(commandLine) | ||
45 | var Process process = null | ||
46 | try { | ||
47 | try { | ||
48 | process = processBuilder.start | ||
49 | process.outputStream.close | ||
50 | val result = readOutput(process.inputStream, printOutput) | ||
51 | val error = readError(process.errorStream, printOutput) | ||
52 | val exitValue = process.waitFor | ||
53 | if (result === null) { | ||
54 | interpretExitStatus(exitValue, error) | ||
55 | } else { | ||
56 | result | ||
57 | } | ||
58 | } catch (IOException e) { | ||
59 | throw new StormDftException("Error during input/output handling of the stochastic solver.", e) | ||
60 | } | ||
61 | } catch (Exception e) { | ||
62 | if (process !== null) { | ||
63 | process.destroyForcibly.waitFor | ||
64 | } | ||
65 | throw e | ||
66 | } | ||
67 | } | ||
68 | |||
69 | private def toCommandLine(extension StormDftConfiguration configuration, String dftFilePath) { | ||
70 | extension val optionsBuilder = ImmutableList.builder | ||
71 | add(solverPath ?: StormDftConfiguration.DEFAULT_SOLVER_PATH) | ||
72 | if (runtimeLimit != SolverConfiguration.Unlimited) { | ||
73 | add("--timeout", runtimeLimit.toString) | ||
74 | } | ||
75 | add("--precision", precision.toString) | ||
76 | if (bisimulation) { | ||
77 | add("--bisimulation") | ||
78 | } | ||
79 | if (symmetryReduction) { | ||
80 | add("--symmetryreduction") | ||
81 | } | ||
82 | if (modularization) { | ||
83 | add("--modularisation") | ||
84 | } | ||
85 | if (!dontCarePropagation) { | ||
86 | add("--disabledc") | ||
87 | } | ||
88 | if (approximationInUse) { | ||
89 | val heuristicName = switch (approximationHeuristic) { | ||
90 | case DEPTH: | ||
91 | "depth" | ||
92 | default: | ||
93 | throw new IllegalArgumentException("Unknown approximation heuristic: " + approximationHeuristic) | ||
94 | } | ||
95 | add("--approximation", approximation.toString, "--approximationheuristic", heuristicName) | ||
96 | } | ||
97 | add("--dftfile", dftFilePath) | ||
98 | switch (objective) { | ||
99 | case FtAnalysisObjective.MTTF: | ||
100 | add("--expectedtime") | ||
101 | FtAnalysisObjective.TimeBound: | ||
102 | add("--timebound") | ||
103 | default: | ||
104 | throw new IllegalArgumentException("Unknown analysis objective: " + objective) | ||
105 | } | ||
106 | if (documentationLevel == DocumentationLevel.FULL) { | ||
107 | add("--verbose") | ||
108 | } | ||
109 | build | ||
110 | } | ||
111 | |||
112 | private def readOutput(InputStream inputStream, boolean printOutput) { | ||
113 | val bufferedReader = new BufferedReader(new InputStreamReader(inputStream)) | ||
114 | try { | ||
115 | var String line | ||
116 | while ((line = bufferedReader.readLine) !== null) { | ||
117 | if (printOutput) { | ||
118 | println(line) | ||
119 | } | ||
120 | val matcher = RESULT_PATTERN.matcher(line) | ||
121 | if (matcher.find) { | ||
122 | try { | ||
123 | val single = matcher.group(SINGLE_RESULT_GROUP) | ||
124 | if (single !== null) { | ||
125 | val singleValue = Double.parseDouble(single) | ||
126 | return new ReliabilityResult.Solution(singleValue) | ||
127 | } | ||
128 | val lower = matcher.group(LOWER_BOUND_GROUP) | ||
129 | val upper = matcher.group(UPPER_BOUND_GROUP) | ||
130 | if (lower !== null && upper !== null) { | ||
131 | val lowerValue = Double.parseDouble(lower) | ||
132 | val upperValue = Double.parseDouble(upper) | ||
133 | return new ReliabilityResult.Solution(lowerValue, upperValue) | ||
134 | } | ||
135 | throw new StormDftException("Inconsistent stochastic solver output: " + line) | ||
136 | } catch (NumberFormatException e) { | ||
137 | throw new StormDftException("Malformatted number from stochastic solver.", e) | ||
138 | } | ||
139 | } | ||
140 | } | ||
141 | } finally { | ||
142 | bufferedReader.close | ||
143 | } | ||
144 | null | ||
145 | } | ||
146 | |||
147 | private def readError(InputStream inputStream, boolean printOutput) { | ||
148 | val bufferedReader = new BufferedReader(new InputStreamReader(inputStream)) | ||
149 | try { | ||
150 | val lines = newArrayList | ||
151 | var String line | ||
152 | while ((line = bufferedReader.readLine) !== null) { | ||
153 | if (printOutput) { | ||
154 | System.err.println(line) | ||
155 | } | ||
156 | lines += line | ||
157 | } | ||
158 | lines.join("\n") | ||
159 | } finally { | ||
160 | bufferedReader.close | ||
161 | } | ||
162 | } | ||
163 | |||
164 | private def interpretExitStatus(int exitValue, String error) { | ||
165 | switch (exitValue) { | ||
166 | case STORM_GENERAL_ERROR: | ||
167 | throw new StormDftException("Storm error: " + error) | ||
168 | case STORM_TIMEOUT, | ||
169 | case SIGNAL_EXIT_VALUE_OFFSET + Signal.SIGXCPU.intValue: | ||
170 | ReliabilityResult.TIMEOUT | ||
171 | case STORM_MEMOUT, | ||
172 | case SIGNAL_EXIT_VALUE_OFFSET + Signal.SIGXFSZ.intValue: | ||
173 | ReliabilityResult.MEMOUT | ||
174 | default: { | ||
175 | if (exitValue > SIGNAL_EXIT_VALUE_OFFSET) { | ||
176 | val signalNumber = exitValue - SIGNAL_EXIT_VALUE_OFFSET | ||
177 | val signal = Signal.values.findFirst[intValue == signalNumber] | ||
178 | if (signal !== null) { | ||
179 | throw new StormDftException("Storm unexpectedly killed by signal " + signal + ": " + error) | ||
180 | } | ||
181 | } | ||
182 | throw new StormDftException("Storm unexpectedly exit with status " + exitValue + ": " + error) | ||
183 | } | ||
184 | } | ||
185 | } | ||
186 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftSolver.xtend b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftSolver.xtend new file mode 100644 index 00000000..931b9f39 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftSolver.xtend | |||
@@ -0,0 +1,43 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ConstantModel | ||
4 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.FaultTree | ||
5 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ReliabilityModel | ||
6 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.ft2galileo.Ft2GalileoTransformation | ||
7 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace | ||
8 | |||
9 | class StormDftSolver { | ||
10 | static val DFT_FILE_NAME = "ft.dft" | ||
11 | |||
12 | val ft2Galileo = new Ft2GalileoTransformation | ||
13 | val handler = new StormDftHandler | ||
14 | |||
15 | def solve(ReliabilityModel reliabilityModel, StormDftConfiguration configuration, | ||
16 | ReasonerWorkspace reasonerWorkspace) { | ||
17 | switch (reliabilityModel) { | ||
18 | FaultTree: | ||
19 | solve(reliabilityModel, configuration, reasonerWorkspace) | ||
20 | ConstantModel: { | ||
21 | val result = if (reliabilityModel.failed) { | ||
22 | 0 | ||
23 | } else { | ||
24 | switch (objective : configuration.objective) { | ||
25 | case FtAnalysisObjective.MTTF: Double.POSITIVE_INFINITY | ||
26 | FtAnalysisObjective.TimeBound: 1 | ||
27 | default: throw new IllegalArgumentException("Unknown objective: " + objective) | ||
28 | } | ||
29 | } | ||
30 | new ReliabilityResult.Solution(result) | ||
31 | } | ||
32 | default: | ||
33 | throw new IllegalArgumentException("Unknown reliability model: " + reliabilityModel) | ||
34 | } | ||
35 | } | ||
36 | |||
37 | def solve(FaultTree faultTree, StormDftConfiguration configuration, ReasonerWorkspace reasonerWorkspace) { | ||
38 | val galileo = ft2Galileo.toGalileo(faultTree) | ||
39 | reasonerWorkspace.writeText(DFT_FILE_NAME, galileo) | ||
40 | val dftFilePath = reasonerWorkspace.getFile(DFT_FILE_NAME).absolutePath | ||
41 | handler.callSolver(dftFilePath, configuration) | ||
42 | } | ||
43 | } | ||
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 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.ComponentFaultTreeTrace.xtendbin b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.ComponentFaultTreeTrace.xtendbin index d26ae359..f705fefe 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.ComponentFaultTreeTrace.xtendbin +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.ComponentFaultTreeTrace.xtendbin | |||
Binary files differ | |||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.ComponentInstanceTrace.xtendbin b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.ComponentInstanceTrace.xtendbin index 03d6064f..bab76345 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.ComponentInstanceTrace.xtendbin +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.ComponentInstanceTrace.xtendbin | |||
Binary files differ | |||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.ComponentNameGenerator.xtendbin b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.ComponentNameGenerator.xtendbin index 1f6758ac..257bfc56 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.ComponentNameGenerator.xtendbin +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.ComponentNameGenerator.xtendbin | |||
Binary files differ | |||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.Ecore2CftTransformation.xtendbin b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.Ecore2CftTransformation.xtendbin index 3569c02f..a1339a18 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.Ecore2CftTransformation.xtendbin +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.Ecore2CftTransformation.xtendbin | |||
Binary files differ | |||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.InputTrace.xtendbin b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.InputTrace.xtendbin index 378550ba..ba19d0fb 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.InputTrace.xtendbin +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.InputTrace.xtendbin | |||
Binary files differ | |||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.LookupHandler.xtendbin b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.LookupHandler.xtendbin index 0b0e534a..1e8612b2 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.LookupHandler.xtendbin +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.LookupHandler.xtendbin | |||
Binary files differ | |||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.MappingHandler.xtendbin b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.MappingHandler.xtendbin index 5e26d4e4..ebe80f2e 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.MappingHandler.xtendbin +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.MappingHandler.xtendbin | |||
Binary files differ | |||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.MappingQueries.xtendbin b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.MappingQueries.xtendbin index 8fb7f13f..03bd16f8 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.MappingQueries.xtendbin +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/.MappingQueries.xtendbin | |||
Binary files differ | |||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/Ecore2CftTransformation.java b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/Ecore2CftTransformation.java index 8b2d9d97..a63c8e78 100644 --- a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/Ecore2CftTransformation.java +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ecore2cft/Ecore2CftTransformation.java | |||
@@ -3,6 +3,7 @@ package hu.bme.mit.inf.dslreasoner.faulttree.transformation.ecore2cft; | |||
3 | import com.google.common.collect.ImmutableList; | 3 | import com.google.common.collect.ImmutableList; |
4 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.MappingDefinition; | 4 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.MappingDefinition; |
5 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.TransformationDefinition; | 5 | import hu.bme.mit.inf.dslreasoner.faulttree.components.cftLanguage.TransformationDefinition; |
6 | import hu.bme.mit.inf.dslreasoner.faulttree.model.cft.ComponentFaultTree; | ||
6 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.ecore2cft.ComponentFaultTreeTrace; | 7 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.ecore2cft.ComponentFaultTreeTrace; |
7 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.ecore2cft.MappingHandler; | 8 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.ecore2cft.MappingHandler; |
8 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.ecore2cft.MappingQueries; | 9 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.ecore2cft.MappingQueries; |
@@ -23,13 +24,18 @@ public class Ecore2CftTransformation { | |||
23 | this.mappingHandlers = ImmutableList.<MappingHandler>copyOf(ListExtensions.<MappingDefinition, MappingHandler>map(transformationDefinition.getMappingDefinitions(), _function)); | 24 | this.mappingHandlers = ImmutableList.<MappingHandler>copyOf(ListExtensions.<MappingDefinition, MappingHandler>map(transformationDefinition.getMappingDefinitions(), _function)); |
24 | } | 25 | } |
25 | 26 | ||
26 | public void createComponentFaultTree() { | 27 | public ComponentFaultTree createComponentFaultTree() { |
27 | final ComponentFaultTreeTrace trace = new ComponentFaultTreeTrace(); | 28 | ComponentFaultTree _xblockexpression = null; |
28 | for (final MappingHandler handler : this.mappingHandlers) { | 29 | { |
29 | handler.instantiateComponents(trace); | 30 | final ComponentFaultTreeTrace trace = new ComponentFaultTreeTrace(); |
30 | } | 31 | for (final MappingHandler handler : this.mappingHandlers) { |
31 | for (final MappingHandler handler_1 : this.mappingHandlers) { | 32 | handler.instantiateComponents(trace); |
32 | handler_1.instantiateConnections(trace); | 33 | } |
34 | for (final MappingHandler handler_1 : this.mappingHandlers) { | ||
35 | handler_1.instantiateConnections(trace); | ||
36 | } | ||
37 | _xblockexpression = trace.getComponentFaultTree(); | ||
33 | } | 38 | } |
39 | return _xblockexpression; | ||
34 | } | 40 | } |
35 | } | 41 | } |
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ft2galileo/.Ft2GalileoTransformation.xtendbin b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ft2galileo/.Ft2GalileoTransformation.xtendbin new file mode 100644 index 00000000..9fe75a0f --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ft2galileo/.Ft2GalileoTransformation.xtendbin | |||
Binary files differ | |||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ft2galileo/.gitignore b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ft2galileo/.gitignore new file mode 100644 index 00000000..3f932890 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ft2galileo/.gitignore | |||
@@ -0,0 +1 @@ | |||
/.Ft2GalileoTransformation.java._trace | |||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ft2galileo/Ft2GalileoTransformation.java b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ft2galileo/Ft2GalileoTransformation.java new file mode 100644 index 00000000..e900c62a --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/ft2galileo/Ft2GalileoTransformation.java | |||
@@ -0,0 +1,181 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.ft2galileo; | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.AndGate; | ||
4 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.BasicEvent; | ||
5 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ConstantDistribution; | ||
6 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Distribution; | ||
7 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ExponentialDistribution; | ||
8 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.FaultTree; | ||
9 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.Gate; | ||
10 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.KOfMGate; | ||
11 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.OrGate; | ||
12 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.RandomEvent; | ||
13 | import java.util.Arrays; | ||
14 | import org.eclipse.emf.common.util.EList; | ||
15 | import org.eclipse.xtend2.lib.StringConcatenation; | ||
16 | import org.eclipse.xtend2.lib.StringConcatenationClient; | ||
17 | |||
18 | @SuppressWarnings("all") | ||
19 | public class Ft2GalileoTransformation { | ||
20 | public CharSequence toGalileo(final FaultTree faultTree) { | ||
21 | StringConcatenation _builder = new StringConcatenation(); | ||
22 | _builder.append("toplevel "); | ||
23 | String _name = faultTree.getTopEvent().getName(); | ||
24 | _builder.append(_name); | ||
25 | _builder.append(";"); | ||
26 | _builder.newLineIfNotEmpty(); | ||
27 | { | ||
28 | EList<RandomEvent> _events = faultTree.getEvents(); | ||
29 | for(final RandomEvent event : _events) { | ||
30 | String _name_1 = event.getName(); | ||
31 | _builder.append(_name_1); | ||
32 | _builder.append(" "); | ||
33 | StringConcatenationClient _defineEvent = this.defineEvent(event); | ||
34 | _builder.append(_defineEvent); | ||
35 | _builder.append(";"); | ||
36 | _builder.newLineIfNotEmpty(); | ||
37 | } | ||
38 | } | ||
39 | return _builder; | ||
40 | } | ||
41 | |||
42 | protected StringConcatenationClient _defineEvent(final BasicEvent basicEvent) { | ||
43 | return this.defineDistribution(basicEvent.getDistribution()); | ||
44 | } | ||
45 | |||
46 | protected StringConcatenationClient _defineDistribution(final ConstantDistribution distribution) { | ||
47 | StringConcatenationClient _client = new StringConcatenationClient() { | ||
48 | @Override | ||
49 | protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { | ||
50 | _builder.append("p="); | ||
51 | double _p = distribution.getP(); | ||
52 | _builder.append(_p); | ||
53 | } | ||
54 | }; | ||
55 | return _client; | ||
56 | } | ||
57 | |||
58 | protected StringConcatenationClient _defineDistribution(final ExponentialDistribution distribution) { | ||
59 | StringConcatenationClient _client = new StringConcatenationClient() { | ||
60 | @Override | ||
61 | protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { | ||
62 | _builder.append("lambda="); | ||
63 | double _lambda = distribution.getLambda(); | ||
64 | _builder.append(_lambda); | ||
65 | } | ||
66 | }; | ||
67 | return _client; | ||
68 | } | ||
69 | |||
70 | protected StringConcatenationClient _defineDistribution(final Distribution distribution) { | ||
71 | throw new IllegalArgumentException(("Unknown distribution: " + distribution)); | ||
72 | } | ||
73 | |||
74 | protected StringConcatenationClient _defineEvent(final Gate gate) { | ||
75 | StringConcatenationClient _client = new StringConcatenationClient() { | ||
76 | @Override | ||
77 | protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { | ||
78 | StringConcatenationClient _defineGate = Ft2GalileoTransformation.this.defineGate(gate); | ||
79 | _builder.append(_defineGate); | ||
80 | _builder.append(" "); | ||
81 | { | ||
82 | EList<RandomEvent> _inputEvents = gate.getInputEvents(); | ||
83 | boolean _hasElements = false; | ||
84 | for(final RandomEvent input : _inputEvents) { | ||
85 | if (!_hasElements) { | ||
86 | _hasElements = true; | ||
87 | } else { | ||
88 | _builder.appendImmediate(" ", ""); | ||
89 | } | ||
90 | String _name = input.getName(); | ||
91 | _builder.append(_name); | ||
92 | } | ||
93 | } | ||
94 | } | ||
95 | }; | ||
96 | return _client; | ||
97 | } | ||
98 | |||
99 | protected StringConcatenationClient _defineGate(final AndGate gate) { | ||
100 | StringConcatenationClient _client = new StringConcatenationClient() { | ||
101 | @Override | ||
102 | protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { | ||
103 | _builder.append("and"); | ||
104 | } | ||
105 | }; | ||
106 | return _client; | ||
107 | } | ||
108 | |||
109 | protected StringConcatenationClient _defineGate(final OrGate gate) { | ||
110 | StringConcatenationClient _client = new StringConcatenationClient() { | ||
111 | @Override | ||
112 | protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { | ||
113 | _builder.append("or"); | ||
114 | } | ||
115 | }; | ||
116 | return _client; | ||
117 | } | ||
118 | |||
119 | protected StringConcatenationClient _defineGate(final KOfMGate gate) { | ||
120 | StringConcatenationClient _client = new StringConcatenationClient() { | ||
121 | @Override | ||
122 | protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { | ||
123 | int _k = gate.getK(); | ||
124 | _builder.append(_k); | ||
125 | _builder.append("of"); | ||
126 | int _size = gate.getInputEvents().size(); | ||
127 | _builder.append(_size); | ||
128 | } | ||
129 | }; | ||
130 | return _client; | ||
131 | } | ||
132 | |||
133 | protected StringConcatenationClient _defineGate(final Gate gate) { | ||
134 | throw new IllegalArgumentException(("Unknown gate: " + gate)); | ||
135 | } | ||
136 | |||
137 | protected StringConcatenationClient _defineEvent(final RandomEvent randomEvent) { | ||
138 | throw new IllegalArgumentException(("Unknown random even: " + randomEvent)); | ||
139 | } | ||
140 | |||
141 | protected StringConcatenationClient defineEvent(final RandomEvent basicEvent) { | ||
142 | if (basicEvent instanceof BasicEvent) { | ||
143 | return _defineEvent((BasicEvent)basicEvent); | ||
144 | } else if (basicEvent instanceof Gate) { | ||
145 | return _defineEvent((Gate)basicEvent); | ||
146 | } else if (basicEvent != null) { | ||
147 | return _defineEvent(basicEvent); | ||
148 | } else { | ||
149 | throw new IllegalArgumentException("Unhandled parameter types: " + | ||
150 | Arrays.<Object>asList(basicEvent).toString()); | ||
151 | } | ||
152 | } | ||
153 | |||
154 | protected StringConcatenationClient defineDistribution(final Distribution distribution) { | ||
155 | if (distribution instanceof ConstantDistribution) { | ||
156 | return _defineDistribution((ConstantDistribution)distribution); | ||
157 | } else if (distribution instanceof ExponentialDistribution) { | ||
158 | return _defineDistribution((ExponentialDistribution)distribution); | ||
159 | } else if (distribution != null) { | ||
160 | return _defineDistribution(distribution); | ||
161 | } else { | ||
162 | throw new IllegalArgumentException("Unhandled parameter types: " + | ||
163 | Arrays.<Object>asList(distribution).toString()); | ||
164 | } | ||
165 | } | ||
166 | |||
167 | protected StringConcatenationClient defineGate(final Gate gate) { | ||
168 | if (gate instanceof AndGate) { | ||
169 | return _defineGate((AndGate)gate); | ||
170 | } else if (gate instanceof KOfMGate) { | ||
171 | return _defineGate((KOfMGate)gate); | ||
172 | } else if (gate instanceof OrGate) { | ||
173 | return _defineGate((OrGate)gate); | ||
174 | } else if (gate != null) { | ||
175 | return _defineGate(gate); | ||
176 | } else { | ||
177 | throw new IllegalArgumentException("Unhandled parameter types: " + | ||
178 | Arrays.<Object>asList(gate).toString()); | ||
179 | } | ||
180 | } | ||
181 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/.ReliabilityResult.xtendbin b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/.ReliabilityResult.xtendbin new file mode 100644 index 00000000..57c4608d --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/.ReliabilityResult.xtendbin | |||
Binary files differ | |||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/.StormDftConfiguration.xtendbin b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/.StormDftConfiguration.xtendbin new file mode 100644 index 00000000..f5cb52f4 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/.StormDftConfiguration.xtendbin | |||
Binary files differ | |||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/.StormDftHandler.xtendbin b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/.StormDftHandler.xtendbin new file mode 100644 index 00000000..5dad0728 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/.StormDftHandler.xtendbin | |||
Binary files differ | |||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/.StormDftSolver.xtendbin b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/.StormDftSolver.xtendbin new file mode 100644 index 00000000..abd8a501 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/.StormDftSolver.xtendbin | |||
Binary files differ | |||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/.gitignore b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/.gitignore new file mode 100644 index 00000000..59cc8fe8 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/.gitignore | |||
@@ -0,0 +1,9 @@ | |||
1 | /.StormDftSolver.java._trace | ||
2 | /.StormDftConfiguration.java._trace | ||
3 | /.StormDftMttfConfiguration.java._trace | ||
4 | /.FtAnalysisObjective.java._trace | ||
5 | /.ApproximationHeuristic.java._trace | ||
6 | /.StormDftHandler.java._trace | ||
7 | /.StormDftException.java._trace | ||
8 | /.ReliabilityModelSolution.java._trace | ||
9 | /.ReliabilityResult.java._trace | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/ApproximationHeuristic.java b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/ApproximationHeuristic.java new file mode 100644 index 00000000..822d4f36 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/ApproximationHeuristic.java | |||
@@ -0,0 +1,8 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver; | ||
2 | |||
3 | @SuppressWarnings("all") | ||
4 | public enum ApproximationHeuristic { | ||
5 | NONE, | ||
6 | |||
7 | DEPTH; | ||
8 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/FtAnalysisObjective.java b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/FtAnalysisObjective.java new file mode 100644 index 00000000..528ada42 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/FtAnalysisObjective.java | |||
@@ -0,0 +1,14 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver; | ||
2 | |||
3 | @SuppressWarnings("all") | ||
4 | public abstract class FtAnalysisObjective { | ||
5 | public static final class TimeBound extends FtAnalysisObjective { | ||
6 | public double timeBound = 0; | ||
7 | } | ||
8 | |||
9 | public static final FtAnalysisObjective MTTF = new FtAnalysisObjective() { | ||
10 | }; | ||
11 | |||
12 | private FtAnalysisObjective() { | ||
13 | } | ||
14 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/ReliabilityResult.java b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/ReliabilityResult.java new file mode 100644 index 00000000..c8c8b000 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/ReliabilityResult.java | |||
@@ -0,0 +1,156 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver; | ||
2 | |||
3 | import org.eclipse.xtend.lib.annotations.Data; | ||
4 | import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor; | ||
5 | import org.eclipse.xtext.xbase.lib.Pure; | ||
6 | import org.eclipse.xtext.xbase.lib.util.ToStringBuilder; | ||
7 | |||
8 | @SuppressWarnings("all") | ||
9 | public abstract class ReliabilityResult { | ||
10 | @Data | ||
11 | public static final class Solution extends ReliabilityResult { | ||
12 | private final double lowerBound; | ||
13 | |||
14 | private final double upperBound; | ||
15 | |||
16 | public Solution(final double value) { | ||
17 | this(value, value); | ||
18 | } | ||
19 | |||
20 | public Solution(final double lowerBound, final double upperBound) { | ||
21 | if ((lowerBound > upperBound)) { | ||
22 | throw new IllegalArgumentException("lowerBound must not be larger than upperBound"); | ||
23 | } | ||
24 | this.lowerBound = lowerBound; | ||
25 | this.upperBound = upperBound; | ||
26 | } | ||
27 | |||
28 | @Override | ||
29 | public ReliabilityResult.Solution getOrThrow() { | ||
30 | return this; | ||
31 | } | ||
32 | |||
33 | @Override | ||
34 | @Pure | ||
35 | public int hashCode() { | ||
36 | final int prime = 31; | ||
37 | int result = 1; | ||
38 | result = prime * result + (int) (Double.doubleToLongBits(this.lowerBound) ^ (Double.doubleToLongBits(this.lowerBound) >>> 32)); | ||
39 | return prime * result + (int) (Double.doubleToLongBits(this.upperBound) ^ (Double.doubleToLongBits(this.upperBound) >>> 32)); | ||
40 | } | ||
41 | |||
42 | @Override | ||
43 | @Pure | ||
44 | public boolean equals(final Object obj) { | ||
45 | if (this == obj) | ||
46 | return true; | ||
47 | if (obj == null) | ||
48 | return false; | ||
49 | if (getClass() != obj.getClass()) | ||
50 | return false; | ||
51 | ReliabilityResult.Solution other = (ReliabilityResult.Solution) obj; | ||
52 | if (Double.doubleToLongBits(other.lowerBound) != Double.doubleToLongBits(this.lowerBound)) | ||
53 | return false; | ||
54 | if (Double.doubleToLongBits(other.upperBound) != Double.doubleToLongBits(this.upperBound)) | ||
55 | return false; | ||
56 | return true; | ||
57 | } | ||
58 | |||
59 | @Override | ||
60 | @Pure | ||
61 | public String toString() { | ||
62 | return new ToStringBuilder(this) | ||
63 | .addAllFields() | ||
64 | .toString(); | ||
65 | } | ||
66 | |||
67 | @Pure | ||
68 | public double getLowerBound() { | ||
69 | return this.lowerBound; | ||
70 | } | ||
71 | |||
72 | @Pure | ||
73 | public double getUpperBound() { | ||
74 | return this.upperBound; | ||
75 | } | ||
76 | } | ||
77 | |||
78 | @Data | ||
79 | public static final class Unknown extends ReliabilityResult { | ||
80 | private final String message; | ||
81 | |||
82 | private final Throwable cause; | ||
83 | |||
84 | @FinalFieldsConstructor | ||
85 | public Unknown(final String message, final Throwable cause) { | ||
86 | super(); | ||
87 | this.message = message; | ||
88 | this.cause = cause; | ||
89 | } | ||
90 | |||
91 | public Unknown(final String message) { | ||
92 | this(message, null); | ||
93 | } | ||
94 | |||
95 | @Override | ||
96 | public ReliabilityResult.Solution getOrThrow() { | ||
97 | throw new RuntimeException(this.message, this.cause); | ||
98 | } | ||
99 | |||
100 | @Override | ||
101 | @Pure | ||
102 | public int hashCode() { | ||
103 | final int prime = 31; | ||
104 | int result = 1; | ||
105 | result = prime * result + ((this.message== null) ? 0 : this.message.hashCode()); | ||
106 | return prime * result + ((this.cause== null) ? 0 : this.cause.hashCode()); | ||
107 | } | ||
108 | |||
109 | @Override | ||
110 | @Pure | ||
111 | public boolean equals(final Object obj) { | ||
112 | if (this == obj) | ||
113 | return true; | ||
114 | if (obj == null) | ||
115 | return false; | ||
116 | if (getClass() != obj.getClass()) | ||
117 | return false; | ||
118 | ReliabilityResult.Unknown other = (ReliabilityResult.Unknown) obj; | ||
119 | if (this.message == null) { | ||
120 | if (other.message != null) | ||
121 | return false; | ||
122 | } else if (!this.message.equals(other.message)) | ||
123 | return false; | ||
124 | if (this.cause == null) { | ||
125 | if (other.cause != null) | ||
126 | return false; | ||
127 | } else if (!this.cause.equals(other.cause)) | ||
128 | return false; | ||
129 | return true; | ||
130 | } | ||
131 | |||
132 | @Override | ||
133 | @Pure | ||
134 | public String toString() { | ||
135 | return new ToStringBuilder(this) | ||
136 | .addAllFields() | ||
137 | .toString(); | ||
138 | } | ||
139 | |||
140 | @Pure | ||
141 | public String getMessage() { | ||
142 | return this.message; | ||
143 | } | ||
144 | |||
145 | @Pure | ||
146 | public Throwable getCause() { | ||
147 | return this.cause; | ||
148 | } | ||
149 | } | ||
150 | |||
151 | public static final ReliabilityResult.Unknown TIMEOUT = new ReliabilityResult.Unknown("Solver timed out"); | ||
152 | |||
153 | public static final ReliabilityResult.Unknown MEMOUT = new ReliabilityResult.Unknown("Solver out of memory"); | ||
154 | |||
155 | public abstract ReliabilityResult.Solution getOrThrow(); | ||
156 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftConfiguration.java b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftConfiguration.java new file mode 100644 index 00000000..e1bb3625 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftConfiguration.java | |||
@@ -0,0 +1,31 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver; | ||
2 | |||
3 | import com.google.common.base.Objects; | ||
4 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver.ApproximationHeuristic; | ||
5 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver.FtAnalysisObjective; | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.SolverConfiguration; | ||
7 | |||
8 | @SuppressWarnings("all") | ||
9 | public final class StormDftConfiguration extends SolverConfiguration { | ||
10 | public static final String DEFAULT_SOLVER_PATH = "storm-dft"; | ||
11 | |||
12 | public double precision = 1e-6; | ||
13 | |||
14 | public boolean bisimulation = true; | ||
15 | |||
16 | public boolean symmetryReduction = true; | ||
17 | |||
18 | public boolean modularization = true; | ||
19 | |||
20 | public boolean dontCarePropagation = true; | ||
21 | |||
22 | public double approximation = 0; | ||
23 | |||
24 | public ApproximationHeuristic approximationHeuristic = ApproximationHeuristic.NONE; | ||
25 | |||
26 | public FtAnalysisObjective objective; | ||
27 | |||
28 | public boolean isApproximationInUse() { | ||
29 | return (!Objects.equal(this.approximationHeuristic, ApproximationHeuristic.NONE)); | ||
30 | } | ||
31 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftException.java b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftException.java new file mode 100644 index 00000000..955c9ed1 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftException.java | |||
@@ -0,0 +1,12 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver; | ||
2 | |||
3 | @SuppressWarnings("all") | ||
4 | public class StormDftException extends RuntimeException { | ||
5 | public StormDftException(final String s) { | ||
6 | super(s); | ||
7 | } | ||
8 | |||
9 | public StormDftException(final String s, final Exception e) { | ||
10 | super(s, e); | ||
11 | } | ||
12 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftHandler.java b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftHandler.java new file mode 100644 index 00000000..003d9cc5 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftHandler.java | |||
@@ -0,0 +1,351 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver; | ||
2 | |||
3 | import com.google.common.base.Objects; | ||
4 | import com.google.common.collect.ImmutableList; | ||
5 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver.ApproximationHeuristic; | ||
6 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver.FtAnalysisObjective; | ||
7 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver.ReliabilityResult; | ||
8 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver.StormDftConfiguration; | ||
9 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver.StormDftException; | ||
10 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.DocumentationLevel; | ||
11 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.SolverConfiguration; | ||
12 | import java.io.BufferedReader; | ||
13 | import java.io.IOException; | ||
14 | import java.io.InputStream; | ||
15 | import java.io.InputStreamReader; | ||
16 | import java.util.ArrayList; | ||
17 | import java.util.regex.Matcher; | ||
18 | import java.util.regex.Pattern; | ||
19 | import jnr.constants.platform.Signal; | ||
20 | import org.apache.commons.lang.SystemUtils; | ||
21 | import org.eclipse.xtend2.lib.StringConcatenation; | ||
22 | import org.eclipse.xtext.xbase.lib.CollectionLiterals; | ||
23 | import org.eclipse.xtext.xbase.lib.Conversions; | ||
24 | import org.eclipse.xtext.xbase.lib.Exceptions; | ||
25 | import org.eclipse.xtext.xbase.lib.Extension; | ||
26 | import org.eclipse.xtext.xbase.lib.Functions.Function0; | ||
27 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
28 | import org.eclipse.xtext.xbase.lib.InputOutput; | ||
29 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
30 | |||
31 | @SuppressWarnings("all") | ||
32 | public class StormDftHandler { | ||
33 | private static final String DOUBLE_REGEX = "[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?"; | ||
34 | |||
35 | private static final String SINGLE_RESULT_GROUP = "single"; | ||
36 | |||
37 | private static final String LOWER_BOUND_GROUP = "lower"; | ||
38 | |||
39 | private static final String UPPER_BOUND_GROUP = "upper"; | ||
40 | |||
41 | private static final String RESULT_REGEX = new Function0<String>() { | ||
42 | public String apply() { | ||
43 | StringConcatenation _builder = new StringConcatenation(); | ||
44 | _builder.append("^Result:\\s*\\[(?:(?<"); | ||
45 | _builder.append(StormDftHandler.SINGLE_RESULT_GROUP); | ||
46 | _builder.append(">"); | ||
47 | _builder.append(StormDftHandler.DOUBLE_REGEX); | ||
48 | _builder.append(")|\\((?<"); | ||
49 | _builder.append(StormDftHandler.LOWER_BOUND_GROUP); | ||
50 | _builder.append(">"); | ||
51 | _builder.append(StormDftHandler.DOUBLE_REGEX); | ||
52 | _builder.append("),\\s*(?<"); | ||
53 | _builder.append(StormDftHandler.UPPER_BOUND_GROUP); | ||
54 | _builder.append(">"); | ||
55 | _builder.append(StormDftHandler.DOUBLE_REGEX); | ||
56 | _builder.append(")\\))\\]"); | ||
57 | return _builder.toString(); | ||
58 | } | ||
59 | }.apply(); | ||
60 | |||
61 | private static final Pattern RESULT_PATTERN = Pattern.compile(StormDftHandler.RESULT_REGEX); | ||
62 | |||
63 | private static final int SIGNAL_EXIT_VALUE_OFFSET = new Function0<Integer>() { | ||
64 | public Integer apply() { | ||
65 | int _xifexpression = (int) 0; | ||
66 | if (SystemUtils.IS_OS_SOLARIS) { | ||
67 | _xifexpression = 0; | ||
68 | } else { | ||
69 | _xifexpression = 0x80; | ||
70 | } | ||
71 | return _xifexpression; | ||
72 | } | ||
73 | }.apply().intValue(); | ||
74 | |||
75 | private static final int STORM_GENERAL_ERROR = ((-1) & 0xff); | ||
76 | |||
77 | private static final int STORM_TIMEOUT = ((-2) & 0xff); | ||
78 | |||
79 | private static final int STORM_MEMOUT = ((-3) & 0xff); | ||
80 | |||
81 | public ReliabilityResult callSolver(final String dftFilePath, final StormDftConfiguration configuration) { | ||
82 | try { | ||
83 | ReliabilityResult _xblockexpression = null; | ||
84 | { | ||
85 | final ImmutableList<String> commandLine = this.toCommandLine(configuration, dftFilePath); | ||
86 | final DocumentationLevel documentationLevel = configuration.documentationLevel; | ||
87 | final boolean printOutput = (Objects.equal(documentationLevel, DocumentationLevel.NORMAL) || | ||
88 | Objects.equal(documentationLevel, DocumentationLevel.FULL)); | ||
89 | final ProcessBuilder processBuilder = new ProcessBuilder().command(commandLine); | ||
90 | Process process = null; | ||
91 | ReliabilityResult _xtrycatchfinallyexpression = null; | ||
92 | try { | ||
93 | ReliabilityResult _xtrycatchfinallyexpression_1 = null; | ||
94 | try { | ||
95 | ReliabilityResult _xblockexpression_1 = null; | ||
96 | { | ||
97 | process = processBuilder.start(); | ||
98 | process.getOutputStream().close(); | ||
99 | final ReliabilityResult.Solution result = this.readOutput(process.getInputStream(), printOutput); | ||
100 | final String error = this.readError(process.getErrorStream(), printOutput); | ||
101 | final int exitValue = process.waitFor(); | ||
102 | ReliabilityResult _xifexpression = null; | ||
103 | if ((result == null)) { | ||
104 | _xifexpression = this.interpretExitStatus(exitValue, error); | ||
105 | } else { | ||
106 | _xifexpression = result; | ||
107 | } | ||
108 | _xblockexpression_1 = _xifexpression; | ||
109 | } | ||
110 | _xtrycatchfinallyexpression_1 = _xblockexpression_1; | ||
111 | } catch (final Throwable _t) { | ||
112 | if (_t instanceof IOException) { | ||
113 | final IOException e = (IOException)_t; | ||
114 | throw new StormDftException("Error during input/output handling of the stochastic solver.", e); | ||
115 | } else { | ||
116 | throw Exceptions.sneakyThrow(_t); | ||
117 | } | ||
118 | } | ||
119 | _xtrycatchfinallyexpression = _xtrycatchfinallyexpression_1; | ||
120 | } catch (final Throwable _t_1) { | ||
121 | if (_t_1 instanceof Exception) { | ||
122 | final Exception e_1 = (Exception)_t_1; | ||
123 | if ((process != null)) { | ||
124 | process.destroyForcibly().waitFor(); | ||
125 | } | ||
126 | throw e_1; | ||
127 | } else { | ||
128 | throw Exceptions.sneakyThrow(_t_1); | ||
129 | } | ||
130 | } | ||
131 | _xblockexpression = _xtrycatchfinallyexpression; | ||
132 | } | ||
133 | return _xblockexpression; | ||
134 | } catch (Throwable _e) { | ||
135 | throw Exceptions.sneakyThrow(_e); | ||
136 | } | ||
137 | } | ||
138 | |||
139 | private ImmutableList<String> toCommandLine(@Extension final StormDftConfiguration configuration, final String dftFilePath) { | ||
140 | ImmutableList<String> _xblockexpression = null; | ||
141 | { | ||
142 | @Extension | ||
143 | final ImmutableList.Builder<String> optionsBuilder = ImmutableList.<String>builder(); | ||
144 | String _elvis = null; | ||
145 | if (configuration.solverPath != null) { | ||
146 | _elvis = configuration.solverPath; | ||
147 | } else { | ||
148 | _elvis = StormDftConfiguration.DEFAULT_SOLVER_PATH; | ||
149 | } | ||
150 | optionsBuilder.add(_elvis); | ||
151 | if ((configuration.runtimeLimit != SolverConfiguration.Unlimited)) { | ||
152 | optionsBuilder.add("--timeout", Integer.valueOf(configuration.runtimeLimit).toString()); | ||
153 | } | ||
154 | optionsBuilder.add("--precision", Double.valueOf(configuration.precision).toString()); | ||
155 | if (configuration.bisimulation) { | ||
156 | optionsBuilder.add("--bisimulation"); | ||
157 | } | ||
158 | if (configuration.symmetryReduction) { | ||
159 | optionsBuilder.add("--symmetryreduction"); | ||
160 | } | ||
161 | if (configuration.modularization) { | ||
162 | optionsBuilder.add("--modularisation"); | ||
163 | } | ||
164 | if ((!configuration.dontCarePropagation)) { | ||
165 | optionsBuilder.add("--disabledc"); | ||
166 | } | ||
167 | boolean _isApproximationInUse = configuration.isApproximationInUse(); | ||
168 | if (_isApproximationInUse) { | ||
169 | String _switchResult = null; | ||
170 | final ApproximationHeuristic approximationHeuristic = configuration.approximationHeuristic; | ||
171 | if (approximationHeuristic != null) { | ||
172 | switch (approximationHeuristic) { | ||
173 | case DEPTH: | ||
174 | _switchResult = "depth"; | ||
175 | break; | ||
176 | default: | ||
177 | throw new IllegalArgumentException(("Unknown approximation heuristic: " + configuration.approximationHeuristic)); | ||
178 | } | ||
179 | } else { | ||
180 | throw new IllegalArgumentException(("Unknown approximation heuristic: " + configuration.approximationHeuristic)); | ||
181 | } | ||
182 | final String heuristicName = _switchResult; | ||
183 | optionsBuilder.add("--approximation", Double.valueOf(configuration.approximation).toString(), "--approximationheuristic", heuristicName); | ||
184 | } | ||
185 | optionsBuilder.add("--dftfile", dftFilePath); | ||
186 | final FtAnalysisObjective objective = configuration.objective; | ||
187 | boolean _matched = false; | ||
188 | if (Objects.equal(objective, FtAnalysisObjective.MTTF)) { | ||
189 | _matched=true; | ||
190 | optionsBuilder.add("--expectedtime"); | ||
191 | } | ||
192 | if (!_matched) { | ||
193 | if (objective instanceof FtAnalysisObjective.TimeBound) { | ||
194 | _matched=true; | ||
195 | optionsBuilder.add("--timebound"); | ||
196 | } | ||
197 | } | ||
198 | if (!_matched) { | ||
199 | throw new IllegalArgumentException(("Unknown analysis objective: " + configuration.objective)); | ||
200 | } | ||
201 | boolean _equals = Objects.equal(configuration.documentationLevel, DocumentationLevel.FULL); | ||
202 | if (_equals) { | ||
203 | optionsBuilder.add("--verbose"); | ||
204 | } | ||
205 | _xblockexpression = optionsBuilder.build(); | ||
206 | } | ||
207 | return _xblockexpression; | ||
208 | } | ||
209 | |||
210 | private ReliabilityResult.Solution readOutput(final InputStream inputStream, final boolean printOutput) { | ||
211 | try { | ||
212 | Object _xblockexpression = null; | ||
213 | { | ||
214 | InputStreamReader _inputStreamReader = new InputStreamReader(inputStream); | ||
215 | final BufferedReader bufferedReader = new BufferedReader(_inputStreamReader); | ||
216 | try { | ||
217 | String line = null; | ||
218 | while (((line = bufferedReader.readLine()) != null)) { | ||
219 | { | ||
220 | if (printOutput) { | ||
221 | InputOutput.<String>println(line); | ||
222 | } | ||
223 | final Matcher matcher = StormDftHandler.RESULT_PATTERN.matcher(line); | ||
224 | boolean _find = matcher.find(); | ||
225 | if (_find) { | ||
226 | try { | ||
227 | final String single = matcher.group(StormDftHandler.SINGLE_RESULT_GROUP); | ||
228 | if ((single != null)) { | ||
229 | final double singleValue = Double.parseDouble(single); | ||
230 | return new ReliabilityResult.Solution(singleValue); | ||
231 | } | ||
232 | final String lower = matcher.group(StormDftHandler.LOWER_BOUND_GROUP); | ||
233 | final String upper = matcher.group(StormDftHandler.UPPER_BOUND_GROUP); | ||
234 | if (((lower != null) && (upper != null))) { | ||
235 | final double lowerValue = Double.parseDouble(lower); | ||
236 | final double upperValue = Double.parseDouble(upper); | ||
237 | return new ReliabilityResult.Solution(lowerValue, upperValue); | ||
238 | } | ||
239 | throw new StormDftException(("Inconsistent stochastic solver output: " + line)); | ||
240 | } catch (final Throwable _t) { | ||
241 | if (_t instanceof NumberFormatException) { | ||
242 | final NumberFormatException e = (NumberFormatException)_t; | ||
243 | throw new StormDftException("Malformatted number from stochastic solver.", e); | ||
244 | } else { | ||
245 | throw Exceptions.sneakyThrow(_t); | ||
246 | } | ||
247 | } | ||
248 | } | ||
249 | } | ||
250 | } | ||
251 | } finally { | ||
252 | bufferedReader.close(); | ||
253 | } | ||
254 | _xblockexpression = null; | ||
255 | } | ||
256 | return ((ReliabilityResult.Solution)_xblockexpression); | ||
257 | } catch (Throwable _e) { | ||
258 | throw Exceptions.sneakyThrow(_e); | ||
259 | } | ||
260 | } | ||
261 | |||
262 | private String readError(final InputStream inputStream, final boolean printOutput) { | ||
263 | try { | ||
264 | String _xblockexpression = null; | ||
265 | { | ||
266 | InputStreamReader _inputStreamReader = new InputStreamReader(inputStream); | ||
267 | final BufferedReader bufferedReader = new BufferedReader(_inputStreamReader); | ||
268 | String _xtrycatchfinallyexpression = null; | ||
269 | try { | ||
270 | String _xblockexpression_1 = null; | ||
271 | { | ||
272 | final ArrayList<String> lines = CollectionLiterals.<String>newArrayList(); | ||
273 | String line = null; | ||
274 | while (((line = bufferedReader.readLine()) != null)) { | ||
275 | { | ||
276 | if (printOutput) { | ||
277 | System.err.println(line); | ||
278 | } | ||
279 | lines.add(line); | ||
280 | } | ||
281 | } | ||
282 | _xblockexpression_1 = IterableExtensions.join(lines, "\n"); | ||
283 | } | ||
284 | _xtrycatchfinallyexpression = _xblockexpression_1; | ||
285 | } finally { | ||
286 | bufferedReader.close(); | ||
287 | } | ||
288 | _xblockexpression = _xtrycatchfinallyexpression; | ||
289 | } | ||
290 | return _xblockexpression; | ||
291 | } catch (Throwable _e) { | ||
292 | throw Exceptions.sneakyThrow(_e); | ||
293 | } | ||
294 | } | ||
295 | |||
296 | private ReliabilityResult.Unknown interpretExitStatus(final int exitValue, final String error) { | ||
297 | ReliabilityResult.Unknown _switchResult = null; | ||
298 | boolean _matched = false; | ||
299 | if (Objects.equal(exitValue, StormDftHandler.STORM_GENERAL_ERROR)) { | ||
300 | _matched=true; | ||
301 | throw new StormDftException(("Storm error: " + error)); | ||
302 | } | ||
303 | if (!_matched) { | ||
304 | if (Objects.equal(exitValue, StormDftHandler.STORM_TIMEOUT)) { | ||
305 | _matched=true; | ||
306 | } | ||
307 | if (!_matched) { | ||
308 | int _intValue = Signal.SIGXCPU.intValue(); | ||
309 | int _plus = (StormDftHandler.SIGNAL_EXIT_VALUE_OFFSET + _intValue); | ||
310 | if (Objects.equal(exitValue, _plus)) { | ||
311 | _matched=true; | ||
312 | } | ||
313 | } | ||
314 | if (_matched) { | ||
315 | _switchResult = ReliabilityResult.TIMEOUT; | ||
316 | } | ||
317 | } | ||
318 | if (!_matched) { | ||
319 | if (Objects.equal(exitValue, StormDftHandler.STORM_MEMOUT)) { | ||
320 | _matched=true; | ||
321 | } | ||
322 | if (!_matched) { | ||
323 | int _intValue_1 = Signal.SIGXFSZ.intValue(); | ||
324 | int _plus_1 = (StormDftHandler.SIGNAL_EXIT_VALUE_OFFSET + _intValue_1); | ||
325 | if (Objects.equal(exitValue, _plus_1)) { | ||
326 | _matched=true; | ||
327 | } | ||
328 | } | ||
329 | if (_matched) { | ||
330 | _switchResult = ReliabilityResult.MEMOUT; | ||
331 | } | ||
332 | } | ||
333 | if (!_matched) { | ||
334 | { | ||
335 | if ((exitValue > StormDftHandler.SIGNAL_EXIT_VALUE_OFFSET)) { | ||
336 | final int signalNumber = (exitValue - StormDftHandler.SIGNAL_EXIT_VALUE_OFFSET); | ||
337 | final Function1<Signal, Boolean> _function = (Signal it) -> { | ||
338 | int _intValue_2 = it.intValue(); | ||
339 | return Boolean.valueOf((_intValue_2 == signalNumber)); | ||
340 | }; | ||
341 | final Signal signal = IterableExtensions.<Signal>findFirst(((Iterable<Signal>)Conversions.doWrapArray(Signal.values())), _function); | ||
342 | if ((signal != null)) { | ||
343 | throw new StormDftException(((("Storm unexpectedly killed by signal " + signal) + ": ") + error)); | ||
344 | } | ||
345 | } | ||
346 | throw new StormDftException(((("Storm unexpectedly exit with status " + Integer.valueOf(exitValue)) + ": ") + error)); | ||
347 | } | ||
348 | } | ||
349 | return _switchResult; | ||
350 | } | ||
351 | } | ||
diff --git a/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftSolver.java b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftSolver.java new file mode 100644 index 00000000..491e7fc1 --- /dev/null +++ b/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/xtend-gen/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/StormDftSolver.java | |||
@@ -0,0 +1,79 @@ | |||
1 | package hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver; | ||
2 | |||
3 | import com.google.common.base.Objects; | ||
4 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ConstantModel; | ||
5 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.FaultTree; | ||
6 | import hu.bme.mit.inf.dslreasoner.faulttree.model.ft.ReliabilityModel; | ||
7 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.ft2galileo.Ft2GalileoTransformation; | ||
8 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver.FtAnalysisObjective; | ||
9 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver.ReliabilityResult; | ||
10 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver.StormDftConfiguration; | ||
11 | import hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver.StormDftHandler; | ||
12 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace; | ||
13 | |||
14 | @SuppressWarnings("all") | ||
15 | public class StormDftSolver { | ||
16 | private static final String DFT_FILE_NAME = "ft.dft"; | ||
17 | |||
18 | private final Ft2GalileoTransformation ft2Galileo = new Ft2GalileoTransformation(); | ||
19 | |||
20 | private final StormDftHandler handler = new StormDftHandler(); | ||
21 | |||
22 | public ReliabilityResult solve(final ReliabilityModel reliabilityModel, final StormDftConfiguration configuration, final ReasonerWorkspace reasonerWorkspace) { | ||
23 | ReliabilityResult _switchResult = null; | ||
24 | boolean _matched = false; | ||
25 | if (reliabilityModel instanceof FaultTree) { | ||
26 | _matched=true; | ||
27 | _switchResult = this.solve(((FaultTree)reliabilityModel), configuration, reasonerWorkspace); | ||
28 | } | ||
29 | if (!_matched) { | ||
30 | if (reliabilityModel instanceof ConstantModel) { | ||
31 | _matched=true; | ||
32 | ReliabilityResult.Solution _xblockexpression = null; | ||
33 | { | ||
34 | double _xifexpression = (double) 0; | ||
35 | boolean _isFailed = ((ConstantModel)reliabilityModel).isFailed(); | ||
36 | if (_isFailed) { | ||
37 | _xifexpression = 0; | ||
38 | } else { | ||
39 | double _switchResult_1 = (double) 0; | ||
40 | final FtAnalysisObjective objective = configuration.objective; | ||
41 | boolean _matched_1 = false; | ||
42 | if (Objects.equal(objective, FtAnalysisObjective.MTTF)) { | ||
43 | _matched_1=true; | ||
44 | _switchResult_1 = Double.POSITIVE_INFINITY; | ||
45 | } | ||
46 | if (!_matched_1) { | ||
47 | if (objective instanceof FtAnalysisObjective.TimeBound) { | ||
48 | _matched_1=true; | ||
49 | _switchResult_1 = 1; | ||
50 | } | ||
51 | } | ||
52 | if (!_matched_1) { | ||
53 | throw new IllegalArgumentException(("Unknown objective: " + objective)); | ||
54 | } | ||
55 | _xifexpression = _switchResult_1; | ||
56 | } | ||
57 | final double result = _xifexpression; | ||
58 | _xblockexpression = new ReliabilityResult.Solution(result); | ||
59 | } | ||
60 | _switchResult = _xblockexpression; | ||
61 | } | ||
62 | } | ||
63 | if (!_matched) { | ||
64 | throw new IllegalArgumentException(("Unknown reliability model: " + reliabilityModel)); | ||
65 | } | ||
66 | return _switchResult; | ||
67 | } | ||
68 | |||
69 | public ReliabilityResult solve(final FaultTree faultTree, final StormDftConfiguration configuration, final ReasonerWorkspace reasonerWorkspace) { | ||
70 | ReliabilityResult _xblockexpression = null; | ||
71 | { | ||
72 | final CharSequence galileo = this.ft2Galileo.toGalileo(faultTree); | ||
73 | reasonerWorkspace.writeText(StormDftSolver.DFT_FILE_NAME, galileo); | ||
74 | final String dftFilePath = reasonerWorkspace.getFile(StormDftSolver.DFT_FILE_NAME).getAbsolutePath(); | ||
75 | _xblockexpression = this.handler.callSolver(dftFilePath, configuration); | ||
76 | } | ||
77 | return _xblockexpression; | ||
78 | } | ||
79 | } | ||