* Example 1:
echo Example 1:
* A very simple reliability block diagram example 
* Each component type has a prob of failure attached to it rather
* than a distribution of time to failure.
* Example 1.11 from p. 32 of Trivedi's book.

block example1
comp 1 prob(0.05)
* thus component labelled 1 has a failure prob of 0.05
comp 2 prob(0.01)
comp 3 prob(0.3)
comp 4 prob(0.25)
comp 5 prob(0.1)
parallel three 3 3 3
parallel four 4 4
series sys1 1 2 three four 5
end

* system unreliability can be computed as 
var sysunrel sysprob(example1)
expr sysunrel

* Example 1a:
* Now we attach a distribution of time to failure
* to each component type. The distributions are
* assumed to be exponential for convenience.
* the failure rate assigned to a component is such
* that its unrelaibility at 10 hours is the one in the
* above example 1.

block example1a
comp 1 exp(0.005129)
comp 2 exp(0.001005)
comp 3 exp(0.003045)
comp 4 exp(0.028768)
comp 5 exp(0.010536)
parallel three 3 3 3
parallel four 4 4
series sys1 1 2 three four 5
end

* can ask for the mean time to system failure
expr mean(example1a)

* can ask for the variance of the system time to failure
expr variance(example1a)

* can ask for the coefficient of variation of system time to failure
var coeff ((variance(example1a))^0.5)/mean(example1a)
expr coeff

* A symbolic expression for the distribution of time to failure
cdf (example1a)

* numerical evaluation of system failure prob 
* at various points in time
eval (example1a) 1 10 1

* alternatively, we can ask for
loop t,1,10,1
   expr value(t;example1a)
* value uses the symbolic cdf and evaluates at requested values of t
end

* alternatively, we can ask for
loop t,1,10,1
   expr tvalue(t;example1a)
* tvalue assigns a numerical failure prob to each comp at time t
* and numercially evaluates the system failure probability; that
* is a recomputation at each time point is involved.
end

end

