System description A batch of slaughter pigs is simulated from insertion of the batch until The SimBatch simulation model slaughter. The pigs are fed ad libitum. Advanced Herd Management Sent to a Danish slaughter house. Anders Ringgaard Kristensen The highest price per kg is obtained in the “optimal” interval from 70 to 84 kg slaughter weight . Delivery is decided on the basis of observed live weight. The slaughter policy is decided by the farmer Slide 1 Slide 2 State of nature, Φ 0 Model type # State of nature information SimBatch is a stateOfNature = list(initialAverage = 30, # Average weight at insertion • Dynamic (i.e. not static) time stepping model initialStdDev = 2, # Std. deviation of weight at insertion averageDG = 0.900, # Average daily gain with daily updating of the states of the pigs and stdDevDG = 0.100, # Std. dev. of daily gain between pigs the batch. autocorrelationDG = 0.99, # Autocor. for individual daily gain diseaseRisk = 0.01, # Risk of disease any day • Mechanistic (i.e. not empirical) model since it diseaseEffectAve = 0.250, # Average effect of disease models a batch by modeling each individual pig. diseaseEffectStd = 0.030, # Standard deviation of disease effect diseaseDurationAv = 5, # Average duration of disease • Initially it is a deterministic model, but in the liveToSlaughterAv = 0.76, # Live w. to slaughter w. conversion exercise it is step by step transformed into a liveToSlaughterStd = 1.4, # Standard deviation of conversion stochastic model. lowerOptimal = 70, # Lower bound of opt. slaughter weight upperOptimal = 84, # Upper bound of opt. slaughter weight • Monte Carlo simulation model, because the deliverEvery = 7) # Days btw. del.(7 = weekly, 1 = daily) simulation mechanism is based on drawing random numbers from relevant distributions. Slide 3 Slide 4 Decision strategy, Θ Modeling a pig # Decision strategy information A pig is defined by 4 state variables decisionStrategy = list(thresholdWeight = 100, # Intended live weight at slaughter minimumDelivery = 10, # Minimum number of pigs to send to • Live weight in kg maximumUnderWeight = 2, # Acc this number of pigs bel. Thresh. • The gain today in kg (if healthy) minimumStock = 50, # Minimum acc. stock: Send all if below maximumAge = 90) # Maximum age before slaughter • An integer, i , defining the status of the pig: • i = -2: The pig has already been slaughtered # Strategy with completely individual delivery • i = -1: The pig is healthy and still present individualStrategy = list(thresholdWeight = 100, # Intended live weight at slaughter • i ≥ 0: The pig is diseased and will stay diseased i minimumDelivery = 1, # Minimum number of pigs to send to maximumUnderWeight = 0, # Acc this number of pigs bel. thres days yet minimumStock = 0, # Minimum acc. stock: Send all if bel maximumAge = 9999) # Maximum age before slaughter • The effect of disease (if any) on daily gain In SimBatch, a pig is represented on a given day # Strategy with slaughter at a given age by a vector with 4 elements. ageStrategy = list(thresholdWeight = 9999, # Intended live weight at slaughter minimumDelivery = 9999, # Minimum number of pigs to send to The state of the pig is updated every day. maximumUnderWeight = 0, # Acc this number of pigs bel. thres minimumStock = 0, # Minimum acc. stock: Send all if bel maximumAge = 90) # Maximum age before slaughter Slide 5 Slide 6 1
Creating and printing a pig Simple functions used with a pig object getStartW eight( stateOfNature) : A start weight (in kg) is returned. Initially, A valid pig object: it only returns the initial average from the state of nature. > pig = c(45.0, 0.956, 3, 0.123) getI nitialDG( stateOfNature) : An initial daily gain (in kg) for a pig is returned. Initially, it only returns the average daily gain from the state of > pig nature. isPigDiseased( stateOfNature) : Returns a logical value. If the pig gets [ 1] 45.000 0.956 3.000 0.123 diseased it returns TRUE, otherwise FALSE. Initially, it always returns FALSE. getDiseaseEffect( stateOfNature) : Returns the reduction (in kg) of daily gain A pig with a live weight of 45 kg, a gain until during a disease period. Initially it only returns the average disease effect from the state of nature. tomorrow of 956 g (if healthy). It is, however getDiseaseDuration( stateOfNature) : Returns the duration (in days) of a diseased and will stay diseased for 3 days. The new disease. Initially, it only returns the average duration from the state of nature. effect of disease is a reduction in daily gain of getSlaughterW eight( liveW eight, stateOfNature) : Transforms the specified 123 g input parameter liveWeight to slaughter weight (in kg). Initially it just multiplies the live weight with the conversion ratio from the state of nature. getObservedW eight( liveW eight) : Returns the observed live weight of a pig with the specified true live weight. Initially, it just returns the true live weight (ignoring the observation error). updateDG( oldDG, stateOfNature) : Returns a new daily gain for the next 24 hours from the specified “old” daily gain (from the previous 24 hours). Initially, it just returns the old value (without any transform). Slide 7 Slide 8 Function updating a pig (don’t change) Function creating a piglet (don’t change) # Updates the state of a pig updatePig = function(pig, son) { pigNew = rep(NA, 4) # Create a "30 kg" piglet at random If (pig[3] > -2) { # Is the pig still present? pigNew[1] = pig[1] + pig[2] - pig[4] # Yes, calculate new weight createPiglet = function(son) { pigNew[2] = updateDG(pig[2], son) # Update daily gain if (pig[3] == -1) { # Is the pig healthy now? piglet = rep(NA, 4) if (isPigDiseased(son)) { # Yes it was. Should it change state? piglet[ 1] = getStartWeight(son) # Draw initial live weight pigNew[3] = getDiseaseDuration(son) # Yes it should. Draw duration of disease pigNew[4] = getDiseaseEffect(son) # Draw effect of disease piglet[ 2] = getInitialDG(son) # Draw initial daily gain } else { # No, the pig remains healthy piglet[ 3] = -1 # Number of days remaining if diseased pigNew[3] = -1 # Define it as healthy # If "-1": Healthy. If "-2": Slaughtered pigNew[4] = 0 # No effect of disease } piglet[ 4] = 0 # Disease effect on daily gain } else { # No, the pig is already diseased return(piglet) 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) } Slide 9 Slide 10 Function updating a batch (don’t change) Representation of a batch on a given day Just an array of pigs. Exam ple of a batch w ith 5 piglets: # Updates the state of a batch updateBatch = function(batchDay, son) { > pig1 = createPiglet(stateOfNature) newBatchDay = array(NA, dim = c(length(batchDay[ ,1] ), length(batchDay[ 1,] ))) > pig2 = createPiglet(stateOfNature) for (i in 1: length(batchDay[ ,1] )) { # Iterate over pigs > pig3 = createPiglet(stateOfNature) pigDay = batchDay[ i,] # Take the i’th pig > pig4 = createPiglet(stateOfNature) pigDay = updatePig(pigDay, son) # Update it > pig5 = createPiglet(stateOfNature) > batchDay = array(NA, dim = c(5, length(pig1))) newBatchDay[ i,] = pigDay # Insert it in the updated batch > batchDay[ 1,] = pig1 } > batchDay[ 2,] = pig2 return(newBatchDay) # Return the updated batch > batchDay[ 3,] = pig3 } > batchDay[ 4,] = pig4 > batchDay[ 5,] = pig5 Function counting pigs left in a batch (don’t change) > batchDay [ ,1] [ ,2] [ ,3] [ ,4] # Counts the number of pigs still present in the batch (not slaughtered) pigsLeft = function(batchDay) { [ 1,] 29.77745 0.8219607 -1 0 left = 0 [ 2,] 27.78206 0.9373041 -1 0 for (i in 1: length(batchDay[ ,1] )) { [ 3,] 27.52593 0.8217774 -1 0 if (batchDay[ i,3] > -2) { [ 4,] 31.96445 0.9472012 -1 0 left = left + 1 } [ 5,] 30.67659 0.8425552 -1 0 } return(left) } Slide 11 Slide 12 2
Recommend
More recommend