Ejemplo n.º 1
0
def plot_curves(system):
    if system.commutation_curve is None:
        print("There is no commutation curve calculated yet.")
        sir.find_commutation_curve(system)
    fig, ax = plt.subplots()
    ax.set_xlim(system.sbar, 1)
    ax.set_ylim(0, system.imax * 1.1)

    s = list(np.linspace(0, 1))
    T = [tau(si, system) for si in s]
    P = [phi(si, system) for si in s]
    C = [com_curve(si, system) for si in s]

    ax.fill_between(s, T, 0, facecolor="blue", alpha=0.5)
    ax.fill_between(s, C, P, facecolor="blue", alpha=0.5)
    ax.fill_between(s, P, 1, facecolor="red", alpha=0.5)
    ax.fill_between(s, T, C, facecolor="red", alpha=0.5)
    return fig
Ejemplo n.º 2
0
def final_cond(t, state, u_func, ref, crit, term_val):
    out = state[0] - term_val
    return out


final_cond.terminal = True

#%%
imax = 0.1
umax = 0.6
gamma = 1 / 7
beta = 0.52
A = sir.SIR()
A.set_params([imax, umax, gamma, beta], flag="bg")
sir.find_commutation_curve(A)

#%%
x0 = np.array([1 - 1e-4, 1e-4, 0, 0, 0]).reshape([
    5,
])
#x0 = np.array([0.5, 0, 0.075, 0, 0]).reshape([5, ])
p = ref(0.52, 1 / 7, 1 / 7, 0.8)
sol = scipy.integrate.solve_ivp(
    SEIIR,
    [0, 1000],
    x0,
    #method = "LSODA", min_step = 1e-3,
    method="RK23",
    args=(u_ori, p, A, A.sbar),
    events=[final_cond])
Ejemplo n.º 3
0
series2 = scipy.integrate.odeint(sir, y0=x0, t=tspan, args=(umax, ))

fig, ax = plt.subplots()
ax.set_xlim(0.4, 1)
ax.set_ylim(0, 0.1 * 1.1)
ax.plot(series[:, 0], series[:, 1], color="xkcd:blue")
ax.plot(series2[:, 0], series2[:, 1], color="xkcd:red")

#%%
ireal = 0.1
ureal = 0.5
greal = 0.1
breal = 0.3
Re = SIR.SIR()
Re.set_params([ireal, ureal, greal, breal], flag="bg")
SIR.find_commutation_curve(Re)

iest = 0.1
uest = 0.5
gest = 0.2
best = 0.5
Est = SIR.SIR()
Est.set_params([iest, uest, gest, best], flag="bg")
SIR.find_commutation_curve(Est)

fig, ax = plt.subplots()
ax.set_xlim(min([Re.sbar, Est.sbar]), 1)
ax.set_ylim(0, max([Re.imax, Est.imax]) * 1.1)
ax.plot(Re.tau.s, Re.tau.i, "b:")
ax.plot(Re.phi.s, Re.phi.i, "r:")
ax.plot(Re.commutation_curve[0], Re.commutation_curve[1], "k:")
Ejemplo n.º 4
0
def final_cond(t, state, u_func, evol, crit, term_val):
    out = state[0] - term_val
    return out


final_cond.terminal = True


#%%
imax = 0.1
umax = 0.6
rreal = 3.64
Re = sir.SIR()
Re.set_params([imax, umax, rreal], flag = "r")
sir.find_commutation_curve(Re)

Ab = sir.SIR()
Ab.set_params([imax, umax, rreal * 1.2], flag = "r")
sir.find_commutation_curve(Ab)

Be = sir.SIR()
Be.set_params([imax, umax, rreal * 0.5], flag = "r")
sir.find_commutation_curve(Be)

sbars = [Re.sbar, Ab.sbar, Be.sbar]

#%%
fig, ax = plt.subplots(figsize = (18, 12))
ax.set_xlim(min(sbars), 1)
ax.set_ylim(0, Re.imax * 2)
Ejemplo n.º 5
0
Created on Fri Aug 14 18:37:30 2020

@author: rmm
"""

import sir
import matplotlib.pyplot as plt
import csv

imax = 0.1
r = 3.64
umax = 0.6

A = sir.SIR()
A.set_params([imax, umax, r], flag="r")
sir.find_commutation_curve(A)

fig, ax = plt.subplots()
ax.set_xlim(A.sbar, 1)
ax.set_ylim(0, A.imax * 1.1)
ax.plot(A.tau.s, A.tau.i, "b-")
ax.plot(A.phi.s, A.phi.i, "r-")
ax.plot(A.commutation_curve[0], A.commutation_curve[1], "k-")
ax.plot([A.sbar, 1], [A.imax, A.imax], "k-.")
ax.set_title("imax = {}, umax = {}, R0 = {}".format(imax, umax, r))
fig.savefig("problema_tulio3.jpg", format="jpg")

with open("problema_tulio_3.csv", "w") as f:
    pt = csv.writer(f, delimiter=",")
    pt.writerow(A.commutation_curve[0])
    pt.writerow(A.commutation_curve[1])
Ejemplo n.º 6
0
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 16 20:51:04 2020

@author: rmm
"""

import sir
import matplotlib.pyplot as plt

imax = 0.1
umax = 0.6
r = 1.73
Dyn = sir.SIR()
Dyn.set_params([imax, umax, r], flag = "r")
sir.find_commutation_curve(Dyn)

"""
end = Dyn.phi._curve_sol(5e-4)[0]
s0, i0 = sir.create_initial_conditions(Dyn, 1e-3, 5e-4, end = end)

for s, i in zip(s0, i0):
    Dyn.add_point(s, i)

Dyn.find_regions()
regs = [p.region for p in Dyn.points]

for p in Dyn.points:
    Mx = sir.MinimumTrajectory(p, Dyn)
    Mx.find_commutation()
    p.least_time = Mx.trajectory