## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----include = FALSE----------------------------------------------------------
library(rescomp)

## ----echo=FALSE, fig.width = 4, fig.height = 3--------------------------------
plot_funcresp(spec_rescomp(
  funcresp = funcresp_type1(crmatrix(0.1)),
  verbose = FALSE
))

## ----echo=FALSE, fig.width = 4, fig.height = 3--------------------------------
plot_funcresp(spec_rescomp(
  funcresp = funcresp_monod(mumax = crmatrix(0.1), ks = crmatrix(0.3)),
  verbose = FALSE
))

## ----echo=FALSE, fig.width = 4, fig.height = 3--------------------------------
plot_funcresp(spec_rescomp(
  funcresp = funcresp_hill(mumax = crmatrix(0.1), ks = crmatrix(0.3), n = crmatrix(2)),
  verbose = FALSE
))

## ----eval=FALSE---------------------------------------------------------------
# library(rescomp)

## -----------------------------------------------------------------------------
pars <- spec_rescomp(
  spnum = 1,
  resnum = 1,
  funcresp = funcresp_monod(mumax = crmatrix(0.12), ks = crmatrix(1)),
  ressupply = ressupply_logistic(r = 3, k = 2),
  rinit = 2,
  totaltime = 500
)

## ----fig.width = 4, fig.height = 3--------------------------------------------
plot_funcresp(pars, maxx = 2)

## -----------------------------------------------------------------------------
m1 <- sim_rescomp(pars)

## ----fig.width = 6, fig.height = 3--------------------------------------------
plot_rescomp(m1)

## -----------------------------------------------------------------------------
m1 <- sim_rescomp(pars, totaltime = 200, cinit = 30000)

## ----fig.width = 6, fig.height = 3--------------------------------------------
plot_rescomp(m1)

## -----------------------------------------------------------------------------
pars <- spec_rescomp(
  spnum = 1,
  resnum = 1,
  funcresp = funcresp_monod(mumax = crmatrix(0.12), ks = crmatrix(1)),
  mort = 0.03,
  ressupply = ressupply_chemostat(dilution = 0.03, concentration = 2),
  rinit = 2,
  totaltime = 300
)

## -----------------------------------------------------------------------------
m1 <- sim_rescomp(pars)

## ----fig.width = 6, fig.height = 3--------------------------------------------
plot_rescomp(m1)

## -----------------------------------------------------------------------------
pars <- spec_rescomp(
  spnum = 2,
  resnum = 1,
  funcresp = funcresp_monod(
    mumax = crmatrix(0.35, 0.05),
    ks = crmatrix(1, 0.015)
  ),
  mort = 0.03,
  ressupply = ressupply_logistic(r = 1, k = 0.2),
  rinit = 0.2,
  totaltime = 2000
)

## ----fig.width = 4, fig.height = 3--------------------------------------------
plot_funcresp(pars, maxx = 0.2)

## -----------------------------------------------------------------------------
m1 <- sim_rescomp(pars)

## ----fig.width = 6, fig.height = 3--------------------------------------------
plot_rescomp(m1)

## -----------------------------------------------------------------------------
pars <- spec_rescomp(
  spnum = 2,
  resnum = 2,
  funcresp = funcresp_type1(crmatrix(
    0.09, 0.04,
    0.05, 0.08
  )),
  ressupply = ressupply_chemostat(dilution = 0.03, concentration = 1),
  mort = 0.03,
  essential = FALSE,
  totaltime = 1000
)

## ----fig.width = 6, fig.height = 3--------------------------------------------
plot_funcresp(pars, maxx = 1)

## -----------------------------------------------------------------------------
m1 <- sim_rescomp(pars)

## ----fig.width = 6, fig.height = 3--------------------------------------------
plot_rescomp(m1)

## -----------------------------------------------------------------------------
pars$essential <- TRUE
m1 <- sim_rescomp(pars)

## ----fig.width = 6, fig.height = 3--------------------------------------------
plot_rescomp(m1)

