Ejemplo n.º 1
0
def system_example():
    r""" Describe the system as a reliability block diagram

              | -- A0 -- | -- M0 -- |
              |            /        |
         E -- | -- A1 -- |          | -- S
              |            \        |
              | -- A2 -- | -- M1 -- |
    """

    alim = [Component('A_%s' % i, 2e-4) for i in xrange(3)]
    motors = [Component('M_%s' % i, 1e-4) for i in xrange(2)]
    S = System()

    S['E'] = [alim[0], alim[1], alim[2]]
    S[alim[0]] = [motors[0]]
    S[alim[1]] = [motors[0], motors[1]]
    S[alim[2]] = [motors[1]]
    S[motors[0]] = 'S'
    S[motors[1]] = 'S'

    print('The MTTF of the system is :', S.mttf)

    timerange = range(0, 2 * 365 * 24, 100)  # 2 years study
    reliability = [S.reliability(t) for t in timerange]
    plot(timerange, reliability)
    show()
Ejemplo n.º 2
0
class TestComponent(unittest2.TestCase):
    """ Test the Component class.
    """
    def setUp(self):
        """ Here we build the component we will use as test subjects
            We assume components have constant failure and maintainability rates
        """

        self.lambda_, self.mu = symbols('l, m',
                                        constant=True,
                                        positive=True,
                                        null=False)
        self.t = symbols('t', positive=True)
        self.component = Component('C', self.lambda_, self.mu)

    def test_reliability(self):
        """ Check the reliability is equals to the theorical one """
        self.assertEqual(exp(-self.lambda_ * self.t),
                         self.component.reliability(self.t))

    def test_maintainability(self):
        """ Check the maintainability is equals to the theorical one """
        self.assertEqual(1 - exp(-self.mu * self.t),
                         self.component.maintainability(self.t))

    def test_availability(self):
        """ Check the availability is equals to the theorical one """
        availability = self.lambda_ * \
                       exp(self.t*(-self.lambda_ - self.mu)) / \
                       (self.lambda_ + self.mu) + \
                       self.mu/(self.lambda_ + self.mu)

        self.assertEqual(availability, self.component.availability(self.t))
Ejemplo n.º 3
0
def markov_example():
    """ Describe the system as a Markov Process.
        states explanations :
            0 : A and B working
            1 : A working and B not working
            2 : A not working and B working
            3 : neither A nor B working
    """
    A = Component('A', 1e-4, 1.1e-3)
    B = Component('B', 4e-4, 1.4e-3)

    components = (A, B)

    initstates = {0: 0.8, 1: 0.1, 2: 0.1}

    process = Markovprocess(components, initstates)

    timerange = range(0, 5000, 10)
    states = {u'nominal' : lambda x: all(x),
              u'dégradé' : lambda x: not(all(x)) and any(x), #at least one but all
              u'défaillant' : lambda x: not(x[0] or x[1]),   #none
              u'disponible' : lambda x: any(x), #at least one
             }

    for name, state in states.iteritems():
        data = [process.value(t, statefunc=state) for t in timerange]
        p.plot(timerange, data, label=name)
    p.legend()
    p.show()
Ejemplo n.º 4
0
def voter_example(nmax=5, nmin=3):
    """
        find when a real voter M/N is equivalent to a single component.
        all real voters (i.e. 1 < M < N) having `nmin <= N < nmax` are studied.

        Parameters
        ----------
        nmax: int, optional
            the maximum value of N (excluded)

        nmin: int, optional
            the minimum value of N (included)

    """
    orders = ((M, N) for N in xrange(nmin, nmax) for M in xrange(2, N))
    l = Symbol('l', positive=True, null=False)
    t = Symbol('t', positive=True)
    x = Symbol('x')
    comp = Component('C', l)

    for order in orders:
        voter = Voter(comp, order[0], order[1])
        crossing = (voter.reliability(t) - comp.reliability(t)).nsimplify()
        roots = solve(crossing.subs(exp(-l * t), x))

        print('For M = {}, N = {}'.format(*order))
        print('− {} roots: '.format(len(roots)))
        for root in roots:
            print(' − {}'.format(root))
        print()
Ejemplo n.º 5
0
    def setUp(self):
        """ Here we build the component we will use as test subjects
            We assume components have constant failure and maintainability rates
        """

        self.lambda_, self.mu = symbols('l, m',
                                        constant=True,
                                        positive=True,
                                        null=False)
        self.t = symbols('t', positive=True)
        self.component = Component('C', self.lambda_, self.mu)
