Beispiel #1
0
    def simulate_catedra(self, time_day):
        '''Simulate a catedra. First, updates the programming level, then simulates a control, then the tips and finally the actividad '''
        if len(self.fechas_catedras) >= 12:
            return
        self.update_programming_level(time_day)
        self.fechas_catedras.append(time_day)
        time_week = int(time_day / 7)
        if time_week <= 11:
            self.events_list.append(('catedra', time_day + 7))

        if bool(bernoulli(0.5)):
            self.simulate_control(time_day)

        for student in self.active_students:
            if bool(bernoulli(0.5)):
                student.listen_tip(time_day)

        i = 0
        while i <= 600:
            student = choice(self.active_students)
            n_questions = round(triangular(1, 10, 3))
            i += n_questions
            student.ask_questions(time_day, n_questions)

        self.simulate_actividad(time_day)
        print('[{}] Hubo una catedra. Fueron {} alumnos'.format(
            time_day, len(self.active_students)))
Beispiel #2
0
    def simulate_one_day(self, infection, prob_die):
        '''It simulates the actions of one day. First they can
        cure themselves, then they infect other people and finally
        they can die. This order makes sense to me'''
        if self.status == "Infectado":
            if self.has_cure:
                p = 0.25 * infection.resistencia_medicina
                if self.infected_total >= 1000:
                    sample = int(str(self.infected_total)[0:3])
                    x = sum(bernoulli(p) for i in range(sample)) / sample
                    new_cured = round(x * self.infected_total)
                    for i in range(new_cured):
                        self.cure_one()
                else:
                    for i in range(self.infected_total):
                        x = bernoulli(p)
                        if x == 1:
                            self.cure_one()

            if self.infected_total >= 1000:
                sample = int(str(self.infected_total)[0:3])
                u_prom = sum(uniform() for i in range(sample)) / sample
                n = round(u_prom * infection.tasa_contagiosidad)
                if self.has_mask:
                    n *= 0.3
                new_infected = round(n * self.infected_total)
                self.infect_one(new_infected)
                self.infected_this_day = min(new_infected, self.healthy_total)
            else:
                self.infected_this_day = 0
                for i in range(self.infected_total):
                    u = uniform()
                    n = u * infection.tasa_contagiosidad
                    if self.has_mask:
                        n *= 0.3
                    self.infect_one(int(n))
                    self.infected_this_day += min(int(n), self.healthy_total)

            if self.infected_total >= 1000:
                sample = int(str(self.infected_total)[0:3])
                x = sum(bernoulli(prob_die) for i in range(sample)) / sample
                new_dead = round(x * self.infected_total)
                self.kill_one(new_dead)
                self.dead_this_day = min(new_dead, self.infected_total)
            else:
                self.dead_this_day = 0
                for i in range(self.infected_total):
                    x = bernoulli(prob_die)
                    if x == 1:
                        self.kill_one()
                        self.dead_this_day += min(1, self.infected_total)
Beispiel #3
0
 def visit_proffesor(self, time_day, proffesor):
     '''Adds the day when the student went to visit the teacher to a list '''
     if self.promedio <= 5.0:
         proffesor.cola.append(self)
     else:
         if bool(bernoulli(0.2)):
             proffesor.cola.append(self)
Beispiel #4
0
 def llegada_tsunami(self, tiempo, potencia_tsunami):
     print("[{}] llego un tsunami".format(tiempo))
     t = Tsunami(potencia_tsunami)
     rango_inf = t.range_in_rute[0]
     rango_sup = t.range_in_rute[1]
     for i in self.poblacion:
         if not i.is_safe:
             if i.in_vehicle:
                 if i.posicion <= rango_sup and i.posicion >= rango_inf:
                     x = bernoulli(t.prob_no_sobrevivir)
                     if x == 1:
                         i.kill_vehicle(reason='tsunami')
             else:
                 if i.posicion <= rango_sup and i.posicion >= rango_inf:
                     x = bernoulli(t.prob_no_sobrevivir)
                     if x == 1:
                         i.kill(reason='tsunami')
Beispiel #5
0
 def simulate_spread_air(self):
     '''Simulates the event of infecting other country by air.
     This does not includes the 4 percent condition'''
     for country in self.air_neighbours_available:
         if country.status == 'Limpio':
             p = self.prob_spread_air
             x = bernoulli(p)
             if x == 1:
                 country.infect_one()
Beispiel #6
0
 def simulate_spread_land(self):
     '''Simulates the event of infecting other country by land'''
     if self.infected_total >= 0.2 * self.initial_population:
         for country in self.neighbours_available:
             if country.status == 'Limpio':
                 p = self.prob_spread_land
                 x = bernoulli(p)
                 if x == 1:
                     country.infect_one()
Beispiel #7
0
 def llegada_replicas(self, tiempo):
     print("[{}] llego una replica".format(tiempo))
     self.tiempo_llegada_replica(tiempo)
     r = Replica()
     # matar y generar tsunami
     for i in self.poblacion:
         if not i.is_safe:
             if i.in_vehicle:
                 # 1 if he dies, 0 eoc
                 x = bernoulli(r.prob_no_sobrevivir_vehiculo)
                 if x == 1:
                     i.kill_vehicle(reason='replica')
             else:
                 x = bernoulli(r.prob_no_sobrevivir_caminando)
                 if x == 1:
                     i.kill(reason='replica')
     # let g = 1 if r generates a marepoto, 0 eoc
     g = bernoulli(r.prob_tsunami)
     if g == 1:
         self.llegada_tsunami(tiempo, r.potencia_tsunami)
Beispiel #8
0
    def __init__(self):
        x = bernoulli(0.5)
        if x == 1:
            self.tipo = 'auto'
        else:
            self.tipo = 'camioneta'

        self.rapidez = random.uniform(12, 20)
        if self.tipo == 'auto':
            self.capacidad = 5
        else:
            self.capacidad = 8
        self.pasajeros = []
Beispiel #9
0
    def __init__(self):
        x = bernoulli(0.7)
        if x == 1:
            tipo = 'debil'
        else:
            tipo = 'fuerte'

        if tipo == 'debil':
            self.prob_no_sobrevivir_caminando = 0.1
            self.prob_no_sobrevivir_vehiculo = 0.15
            self.prob_tsunami = 0
            self.potencia_tsunami = 0
        else:
            self.prob_no_sobrevivir_caminando = 0.3
            self.prob_no_sobrevivir_vehiculo = 0.6
            self.prob_tsunami = 0.7
            self.potencia_tsunami = random.randint(3, 8)
Beispiel #10
0
 def simulate_infection_detection(self):
     '''Simulates the bernoulli event of detecting the infection'''
     x = bernoulli(self.prob_detect_infection)
     if x == 1:
         self.infection_detected = True
         self.infection_detection_day = self.day