## -----------------------------------------------------------------------------
pars <- spec_rescomp(
  spnum = 2,
  resnum = 2,
  funcresp = funcresp_type1(crmatrix(
    0.09, 0.04,
    0.05, 0.08
  )),
  quota = crmatrix(
    0.001, 0.005,
    0.005, 0.001
  ),
  ressupply = ressupply_chemostat(dilution = 0.03, concentration = 1),
  mort = 0.03,
  essential = TRUE
)

## -----------------------------------------------------------------------------
m1 <- sim_rescomp(pars)

## ----fig.width = 6, fig.height = 3--------------------------------------------
plot_rescomp(m1)

## -----------------------------------------------------------------------------
pars <- spec_rescomp(
  spnum = 2,
  resnum = 1,
  funcresp = funcresp_monod(
    mumax = crmatrix(0.7, 0.05),
    ks = crmatrix(2, 0.015)
  ),
  ressupply = ressupply_constant(0),
  events = list(
    event_schedule_periodic(
      event_res_add(0.3),
      period = 100
    )
  )
)

## ----fig.width = 4, fig.height = 3--------------------------------------------
plot_funcresp(pars, maxx = 0.3)

## -----------------------------------------------------------------------------
m1 <- sim_rescomp(pars)

## ----fig.width = 6, fig.height = 3--------------------------------------------
plot_rescomp(m1)

## -----------------------------------------------------------------------------
pars <- spec_rescomp(
  spnum = 2,
  resnum = 1,
  funcresp = funcresp_monod(
    mumax = crmatrix(0.2, 0.2),
    ks = crmatrix(0.3, 0.2)
  ),
  ressupply = ressupply_constant(0),
  mort = 0,
  events = list(
    event_schedule_periodic(
      event_batch_transfer(dilution = 0.2, resources = 1),
      period = 100
    )
  ),
  rinit = 0.6
)

## ----fig.width = 4, fig.height = 3--------------------------------------------
plot_funcresp(pars, maxx = 1)

## -----------------------------------------------------------------------------
m1 <- sim_rescomp(pars)

## ----fig.width = 6, fig.height = 3--------------------------------------------
plot_rescomp(m1)

## -----------------------------------------------------------------------------
pars <- spec_rescomp(ressupply = ressupply_constant(0), mort = 0, totaltime = 500)
m1 <- sim_rescomp(pars)

## ----fig.width = 6, fig.height = 3--------------------------------------------
plot_rescomp(m1)

## -----------------------------------------------------------------------------
pars <- spec_rescomp(
  spnum = 2,
  resnum = 1,
  funcresp = funcresp_monod(
    mumax = rescomp_coefs_lerp(
      crmatrix(0.2, 0.5),
      crmatrix(0.3, 0.1),
      "env_state"
    ),
    ks = crmatrix(0.1)
  ),
  params = list(
    env_state = rescomp_param_square(period = 100)
  ),
  ressupply = ressupply_chemostat(dilution = 0.03, concentration = 0.1),
  rinit = 0.1,
  mort = 0.03,
  totaltime = 2000
)

## ----fig.width = 6, fig.height = 3--------------------------------------------
plot_funcresp(pars, maxx = max(pars$rinit))

## -----------------------------------------------------------------------------
m1 <- sim_rescomp(pars)

## ----fig.width = 6, fig.height = 3--------------------------------------------
plot_rescomp(m1)

## -----------------------------------------------------------------------------
pars <- spec_rescomp(
  spnum = 3,
  resnum = 3,
  funcresp = funcresp_type1(crmatrix(
    0.11, 0.07, 0.045,
    0.05, 0.11, 0.07,
    0.07, 0.047, 0.1
  )),
  quota = crmatrix(
    0.2, 0.7, 0.4,
    0.4, 0.2, 0.7,
    0.7, 0.4, 0.2
  ),
  ressupply = ressupply_logistic(r = 10, k = 0.5),
  rinit = 0.5,
  mort = 0.015,
  essential = TRUE,
  totaltime = 2000
)

## ----fig.width = 4, fig.height = 5--------------------------------------------
plot_funcresp(pars, maxx = max(pars$rinit))

## -----------------------------------------------------------------------------
m1 <- sim_rescomp(pars)

## ----fig.width = 6, fig.height = 3--------------------------------------------
plot_rescomp(m1)

