The SimBatch simulation model
Anders Ringgaard Kristensen
Department of Large Animal Sciences
The SimBatch simulation model Anders Ringgaard Kristensen - - PowerPoint PPT Presentation
Department of Large Animal Sciences The SimBatch simulation model Anders Ringgaard Kristensen Department of Large Animal Sciences System description A batch of slaughter pigs is simulated from insertion of the batch until slaughter.
Department of Large Animal Sciences
Advanced Quantitative Methods in Herd Management
Department of Large Animal Sciences
Slide 2
Advanced Quantitative Methods in Herd Management
Department of Large Animal Sciences
Slide 3
Advanced Quantitative Methods in Herd Management
Department of Large Animal Sciences
Slide 4
Advanced Quantitative Methods in Herd Management
Department of Large Animal Sciences
Slide 5
Advanced Quantitative Methods in Herd Management
Department of Large Animal Sciences
Slide 6
Advanced Quantitative Methods in Herd Management
Department of Large Animal Sciences
Slide 7
Advanced Quantitative Methods in Herd Management
Department of Large Animal Sciences
Slide 8
Advanced Quantitative Methods in Herd Management
Department of Large Animal Sciences
Slide 9
# Updates the state of a pig updatePig = function(pig, son) { pigNew = rep(NA, 4) If (pig[3] > -2) { # Is the pig still present? pigNew[1] = pig[1] + pig[2] - pig[4] # Yes, calculate new weight pigNew[2] = updateDG(pig[2], son) # Update daily gain if (pig[3] == -1) { # Is the pig healthy now? if (isPigDiseased(son)) { # Yes it was. Should it change state? pigNew[3] = getDiseaseDuration(son) # Yes it should. Draw duration of disease pigNew[4] = getDiseaseEffect(son) # Draw effect of disease } else { # No, the pig remains healthy pigNew[3] = -1 # Define it as healthy pigNew[4] = 0 # No effect of disease } } else { # No, the pig is already diseased if (pig[3] > 0) { # Has it still at least one day left of disease? pigNew[3] = pig[3] - 1; # Yes, reduce the number of days left by one pigNew[4] = pig[4] # Keep the disease effect on daily gain } else { # No, it is the last day of the disease pigNew[3] = -1; # Change state to healthy pigNew[4] = 0 # No disease effect next time } } } else { # The pig is already slaughtered pigNew = pig # Leave it as it is } return(pigNew) }
Advanced Quantitative Methods in Herd Management
Department of Large Animal Sciences
Slide 10
Advanced Quantitative Methods in Herd Management
Department of Large Animal Sciences
Slide 11
# Counts the number of pigs still present in the batch (not slaughtered) pigsLeft = function(batchDay) { left = 0 for (i in 1:length(batchDay[,1])) { if (batchDay[i,3] > -2) { left = left + 1 } } return(left) } Department of Large Animal Sciences
Slide 12
# Applies the decision strategy on the batch a given day selectForSlaughter = function(batchDay, age, dec) { correctedDay = array(NA, dim=c(length(batchDay[,1]), length(batchDay[1,])))
for (i in 1:length(batchDay[,1])) { correctedDay[i,] = batchDay[i,] # Copy pigs to new array
# Get observed weights } leftPigs = pigsLeft(batchDay) # How many pigs are still present if (leftPigs < dec$minimumStock || # Fewer than minimum? age > dec$maximumAge) { # Maximum age exceeded? for (i in 1:length(batchDay[,1])) { # Yes, correctedDay[i,3] = -2 # ... cull the rest } } readyIndexes = which(observedDay >= dec$thresholdWeight) # Find the pigs with observed weights exceeding threshold readyCount = length(readyIndexes) # How many were there if (readyCount < dec$minimumDelivery) { # Are there two few? if (readyCount > dec$minimumDelivery - dec$maximumUnderWeight) { # Yes, but are there so many that we slaughter anyway? sortedVector = sort(observedDay, decreasing = TRUE) # Yes, find the biggest pigs realThres = sortedVector[dec$minimumDelivery] # Find the real threshold readyIndexes = which(observedDay >= realThres) # Pick all pigs exceeding the real threshold for (i in readyIndexes) { correctedDay[i,3] = -2 # Mark them as slaughtered } } } else { # No, there were enough pigs for (i in readyIndexes) { # Pick them correctedDay[i,3] = -2 # Mark them as slaughtered } } return(correctedDay) # Return the pigs with the slaughtered marked }
Advanced Quantitative Methods in Herd Management
Department of Large Animal Sciences
Slide 13
Advanced Quantitative Methods in Herd Management
Department of Large Animal Sciences
Slide 14
Advanced Quantitative Methods in Herd Management
Department of Large Animal Sciences
Slide 15
Advanced Quantitative Methods in Herd Management
Department of Large Animal Sciences
Slide 16
Department of Large Animal Sciences
Advanced Quantitative Methods in Herd Management Slide 17
Advanced Quantitative Methods in Herd Management
Department of Large Animal Sciences
Slide 18