Exemple #1
0
    def __init__(self, parameters):
        self._parameters = dict(parameters)  # to not modify parameters
        self._integer = parameters['integer_flux']

        self._boxes = {
            'SE':
            BoxSource('SE'),
            'INCUB':
            BoxConvolution('INCUB', compute_khi_delay(self.delay('dm_incub')),
                           self._integer),
            'IR':
            BoxConvolution('IR', compute_khi_exp(self.delay('dm_r')),
                           self._integer),
            'IH':
            BoxConvolution('IH', compute_khi_exp(self.delay('dm_h')),
                           self._integer),
            'SM':
            BoxConvolution('SM', compute_khi_exp(self.delay('dm_sm')),
                           self._integer),
            'SI':
            BoxConvolution('SI', [
                0, 0.03, 0.03, 0.04, 0.05, 0.05, 0.05, 0.05, 0.1, 0.1, 0.1,
                0.1, 0.1, 0.1, 0.05, 0.03, 0.02
            ], self._integer),
            'SS':
            BoxConvolution('SS', compute_khi_exp(self.delay('dm_ss')),
                           self._integer),
            'R':
            BoxTarget('R'),
            'DC':
            BoxTarget('DC')
        }

        # src -> [targets]
        def lambda_coefficient(a, b=None):
            if isinstance(a, int):
                return lambda: a
            elif b == None:
                return lambda: self.coefficient(a)
            else:
                return lambda: self.coefficient(a) * self.coefficient(b)

        self._moves = {
            'INCUB': [('IH', lambda_coefficient('pc_ih')),
                      ('IR', lambda_coefficient('pc_ir'))],
            'IR': [('R', lambda_coefficient(1))],
            'IH': [('SM', lambda_coefficient('pc_sm')),
                   ('SI', lambda_coefficient('pc_si'))],
            'SM': [('SI', lambda_coefficient('pc_sm_si')),
                   ('DC', lambda_coefficient('pc_sm_dc')),
                   ('SS', lambda_coefficient('pc_sm_out', 'pc_h_ss')),
                   ('R', lambda_coefficient('pc_sm_out', 'pc_h_r'))],
            'SI': [('DC', lambda_coefficient('pc_si_dc')),
                   ('SS', lambda_coefficient('pc_si_out', 'pc_h_ss')),
                   ('R', lambda_coefficient('pc_si_out', 'pc_h_r'))],
            'SS': [('R', lambda_coefficient(1))]
        }

        self.time = -1  # first step should be t=0
        self.e0 = int(self.constant('population') * self.coefficient('kpe'))
        self.box('SE').add(self.e0 - self.constant('patient0'))
        self.box('INCUB').add(self.constant('patient0'))
Exemple #2
0
 def test_box_source4(self):
     box = BoxSource('SOURCE')
     box.add(100)
     box.step()
     self.assertEqual(box.size(), 100)
     self.assertEqual(box.output(), 100)
     box.step()
     self.assertEqual(box.size(), 100)
     self.assertEqual(box.output(), 100)
     box.remove(10)
     box.step()
     self.assertEqual(box.size(), 90)
     self.assertEqual(box.output(), 90)
Exemple #3
0
 def test_box_source2(self):
     box = BoxSource('SOURCE')
     box.add(100)
     self.assertEqual(box.input(), 100)
     box.step()
     self.assertEqual(box.output(), 100)
     box.step()
     self.assertEqual(box.output(), 100)
     box.add(10)
     box.step()
     self.assertEqual(box.input(), 0)
     self.assertEqual(box.size(), 110)
     self.assertEqual(box.output(), 110)
Exemple #4
0
    def test_box_source3(self):
        box = BoxSource('SOURCE')
        box.add(100)
        self.assertEqual(box.input(), 100)
        box.step()
        self.assertEqual(box.output(), 100)
        box.remove(10)
        self.assertEqual(box.removed(), 10)
        box.step()
        self.assertEqual(box.removed(1), 10)
        self.assertEqual(box.removed(), 0)
        self.assertEqual(box.output(), 90)

        box.remove(10)
        box.remove(10)
        self.assertEqual(box.removed(), 20)
        box.step()
        self.assertEqual(box.removed(1), 20)
        self.assertEqual(box.removed(), 0)
        self.assertEqual(box.output(), 70)
Exemple #5
0
    def test_box_source6(self):
        box = BoxSource('SOURCE')
        box.add(100)
        box.step()
        for i in range(1, 10):
            box.remove(i)
            box.step()

        self.assertEqual(box.get_input_history(), [100]+[0]*10)
        self.assertEqual(box.get_removed_history(), [
                         0]+list(range(1, 10)) + [0])
        self.assertEqual(box.get_output_history(), [0]+[
                         100-int(n*(n+1)/2) for n in range(1, 10)] + [100-45])
        self.assertEqual(box.get_output_history(), box.get_size_history())