Want to create time series for the nuclear power plant performance using the equation for Time to fail and time to repair for 8736 hours in the year so that I have the time series in hours when the generator is operating in when is not. The starting condition is that the generator is operating on the first hour.
For sure there is a more elegant solution for simulating this I'm just not able to find it. Any comment or help will be appreciated. The code is working but I think there is a better solution
TTF<-2940 # MEDIUM TIME TO FAIL(hours)
MTTR<-60 # MEDIUM TIME TO REPAIR (hours)
TTF<--MTTF*log(runif(100))# equation for Time to fail
TTR<--MTTR*log(runif(100))# equation for Time to repair
mix<-rep(0,length(TTF)+length(TTR))
sw<-rep(0,length(TTF)+length(TTR))
for(i in 1:length(TTF)){
mix[2*i-1]<-TTF[i]
sw[2*i-1]<-1
mix[2*i]<-TTR[i]
}
cmix<-cumsum(mix)
ccmix<-cbind(cmix[1:which(cmix>8736)],sw[1:which(cmix>8736)])
ccmix[dim(ccmix)[1],1]<-8736
G1<-round(ccmix)
# transform binary values
G1[,2][G1[,2] == 1] <- 400 # 400 MW is the capacity of power plant
G1 <- cbind(G1, c(G1[1,1], diff(G1[,1])))
a1 <- rep(G1[,2], G1[,3]) ## GENERATING 8736 Values
So the desired output are 8736 values of 400 when is ON and 0 when is OFF. Finally I need to simulate 100000 years of generation.