Ejemplo n.º 6
0
    def setUp(self):
        #Let’s build some standard systems
        systems = {
            'series-parallel': System(),
            'parallel-series': System(),
            'simple': System()
        }

        lambdas = {'alim': 1e-4, 'motor': 2e-5}
        mus = {'alim': 5e-4, 'motor': 2e-3}

        alim = [
            Component('Alim_A', lambda_=lambdas['alim'], mu=mus['alim']),
            Component('Alim_B', lambda_=lambdas['alim'], mu=mus['alim']),
        ]
        motors = [
            Component('Motor_A', lambda_=lambdas['motor'], mu=mus['motor']),
            Component('Motor_B', lambda_=lambdas['motor'], mu=mus['motor']),
        ]

        systems['simple']['E'] = alim[0]
        systems['simple'][alim[0]] = motors[0]
        systems['simple'][motors[0]] = 'S'

        systems['series-parallel']['E'] = [alim[0], alim[1]]
        systems['series-parallel'][alim[0]] = motors[0]
        systems['series-parallel'][alim[1]] = motors[1]
        systems['series-parallel'][motors[0]] = 'S'
        systems['series-parallel'][motors[1]] = 'S'

        systems['parallel-series']['E'] = [alim[0], alim[1]]
        systems['parallel-series'][alim[0]] = [motors[0], motors[1]]
        systems['parallel-series'][alim[1]] = [motors[0], motors[1]]
        systems['parallel-series'][motors[0]] = 'S'
        systems['parallel-series'][motors[1]] = 'S'

        #Let’s build the markov equivalent system
        self.components = (alim[0], alim[1], motors[0], motors[1])
        self.process = Markovprocess(self.components,
                                     {0: 1})  #All the components work

        self.states = {
            'series-parallel': lambda x: (x[0] * x[2]) + (x[1] * x[3]),
            'parallel-series': lambda x: (x[0] + x[1]) * (x[2] + x[3]),
            'simple': lambda x: x[0] * x[2],
        }

        self.systems = systems
Ejemplo n.º 7
0
    def test_cache(self):
        """ Perfom some tests on the cache
        """
        components = [Component('C{}'.format(i), 1e-3) for i in (0, 1, 2)]
        system = System()

        #      +-- C0 --+
        #      |        |
        # E ---|        +-- C2 -- S
        #      |        |
        #      +-- C1 --+

        system['E'] = [components[0], components[1]]
        system[components[0]] = components[2]
        system[components[1]] = components[2]
        system[components[2]] = 'S'

        self.assertAlmostEqual(system.mttf, 2000 / 3.)
        self.assertIn('mttf', system._cache)  #The mttf is cached

        components[0].lambda_ = 0.05  #Let’s change the failure rate
        self.assertEqual(system._cache, dict())  #The cache is now empty
        self.assertAlmostEqual(system.mttf, 331750 / 663.)
        self.assertIn('mttf', system._cache)  #The mttf is cached

        #now, check if it works with a shared component
        othersystem = System()
        othersystem['E'] = components[0]
        othersystem[components[0]] = 'S'

        self.assertAlmostEqual(othersystem.mttf, 20)
        components[0].lambda_ = 2e-4
        self.assertAlmostEqual(othersystem.mttf, 5000)
        self.assertAlmostEqual(system.mttf, 29000 / 33.)
Ejemplo n.º 8
0
    def test_graphmanagement(self):
        """ Check if the constructing a system by its graph works as intended.
        """
        component = [Component('C%s' % i, 1e-3) for i in range(4)]
        system = System()

        #because 'E' must be the first inserted element
        with self.assertRaises(ValueError):
            system[component[0]] = 'S'

        #Assert the following constructions don’t fail.
        #from a list
        system['E'] = [component[0], component[1]]
        system[component[0]] = 'S'
        wanted = DiGraph({
            'E': [component[0].__str__(), component[1].__str__()],
            component[0].__str__(): ['S']
        })
        self.assertTrue(is_isomorphic(system._graph, wanted))

        del system[component[0]]  #This component isn’t used anymore
        #from a single element
        system['E'] = component[1]
        system[component[1]] = 'S'
        wanted = DiGraph({
            'E': [component[1].__str__()],
            component[1].__str__(): 'S'
        })
        self.assertTrue(is_isomorphic(system._graph, wanted))
Ejemplo n.º 9
0
from fiabilipy import Component, Markovprocess
from fiabilipy import System
machineA = Component("mA", 0.0001, 0.0011)
machineB = Component("mB", 0.0004, 0.0014)
machineC = Component("mC", 0.0001, 0.001)

S = (machineA, machineB, machineC)


def normal(x):
    return all(x)


def available(x):
    return ((x[0] and x[1]) or (x[2] and x[1]) or (x[0] and x[2]))


