aboutsummaryrefslogtreecommitdiffstats
path: root/Stochastic/hu.bme.mit.inf.dslreasoner.faulttree.transformation/src/hu/bme/mit/inf/dslreasoner/faulttree/transformation/solver/ReliabilityResult.xtend
blob: 19c3d17db943b411fafa2d2b0a32122cfaf83304 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package hu.bme.mit.inf.dslreasoner.faulttree.transformation.solver

import org.eclipse.xtend.lib.annotations.Data
import org.eclipse.xtend.lib.annotations.FinalFieldsConstructor

abstract class ReliabilityResult {
	public static val TIMEOUT = new Unknown("Solver timed out")
	public static val MEMOUT = new Unknown("Solver out of memory")

	abstract def Solution getOrThrow()

	@Data
	static final class Solution extends ReliabilityResult {
		val double lowerBound
		val double upperBound

		new(double value) {
			this(value, value)
		}

		new(double lowerBound, double upperBound) {
			if (lowerBound > upperBound) {
				throw new IllegalArgumentException("lowerBound must not be larger than upperBound")
			}
			this.lowerBound = lowerBound
			this.upperBound = upperBound
		}

		override getOrThrow() {
			this
		}
	}

	@Data
	static final class Unknown extends ReliabilityResult {
		val String message
		val Throwable cause

		@FinalFieldsConstructor
		new() {
		}

		new(String message) {
			this(message, null)
		}

		override getOrThrow() {
			throw new RuntimeException(message, cause)
		}
	}
}