# NOT RUN {
## -----------
## define model parameters
## Define the annual probability of a failure
prob.failure.exp <- function(age, age.last.failure, n.failure) {
if(n.failure==0){
return(1/30)
} else {
return(1/10)
}
}
## define a complicated (and probably useless) rehabilitation strategy
mystrategy <- . %>%
replace.n.highest.risk(n=2, prob.failure=prob.failure.exp) %>%
replace.more.failures.than(failures=5) %>%
replace.older.than(age=70, max.cost=2e6) %>%
replace.n.oldest(n=3) %>%
replace.n.random(n=2)
## This means: every year (if we have enough budget!), replace first the 2 pipes
## with the highest risk, then all pipes with more than 5 failures,
## then all pipes older then 70 years (up to costs of 2e6), then the 3
## oldest pipes remaining, and finally replace 2 randomly selected pipes.
## -----------
## run the simulation in steps
statelist <- initiate.network(inventory = 50, budget = 1e7)
statelist <- simulate_network.period(
statelist, # state list to update
n.years = 20, # run it for 20 years
expansion = 10, # build 10 pipes per year (if money is available)
rehabilitation = mystrategy, # use the strategy defined above
prob.failure = prob.failure.exp, # use the probability function defined above
income = 1e6 # the annual income
)
statelist <- simulate_network.period(
statelist, # state list to update
n.years = 10, # run it for 10 more years
expansion = 2, # now, build only 2 pipes per year (if money is available)
rehabilitation = mystrategy, # use the strategy defined above
prob.failure = prob.failure.exp, # use the probability function defined above
income = 1e6 # the annual income
)
## look at some results
## str(statelist)
## str(statelist$time.30)
# }
Run the code above in your browser using DataLab