def damaged(x):
    return available(x) and not (normal(x))


def dead(x):
    return not available(x)


initstates = {0: 1}
process = Markovprocess(S, initstates)

print(process.value(5000, available))
#0.957231110811
Ejemplo n.º 10
0
import fiabilipy
from fiabilipy import Component, Markovprocess
A0, A1, A2 = [
    Component('A{}'.format(i), 1e-4, 1.1e-3, 1.1e-3) for i in range(3)
]
M0, M1, M2 = [
    Component('M{}'.format(i), 1e-3, 1.2e-2, 1.2e-3) for i in range(3)
]
compA = (A0, A1, A2)
compM = (M0, M1, M2)
components = (compA + compM)
initstates = {0: 0.9, 1: 0.1}
process = Markovprocess(components, initstates)


def normal(x):
    return all(x)


def available(x):
    return (x[0] or x[1] or x[2]) and (x[3] or x[4] or x[5])


def damaged(x):
    return available(x) and not (normal(x))


def faulty(x):
    return not available(x)

Ejemplo n.º 11
0
#ARCHI0

import networkx as nx
import matplotlib.pyplot as plt

from fiabilipy import Voter, Component
from sympy import Symbol
from fiabilipy import System
import pylab as p

p1 = Component('p1', 2.28e-4, 0)
p2 = Component('p2', 2.28e-4, 0)
p3 = Component('p3', 2.28e-4, 0)
m1 = Component('m1', 2.94e-4)
m2 = Component('m2', 2.94e-4, 0)
bus = Component('bus', 1e-4, 0)
voter = Voter(p1, 2, 3)

p1_b = Component('p1_b', 2.28e-4, 0)
bus_b = Component('bus_b', 1)
voter_b = Voter(p1_b, 2, 2)
m1_b = Component('m1_b', 1)

S = System()

S['E'] = [voter]
S[m1] = S[m2] = 'S'
S[voter] = [bus]
S[bus] = [m1, m2]

Sb = System()
Ejemplo n.º 12
0
#ARCHI 2
from fiabilipy import Voter,Component
from sympy import Symbol
from fiabilipy import System
import pylab as p

p1= Component('p1',2.28e-4,0)
voter= Voter(p1,2,3)
m1 = Component('m1', 2.94e-4,0)
m2 = Component('m2', 2.94e-4,0)
bus = Component ('bus',1e-4,0)
alim1= Component ('alim1',2.28e-4,0)
alim2= Component ('alim2',2.28e-4,0)

S=System()

S['E']=[alim1,alim2]
S[alim1]=S[alim2]
S[m1]=S[m2]='S'
S[alim1]=S[alim2]=[voter]
S[voter]=[bus]
S[bus]=[m1,m2]


timerange=range(0,43800,100)


availability = [S.availability(t) for t in timerange]
p.plot(timerange,availability)
p.show()
Ejemplo n.º 13
0
import fiabilipy
import time
from fiabilipy import Component
from fiabilipy import Component, Markovprocess
A0, A1, A2 = [Component('A{}'.format(i), 700, 200, 300) for i in range(3)]
M0, M1, M2 = [Component('M{}'.format(i), 650, 450, 330) for i in range(3)]
A3 = Component('A3', 120)
M3 = Component('M3', 110)
compA = (A0, A1, A2, A3)
compM = (M0, M1, M2, M3)
components = (A0, A1, A2, A3, M0, M1, M2, M3)
initstates = {0: 0.6, 1: 0.40}
process = Markovprocess(components, initstates)


def normal(x):
    return all(x)


def available1(x):
    for i in compA:
        return (x[0] or x[i] or x[i + 1])


def available2(x):
    for j in compM:
        return (x[0] or x[j] or x[j + 1])


def available(x):
    return (available1) and (available2)
Ejemplo n.º 14
0
    def setUp(self):
        """ Here we build some standard systems we will use as test subjects
        """
        systems = {
            'simple': System(),
            'series-parallel': System(),
            'parallel-series': System(),
            'complex': System(),
            'voter': System(),
        }

        lambdas = {
            'alim': symbols('l_alim', positive=True, null=False),
            'motor': symbols('l_motor', positive=True, null=False),
        }
        mus = {
            'alim': symbols('m_alim', positive=True, null=False),
            'motor': symbols('m_motor', positive=True, null=False),
        }

        alim = [
            Component('Alim_A', lambda_=lambdas['alim'], mu=mus['alim']),
            Component('Alim_B', lambda_=lambdas['alim'], mu=mus['alim']),
            Component('Alim_C', lambda_=lambdas['alim'], mu=mus['alim']),
        ]
        motors = [
            Component('Motor_A', lambda_=lambdas['motor'], mu=mus['motor']),
            Component('Motor_B', lambda_=lambdas['motor'], mu=mus['motor']),
        ]

        voter = Voter(alim[0], M=2, N=3)

        systems['simple']['E'] = alim[0]
        systems['simple'][alim[0]] = motors[0]
        systems['simple'][motors[0]] = 'S'

        systems['series-parallel']['E'] = [alim[0], alim[1]]
        systems['series-parallel'][alim[0]] = motors[0]
        systems['series-parallel'][alim[1]] = motors[1]
        systems['series-parallel'][motors[0]] = 'S'
        systems['series-parallel'][motors[1]] = 'S'

        systems['parallel-series']['E'] = [alim[0], alim[1]]
        systems['parallel-series'][alim[0]] = [motors[0], motors[1]]
        systems['parallel-series'][alim[1]] = [motors[0], motors[1]]
        systems['parallel-series'][motors[0]] = 'S'
        systems['parallel-series'][motors[1]] = 'S'

        systems['complex']['E'] = [alim[0], alim[1], alim[2]]
        systems['complex'][alim[0]] = motors[0]
        systems['complex'][alim[1]] = [motors[0], motors[1]]
        systems['complex'][alim[2]] = motors[1]
        systems['complex'][motors[0]] = 'S'
        systems['complex'][motors[1]] = 'S'

        systems['voter']['E'] = voter
        systems['voter'][voter] = [motors[0], motors[1]]
        systems['voter'][motors[0]] = 'S'
        systems['voter'][motors[1]] = 'S'

        self.systems = systems
        self.alim = alim
        self.motors = motors
        self.voter = voter
        self.lambdas = lambdas
        self.mus = mus
#ARCHI 1
from fiabilipy import Voter, Component
from sympy import Symbol
from fiabilipy import System
import pylab as p
p1 = Component('p1', 2.28e-4, 0)
p2 = Component('p2', 2.28e-4, 0)
p3 = Component('p3', 2.28e-4, 0)
m1 = Component('m1', 2.94e-4, 0)
m2 = Component('m2', 2.94e-4, 0)
bus = Component('bus', 0, 0)
voter = Voter(p1, 2, 3)
alim = Component('alim', 2.28e-4, 0)

bus_b = Component('bus_b', 1)
voter_b = Voter(p1, 2, 2)
m1_b = Component('m1_b', 1)
alim_b = Component('alim_b', 1)

S = System()

S['E'] = [alim]
S[m1] = S[m2] = 'S'
S[alim] = [voter]
S[voter] = [bus]
S[bus] = [m1, m2]

Sb = System()

Sb['E'] = [alim]
Sb[m1] = Sb[m2] = 'S'
Ejemplo n.º 16
0
#ARCHI 3
from fiabilipy import Voter,Component
from sympy import Symbol
from fiabilipy import System
import pylab as p
p1= Component('p1',2.28e-4,0)
m1 = Component('m1', 2.94e-4,0)
m2 = Component('m2', 2.94e-4,0)
bus = Component ('bus',1e-4,0)
voter= Voter(p1,2,3)
alim1= Component ('alim1',2.28e-4,0)
voter2=Voter(alim1,2,3)

p1_b= Component('p1_b',2.28e-4,0)
bus_b= Component('bus_b',1)
voter_b=Voter(p1_b,2,2)
m1_b = Component('m1_b', 1)
alim1_b=Component('alim_b',1)
voter2_b=Voter(alim1,2,2)

S=System()

S['E']=[voter2]
S[m1]=S[m2]='S'
S[voter2]=[voter]
S[voter]=[bus]
S[bus]=[m1,m2]


Sb=System()
Ejemplo n.º 17
0
import fiabilipy
from fiabilipy import Component
from sympy import Symbol
t = Symbol('t', positive=True)
comp = Component('C0', 1e-4)
print(comp.reliability(100))
print(comp.reliability(t=33))
print(comp.mttf)
from fiabilipy import System
power = Component('P0', 1e-6)
motor = Component('M0', 1e-3)
print(power)
S = System()
S['E'] = [power]
S[power] = [motor]
S[motor] = 'S'
print(S.reliability(t))
print(S.mttf)
print(float(S.mttf))
a, b, c, d, e, f, g = [Component('C%i' % i, 1e-4) for i in range(7)]
S = System()
S['E'] = [a, b, c, g]
S[a] = S[g] = S[e] = S[d] = 'S'
S[b] = S[c] = [f]
S[f] = [e, d]
print(a)
print(S.mttf)
print(float(S.mttf))
print(S.reliability(t))
import pylab as p
a, b = Component('a', 1e-5), Component('b', 1e-7)