optimization of delivery strategies for slaughter pigs

121
Optimization of delivery strategies for slaughter pigs Master thesis by Merete Stenner Hansen L10457 48 Points (ECTS) February 2006 Supervisor: Anders Ringgaard Kristensen Department of Large Animal Sciences Royal Veterinary and Agricultural University Grønnegårdsvej 2 DK-1870 Frederiksberg C Denmark

Upload: others

Post on 25-Oct-2021

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Optimization of delivery strategies for slaughter pigs

Optimization of delivery strategies forslaughter pigs

Master thesisby

Merete Stenner HansenL10457

48 Points (ECTS)February 2006

Supervisor:Anders Ringgaard Kristensen

Department of Large Animal SciencesRoyal Veterinary and Agricultural University

Grønnegårdsvej 2DK-1870 Frederiksberg C

Denmark

Page 2: Optimization of delivery strategies for slaughter pigs
Page 3: Optimization of delivery strategies for slaughter pigs

Abstract

With the current pressure on pig production to be more and more effective in orderto still be profitable, a big effort is put into developing systems that can increaseefficiency and/or decrease the demand for man hours. One such system is auto-matic weighing equipment. In order to get the most of an investment in automaticweighing equipment, a decision support system (DSS) may be used.

The DSS developed here, called PigLimid, is based on “LImited Memory Influ-ence Diagrams” (LIMIDs). The LIMID uses single policy updating (SPU) to findlocally optimal strategies. The PigLimid constructed here assumes, that the farmhas single pig registration, so individual weight data is available from all pigsduring the finishing period. The model is build to handle up to 16 pigs in a pen.Issues arose regarding the ressource consumption during optimization. If theseproblems are resolved, possibly by implementation of object orientation, LIMIDsmight be a good way of developing a DSS for slaughter pig marketing. Such aLIMID might also be incorporated as part of e.g. a bigger DSS based on MultiLevel Hierarchic Markov Processes.

Resume

Svineproducenterne er under et stort pres for at være konkurrencedygtige. Dettegør, at der bliver brugt store ressourcer på at udvikle værktøjer der kan højne ef-fektiviten og mindske antallet af mandetimer i produktionen. Et eksempel er etautomatiske vejesystemer. For at få mest muligt ud af en investering i et automa-tisk vejesystem kan anvendelse af et beslutningstøtteværktøj (Decicion supportsystem, DSS) være aktuelt.

Det DSS som er udviklet i dette projekt, PigLimid, benytter “LImited MemoryInfluence Diagrams” (LIMIDs). LIMIDs bruger single policy updating (SPU) forat udregne lokalt optimale strategier. PigLimid forudsætter at producenten harenkeltgris registrering, således at individuelle vægt data er tilgængelige for allegrisene i perioden op til slagtningen. Modellen kan håndtere op til 16 grise i ensti.

Systemets begrænsningen viste sig i ressourceforbruget under optimeringsudreg-ningerne. Når denne begrænsning omgås, muligvis ved at ombygge systemet tilat være objekt orienteret, kan LIMIDs være en god model for udvikle et DSS tilgriseproduktion. LIMID systemer kunne også indbygges i et DSS med en størretidshorisont, evt. baseret på Multi Level Hierakiske Markov processer.

Page 4: Optimization of delivery strategies for slaughter pigs
Page 5: Optimization of delivery strategies for slaughter pigs

Preface

This Master thesis is written as the final part of my education in agricultural sci-ences, at the Royal Veterinary and Agricultural University.The CD included with this reports contains the following

• The “Esthauge LIMID software system” as the Limid.jar file and associatedlicense file.

• The report as a pdf file.

• The PigLimid.java file

• Several examples of LIMIDs generated from the PigLimid.

I would Like to thank my supervisor Anders Ringaard Kristensen for his help andsupport during this project.

Merete Stenner HansenKVL 28. february 2006

v

Page 6: Optimization of delivery strategies for slaughter pigs
Page 7: Optimization of delivery strategies for slaughter pigs

Contents

1 Introduction 11.1 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.2 The problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2 LIMIDs 92.1 The structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.2 Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

2.2.1 Moralization . . . . . . . . . . . . . . . . . . . . . . . . 122.2.2 Triangulation . . . . . . . . . . . . . . . . . . . . . . . . 132.2.3 Identification of cliques and construction of junction tree . 142.2.4 Elimination in junction trees . . . . . . . . . . . . . . . . 152.2.5 Single policy updating . . . . . . . . . . . . . . . . . . . 15

3 Model basis 173.1 The production system . . . . . . . . . . . . . . . . . . . . . . . 173.2 The parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . 183.3 Available data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

3.3.1 Group registration . . . . . . . . . . . . . . . . . . . . . 203.3.2 Single pig registration . . . . . . . . . . . . . . . . . . . 213.3.3 Feed consumption . . . . . . . . . . . . . . . . . . . . . 21

3.4 Level of decision . . . . . . . . . . . . . . . . . . . . . . . . . . 21

4 Modelling the pig 234.1 Growth parameters . . . . . . . . . . . . . . . . . . . . . . . . . 234.2 Feed parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . 264.3 Price parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . 274.4 Pen size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

5 Building the LIMID 315.1 One pig . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

5.1.1 Nodes and edges . . . . . . . . . . . . . . . . . . . . . . 32

vii

Page 8: Optimization of delivery strategies for slaughter pigs

viii CONTENTS

5.1.2 Potential tables . . . . . . . . . . . . . . . . . . . . . . . 365.2 Several pigs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

5.2.1 Model problems . . . . . . . . . . . . . . . . . . . . . . 39

6 Verification and validation of model 416.1 Conceptual model validity . . . . . . . . . . . . . . . . . . . . . 426.2 Computerized model verification . . . . . . . . . . . . . . . . . . 436.3 Operational validity . . . . . . . . . . . . . . . . . . . . . . . . . 436.4 Data validity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436.5 Results of verification and validation . . . . . . . . . . . . . . . . 44

6.5.1 Conceptual model validity . . . . . . . . . . . . . . . . . 446.5.2 Computerized model verification . . . . . . . . . . . . . . 446.5.3 Operational validity . . . . . . . . . . . . . . . . . . . . 46

6.6 Conclusions of the verification and validation . . . . . . . . . . . 47

7 Evaluation of parameter sensibility 497.1 Feed efficiency and price . . . . . . . . . . . . . . . . . . . . . . 497.2 Standard deviation . . . . . . . . . . . . . . . . . . . . . . . . . 507.3 Number of pigs left . . . . . . . . . . . . . . . . . . . . . . . . . 537.4 Start - and termination week . . . . . . . . . . . . . . . . . . . . 537.5 Conclusions of the evaluation . . . . . . . . . . . . . . . . . . . . 54

8 Discussion 558.1 Modelling of the pig . . . . . . . . . . . . . . . . . . . . . . . . 558.2 Building the LIMID . . . . . . . . . . . . . . . . . . . . . . . . . 568.3 Future perspectives . . . . . . . . . . . . . . . . . . . . . . . . . 57

9 Conclusions 59

A Verification log 63

B Code 85

Page 9: Optimization of delivery strategies for slaughter pigs

Chapter 1

Introduction

The profit from pig production will be affected by many parameters including theprice of feedstuffs, meat price and farm management. In order to effectively in-crease the profit, the farmer must decide which parameters to focus on. The meatprice is, with the current Danish pricing system, beyond the farmers direct influ-ence, whereas the feed price might be altered through different feeding systems(e.g. wet or dry) or change of supplier. Other important management parametersare feeding intensity, weight at insertion in the finishing unit, stocking intensity,pen size and weight at delivery to slaughter. Even small changes in these param-eters may have a significant effect, and this will be especially important when theslaughter price is low.

Weight at delivery is one of the parameters that influence the profit. The priceof the slaughtered pig is based on the slaughter weight. The price per kilogramis reduced if the pig is outside the optimal weight interval of 70.0 to 84.9 kgslaughtered weight (Danish Crown, 2005). Often, the live weights of the pigsare estimated by the farmer by looking at the pigs, and based on his experience,he decides which ones are slaughtered that week. Another more accurate, butalso more time consuming way is to put the pigs on a scale, and get an accuratemeasure either of all the pigs or of a representative sample.

These methods are either inaccurate or time and labour consuming. Consequentlyit may be profitable to develop faster, easier and more accurate systems. Currentlysystems with mechanical scales in the pen, and weight estimation from videosurveillance (the PigVision project) is under development.

A typical reduction in the price per pig is 5 to 15 DKK. This is based on lean meat

1

Page 10: Optimization of delivery strategies for slaughter pigs

2 CHAPTER 1. INTRODUCTION

percentage, illnesses and slaughter weight. Usually slaughter weight is the maincontributor to the reduction (Rasmussen, 2004).

When the farmer has access to weight data with a known precision, it will bepossible to deliver most of the pigs in the weight interval with the highest priceper kilogram. This is, however, not necessarily the optimal time for all pigs, asmultiple parameters affects the gross margin per pig or pen, some of these are:

• Weight of the pig

• Meat price according to slaughter weight

• Feed consumption and price

• Lean percentage in the pig

• Housing capacity

• Supply of young pigs

In order to maximize the profit, the farmer must include as many of these param-eters as possible when deciding the slaughter week of each pig. With currentlyavailable farm management systems such as AgroSoft or Bedriftsløsningen com-bined with an automatic weighing system, most of these data are available. Un-fortunately the large amount data makes the decision process rather overwhelm-ing and the necessary calculations are often impossible without assistance from acomputer system.

This is were a computer based decision support system (DSS) is applicable. Awell designed DSS helps the farmer to more closely optimize decisions based onthe many parameters and large amounts of information.

Good decision support systems are able to combine information about the differ-ent parameters. Through one or more of several available mathematical methods,they calculate the utility value of different decisions. The utility value of a deci-sion is often interpreted as the monetary value, but it is possible to assign otherthings a utility value as well. If a farmer priorities increased spare time higherthan increased profit, it will be appropriate to assign a positive utility value tospare time (or a negative value to increased work load), then the optimal decision(maximal utility value) will not necessarily be the one with the highest profit.

Several more or less complex systems have been created in an attempt to maxi-mize the profit from slaughter pig production. Roemen and de Klein (2000) made

Page 11: Optimization of delivery strategies for slaughter pigs

3

a model of the relation between the slaughter price and optimal age at slaughter.Their model aimed to describe how slaughter strategies change with the slaugh-ter price. It did not take into account the differentiated meat prices according toslaughter weight, and is thus not very compatible with the Danish pricing system.

Kure (1997) wanted to solve the “slaughter pig marketing management problem”by incorporating the already registered data from the farm in a marketing manage-ment support tool consisting of a belief management system and a DSS. A beliefmanagement system is a system, that analyses farm data and uses them to updatethe beliefs in the future production. These beliefs are used to update the probabil-ities used in a corresponding DSS. Kure (1997) concluded, that his models mightbe used to make general guidelines, and if more relevant data on individual pigswere available they could be used for a marketing management support tool.

Jørgensen (1993) investigated the effects of weighing precision on delivery de-cisions and the value of increased precision. The conclusion was that the valueof increased precision is low, especially in pens with many pigs. He also com-mented, that the weighing data should not only be used for the decisions concern-ing the current pen, but should be used to update the future beliefs in the state ofthe herd, and ideally be combined with data from the automatic feeding system.

Toft et al. (2005) created a DSS to both find the optimal time of slaughter andprovide a control strategy for infectious diseases. The decisions were made onbatch level, where one batch is a section of pigs from insertion to delivery. Thedelivery decisions consisted of how many of the heaviest pigs (in multiplums of40) to deliver in each of the four weeks, where delivery was possible. The systemwas able to present a strategy for delivery based on the level of infection in thecurrent batch, but the disease model used was too simplified to be implementedas it was.

Several attempts have been made at developing a functional DSS, but at the mo-ment there is no such system on the market, but a system is under development aspart of the PigVision project. One of the things both Jørgensen (1993) and Kure(1997) wanted was more information about the herds and an integrated systemwhere all the relevant data were stored. This is (and was) done in programs suchas Bedriftsløsningen or AgroSoft. With the increasing amount of electronic con-trolled systems, such as feeding systems, an increasing amount of farm specificdata is available to calibrate the DSS. These data combined with frequent weightdata from a non-labour intensive weighing system constitutes a good foundationfor developing a useful DSS.

Page 12: Optimization of delivery strategies for slaughter pigs

4 CHAPTER 1. INTRODUCTION

1.1 Theory

There are several available methods for creating DSSs, they all have differentstrengths and weaknesses, and are useful for different problems.

The methods can be separated into two distinct types, those that model the system,and those that model the expert who would traditionally be consulted in order tosolve the problem. An example of the latter is “rule based expert systems”, theymake decisions based on extensive databases containing rules and knowledge. Ifthe database is well developed, the system is able to make rather accurate deci-sions. Since the decisions are based on databases containing as much existingknowledge as possible about the given problem, it is a very useful diagnostic tool.One of its disadvantages is, that it is not well equipped to handle uncertainties(Kristensen and Jørgensen, 1996). The rule based systems will not be consideredfurther in this thesis.

The methods, that models the system instead of the expert, may be divided into de-terministic and stochastic methods, the deterministic methods are the ones wherethe outcome of a given decision can be predicted with certainty, and for thestochastic methods, the outcome of a decision will predicted with some degreeof uncertainty.

A widely used deterministic method is linear programming. It optimizes a prob-lem under given restraints and rewards. In the farming industry, it is a commontool in ration formulations, where it can find the most cost effective combinationof available feedstuffs, that covers the requirements of the animals. But, as is thenature of deterministic methods, it can not handle uncertainties (Kristensen andJørgensen, 1996). Optimization through linear programming usually comes as abuilt in tool in spreadsheet programs, and is hence readily available.

The stochastic methods can be further subdivided into probabilistic methods andMonte Carlo methods. In Monte Carlo simulations, the model draws random val-ues (based on the probability distribution of the variables) for each input variable.Then it calculates the output of the specific combination of variables. By go-ing through this procedure many times, the simulations are able to determine thedistribution of the output variables (Kristensen and Jørgensen, 1996).

The probabilistic methods includes dynamic programming with the use of theMarkov chain method and the inherently static methods of Bayesian networksand influence diagrams. The static methods are adapted through the use of severalstages (time steps) to be able to represent dynamic systems.

Page 13: Optimization of delivery strategies for slaughter pigs

1.1. THEORY 5

Dynamic programming is a way of finding optimal strategies for decision prob-lems over several stages. At each stage the state of the unit (i.e. pig) is observed,and a decision is made, that affects the probability distribution of possible statesat the next stage. Each possible decision has a utility value, and the aim of thestrategy is to maximize the utility value over time. The strategy consists of the setof decisions for each combination of state and stage, that gives the optimal utilityvalue.

When the planning horizon is finite, the strategy is found through value iteration.With an infinite (or very long) planning horizon, policy iterations may be used in-stead, they can (amongst other possibilities) optimize the average utility value perstage or per output unit. The value and policy iteration methods use the Markovchain, where only the present, and not the past, influences the future (Howard,1960).

If the problem has many stages, and each stage has many possible states, a dy-namic programming model becomes very large, and increasingly difficult to opti-mize. This can be helped by the use of hierarchic Markov Processes (Kristensenand Jørgensen, 2000).

Another way to handle problems with uncertainties is through probabilistic expertsystems based on Bayesian networks. Where the rule based expert system mod-els (and seeks to replace) the expert, the probabilistic expert system models thedomain in order to support the expert in the decision process (Jensen, 1996). TheBayesian network is represented graphically as a directed acyclic graph (DAG) (il-lustrated in figure 1.1) which consists of discrete variables represented as chancenodes (A,B andC) and directed edges between them (Jensen, 2001). A Bayesiannetwork is inherently static, but can handle dynamic problems through the use oftime steps.

Figure 1.1: A Bayesian network

Page 14: Optimization of delivery strategies for slaughter pigs

6 CHAPTER 1. INTRODUCTION

A Bayesian network in itself cannot make decisions. It can only provide proba-bilities for the expert to base his decisions upon. Influence diagrams are based onBayesian networks. In an influence diagram the chance nodes are complementedwith decision and utility nodes. The states in the decision nodes represent thepossible choices in each decision. A utility node represents the utility value of thestates of its parent(s). This gives the possibility of calculating the utility value ofa given decision. In an influence diagram, there must be a directed path contain-ing all decision nodes and determining the order in which the decisions are taken(Jensen, 2001).

The influence diagrams operates under the “no forgetting” assumption, whichmeans, that the past decisions and observations are remembered, and must betaken into account when a decision is made, this can make the decision processoverwhelmingly complex. In order to decrease the complexity the limited mem-ory influence diagram (LIMID) is introduced by Lauritzen and Nilsson (2001).LIMIDs operate like Bayesian networks without the “no forgetting” assumption,so only variables with edges into the decision node are taken into account in thedecision process (Lauritzen and Nilsson, 2001).

LIMIDs are not only less complex than influence diagrams. Due to the fact, thatonly the variables that have just been observed influences a given decision, theyalso allow for different decision makers without full information sharing, or forforgetful decision makers (Lauritzen and Nilsson, 2001).

1.2 The problem

As discussed in the introduction the profit from slaughter pig production may beincreased by delivering the pigs for slaughter at the right time. The right timedoes not only depend on weight, but also on feeding efficiency, growth rate andother parameters. Consequently it will be relevant to develop a DSS to help thefarmer make the optimal slaughter time decision.

This leads to the following problem to be solved:

“How may a decision support system, using LImited Memory Influence Diagrams(LIMIDs), be developed, that helps the farmer find the optimal time of slaughterfor the pigs in a pen, when knowledge of feed consumption and weight throughoutthe growth period is available?”

Page 15: Optimization of delivery strategies for slaughter pigs

1.2. THE PROBLEM 7

The development of the DSS will include the following steps:

• Description of the production system

• Choice of degree of complexity (i.e. which parameters to include)

• Choice of model structure (i.e. single pig or pen)

• Model of pig growth

• Calculation/estimation of parameters

• Building the DSS

• Verification and validation

• Evaluation of parameter sensibility

• Discussion of the DSS

• Conclusion of whether the LIMID can be used to solve the problem

Page 16: Optimization of delivery strategies for slaughter pigs
Page 17: Optimization of delivery strategies for slaughter pigs

Chapter 2

LIMIDs

In the following is described the structure of the LIMID and the decision policies.

2.1 The structure

The limited memory influence diagram consists of chance nodes (representing thediscrete variables), decision nodes and utility nodes. In figure 2.1 a simple LIMIDconsisting of 4 chance nodes (Chance1, Chance2, Chance3, Chance4), a de-cision node (Decision) and a utility node (Utility) is shown.

Traditionally chance nodes are represented as circles, decision nodes as squaresand utility nodes as diamonds. In the “Esthauge LIMID software system” beingused for this project, all nodes are represented as coloured circles. Chance nodesare yellow, decision nodes are green and utility nodes are purple. When shown ingrayscale, the chance nodes are lightest and the utility nodes darkest.

In figure 2.1 variableChance4 is parent of variableChance3 since there is a di-rected edge fromChance4 to Chance3. Chance1 andChance2 are parents ofDecision. Chance3 is the child ofDecision andChance4. Chance1,Chance2andChance3 are the neighbours ofDecision. The neighbours ofDecision to-gether with theDecision node itself forms the family ofDecision (Jensen, 2001).

Each variable has a number of mutually exclusive states, and a correspondingpotential table. Since variableChance4 has no parents, its potential table is theunconditional probabilities ofP (Chance4) shown in figure 2.2.Chance4 has

9

Page 18: Optimization of delivery strategies for slaughter pigs

10 CHAPTER 2. LIMIDS

Figure 2.1: A LIMID

the states A, B and C,Chance1 has the states 1, 2 and 3,Chance2 has the statesX and Y,Chance3 has the states I, II and III, and the decision node has the statesYes and No.

Figure 2.2: The unconditional probabilities ofChance4.

Edges into chance nodes represents the variable’s dependence of the parent, thedependence is quantified in the potential table as illustrated in figure 2.3, wherethe numbers are the conditional probabilities for the states in variable 3 given thestates of the parentsP (Chance3| Decision, Chance4). It does not influence thelayout of the potential table whether the parents are chance or decision nodes.

Edges into decision nodes mean, that the states of the parent nodes must be takeninto account when the decision is made. The decision nodes are only influencedby their parents, and only variables that can be observed are used as parents fordecision nodes(Lauritzen and Nilsson, 2001). Based on the parental states, astrategy for the decision is given, this is illustrated in figure 2.4. In this casethe strategy is Yes for all combinations of states inChance1 andChance2.

The utility nodes can be children of decision nodes if the decision in itself hasa value, or they can be children of chance nodes that have the decision node asparent and hence is affected by the decision. Utility nodes cannot have children(Lauritzen and Nilsson, 2001). A utility node contains a utility table representing

Page 19: Optimization of delivery strategies for slaughter pigs

2.1. THE STRUCTURE 11

Figure 2.3: Potential table for nodeChance3 with parentsDecision andChance4.

Figure 2.4: Decision strategy depending on the states of the parents.

Page 20: Optimization of delivery strategies for slaughter pigs

12 CHAPTER 2. LIMIDS

the utility gained by each parental state (or combinations thereof), an example ofa utility table is given in figure 2.5. The column labelled “Time” is not used in thisversion of the software but is intended for future implementation of discountingutilities (Kristensen, 2003)

Figure 2.5: Utility table of theUtility node.

2.2 Optimization

As opposed to influence diagrams, a LIMID finds an approximately optimal strat-egy (local optimum) instead of a strict optimal strategy (global optimum). In orderto use the LIMID to find approximately optimal solutions to the delivery problem,the LIMID has to be compiled. The compilation consists of the following steps(Lauritzen and Nilsson, 2001):

• Moralization.

• Triangulation.

• Identification of cliques and construction of junction tree.

The result of the compilation is the junction tree that is used for message passingduring the optimization.

2.2.1 Moralization

The moralization adds undirected edges between unconnected nodes with com-mon children and removes direction on existing edges. As shown in figure 2.6

Page 21: Optimization of delivery strategies for slaughter pigs

2.2. OPTIMIZATION 13

an edge is added between nodesChance1 andChance2 and betweenDecisionandChance4, and the directions of the original edges are removed. Furthermoreedges to utility nodes are removed (Jensen, 2001).

Figure 2.6: The simple LIMID after moralization.

2.2.2 Triangulation

Triangulation consists of creating a perfect elimination sequence for the moralgraph. An elimination sequence is the order in which the nodes can be removedfrom the graph without loosing information about the probability distributions ofthe remaining variables. When a node is eliminated, there has to be edges betweenall its neighbours, if an edge is missing it will be added. In a perfect elimination noextra edges are added. A node that can be eliminated without adding extra edgesis called simplicial. In triangulation edges are added so that a perfect eliminationsequence is made through which all nodes can be removed (Jensen, 2001). Themoral graph in figure 2.6 is also triangulated.

As opposed to influence diagrams the nodes of a LIMID can be eliminated inany order (like a Bayesian network). An influence diagram must have a strongelimination order, where the decision nodes are eliminated in reverse order, and achance node must be eliminated between the neighbouring decision nodes in theinfluence diagram.

The triangulation is not a unique process and a graph might be triangulated indifferent ways. The triangulation will affect the complexity of the following op-timization, so it is sensible to choose the triangulation that minimizes the compu-tational costs (Lauritzen and Nilsson, 2001). A method of triangulation is givenby Cowell et al. (1999):

Page 22: Optimization of delivery strategies for slaughter pigs

14 CHAPTER 2. LIMIDS

One-step look ahead triangulation

– Start with all nodes unnumbered, set counteri:=k, wherek is the num-ber of nodes.

– While there are still unnumbered nodes:

∗ Select an unnumbered noden to optimize the criterionc(n).

∗ Label it with the numberi, i.e. letni:=n.

∗ Form the setCi consisting ofni and its unnumbered neighbours.

∗ Fill in missing edges between all nodes inCi.

∗ Eliminateni and decrementi by 1.

The optimality criterionc(n) can be the number of fill in edges required for agiven node or the cardinality of the joint state space ofCi (Cowell et al., 1999).In this case the minimal cardinality criterion is used in order to choose the trian-gulation that produces the smallest joint potential tables.

2.2.3 Identification of cliques and construction of junction tree

A clique is defined as a complete node set that is not a subset of another completeset. A complete node set is a set of nodes that are all pairwise linked (Jensen,2001). The triangulated graph in figure 2.6 has two cliques:

1. Chance1, Chance2 andDecision

2. Chance4, Chance3 andDecision

Decision is called a separator. A separator is the remaining nodes in a cliqueafter the nodes in the clique, that only had neighbours in the clique, have beeneliminated (Jensen, 2001). The nodes in a clique, that are not in the separator, aresimplicial.

When the cliques and separators have been identified, the junction tree can becreated. In the making of the junction tree edges are added between a cliquewhose separator is part of another clique and that clique. A junction tree for thegraph in figure 2.6 is shown in figure 2.7.

Page 23: Optimization of delivery strategies for slaughter pigs

2.2. OPTIMIZATION 15

Figure 2.7: The junction tree of the LIMID in figure 2.1.

2.2.4 Elimination in junction trees

After constructing the junction tree, the elimination sequence can be establishedby repeatedly eliminating the simplicial nodes. The nodes in figure 2.6 can beeliminated in the following sequence:

1. Chance1

2. Chance2

3. Decision

4. Chance4

5. Chance3

From the beginning all the chance nodes are simplicial and the elimination mightstart with anyone of them. After eliminatingChance1 andChance2 Decisionbecomes simplicial and can also be eliminated.

Before the junction tree can be used in the optimization, it must be initialized asdescribed in Lauritzen and Nilsson (2001), the corresponding mathematics willnot be described here.

2.2.5 Single policy updating

The single policy updating (SPU) is the tool used to optimize the LIMIDs. SPUcan find locally optimal decision strategies. This means, that at a local maximumno single change of policy can increase the utility value. SPU uses message pass-ing in the junction tree created in the compilation (Lauritzen and Nilsson, 2001).

Page 24: Optimization of delivery strategies for slaughter pigs

16 CHAPTER 2. LIMIDS

During the SPU the LIMID is treated as a single action network. This means thatthe decisions are optimized one at a time. The last decision is considered first (thisis not mandatory) and the optimal decision policy is found based on the initialvalues of the preceding decisions. Then the second last decision is optimized andso on until all decisions have been optimized. The process is iterative, and afterconsidering all decisions the optimization is repeated based on the new decisionpolicies. This is repeated until convergence (Jensen, 2001).

The junction tree is used for message passing during the SPU. Message passingcan consist of the algorithms calledCollectEvidenceandDistributeEvidence, inSPU onlyCollectEvidenceis used. DuringCollectEvidencethe potentials andcorresponding utility values from all the nodes are marginalized down on thecollecting clique (the clique containing the current decision node).

The marginalization starts in the leaf cliques of the junction tree, where all poten-tials are marginalized down on the separator, this is repeated until all potentialshave been marginalized down on the selected clique. Then the potentials of thecollecting clique are marginalized down on the parents of the decision node, andfor each combination of parent states the decision with the highest utility value ischosen, then the process is repeated with the next decision node until convergence(Jensen, 1996).

Page 25: Optimization of delivery strategies for slaughter pigs

Chapter 3

Model basis

The first step in the development of the DSS is the definition of the basis for themodel. This includes:

• The production system the model applies to.

• Which parameters to include when modelling the pig.

• Assumptions concerning data availability.

• Whether to model a pen as one unit or as a number of individually modeledpigs.

3.1 The production system

The problem will be solved for a specific production system and the solutionmight then later on be altered to be used with other systems as well.

The following assumptions are made regarding the production system.

• Start weight -The new pigs will have a weight at insertion of approximately 30kg, with a standard deviation of 1.5 kg

• Weeks for delivery -Each pen will be emptied over 4 weeks, and the pen mustbe empty before insertion of new pigs.

17

Page 26: Optimization of delivery strategies for slaughter pigs

18 CHAPTER 3. MODEL BASIS

• Production type -The production is of standard pigs, not UK, Antonius or anotherspeciality, and the pigs are mixed gilts and castrates.

• Pen size -There is a maximum of 16 pigs per pen.

• Weighing -The pen has an automatic weighing system.

• Feeding regime -The pigs are fed ad lib pelleted dry feed.

3.2 The parameters

As mentioned in the introduction, there are many parameters influencing thegrowth of a slaughter pig and the optimal time of slaughter. It is necessary todecide which parameters to include in the model, since it will be extremely com-plex (and practically impossible) to include every parameter. The parameters canbe split into different categories

• Pig growth

• Farm

• Economy

The parameters concerning pig growth are:

• Weight of the pig (or pen average) from insertion in finishing unit to timeof decision -This parameter is of vital importance to the DSS since it is the foun-dation for the beliefs in slaughter weight, weight next week and feed efficiency.

• Average growth rate of the herd -This can be used to help estimate the futureweight.

• Feeding regime -E.g. wet or dry feed, and ad lib or restricted. It will influenceboth growth rate and feed efficiency.

• Feed efficiency -Helps predict the amount of feed necessary for the expectedgrowth.

• Feed consumption -Influences growth and production costs.

Page 27: Optimization of delivery strategies for slaughter pigs

3.2. THE PARAMETERS 19

Since the purpose of the DSS is to decide when to slaughter the pigs in orderto maximize profit, the weight and growth rate will have to be included, as theslaughter price is based on the weight, and the growth rate is needed in orderto predict the weight in the coming weeks. The feeding regime will influencethe beliefs concerning growth rate and feed efficiency. Since it (in the decisionperiod) is a fixed parameter, it will not be directly included in the model, but theassumptions about the production system will have to include a choice of feedingregime in order to effectively predict future feed consumption and growth. Theexpected feed efficiency and the measured consumption directly influences thecost of the production, and will have to be included in the model.

The farm related parameters

• Pen size and stocking rate -Influences the growth of the pigs and might resultin a minimum number of pigs that must be delivered in the first week.

• Illnesses in the herd -Influences the growth rate and feed consumption and mightinfluence meat price.

• Supply of young pigs -If the supply is flexible (own piglet production) it mightbe possible to increase profit by terminating a batch of pigs one week earlier thanusual.

Of the farm related parameters only pen size will be included as it determineshow many pigs the model will have to be able to include. It will be assumed,that the stocking rate will not force a number of pigs to be delivered in the firstweek. Illnesses in the herd influences the possible profit, but is not crucial for thefunctionality of the model, and will not be included.

To include a flexible supply of young pigs in the model gives the possibility toterminate the pen earlier than normal and then insert a new batch of pigs. Whichincreases the number of pigs produced per time unit, and might increase the profitper time unit. This increases the dynamics of the model, and will be included.

In order to make a DSS that can maximize the farmers profit (economy is the onlyutility factor in this model), it is necessary to include the parameters that directlyinfluence the expenses or income of the production, these are

• Meat price according to slaughter weight -This is necessary in order to calcu-late the income from the production. And the price deduction outside the optimalweight interval will influence the optimal time of slaughter.

Page 28: Optimization of delivery strategies for slaughter pigs

20 CHAPTER 3. MODEL BASIS

• Lean percentage in the pig -Influences the meat price.

• Feed price -Helps determine the cost of the production.

• Price of young pigs

Only the lean meat percentage will not be included in the model. It is decided toleave the lean meat percentage out because the prediction is difficult, and it willadd complexity to the model with no guarantee of a better result. The rest of theparameters will be included since they influence the profit directly, and are eitherfixed or predictable.

3.3 Available data

The effectiveness of the DSS and the way it will be constructed depends on thedata available. The quality and nature of the weight data will be determiningfor the structure of the DSS. The weighing systems can be divided into two sub-groups:

• Group registration -With group registration, the weight data is not assigned tospecific pigs. The weight data is used to calculate mean and variation for the pen,and it might be possible to divide the data into a number of groups correspondingto the number of pigs.

• Single pig registration -With single pig registration the pigs are given somesort of ID-tag, which can be identified by the weighing system, so the registeredweights will be assigned to specific pigs.

Whether it is possible to assign data to a specific pig will influence how the modelis to be designed. With individual registration it is possible to decide when todeliver each specific pig, but with group registration it will probably only be pos-sible to decide how many of the heaviest pigs that are going to be delivered in thecurrent week.

3.3.1 Group registration

With group registration in its simplest form, the model will be based solely onmean and variation for the current pen. This means, that each node will represent

Page 29: Optimization of delivery strategies for slaughter pigs

3.4. LEVEL OF DECISION 21

all pigs by the mean and variation. It will then be possible to split the weightsof the pigs (and the other relevant nodes, like feed consumption) into appropriatediscrete intervals and assign probabilities to the intervals. Then it is possible tocalculate the utility value of slaughtering or keeping the pigs in a certain interval.

3.3.2 Single pig registration

If the pigs are registered individually, it will be possible to calculate the utilityvalue for slaughtering or keeping each specific pig. When building the net, it willprobably be best to have the pig specific data (current weight and gain profile)represented in separate nodes for each pig, whereas herd (or pen) specific data(like feed consumption and piglet price) will be represented in nodes that appliesto all pigs.

Since single pig registration gives the most detailed data, and it probably will beavailable as the development of weighing systems continues, it will be assumedthat single pig registration is available for the DSS.

3.3.3 Feed consumption

The accuracy of the feed consumption registration can be anything from farm totalto registrations from each pen (and in the future each pig). It is not necessary toknow which method is used in order to make the DSS, but the precision of thecalculated utility values (and hence the resulting decision) will be influenced bythe method.

It is assumed, that feed consumption, measured as FEsv1, is measured in each penin order to get the most from the use of a DSS.

3.4 Level of decision

The level of decision can be either herd, pen or single pig. If the decision is onherd level, the DSS will provide a general delivery strategy for the entire herd.

1FEsv is the Danish energy unit used in feeding slaughter pigs and lactating sows, 1 FEsvequals 7.72 MJ net energy.

Page 30: Optimization of delivery strategies for slaughter pigs

22 CHAPTER 3. MODEL BASIS

A strategy could include how many pigs to deliver from each pen each week,depending on the stage in the production cycle (from insertion to slaughter) of thepen.

Decisions on pen level determines how many of the largest pigs in the pen toslaughter in the current week, based on the assumed distribution of the parame-ters (like gain and feed consumption) between pigs. If the decisions are made onsingle pig level, the DSS will decide when it is optimal to slaughter each individ-ual pig, this requires individual weight data.

The increased precision in the decision will enhance the complexity of the DSS,but it will hopefully also enhance the value of the decision and hence the increasein profit due to the investment in a weighing system. It is assumed, that theincreased value of the decision justifies the increased complexity from decidingon pig level, hence the decisions in this DSS will be made on pig level. This alsoincreases the value of the assumption of single pig weight registrations.

Page 31: Optimization of delivery strategies for slaughter pigs

Chapter 4

Modelling the pig

In this chapter each parameter included in the model will be defined and de-scribed. The model will be split into one stage for the time from insertion ofthe pigs (t0) until the first potential time of slaughter (tSO), where the weeklyobservations and decisions begins, and a stage for each following week until thetime of termination of the pen (tT ).

The parameters included in the model and their values, symbols and abbreviationsare listed in table 4.1. Where the parameters have random variation, it is assumednormally distributed.

4.1 Growth parameters

In order to predict the growth rate over time, a model for pig growth has to befound. Wellock et al. (2004) did a comparison of different growth models, andcame to the conclusion, that the Gompertz function was the best suited. TheGompertz function shows increased daily weight gain almost until a live weightof 100 kg. After that, the daily gain decreases. Since the Gompertz functionexpresses growth potential and not actual growth in a production herd, it can notbe incorporated directly in the DSS.

Data from Danish herds are consistent with the increase in growth rate in the be-ginning of the finishing period followed by stagnation from 70 to 100 kg (Callesenand Pedersen, 2004), this will be used in the DSS. Since only the last weeks of thefinishing period will be modeled individually, it will be assumed, that the growth

23

Page 32: Optimization of delivery strategies for slaughter pigs

24 CHAPTER 4. MODELLING THE PIG

Table 4.1: Parameters included in the modelParameter Symbol Abbreviation Initial

(in thesis) (in software) valueHerd parametersNumber of pigs per pen np NP 16Time of insertion t0 0Start time of observation, weeks tSO SO 9Last week of observation (latest time of slaughter) tT 12Number of stages ns NS 5Days from decision to slaughter, days d DS 3Mortality rate fromt = t0 to t = tT m MR 0.044Mortality rate fromt = t0 to t = tSO mt0 MR0 0.033Weekly mortality rate fort ≥ tSO mtT MRT 0.004Growth parametersAverage live weight at insertion, kg wt0 LWt = 0 30Current live weight (at weekt), kg wt LWt = tObserved live weight (at weekt), kg woi,t OLWt = tAverage weekly gain fromt = t0 to t = tT , kg g G 6Average weekly gain fort ≤ tSO , kg gt0−tSO G0 5.76Average weekly gain fort ≥ tSO, kg gtSO−tT GT 6.42Growth capacity (at weekt), kg/week gi,t GCt = tSlaughter weight (at weekt), kg wsi,t SWt = tScaling factor forg for t ≤ tSO γgO GF 0.96Scaling factor forg for t ≥ tSO γgT GL 1.07Slaughter factor γs SF 0.763Std. dev. of weight at insertion SigmaWI 1.5Std. dev. of weekly gain σε SigmaGC 0.5Std. dev. of measurement error σe SigmaOW 1.0Std. dev. of calculated slaughter weight ση SigmaSW 1.0Feed parametersAverage Feed efficiency, FEsv/kg f F 2.9Average Feed efficiency fort ≤ tSO , FEsv/kg f t0−tSO F0 2.78Average Feed efficiency fort ≥ tSO, FEsv/kg f tSO−tT FT 3.13Feed efficiency (at weekt), FEsv/kg ft FEt = tFeed consumption (at weekt), FEsv ct FCt = t

Scaling factor forf for t ≤ tSO γfO FF 0.96Scaling factor forf for t ≥ tSO γfT FL 1.08Std. dev. of feed efficiency συ SigmaFE 0.05Std. dev. of feed consumption στ SigmaFC 1.0Price parametersTotal slaughter price, DKK/pig ps SPt = tSlaughter price per kg, DKK/kg pkg SPR 8.70Total Feed price, DKK pf FPt = tFeed price per FEsv, DKK/FEsv pFE FPR 1.10Price of young pigs, DKK/pig pp PP 330Average gross margin per pig, DKK pgm GM 100Value of terminating the pen, DKK pT TV

Page 33: Optimization of delivery strategies for slaughter pigs

4.1. GROWTH PARAMETERS 25

rate in these weeks is constant. The growth model for the DSS will be split intoaverage growth for the weeks before start of observation and average growth forthe weeks after. The average weekly growth rates may be calculated from thetotal average weekly growth rate (g):

gt0−tSO = g · γg0 (4.1)

gtSO−tT = g · γgT (4.2)

wheregt0−tSO andgtSO−tT are average growth rates from time of insertion untilstart of observation, and from start of observation until time of slaughter respec-tively. g is the average growth rate from insertion to slaughter, andγg0 andγgTare the scaling factors calculated as percentage ofg.

The average growth rate,g, is set to 6 kg based on Jultved (2005) and Calle-sen and Pedersen (2004), and the scaling factors,γg0 andγgT , are 0.96 and 1.07respectively and are calculated from the weight data given by Callesen and Ped-ersen (2004). The growth rate and the scaling factors are farm specific and mustbe adjusted accordingly.

The initial weekly growth capacity of each pig (gi,t0) will be based on herd aver-age and then adjusted as individual data are available.

gi,t =

gt0−tSO + εt for t = t0gi,t0 · γgTγg0 + εt for t = tSO

gi,t−1 + εt for t > tSO

(4.3)

whereεt is the random variation in weekly gain over time and it is assumed thatεt ∼ N (0, σ2

ε), i.e. εt is normal distributed with mean 0 and standard deviationσε. σε is approximated to 0.5 based on Callesen (1998), with sufficient weightdata available a farm specific value can (and should) be calculated.

The estimated live weight of an individual pig at each time step (week) (wi,t) iscalculated with use of the growth capacities:

wi,t =

wi,t0 for t = t0wi,t0 + gi,t0 · tSO + νt for t = tSOwi,t−1 + gi,t−1 + νt for t > tSO

(4.4)

Page 34: Optimization of delivery strategies for slaughter pigs

26 CHAPTER 4. MODELLING THE PIG

whereνt ∼ N (0, σ2ν), with σν = σε since the current live weight is the sum of the

previous live weight and the current true growth capacity.

The observed live weight (woi,t) depends on the true live weight and the precisionof the weighing system.

woi,t = wi,t + et, (4.5)

whereet is the measurement error in the weighing system and is assumedet ∼N (0, σ2

e). σe is assumed to be 1.0, which is a rough estimate and depends on theweighing equipment. The influence of the weighing precision on the model willbe evaluated during the evaluation of the model (see chapter 7).

The estimated slaughter weight depends on current live weight, growth capacityand days from decision until slaughter (d):

wsi,t = (wi,t + gi,t · d/7)γs + ηt, (4.6)

Whereγs is the slaughter factor defined as percentage of live weight, andηt isthe variation in slaughter weight for a specific live weight and is assumedηt ∼N (0, σ2

η). The slaughter factor,γs, is set to 0.763 andση is set to 1.0 based onJørgensen (1993).

4.2 Feed parameters

It is assumed, that the average feed efficiency for the pen is calculated each week.Based on that, the feed consumption of each pig is estimated. Similar to thegrowth capacity, the feed efficiency is split into a value before start of observationand one after.

f t0−tSO = f · γf0 (4.7)

f tSO−tT = f · γfT (4.8)

wheref is the average feed efficiency from insertion until slaughter,f t0−tSO andf tSO−tT are the average feed efficiencies from time of insertion until start of obser-vation, and from start of observation until time of slaughter respectively.γf0 and

Page 35: Optimization of delivery strategies for slaughter pigs

4.3. PRICE PARAMETERS 27

γfT are the scaling factors calculated as percentage off . f is set to 2.9 FEsv/kgbased on Jultved (2005) and Callesen and Pedersen (2004). The scaling factors,γf0 andγfT , are calculated to 0.96 and 1.08 respectively based on Callesen andPedersen (2004).

The true feed efficiency (ft) is calculated like the growth capacity:

ft =

f t0−tSO + υt for t = t0 − tSOft0 ·

γftTγft0

+ υt for t = tSO

ft−1 + υt for t > tSO

(4.9)

whereυt is the random variation in feed efficiency over time and it is assumedthatυt ∼ N (0, σ2

υ). συ is estimated to 0.05 based on Jørgensen (1993).

Based onft the feed consumption (ci,t) is estimated as follows:

ci,t =

{(wi,tSO − wi,0)ft0−tSO + (gtSO−tT · d/7)f tSO−tT + τt for t = t0 − tSO(wi,t+1 − wi,t)ft + τt for t ≥ tSO

(4.10)

whereτt is a random variation assumedτt ∼ N (0, σ2τ ), andd is the number of

days from the start of the week (time of decision) until time of slaughter. Inorder to simplify calculations, the feed consumption between the decision and theactual slaughter time is included at the very beginning of the observation period,so the feed consumption for the rest of the stages can be calculated in entire weeksregardless of whether the pig is slaughtered or not.στ is estimated to 1.0 basedon Jørgensen (1993).

4.3 Price parameters

The price parameters include meat price, feed price and the price of young pigs.

The price is also influenced by lean meat percentage. Where the base value is60% and the price is reduced or increased with 0.10 DKK per percentage point(from 48% to 65%) (Danish Crown, 2005). As explained in 3.2 the lean meatbonus is not included in the current model.

Page 36: Optimization of delivery strategies for slaughter pigs

28 CHAPTER 4. MODELLING THE PIG

The slaughter price used in the model is:

psi,t = wsi,tpkg (4.11)

wherepkg is the meat price per kilogram paid by the slaughter house (dependenton slaughter weight, see table 4.2). The price per pig at insertion is approximately330 DKK for a 30 kg pig (Danish Crown, 2005), it is assumed, that all pigs costthe same regardless of the variation in weight.

Table 4.2: Meat price according to slaughtered weight (Danish Crown, 2005)SlaughteredWeight (kg)

Price(DKK/kg)

SlaughteredWeight (kg)

Price(DKK/kg)

SlaughteredWeight (kg)

Price(DKK/kg)

50.0 - 50.9 5.70 61.0 - 61.9 7.80 86.0 - 86.9 8.5051.0 - 51.9 5.90 62.0 - 62.9 7.90 87.0 - 87.9 8.4052.0 - 52.9 6.10 63.0 - 63.9 8.00 88.0 - 88.9 8.3053.0 - 53.9 6.30 64.0 - 64.9 8.10 89.0 - 89.9 8.2054.0 - 54.9 6.50 65.0 - 65.9 8.20 90.0 - 90.9 8.1055.0 - 55.9 6.70 66.0 - 66.9 8.30 91.0 - 91.9 8.0056.0 - 56.9 6.90 67.0 - 67.9 8.40 92.0 - 92.9 7.9057.0 - 57.9 7.10 68.0 - 68.9 8.50 93.0 - 93.9 7.8058.0 - 58.9 7.30 69.0 - 69.9 8.60 94.0 - 99.9 7.7059.0 - 59.9 7.50 70.0 - 84.9 8.70 100.0 - 109.9 7.5060.0 - 60.9 7.70 85.0 - 85.9 8.60

The price of the feed (pFE) is estimated to 1.10 DKK/FEsv. The price of theweekly feed consumption (pfi,t) is:

pfi,t = ci,tpFE (4.12)

The average gross margin per pig,pgm, is used to calculate the value of termi-nating the pen earlier than planned. The gross margin is derived from the modelafter running it, it may also be taken from the farm data when implemented. Inthis case it is set to 100 DKK per pig based on the preliminary results from theLIMID.

pT =pgmnptT

(4.13)

Page 37: Optimization of delivery strategies for slaughter pigs

4.4. PEN SIZE 29

where, the termination value,pT , is the reward given for each week the pen isempty andnp is the number of pigs per pen.

4.4 Pen size

The model will first be build for one pig, but the goal is a model that is able tohandle a pen with 16 pigs.

Page 38: Optimization of delivery strategies for slaughter pigs
Page 39: Optimization of delivery strategies for slaughter pigs

Chapter 5

Building the LIMID

The construction of the LIMID is based on the models described in chapter 4.The LIMID is constructed in the “Esthauge LIMID software system”. In order tomake the LIMID as flexible as possible, a Java program is written, that uses theEsthauge API to generate the LIMID. The PigLimid.java file is included on theCD, and the code can be seen in appendix B. In order to increase the flexibility ofthe model, the PigLimid.java is made as generic as possible, which means that itis possible to change most of the input parameters like weekly gain or feed price.

Each node has a number of states, and the numerical interval represented in eachstate in a node has the same size. The number of states in each node is defined as“number of weight intervals (NWI)” for the weight related nodes (including feedconsumption), and as “number of feed efficiency intervals (NFEI)” for the feedefficiency nodes.

The difference between the states is defined as a function of the standard de-viation, the numeric interval represented in each node is based on a2n-sigmainterval, wheren typical will be 2 or 3. So forn = 2 the node interval is4σ,corresponding to a 95%-confidence interval. Each state is labelled with a singlevalue, but in the potential table calculations, the state is treated as representingthe entire interval between states. The difference between the numerical value ofthe states, and the width of the state interval is the same.

At first the LIMID is designed for just one pig, and then it is expanded to severalpigs. Parameters with variable names an values may be found in table 4.1 p.24

31

Page 40: Optimization of delivery strategies for slaughter pigs

32 CHAPTER 5. BUILDING THE LIMID

5.1 One pig

The LIMID is split into stages, the initial stage corresponds to the weeks frominsertion until start of observation, after that each week is represented as a stage.

5.1.1 Nodes and edges

The LIMID has the following nodes

Chance nodes

– Growth capacity (gi,t, all stages)

– Live weight (wi,t, all stages)

– Observed live weight (woi,t, observed stages)

– Slaughter weight (wsi,t, observed stages)

– Feed efficiency (ft, all stages, observed at pen level)

– Feed consumption (ci,t, all stages but the final)

Decision nodes

– Slaughter (si,t, observed stages)

Utility nodes

– Piglet price (ppi,t, initial stage)

– Slaughter price (psi,t, observed stages)

– Feed price (pfi,t, all stages but the final)

Growth capacity Each stage has a growth capacity node. The growth capac-ity is only parented by the previous growth capacity. The interval in each nodedepends onσε, and the value of the states is based ongt0−tS0

for t = t0 and ongtS0−tT for t ≥ tSO, as shown in equation 4.3. Each growth capacity node hasNWI states.

Page 41: Optimization of delivery strategies for slaughter pigs

5.1. ONE PIG 33

Figure 5.1: The Onepig LIMID

Page 42: Optimization of delivery strategies for slaughter pigs

34 CHAPTER 5. BUILDING THE LIMID

Live Weight The live weight nodes, that represents the true weight of the pig,hasNWI states representing the weight interval, and, except for the first stage,they also have an extra state representing dead or delivered pigs. In agreementwith equation 4.4, the parents of the current live weight is the previous live weightand growth capacity, except the live weight at insertion, which has no parents.Additionally whent > tSO it has the previous Slaughter decision node as parent,in order to handle whether it has been delivered or not.

The calculation of live weight is based on the growth capacity, and at each stagethe average value ofgi,t−1 is added to the average value ofwi,t−1, the lowest valueof gi,t−1 is added to the lowest value ofwi,t−1 and so on. The lowest value ofwi,twill represent a pig, that has had the lowest value ofgi,t through all the precedingstages. Hence the interval represented in each live weight node will increase overstages. The value of the states att = tSO is the summation of the stages betweent = t0 andt = tSO.

Observed live Weight The observed live weight node is where evidence fromthe weighing system about the weight of the pig can be entered. The live weightis parent of the observed live weight at the same stage. The states in each node arethe same as in the corresponding live weight node, since the observed live weightis assumed normal distributed around the true live weight as shown in equation4.5. Fort = t0 the live weight is only registered as the weight at insertion, andthere is no node for observed live weight.

Slaughter Weight The slaughter weight node represents the expected weight atslaughter based on the current live weight and the corresponding growth capacity.It is calculated as shown in equation4.6. It has the same number of states as thelive weight nodes. Besides live weight and growth capacity, it is parented bythe Slaughter decision node, since the slaughter weight is zero if the pig is notslaughtered.

Feed efficiency The feed efficiency is, unlike all other nodes, registered at penlevel. It is parented by the previous feed efficiency node. Fort ≤ tSO the value ofthe states is based onf t0−tS0

and fort ≥ tSO onf tS0−tT as shown in equation4.9.The feed efficiency nodes hasNFEI states, and the interval in each node dependsonσυ.

Page 43: Optimization of delivery strategies for slaughter pigs

5.1. ONE PIG 35

Feed consumption The feed consumption is calculated between slaughter days.Thus the feed consumption in the days from decision in the first week of observa-tions until slaughter in that week is included in the first feed consumption node.Each node represents the feed consumption from the current stage until the next.The node has current feed efficiency, current live weight and live weight at nextstage as parents. The feed consumption in each stage is calculated as shown inequation 4.10.

Each node hasNWI+1 states. The extra state is for no feed consumption, whichis the case if the pig is already dead or if it is delivered in the current week. Sincethe feed consumption nodes includes the time until next weeks slaughter, the finalweek has no feed consumption node, since the pig must be slaughtered then.

Slaughter The Slaughter decision node has the states “Yes” and “No” except att = tT where it has only “Yes” since all remaining pigs must be slaughtered thatweek. The node is only present in the weeks of observation, which is the weekswhere decisions about slaughter is made. The observed live weight (or weightat insertion) of the current and previous stage and the current feed efficiency areparents of theSlaughter? node.

Piglet price The piglet price node is a utility node. It is only present once, andhas the live weight at insertion as parent. It is assumed, that the piglet price is afixed value.

Slaughter price The slaughter price utility node is present at the observedstages, and has the current slaughter weight as parent. The utility value of eachslaughter weight state is the product of the slaughter weight and the correspondingprice per kg (listed in table 4.2) as shown in equation 4.11.

Feed price The feed price is, as its parent the feed consumption, present at allstages but the final. Since the feed price is an expense, the utility value is thenegative product of the value of the feed consumption state and the price perFEsv, as shown in equation 4.12.

Page 44: Optimization of delivery strategies for slaughter pigs

36 CHAPTER 5. BUILDING THE LIMID

5.1.2 Potential tables

The potential table represents the probabilities for each state in the node giventhe state of the parents. The probabilities for the states of the node sums to 1 forevery combination of parent states.

The values in the potential tables are, as assumed earlier, calculated with the useof normal probability distributions.

Equation 5.1 is an example of how the potentials are calculated in the live weightnode fort > tSO.

P (k|i, j) =

P(

(k+0.5·∆w)−(i+j)σε

)· (1−mtT ) for k = 0[

P(

(k+0.5·∆w)−(i+j)σε

)

−P(

(k−0.5·∆w)−(i+j)σε

)]· (1−mtT ) for 0 < k < NWI − 1[

1− P(

(k−0.5·∆w)−(i+j)σε

)]· (1−mtT ) for k = NWI − 1

(5.1)

wherek is the state forwt, j is the state forgt−1 andi is the state forwt−1, beingLWt = 10, GCt = 9 andLWt = 9 respectively, in the table notation.mtT isthe mortality rate for the period from start of observation until slaughter.σε is thestandard deviation of the weekly gain and∆w is the size of the state intervals.Hence the potential is the probability for the live weight to be in a certain intervalgiven the previous live weight and growth capacity.

In figure 5.2 is shown part of the potential table for the live weight node att = 10.

Growth capacity The growth capacity depends only on the previous growth ca-pacity, hence the potentials are calculated based on the previous growth capacityand the standard deviation for the growth capacityσε.

Live Weight The live weight depends on the previous live weight, growth ca-pacity and slaughter decision. If the pig has been slaughtered the potentails are0 for all weights, else the potentials are calculated based on previous live weight,growth capacity and the standard deviation for the growth capacityσε. The mor-tality rate,mtT , is also taken into account.

Page 45: Optimization of delivery strategies for slaughter pigs

5.1. ONE PIG 37

Figure 5.2: The potential table for the live weight node att = 10.

Observed live Weight The observed live weight depends on the live weight.The potentials are calculated based on the live weight and the standard deviationon the measurement errorσe.

Slaughter Weight The slaughter weight depends on the current live weight,growth capacity and slaughter decision. If the slaughter decision is No, theslaughter weight potentials are 0, else they are calculated based on live weight,growth capacity and the standard deviation of the slaughter weightση.

Feed efficiency The feed efficiency depends on the previous feed efficiencynode. The potentials are calculated based on previous feed efficiency and thestandard deviation for feed efficiencyσυ.

Feed consumption The feed consumption depends on feed efficiency and cur-rent and next live weight. The potentials are calculated based on the feed effi-ciency, the difference in live weight and the standard deviation for feed consump-tion στ .

Page 46: Optimization of delivery strategies for slaughter pigs

38 CHAPTER 5. BUILDING THE LIMID

5.2 Several pigs

When the LIMID is extended to more pigs, extra nodes are added.

Chance nodes

– Feed efficiency (all stages, pen level)

– Dead or alive (observed stages, each pig)

– Pig counter level 1 (observed stages, every second pig)

– Pig counter level 2 (observed stages, every 4’th pig)

– Pig counter level 3 (observed stages, every 8’th pig)

– Pig counter level 4 (observed stages, every 16’th pig)

Utility nodes

– Termination value (observed stages, pen level)

Feed efficiency Since the feed efficiency is observed at pen level, it is commonfor all the pigs in the pen. It is parent of the feed consumption for the individualpig.

Dead or alive The dead or alive nodes monitors whether a pig is dead or alive,it has the observed live weight as parent.

Pig counter The pig counter nodes are made to be able to monitor how manypigs that are left in the pen at a given stage. The dead or alive nodes for the currentand previous pig are parents of the level 1 pig counter nodes. The rest of the pigcounter nodes has the previous level as parents.

The pig counter nodes are divided into levels in order to keep the size of the final(in this case level 4) potential table manageable. This principle is called divorcing(Jensen, 2001) and consists of dividing the parents of a node into smaller groupsand thus keeping the potential table of the child from growing too large.

Page 47: Optimization of delivery strategies for slaughter pigs

5.2. SEVERAL PIGS 39

Termination value The termination value represents the value of terminatingthe pen earlier than planned. If the total number of pigs in the current week iszero, the utility value corresponds to the average weekly gross margin per penelse the utility value is zero.

The termination value is added in order to be able to test the herd delivery strategy.This can be done by setting all slaughter decisions in a given week (before the last)to Yes and observing the effect on the utility value. If the utility value is increasedit indicates that it could be profitable to change the delivery strategy to an earliertermination week.

5.2.1 Model problems

After the LIMID had been build with up to 16 pigs, it was obvious that the tri-angulation got extremely complex. Which made it impossible to compile it withmore than a few pigs. The main cause to the problem was located to the penlevel feed efficiency nodes, they were connected to many other nodes. Hence theresulting cliques in the junction tree became very large.

Some experimentation was done with different model designs and an alternativetriangulation criterion. The new triangulation criterion punished edges betweennodes in different pigs in an attempt to force the system to triangulate mostlylocally in each pig and only add absolutely necessary edges between pigs, unfor-tunately this had no effect.

Since no other solution was found to the triangulation problem, it was decidedto leave the feed efficiency nodes out alltogether. Hence the feed consumptionnodes now have only the current and next live weight as parents. The final resultof these adjustments are shown in figure 5.3. Other future possibilities for solvingthe complexity problems are discussed in the discussion (p. 55).

Page 48: Optimization of delivery strategies for slaughter pigs

40 CHAPTER 5. BUILDING THE LIMID

Figure 5.3: The first pig in the final PigLimid model with 16 pigs.

Page 49: Optimization of delivery strategies for slaughter pigs

Chapter 6

Verification and validation of model

After the model is built it must be verified that it is working satisfactory. Sørensen(1990) did a review of the methods being used to validate livestock herd simula-tion models. He found a general lack of consistency in the validation techniques.In general a goodness of fit test, that compares the simulated data with real herddata, is considered a proper way of validating the models, but this was seldom fol-lowed through either because of lack of data or because the management strategyin the herd had not been consistent during the test period.

Sørensen (1990) also found that the validation process could be split into twoparts, the first being to determine whether the model behaved as intended, oftencalled verification, and the second to evaluate the agreement between model be-haviour and real system behaviour, often called validation. The goodness of fittest belongs in the validation category.

If it is not possible to perform a goodness of fit test, a subjective evaluation mustbe done. The subjective validation methods can be split into (Sørensen, 1990):

• Face validity -where the model is validated by having people with insight in themodeled problem evaluate the conceptual model.

• Trace validity -where the validation consists of following entities in the model,to determine if the logic is correct.

• Sensitivity analysis -which can be split into finding the ranges in which themodel produces satisfactory results and finding the effect of changes in the fixedparameters of the model.

41

Page 50: Optimization of delivery strategies for slaughter pigs

42 CHAPTER 6. VERIFICATION AND VALIDATION OF MODEL

The validation process can be split into the parts shown in figure 6.1; Conceptualmodel validity, computerized model verification, operational validity and data va-lidity (Sargent, 1998). These definitions will be used in the validation and verifi-cation of the model. It is considered, that allthough the validation and verificationmethods presented by Sargent (1998) and Sørensen (1990) are meant for simula-tion models, they can be used on a LIMID since the parts that should be validatedare much alike, and no literature has been found on the validation of LIMIDs.

Figure 6.1: The validation problem (Sargent, 1998)

6.1 Conceptual model validity

The conceptual model validity concerns the transformation of the real probleminto the mathematical model representation. Some of the useful techniques are inthis case face and trace validity (Sargent, 1998). In the verification and validationof this model the conceptual model validity will consist of a self performed face

Page 51: Optimization of delivery strategies for slaughter pigs

6.2. COMPUTERIZED MODEL VERIFICATION 43

validation of the used formulas. This is assumed sufficient because of the relativesimplicity of the model. In case the model is to be further developed and usedin farm systems a new face validation should be made, and trace validity testsperformed.

6.2 Computerized model verification

The computerized model verification tests that the computer model is working asintended and is a satisfactory implementation of the conceptual model (Sargent,1998). This is where the main focus will be put in the verification and validationof this model. The verification will consist of the following parts.

• Visual check -Does the model look as intended? Are all nodes named and placedcorrectly and are all edges placed as intended by the model?

• Numerical state check -Are the values of the node states correct? This ischecked by manual calculation of a number of state values

• Potential table check -Does all potentials sum to 1 and are the potentials cal-culated correctly? This is checked by visual examination of the potential tablesand by manual calculation of a number of potentials. The utility values are alsoincluded in this check.

6.3 Operational validity

The operational validity examines the correspondence between the computer modeland the real problem. Since no data is available for a goodness of fit test, the mainfocus will be put on verifying that the model behaves as intended. This will bedone by entering evidence in the model and registering its behaviour and by ex-amining the strategies provided by the single policy updating (SPU).

6.4 Data validity

The data validity concerns the quality of the data used in model building andvalidation (Sargent, 1998). Since very limited amounts of data have been directly

Page 52: Optimization of delivery strategies for slaughter pigs

44 CHAPTER 6. VERIFICATION AND VALIDATION OF MODEL

involved in the construction of the model, no data validation will be done. Whenthe model is to be tested on farm data the validity of these data must be considered,that includes knowledge of changes in management practice or other irregularitiesin the production during the sampling period.

The values used for the parameters in the model is based on literature and isgenerally considered valid, but they should be revised during implementation ofthe PigLimid.

6.5 Results of verification and validation

A detailed description of the verification and validation (including tables and fig-ures) may be found in appendix A. Only the conclusions are given in this chapter.

6.5.1 Conceptual model validity

It is considered that the conceptual model used is valid. It is a simplification of areal farm setup, but it is believed, that the model has a good correspondence withthe real problem.

6.5.2 Computerized model verification

The computerized model verification contains the following parts.

• Visual check

• Numerical state check

• Potential table check

Visual check (See appendix A, p. 63-64) The visual check was done by build-ing the model with 16 pigs and checking that the overall structure looked right.The structure was compared with the intended structure described in chapter 4and 5. The visual check showed that the LIMID was a correct representation

Page 53: Optimization of delivery strategies for slaughter pigs

6.5. RESULTS OF VERIFICATION AND VALIDATION 45

of the conceptual model, all nodes and edges were created as intended and nomodifications to the LIMID were necessary.

Numerical state check (See appendix A, p. 65-66) During the numerical statecheck the model was build with 4 pigs and 11 weight intervals. The numericalstate check was done by first looking through the states of the nodes and checkingthat the values (numbers and intervals) appeared correct. This was done in orderto catch any obvious errors before checking the values more thoroughly. No errorswere found during this check.

After the initial check of the state values, 10 states were picked from differentnodes and the values were calculated manually. The states and nodes were chosenso that different ways of creating the nodes (through the java code) and differentstate numbers were represented.

An error was found in the slaughter weight node att = 10. After the correctionof the code the model was rebuild and the state checked again with a resultingmatch. This was the only error that was found during the numerical state test.

Potential table check (See appendix A, p. 66-78) During the potential tablecheck the model was build with 16 pigs and 11 weight intervals. The potentialtables were first checked by making sure that all rows summed to one. This wasdone only for pig number one, since the programming is the same for all pigs. Noerrors were found.

After checking that all rows summed to 1, specific values in the potential tableswere tested. Errors were found in the observed live weight nodes at all stagesand in the growth capacity node att = 9. These errors were corrected and thenodes were checked again with correct results. No other errors were found in thepotential tables or in the utility value tables.

After the visual -, the numerical state - and the potential table check it is con-sidered verified that the PigLimid is a satisfying representation of the conceptualmodel.

Page 54: Optimization of delivery strategies for slaughter pigs

46 CHAPTER 6. VERIFICATION AND VALIDATION OF MODEL

6.5.3 Operational validity

The operational validity of the PigLimid is checked by testing the logic of theoutput, first by putting evidence in the model and then by the strategies providedby the SPU. The PigLimid is built with 4 pigs and 11 weight intervals. Thiscombination is chosen in order to keep the dynamics from having several pigs,and still be able to have enough states without requiring excessive processingtime. The details of the operational validation is found in appendix A, p. 79-84.

Evidence insertion First the model was compiled, the decision node order wasset to go from week 12 to 9, and a single policy update was performed. Then allmonitor windows for the first pig were opened as well as the pig counter 2.

Then evidence was entered in the live weight at insertion and the observed liveweight nodes, and the behaviour of the net was observed. The behaviour was asexpected and hence no modifications were made.

Strategies Finally the strategies provided by the SPU were checked

During this test several problems were found:

• The value in the SPU table did not match the value in the monitor window,and they should be identical.

• The utility value (shown in the monitor window) after the SPU was lowerthan the one found by keeping all pigs until week 12, which indicated thatthe strategy was not globally optimal, furthermore the strategies in week 11were different for the 4 pigs, which should not be the case since the pigsare identical before evidence is entered.

• By changing the strategies one state at a time it was shown, that the strategygiven by the SPU was not only not globally optimal but not locally optimaleither. The optimal strategy was found to be to slaughter only pigs in theheaviest state in week 11 and all other in week 12.

These problems were given much consideration, and the first conclusion was, thatit had to be due to an error in the “Esthauge LIMID software system”, this wasinvestigated, but no errors were found, and the problems seen in the PigLimid

Page 55: Optimization of delivery strategies for slaughter pigs

6.6. CONCLUSIONS OF THE VERIFICATION AND VALIDATION 47

could not be found in other LIMIDs. Hence the problems seemed to be caused bysomething in the PigLimid, and the search for causes continued.

By setting the mortality rate to 0 the difference between the SPU table utility valueand the value in the monitor window was eliminated, hence it was believed that thedifferences were caused by handling pigs that died before they were slaughteredin the same state as the delivered pigs.

The problem should then be a numerical instability caused by the fact that theDead/delivered state represented very different utility values. When the potentialswere marginalized down on the observed live weight node (the only parent of thedecision node) the utility value presented by the dead/delivered state would bea fictive value somewhere between the two extremes and thus highly sensitiveto small instabilities during the SPU. This might also be the reason for the notoptimal strategies.

The PigLimid was reprogrammed in order to split the options dead and deliveredinto two separate states, but as opposed to the expected effect of removing theproblem with different utility values, only a very little change was seen. Althoughit did not have the desired effect, the separate states for dead and delivered werekept in the model since it was considered to be more informative and correct. Itwas checked that the affected potential tables looked right, but no new verificationwas done.

Experiments were made with removing the termination value nodes, the removalof the termination value nodes eliminated the strategy problem. Unfortunatelythe termination value is the only connection between the pigs, and if it is left out,the model might as well be made for just one pig. But it indicates, that it is thestructure of the PigLimid that causes the problems, and this must be addressed ina further development of the model.

6.6 Conclusions of the verification and validation

The PigLimid fared well during the conceptual model validation and the comput-erized model verification. The few errors found were corrected, and the modelbehaved as intended, hence the PigLimid is considered a valid representation ofthe traits of slaughter pigs during the finishing period.

The operational validation proved otherwise troublesome. It seems that some-

Page 56: Optimization of delivery strategies for slaughter pigs

48 CHAPTER 6. VERIFICATION AND VALIDATION OF MODEL

thing in the structure of the PigLimid conflicts with the optimization procedureof the “Esthauge LIMID software system”. It was not possible to solve theseproblems during the project period, and they will have to be taken care of duringfurther development of the model. As a result of the faulty strategies, the resultsof SPU reached during evaluation of the parameter sensibility will have to bechecked, and if necessary the optimal strategy must be found manually.

Page 57: Optimization of delivery strategies for slaughter pigs

Chapter 7

Evaluation of parameter sensibility

In order to illustrate the effect of different inputs and/or strategies several exam-ples are made. During all the examples the mortality rate is set to 0.

In the tables the termstrategy week Xindicates the values in the node table of thegiven decision node. If the strategy isAll: No the decision for all states is no,if the strategy is3 Yes, pigs in the 3 heaviest states are to be slaughtered. If thestrategy isYes = 0.38it is the probability for the pig being slaughtered shown inthe monitor window.

7.1 Feed efficiency and price

The influence of the feed efficiency on strategy and utility value is tested in orderto be able to evaluate the consequences of taking the pen level feed efficiency outof the model. The tests are performed using 2 pigs, 11 weight intervals and a feedefficiency ranging from 2.7 FEsv/kg to 3.9 FEsv/kg.

As seen in table 7.1, the feed efficiency has an effect on the utility value, but onlywhen it was increased to 3.9 FEsv/kg the strategy was changed so pigs in theheaviest and the second heaviest weight interval should be delivered. This makesgood sense since a pig with an inferior feed efficiency will be more expensive tofeed. Thus the increased profit gained by letting the pig grow for an extra weekwill literally be eaten up by feed costs.

A similar test was done with the feed price, where the price was changed from

49

Page 58: Optimization of delivery strategies for slaughter pigs

50 CHAPTER 7. EVALUATION OF PARAMETER SENSIBILITY

Table 7.1: The influence of feed efficiencyFeed efficiency 2.7 FEsv/kg 2.8 FEsv/kg 2.9 FEsv/kg 3.0 FEsv/kg 3.1 FEsv/kgUtility value after SPU 279.67 263.64 247.62 231.59 215.56Strategy week 9 All: No All: No All: No All: No All: NoStrategy week 10 All: No All: No All: No All: No All: NoStrategy week 11 1 Yes 1 Yes 1 Yes 1 Yes 1 YesFeed efficiency 3.2 FEsv/kg 3.3 FEsv/kg 3.5 FEsv/kg 3.7 FEsv/kg 3.9 FEsv/kgUtility value after SPU 199.54 183.51 151.46 119.40 87.51Strategy week 9 All: No All: No All: No All: No All: NoStrategy week 10 All: No All: No All: No All: No All: NoStrategy week 11 1 Yes 1 Yes 1 Yes 1 Yes 2 Yes

0.90 DKK/FEsv to 1.50 DKK/FEsv. As seen in table 7.2, the strategy was affectedby the feed price in a similar way as the feed efficiency. If the pig is cheap to feed,it will be kept longer than if it is expensive.

Table 7.2: The influence of feed efficiencyFeed price 0.9 DKK/FEsv 1.1 DKK/FEsv 1.3 DKK/FEsv 1.5 DKK/FEsvUtility value after SPU 332.13 247.62 163.10 78.79Strategy week 9 All: No All: No All: No All: NoStrategy week 10 All: No All: No All: No All: NoStrategy week 11 All: No 1 Yes 1 Yes 2 Yes

Since only a very bad feed efficiency changed the strategy, it indicates that thefeed consumption plays only a minor role in the decision process. Hence theremoval of the pen level feed efficiency nodes is considered to have a negligibleeffect on the strategies.

7.2 Standard deviation

Since the standard deviations used in the PigLimid are estimates, the effect ofchanges in the standard deviations must be considered.

In table 7.3 is shown the results of changing the standard deviation of the weeklygain from 0.3 to 0.7. It is tested with start of observations at both 9 and 10 weeksin order to see the full effect. There is not a very large difference in utility values,but the strategies clearly change towards earlier delivery when the standard devi-ation is increased. This may be caused by the increased possibility of a smallerpig reaching the threshold weight when the standard deviation is bigger.

Page 59: Optimization of delivery strategies for slaughter pigs

7.2. STANDARD DEVIATION 51

The measurement error in the weighing system will be an important factor whenchoosing a system. Hence knowledge of the influence the measurement error hason the production results is important. In order to evaluate the influence of themeasurement error two tests were carried out. First the strategies and resultingutility values for a standard deviation of the measurement error from 0 to 1.4were found. This was done using two pigs and a start of observation at 9 or 10weeks. The results are shown in table 7.5. This had a minimal effect on the utilityvalue and no effect on the strategies.

Then evidence of the live weight was entered. This time only start of observationin week 10 was used, and a standard deviation ranging from 0 to 5 was tested.The results are shown in table 7.5. The insertion of evidence did not increase theeffect.

Finally the effect of the measurement error was tested on 5 pigs, this time usingonly 3 weeks for delivery (in order to reduce processing time) and start of ob-servations at week 11. The results are shown in table 7.6 Again only a minimaleffect was seen.

The connection between the measurement error and the utility value is smallerthan expected. This might be due to the fact that the PigLimid optimizes basedon the known probability distributions of the parameters. Hence the importantthing is, that the measurement error is normal distributed with a known mean andstandard deviation.

Table 7.3: The influence of standard deviation of weekly gainStd.dev. for weekly gain 0.3 0.4 0.5 0.6 0.7Start week of observation = 9Utility value after SPU 252.04 249.79 247.62 243.46 239.25Strategy week 9 All: No All: No All: No All: No All: NoStrategy week 10 All: No All: No All: No All: No All: NoStrategy week 11 All: No All: No 1 Yes 2 Yes 3 YesStart week of observation = 10Utility value after SPU 280.56 277.24 274.22 270.52 267.50Strategy week 10 All: No All: No All: No All: No All: NoStrategy week 11 All: No All: No 1 Yes 2 Yes 2 YesStrategy week 12 3 Yes 4 Yes 4 Yes 5 Yes 5 Yes

Page 60: Optimization of delivery strategies for slaughter pigs

52 CHAPTER 7. EVALUATION OF PARAMETER SENSIBILITY

Table 7.4: The influence of the measurement errorStd.dev. for obs. live weight 0.0 0.6 0.8 1.0 1.2 1.4Start week of observation = 9Utility value after SPU 247.78 247.74 247.68 247.62 247.56 247.49Strategy week 9 All: No All: No All: No All: No All: No All: NoStrategy week 10 All: No All: No All: No All: No All: No All: NoStrategy week 11 1 Yes 1 Yes 1 Yes 1 Yes 1 Yes 1 YesStart week of observation = 10Utility value after SPU 274.83 274.70 274.47 274.23 274.00 273.76Strategy week 10 All: No All: No All: No All: No All: No All: NoStrategy week 11 1 Yes 1 Yes 1 Yes 1 Yes 1 Yes 1 YesStrategy week 12 4 Yes 4 Yes 4 Yes 4 Yes 4 Yes 4 Yes

Table 7.5: The influence of the measurement error - with insertion of evidence #1Std.dev. for observed live weight 0.0 1.0 3.0 5.0Utility value after SPU 274.83 274.23 271.89 269.75Live weight, pig 1, week 10 85.60 85.60 85.60 85.60Live weight, pig 1, week 11 91.82 91.82 91.82 91.82Live weight, pig 2, week 10 93.60 93.60 93.60 93.60Live weight, pig 2, week 11 100.62 100.62 100.62 100.62Strategy week 11 pig 1 Yes = 0 Yes = 0 Yes = 0 Yes = 0Strategy week 11 pig 2 Yes = 0 Yes = 4.83E-4 Yes = 0 Yes = 0Strategy week 12 pig 1 Yes = 0 Yes = 1.13E-5 Yes = 0.028 Yes = 0.120Strategy week 12 pig 2 Yes = 1 Yes = 0.991 Yes = 0.869 Yes = 0.754Utility value after evidence 287.04 287.01 284.84 281.91

Table 7.6: The influence of the measurement error - with insertion of evidence #2Std.dev. for observed live weight 0.0 1.0 3.0 5.0Utility value after SPU 686.82 685.67 680.29 675.25Strategy week 11 All: No All: No All: No All: NoStrategy week 12 4 Yes 4 Yes 4 Yes 4 YesStrategy week 13 All: Yes All: Yes All: Yes All: YesUtility value after evidence 674.91 673.17 667.40 661.51

Page 61: Optimization of delivery strategies for slaughter pigs

7.3. NUMBER OF PIGS LEFT 53

7.3 Number of pigs left

In order to increase the influence the pigs in the pen has on each other, edges areadded from the pig counter node to the decision node in each week (besides thelast where the decision always is yes). The test is done with 2 pigs with start ofobservations in week 10.

The results are shown in table 7.7, where it can be seen that the strategies are in-fluenced. In week 10 and 11 the current pig will always be slaughtered if the otheris already dead or delivered. In week 12 the pen will only be terminated early ifthe pig is in one of the 5 heaviest intervals (in the 4 heaviest it is slaughteredregardless of the other pig). This difference in strategies between weeks mustbe due to the termination value, where termination in week 10 or 11 will give abonus that exceeds the expected increase in slaughter price. Whereas terminationin week 12 in most cases will give a smaller bonus than the increase in slaughterprice by waiting a week.

Table 7.7: The influence of adding edges from the pigcounter nodes to the deci-sion nodes

Normal PigLimid Edges from PC2 to S?Pigs alive N/A 0 1 2Strategy week 10 All: No All: Yes All: Yes All: YesStrategy week 11 1 Yes All: Yes All: Yes 5 YesStrategy week 12 4 Yes All: Yes 1 Yes 4 Yes

7.4 Start - and termination week

As can be seen in the different tables in this section, the strategies and resultingutility values are influenced by the choice of start - and termination weeks. Intable 7.6 the PigLimid is built with 5 pigs, but with only 3 observed weeks. Thatresulted in a relatively fast working model. All decisions in the first observedweek is No, which indicates that it is not a too late start of observation. Hence itis a possibility to work with just 3 observed weeks in order to handle more pigs.

It must also be considered when to terminate the pen, the default value in thePigLimid is week 12. In table 7.3 the PigLimid is used with both week 12 and13 as termination weeks. For the default settings the utility value is 247.62 DKKwhen terminating in week 12 and 274.23 DKK when terminating in week 13. Thisgives a weekly utility value of 19.05 DKK and 19.59 DKK respectively. Hence

Page 62: Optimization of delivery strategies for slaughter pigs

54 CHAPTER 7. EVALUATION OF PARAMETER SENSIBILITY

with the current settings it is slightly more profitable to terminate at week 13 thanweek 12.

In table 7.8 the effect of the termination week is tested in relation to the expectedgross margin per pig. The changes in gross margin has no effect on neither strat-egy nor utility value.

Table 7.8: The influence of start and termination weekAverage gross margin per pig 100 DKK 150 DKKStart week of observation = 9Utility value after SPU 247.62 247.63Strategy week 9 All: No All: NoStrategy week 10 All: No All: NoStrategy week 11 1 Yes 1 YesStart week of observation = 10Utility value after SPU 274.23 274.87Strategy week 10 All: No All: NoStrategy week 11 1 Yes 1 YesStrategy week 12 4 Yes 4 Yes

7.5 Conclusions of the evaluation

In this chapter it has been shown that the model is stable and only minimallyinfluenced by large changes in parameter values.

Page 63: Optimization of delivery strategies for slaughter pigs

Chapter 8

Discussion

In the following the results and problems encountered while building the PigLimidis discussed and possibilities for future development is presented.

8.1 Modelling of the pig

During the creation of the mathematical model of the pig several assumptionswere made.

• Assumption of linear growth in the decision period -Based on the datasetused in the growth calculations (Callesen and Pedersen, 2004) this is an accept-able solution, but it must be reconsidered when specific farm data is available. Ifnecessary the model must be adjusted to fit the different growth patterns.

• The standard deviation of weekly gain -As shown in table 7.3 the size of thestandard deviation of weekly gain influences both utility value and strategy. Thus itwill be important to calculate the farm specific value in order to get the best effectof using the PigLimid.

• The measurement error -As shown in table 7.4, 7.5 and 7.6 the size of the mea-surement error does not have a large effect on neither strategies nor the resultingutility values. This must be investigated further in order to be able to give a moreprecise evaluation of a potential value of a weighing system with increased preci-sion.

55

Page 64: Optimization of delivery strategies for slaughter pigs

56 CHAPTER 8. DISCUSSION

• The assumptions about feed consumption are rough estimates -but as shownin table 7.1 it does not have much influence on the strategy, only on the utilityvalue. Hence precision in this parameter is not important.

• Lean meat percentage -If knowledge about the interactions between lean meatpercentage and growth rate, for instance, can be established, it would be a goodextension to the model. It would add an extra dimension to the slaughter price,which might affect the strategy.

• Normal distributed parameters -It is assumed, that all parameters are strictlynormal distributed. This is not necessarily the case. A way to establish the realprobability distributions could be to train the network on a data set. Thus letting themodel calculate the potential tables. This might also give an indication of whetherit is best to have equal sized states, or states that represents smaller intervals in themost probable areas, and thus get a better resolution without adding extra states.

8.2 Building the LIMID

During the construction of the PigLimid it became obvious, that the LIMID methodas it is currently used in the “Esthauge LIMID software system”, is inadequate athandling large models. The triangulation becomes too complex, which results ina junction tree with very large cliques, which in turn results in huge optimizationcalculations.

A possible solution to this problem may be object oriented LIMIDs. Bangsø(2004) presented an object oriented framework for Bayesian networks. The Baye-sian network is split into objects built from classes. A pig could be a class, andthen for each pig needed in the network, a pig object would be created as aninstance of the pig class. The computational advantage of object orienting isthe possibility for triangulating each class separately, which will help keep thecliques, and thus the joint probability tables, at a manageable size. Based onthe similar structure of Bayesian networks and LIMIDs, this method should beapplicable on LIMIDs as well.

Page 65: Optimization of delivery strategies for slaughter pigs

8.3. FUTURE PERSPECTIVES 57

8.3 Future perspectives

The object oriented approach is judged to be the best way to solve the complexityproblems. If it is implemented successfully it will be possible to handle penswith more than 16 pigs and have more parameters for each pig, and more statesin the nodes. As seen in table 7.7, it gives an increased interaction between pigsif edges are added from the pig counter to the decision nodes. With an objectoriented LIMID it should be possible to build this into the model.

When aiming for an implementable version of the PigLimid, the computer poweravailable at the farm must also be taken into consideration. It is tempting totry and solve the complexity problems by acquiring more processing power, butthis might make the PigLimid worthless to a farmer who does not own state-of-the-art computer systems. On the other hand the implementation of a DSSsuch as the PigLimid will take time, and is also dependant of reliable weighingsystems. The current development rate of high powered computers makes theproblem of optimizing negligible, if the programming eliminates exponentiallyincreasing optimization algorithms.

Before the PigLimid can be implemented the issues with the SPU must also beaddressed. Since all pigs are equal before insertion of evidence, the only logicalstrategies are the ones that are the same for all pigs. This might be used to helpthe LIMID make strategies that are at least always locally optimal. The ideaof linking the strategies between pigs works well with the possibilities of objectorientation.

The problem with the mortality rate must be resolved since a model that cannothandle pigs that die without being slaughtered, is not compatible with real life.The results from such a model might not be valid, hence the value of the DSS willbe diminished.

The PigLimid presented here only concerns a single batch of pigs. In order tobe able to use the DSS for long term strategic planning it must be expanded. Amethod combining the LIMID with a Markov process is presented by Nilssonand Kristensen (2002). This gives the possibility of expanding a DSS to involveseveral pig batches by using a Markov process at the founder level (representingthe herd), and a LIMID as a child process (representing each batch of pigs). Thismakes it possible to use the LIMID for optimizing the decisions in each pen,and using the Markov process to incorporate long term effects in the decisionprocess. This will also allow for taking net present value and discount rate intoconsideration in the long term decision process, which might affect the decision

Page 66: Optimization of delivery strategies for slaughter pigs

58 CHAPTER 8. DISCUSSION

strategies.

Page 67: Optimization of delivery strategies for slaughter pigs

Chapter 9

Conclusions

The aim of this project was to establish how a decision support system, usingLImited Memory Influence Diagrams (LIMIDs), may be developed, that helps thefarmer find the optimal time of slaughter for the pigs in a pen, when knowledgeof feed consumption and weight throughout the growth period is available.

In this thesis the “Esthauge LIMID software system” has been used to construct aLIMID emulating the decision process. The PigLimid has the following features.

• Scalable from 2 to 16 pigs

• Variable number of states

• High degree of flexibility in parameter values due to generic construction

• Calculation of potential tables based on normal distributions

The PigLimid has the following limitations

• The complexity problem, which might be solved with object orientation.

• The single policy updating, which might work better if the pigs are forcedto have identical strategies.

• The mortality rate must be included in the model. No obvious solution isavailable and the first step is to pinpoint the cause of the problem.

59

Page 68: Optimization of delivery strategies for slaughter pigs

60 CHAPTER 9. CONCLUSIONS

If these problems are resolved, the PigLimid should be able to help the farmerproperly utilize the data given by an automatic weighing system. It might even insome form be incorporated into a larger DSS, for example as a child process in aMarkov decision process.

Page 69: Optimization of delivery strategies for slaughter pigs

Bibliography

Bangsø, O., 2004. Object Oriented Bayesian Networks. Phd thesis, Aalborg Uni-versity.

Callesen, J., 1998. Meddelelse nr. 403, porzyme 9300 til slagtesvin. Landsudval-get for Svin, Den rullende Afprøvning.

Callesen, J., Pedersen, A. Ø., November 2004. Foderoptagelse og tilvækst− nø-gletal. Landsudvalget for Svin, Copenhagen.

Cowell, R. G., Dawid, A. P., Lauritzen, S. L., Spiegelhalter, D. J., 1999. Proba-bilistic Networks and Expert Systems. Statistics for Engineering and Informa-tion Science. Springer-verlag, New York, Berlin, Heidelberg.

Danish Crown, August 2005. Notering og markedssituation. Ugeinfo (31).

Howard, R., 1960. Dynamic Programming and Markov Processes. The M.I.T.Press, Cambridge, Massachusetts.

Jensen, F. V., 1996. An Introduction to Bayesian Networks. UCL Press, London.

Jensen, F. V., 2001. Bayesian Networks and Decision Graphs. Springer, NewYork.

Jørgensen, E., August 1993. The influence of weighing precision on delivery de-cisions in slaughter pig production. Acta Agriculturæ Scandinavica, Section A43 (3), 181–189.

Jultved, C. R., 2005. Notat nr. 0532, rapport over p-rapporternes resultater okto-ber 2005. Landsudvalget for Svin, Dansk Landbrugsrådgivning, Landscentret |Svin.

Kristensen, A. R., 2003. Implementation of Markov LIMID Processes in Java,I. LImited Memory Influence Diagrams. Master’s thesis, The IT-University ofCopenhagen.

61

Page 70: Optimization of delivery strategies for slaughter pigs

62 BIBLIOGRAPHY

Kristensen, A. R., Jørgensen, E., 2000. Multi-level hierarchic markov processesas a framework for herd management support. Annals of Operations Research.94, 69–89.

Kristensen, A. R., Jørgensen, E., 1996. Textbook notes of herd management: Ba-sic concepts. Dina Research Report 48.

Kure, H., 1997. Marketing management support in slaughter pig production.Ph.D. thesis, The Royal Veterinary and Agricultural University.

Lauritzen, S. L., Nilsson, D., 2001. Representing and Solving Decision Problemswith Limited Information. Management Science 47, 1235–51.

Nilsson, D., Kristensen, A. R., 2002. Markov limid processes for representing andsolving renewal problems. In: First European Workshop on Sequential Deci-sions under Uncertainty in Agriculture and Natural Resources. INRA, Septem-ber 19-20, 2002, Toulouse, France, pp. 97–104.

Rasmussen, F., 11. August 2004. Vigtigt at ramme den rigtige slagtevægt.http://www.agrogaarden.dk/Svinebrug/Nyheder/Svinebrugsnyt.htm#11/08-%202004.

Roemen, J., de Klein, J., 2000. An optimal marketing strategy for porkers withdifferences in growth rates and dependent prices. In: Proceedings of the In-ternational Symposium on Pig Herd Management Modeling and InformationTechnologies Related.

Sargent, R. G., 1998. Verification and validation of simulation models. In: Pro-ceedings of the 1998 Winter Simulation Conference, D.J. Medeiros, E.F. Wat-son, J.S. Carson and M.S. Manivannan, eds. December 13-16, 1998, Washing-ton DC, USA., pp. 121–130.

Sørensen, J. T., 1990. Validation of livestock herd simulation models: a review.Livestock Production Science 26, 79–90.

Toft, N., Kristensen, A. R., Jørgensen, E., August 2005. A framework for decisionsupport related to infectious diseases in slaughter pig fattening units. Agricul-tural Systems 85(2), 120–137.

Wellock, I. J., Emmans, G. C., Kyriazakis, I., 2004. Describing and predictingpotential growth in the pig. Animal Science 78, 379–388.

Page 71: Optimization of delivery strategies for slaughter pigs

Appendix A

Verification log

This is the log over how the verification and validation was done.

Conceptual model validity

The conceptual model is not validated as such. It is assumed that the formulasused to build the model are good enough under the given circumstances. Thechapter about the pig model (chapter 4) has been reexaminated in order to checkfor mistakes, none was found.

Computerized model verification

The verification of the computer model is done in three stages; the visual check,numerical state check and potential table check.

Visual check

The visual check is done by building the model with 16 pigs and checking thatthe overall structure looks right. The structure is compared with the intendedstructure described in chapter 5.

63

Page 72: Optimization of delivery strategies for slaughter pigs

64 APPENDIX A. VERIFICATION LOG

Chance nodes

– Growth capacity (gi,t, all stages), parents: previous growth capacity -OK

– Live weight (wi,t, all stages) parents: previous live weight, growthcapacity and slaughter decision node - OK

– Observed live weight (woi,t, observed stages) parents: current liveweight - OK

– Slaughter weight (wsi,t, observed stages) parents: current live weight,growth capacity and slaughter decision node - OK

– Feed consumption (ci,t, all stages but the final) parents: current andnext live weight - OK

– Dead or alive (observed stages, each pig) parent: current observed liveweight - OK

– Pig counter level 1 (observed stages, every second pig) parents: twocurrent dead or alive nodes - OK

– Pig counter level 2 (observed stages, every 4’th pig) parents: two cur-rent pig counter 1 - OK

– Pig counter level 3 (observed stages, every 8’th pig) parents: two cur-rent pig counter 2 - OK

– Pig counter level 4 (observed stages, every 16’th pig) parents: twocurrent pig counter 3 - OK

Decision nodes

– Slaughter (si,t, observed stages) parents: current observed live weight- OK

Utility nodes

– Piglet price (ppi,t, initial stage) parents: live weight at insertion - OK

– Slaughter price (psi,t, observed stages) parents: current slaughter weight- OK

– Feed price (pfi,t, all stages but the final) parents: current feed con-sumption - OK

– Termination value (observed stages, pen level) parents: current pigcounter 4 - OK

During the visual check no errors were found and hence no modifications made.

Page 73: Optimization of delivery strategies for slaughter pigs

65

Numerical state check

During the numerical state check the model is build with 4 pigs and 11 weightintervals. The numerical state check is done by first looking through the statesin the nodes and checking that the values (numbers and intervals) looks right.This is done in order to catch any obvious errors before checking the values morethoroughly. No errors were found during this check.

After the initial check of the state values 10 states were picked from differentnodes and the values were calculated manually. The states and nodes were chosenso that different ways of creating the nodes (through the java code) and differentstate numbers were represented. The results are shown in table A.1.

Nodeis the node name,State no.is the number of the state being checked, countedfrom top to bottom starting with 0,Value in modelis the value (name) of the stateas shown in the LIMID,Expected valueis the manual calculation of the statevalue andMatch? is an indication of whether the expected value and the oneshown in the model are the same.

Table A.1: Numerical state checkNode State no. Value in model Expected value Match?1:GC t=10 3 6.02 6.02 OK1:SW t=10 7 70.39 72.62 NO!1:SW t=10 7 72.62 72.62 OK2:FC t=10-11 1 16.98 16.98 OK4:OLW t=11 9 101.28 101.28 OK4:LW t=9 11 90.84 90.84 OK3:FC t=0-9 1 127.88 127.88 OK3:GC t=0 0 4.76 4.76 OK2:LW t=12 3 93.9 93.9 OK2:OLW t=10 6 88.26 88.26 OK1:SW t=12 11 88.72 88.72 OK

An error was found in1:SW t=10. It was due to a programming error, where theextra growth in the days from the decision until the pig is slaughtered was 0. Thegrowth was 0 because both the days until slaughter (3) and the 7 days in a weekwere defined as integers, hence3/7 = 0 which resulted in the extra growth being0. This was corrected by dividing the days until slaughter with 7.0 instead of 7 inorder to get a float value. The error in the slaughter weight node was located to bedue to a programming error that caused the growth in the days from the decision ismade until the pig is slaughtered to be 0. The growth was 0 because both the days

Page 74: Optimization of delivery strategies for slaughter pigs

66 APPENDIX A. VERIFICATION LOG

until slaughter and the 7 days in a week were defined as integers, hence3/7 = 0which resulted in the extra growth being 0. This was corrected by dividing thedays until slaughter with 7.0 instead of 7 in order to get a float value. After thecorrection of the code the model was rebuild and the state checked again with aresulting match. That was the only error that was found during the numerical statetest.

Potential table check

During the potential table check the model is build with 16 pigs and 11 weightintervals. The potential tables are first checked by making sure that all rows sumto one this is done only for pig number one, since the programming is the samefor all pigs. The results are shown in table A.2.Nodeis the name of the node andWeek 0-12is the week number.

Table A.2: Potential sum checkNode Week 0 Week 9 Week 10 Week 11 Week 12Growth capacity (GC) OK OK OK OK OKLive weight (LW) OK OK OK OK OKObs. live weight (OLW) N/A OK OK OK OKSlaughter weight (SW) N/A OK OK OK OKFeed consumption (FC) OK OK OK OK N/ADead or alive (D/A?) N/A OK OK OK OKPig counter 1 (PC1) N/A OK OK OK OKPig counter 2 (PC2) N/A OK OK OK OKPig counter 3 (PC3) N/A OK OK OK OKPig counter 4 (PC4) N/A OK OK OK OK

After checking that all rows sums to 1, specific values in the potential tables weretested. The first test was carried out on the1:OLW t=9 node, and it gave theresult presented in table A.3, whereNode is the name of the node,Node stateis the name (value) of the chosen state (column),Parent stateis the name ofthe chosen state(s) of the parental node(s) (row),sigmais the standard deviationused,meanis the value represented by the parent state(s),interval sizeis the sizeof the node states,Interval centreis the value of the node state, andP((istart-mean)/sigma<X<(islut-mean)/sigma)= P(X<(islut-mean)/sigma)- P(X<(istart-mean)/sigmais the probability for the parent state(s) yielding the node state. Asseen in the table, the value in the potential table was not as expected. The codewas examined, and the error was found. The error was, that the interval used was

Page 75: Optimization of delivery strategies for slaughter pigs

67

that of the growth capacity states instead of that interval multiplied with the weeknumber. This was corrected and the results shown in table A.4.

Table A.3: Potential table check - observed live weight #1Name valueNode 1:OLW t=9Node state 78.24 kgParent state 83.64 kgsigma 1 kgmean 83.64 kginterval size 1.8 kgInterval centre 78.24 kgP(X<(istart-mean)/sigma) 0.00000P(X<(islut-mean)/sigma) 0.00000P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.00000Value in table 0.067Match? No

After the potential tables of the observed live weight nodes had been checked, thegrowth capacity node for t=9 was checked, it had the results shown in table A.5.Since the results did not match the code was examined. It was concluded thatthe error was due to the difference in growth capacity before and after the startof observation, this was compensated for and the results shown in table A.6 wasreached.

Then the growth capacity nodes for the following weeks were checked, and as isshown in table A.7 no errors were found. Since the potential tables are identicalfor the last 3 weeks all growth capacity nodes are considered to be correct.

Then the live weight nodes are tested. Here the mortality rate must be taken intoaccount. The check gave the results shown in table A.8 and A.9 which includedno errors.

In table A.10 the test results for the initial live weight and growth capacity areshown. No errors were found in the initial potential tables.

The feed consumption potential tables are checked and no errors are found, theresults are shown in table A.11.

The testresults for the slaughter weight nodes are shown in table A.12, no errorswere found.

The dead or alive nodes are checked by looking at the tables and making sure that

Page 76: Optimization of delivery strategies for slaughter pigs

68 APPENDIX A. VERIFICATION LOG

Table A.4: Potential table check - observed live weight #2Name valueNode 1:OLW t=9Node state 78.24 kgParent state 83.64 kgsigma 1 kgmean 83.64 kginterval size 1.8 kgInterval centre 78.24 kgP(X<(istart-mean)/sigma) 0.00000P(X<(islut-mean)/sigma) 0.00000P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.00000Value in table 0.000Match? Yes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:OLW t=9Node state 83.64 kgParent state 83.64 kgsigma 1 kgmean 83.64 kginterval size 1.8 kgInterval centre 83.64 kgP(X<(istart-mean)/sigma) 0.18406P(X<(islut-mean)/sigma) 0.81594P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.63188Value in table 0.632Match? Yes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:OLW t=11Node state 96.68 kgParent state 94.68 kgsigma 1 kgmean 94.68 kginterval size 2.2 kgInterval centre 96.88 kgP(X<(istart-mean)/sigma) 0.86433P(X<(islut-mean)/sigma) 0.99952P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.13518Value in table 0.135Match? Yes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:OLW t=11Node state 105.68 kgParent state 105.68 kgsigma 1 kgmean 105.68 kginterval size 2.2 kgInterval centre 105.68 kgP(X<(istart-mean)/sigma) 0.13567P(X<(islut-mean)/sigma) 0.86433P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.72867Value in table 0.864Match? Yes (border state)

Page 77: Optimization of delivery strategies for slaughter pigs

69

Table A.5: Potential table check - growth capacity #1Name valueNode 1:GC t=9Node state 5.82 kgParent state 6.36 kgsigma 0.5 kgmean 7.09 kginterval size 0.2 kgInterval centre 5.82 kgP(X<(istart-mean)/sigma) 0.00310P(X<(islut-mean)/sigma) 0.00971P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.00661Value in table 0.009Match? No. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:GC t=9Node state 5.82 kgParent state 5.16 kgsigma 0.5 kgmean 5.75 kginterval size 0.2 kgInterval centre 5.82 kgP(X<(istart-mean)/sigma) 0.47508P(X<(islut-mean)/sigma) 0.63213P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.15705Value in table 0.159Match? No. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:GC t=9Node state 7.02 kgParent state 6.56 kgsigma 0.5 kgmean 7.31 kginterval size 0.2 kgInterval centre 7.02 kgP(X<(istart-mean)/sigma) 0.21672P(X<(islut-mean)/sigma) 0.35074P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.13402Value in table 0.146Match? No

Page 78: Optimization of delivery strategies for slaughter pigs

70 APPENDIX A. VERIFICATION LOG

Table A.6: Potential table check - growth capacity #2Name valueNode 1:GC t=9Node state 5.82 kgParent state 6.36 kgsigma 0.5 kgmean 7.09 kginterval size 0.2 kgInterval centre 5.82 kgP(X<(istart-mean)/sigma) 0.00310P(X<(islut-mean)/sigma) 0.00971P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.00661Value in table 0.007Match? Yes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:GC t=9Node state 6.62 kgParent state 6.16 kgsigma 0.5 kgmean 6.87 kginterval size 0.2 kgInterval centre 6.62 kgP(X<(istart-mean)/sigma) 0.24457P(X<(islut-mean)/sigma) 0.38527P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.14070Value in table 0.141Match? Yes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:GC t=9Node state 5.42 kgParent state 4.76 kgsigma 0.5 kgmean 5.31 kginterval size 0.2 kgInterval centre 5.42 kgP(X<(istart-mean)/sigma) 0.51163P(X<(islut-mean)/sigma) 0.66610P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.15446Value in table 0.666Match? Yes, since border state

Page 79: Optimization of delivery strategies for slaughter pigs

71

Table A.7: Potential table check - growth capacity #3Name valueNode 1:GC t=10Node state 6.02 kgParent state 5.82 kgsigma 0.5 kgmean 5.82 kginterval size 0.2 kgInterval centre 6.02 kgP(X<(istart-mean)/sigma) 0.57926P(X<(islut-mean)/sigma) 0.72575P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.14649Value in table 0.146Match? Yes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:GC t=10Node state 7.42 kgParent state 7.42 kgsigma 0.5 kgmean 7.42 kginterval size 0.2 kgInterval centre 7.42 kgP(X<(istart-mean)/sigma) 0.42074P(X<(islut-mean)/sigma) 0.57926P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.15852Value in table 0.579Match? Yes (border state). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:GC t=11Node state 7.02 kgParent state 6.02 kgsigma 0.5 kgmean 6.02 kginterval size 0.2 kgInterval centre 7.02 kgP(X<(istart-mean)/sigma) 0.96407P(X<(islut-mean)/sigma) 0.98610P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.02203Value in table 0.022Match? Yes

Page 80: Optimization of delivery strategies for slaughter pigs

72 APPENDIX A. VERIFICATION LOG

Table A.8: Potential table check - live weight #1Name valueNode 1:LW t=11Node state 88.08 kgParent state No, 5.62 kg, 84.26 kgsigma 0.5 kgmean 88.08 kginterval size 2.2 kgInterval centre 89.88 kgP(X<(istart-mean)/sigma) 0.91557P(X<(islut-mean)/sigma) 0.99600P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.08043Value in table 0.080Match? Yes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:LW t=11Node state 94.68 kgParent state No, 5.82 kg, 88.26 kgsigma 0.5 kgmean 94.08 kginterval size 2.2 kgInterval centre 94.68 kgP(X<(istart-mean)/sigma) 0.15802P(X<(islut-mean)/sigma) 0.99566P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.83764Value in table 0.838Match? Yes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:LW t=11Node state 96.88 kgParent state No, 5.82 kg, 90.26 kgsigma 0.5 kgmean 96.08 kginterval size 2.2 kgInterval centre 96.88 kgP(X<(istart-mean)/sigma) 0.27316P(X<(islut-mean)/sigma) 0.99593P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.72277Value in table 0.723Match? Yes

Page 81: Optimization of delivery strategies for slaughter pigs

73

Table A.9: Potential table check - live weight #2Name valueNode 1:LW t=9Node state 76.44 kgParent state 5.16 kg, 31.2 kgsigma 0.5 kgmean 77.64 kginterval size 1.8 kgInterval centre 76.44 kgP(X<(istart-mean)/sigma) 0.00001P(X<(islut-mean)/sigma) 0.26520P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.26519Value in table 0.265Match? Yes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:LW t=9Node state 90.84 kgParent state 6.76 kg, 30.0 kgsigma 0.5 kgmean 90.84 kginterval size 1.8 kgInterval centre 90.84 kgP(X<(istart-mean)/sigma) 0.03474P(X<(islut-mean)/sigma) 0.93226P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.89751Value in table 0.932Match? Yes (border state). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:LW t=10Node state 90.26 kgParent state No, 6.22 kg, 85.44 kgsigma 0.5 kgmean 91.66 kginterval size 2 kgInterval centre 90.26 kgP(X<(istart-mean)/sigma) 0.00000P(X<(islut-mean)/sigma) 0.21101P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.21101Value in table 0.211Match? Yes

Page 82: Optimization of delivery strategies for slaughter pigs

74 APPENDIX A. VERIFICATION LOG

Table A.10: Potential table check - initial valuesName valueNode 1:LW t=0Node state 28.8 kgParent state 30 kgsigma 1.5 kgmean 30 kginterval size 0.6 kgInterval centre 28.8 kgP(X<(istart-mean)/sigma) 0.15866P(X<(islut-mean)/sigma) 0.27425P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.11560Value in table 0.116Match? Yes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:GC t=0Node state 5.76 kgParent state 5.76 kgsigma 0.5 kgmean 5.76 kginterval size 0.2 kgInterval centre 5.76 kgP(X<(istart-mean)/sigma) 0.42074P(X<(islut-mean)/sigma) 0.57926P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.15852Value in table 0.159Match? Yes

Page 83: Optimization of delivery strategies for slaughter pigs

75

Table A.11: Potential table check - feed consumptionName valueNode 1:FC t=0-9Node state 162.96 FEsvParent state 27.0 kg, 83.64 kgsigma 1 FEsvmean 166.3 FEsvinterval size 5.01 FEsvInterval centre 162.96 FEsvP(X<(istart-mean)/sigma) 0.00000P(X<(islut-mean)/sigma) 0.20165P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.20165Value in table 0.202Match? Yes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:FC t=9-10Node state 20.73 FEsvParent state 72.84 kg, 80.26 kgsigma 1 FEsvmean 23.24 FEsvinterval size 0.63 FEsvInterval centre 20.73 FEsvP(X<(istart-mean)/sigma) 0.00238P(X<(islut-mean)/sigma) 0.01404P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.01166Value in table 0.012Match? Yes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:FC t=9-10Node state 23.24 FEsvParent state 78.24 kg, 86.26 kgsigma 1 FEsvmean 25.12 FEsvinterval size 0.63 FEsvInterval centre 23.24 FEsvP(X<(istart-mean)/sigma) 0.01416P(X<(islut-mean)/sigma) 0.05862P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.04446Value in table 0.986Match? Yes (border state)

Page 84: Optimization of delivery strategies for slaughter pigs

76 APPENDIX A. VERIFICATION LOG

Table A.12: Potential table check - slaughter weightName valueNode 1:SW t=9Node state 58.79 kgParent state Yes, 72.84 kg, 7.02 kgsigma 1 kgmean 57.87 kginterval size 1.44 kgInterval centre 58.79 kgP(X<(istart-mean)/sigma) 0.57775P(X<(islut-mean)/sigma) 0.94897P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.37122Value in table 0.371Match? Yes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:SW t=9Node state 68.86 kgParent state Yes, 90.84 kg, 5.82 kgsigma 1 kgmean 71.21 kginterval size 1.44 kgInterval centre 68.86 kgP(X<(istart-mean)/sigma) 0.00106P(X<(islut-mean)/sigma) 0.05102P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.04996Value in table 0.050Match? Yes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:SW t=11Node state 65.62 kgParent state Yes, 88.08 kg, 6.02 kgsigma 1 kgmean 69.17 kginterval size 1.74 kgInterval centre 65.62 kgP(X<(istart-mean)/sigma) 0.00000P(X<(islut-mean)/sigma) 0.00366P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.00366Value in table 0.004Match? Yes (border state). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:SW t=11Node state 74.34 kgParent state Yes, 96.88 kg, 7.02 kgsigma 1 kgmean 76.21 kginterval size 1.74 kgInterval centre 74.34 kgP(X<(istart-mean)/sigma) 0.00301P(X<(islut-mean)/sigma) 0.15796P((istart-mean)/sigma<X<(islut-mean)/sigma) 0.15495Value in table 0.155Match? Yes

Page 85: Optimization of delivery strategies for slaughter pigs

77

the potential for alive is 0 if the observed live weight is dead or delivered and 1 inall other cases. No errors were found.

The pig counter nodes are also checked just by looking at the tables and makingsure that the potentials are 1 and 0 in the right places, this is simplified by thesymmetry in the potential tables. No errors were found.

Now all potential tables for the chance nodes have been verified.

The Utility nodes do not have potentials, but specific values for each parent statecombination. The correctness of these values are checked and the results arepresented here.

The pig price is -330 DKK (an expense) for all states, that is correct since it isassumed that the pigs are not paid by individual weight.

The feed price is tested and the results are shown in table A.13, whereNodeis thename of the node,Parent stateis the chosen state of the parent(s),Expected utilityis a the manually calculated utility value based on the parental state(s),Utility intableis the value shown in the utility table andMatch? is an indication of whetherthe two utility values are the same. No errors were found.

Table A.13: Utility value check - feed priceName valueNode 1:FP t=0-9Parent state 137.91 FEsvExpected utility -151.7 DKKUtility in table -151.7 DKKMatch? Yes. . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:FP t=0-9Parent state 172,98 FEsvExpected utility -190.28 DKKUtility in table -190,28 DKKMatch? Yes. . . . . . . . . . . . . . . . . . . . . . . . . . . . .Node 1:FP t=10-11Parent state 23.24 FEsvExpected utility -25.56 DKKUtility in table -25.56 DKKMatch? Yes

In table A.14 is shown the results of the checks of the slaughter price nodes. Allchecked values were correct.

Page 86: Optimization of delivery strategies for slaughter pigs

78 APPENDIX A. VERIFICATION LOG

Table A.14: Utility value check - slaughter priceName valueNode 1:SP t=9Parent state 70.30 kgExpected utility 611.60 DKKUtility in table 611.60 DKKMatch? Yes

Node 1:SP t=9Parent state 57.35 kgExpected utility 407.18 DKKUtility in table 407.18 DKKMatch? Yes

Node 1:SP t=12Parent state 88.72 kgExpected utility 736.39 DKKUtility in table 736.39 DKKMatch? Yes

The result of checking the termination value is shown in table A.15. Since thetermination value is the same for all weeks, it is only tested fort = 9 and it ischeck that all termination value utility tables are identical. The value was foundto be correct.

Table A.15: Utility value check - termination valueName valueNode TV t=9Parent state 0 aliveExpected utility 133.33 DKKUtility in table 133.33 DKKMatch? Yes

No errors were found during the utility value checks.

The computerized model verification has been completed, the errors have beencorrected and it can be verified that the PigLimid is a satisfying representation ofthe conceptual model made in chapter 4.

Page 87: Optimization of delivery strategies for slaughter pigs

79

Operational validity

The operational validity of the PigLimid is checked by testing the logic of theoutput.

The PigLimid is built with 4 pigs and 11 weight intervals. This combination ischosen in order to keep the dynamics from having several pigs, and still be ableto have enough states without requiring too much processing time.

First the model is compiled, the decision node order is set to go from week 12 to9, and a single policy update is performed. Then all monitor windows for the firstpig are opened as well as the pig counter 2. A screen dump is taken in order to beable to review the result later.

Then evidence is entered as shown in the list below and the behaviour of thepotentials are observed. A screen dump is taken each time and two of those canbe seen in figure A.1 and A.2

• 1:LW t=0: set to 28.8 kg -The potentials for live weight and observed liveweight are shifted slightly towards lower weights, the utility value is decreasedand the probability for slaughter at t=11 is decreased.

• 1:OLW t=9: set to 80.04 kg -The potentials for live weight and observed liveweight are clearly concentrated around the chosen state. In most monitor windowsonly 3 or 4 states have visible potentials, with the distribution of the observed liveweights being slightly broader than that of the live weight. The potentials for thegrowth capacity fort = 0 are also concentrated on 4 states, the feed consumptionpotentials are slightly more concentrated as are the potentials for the slaughterweight att = 12, which is the only week slaughter is taking place.

• 1:OLW t=10: set to 84.26 kg -This evidence insertion further narrows thevisible potentials, as can be seen in figure A.2. The growth capacity potentials aremoved slightly upwards.

• 1:OLW t=11: set to 90.28 kg -The narrowing is continued

• 1:OLW t=12: set to 96.30 kg -The insertion of the final observed live weightnarrows the visible potentials a bit more.

It is concluded that the behaviour of the model is as intended, and no changes aremade.

Page 88: Optimization of delivery strategies for slaughter pigs

80 APPENDIX A. VERIFICATION LOG

Figure A.1: The operational validity test without any evidence entered.

Page 89: Optimization of delivery strategies for slaughter pigs

81

Figure A.2: The operational validity test with live weight entered in week 0, andobserved live weight entered in week 9 and 10.

Page 90: Optimization of delivery strategies for slaughter pigs

82 APPENDIX A. VERIFICATION LOG

Finally it is checked whether the strategies created by the single policy updating(SPU) are satisfying. The model is built with 4 pigs and 11 weight intervals. Themodel is compiled and the decision node order is set to go from week 12 to 9. Theresults are shown in table A.16, whereAll S? = No indicates that all states in thedecision nodes from week 9 to 11 is set to No (week 12 only has Yes as option),Utility Value is the value given in the utility node monitor window after the actionabove has taken place,S? = yes, for t= Xindicates, that all states in the decisionnode for week X has been set to yes.

During the test, only the changes mentioned in the table is made, and the changesare kept during the rest of the changes. After finding the utility value for slaugh-tering all pigs in a given week, a SPU was performed,Utility value in tableis thelast value in the iteration window shown after the SPU is finished,Utility value inmonitor windowis the utility value shown in the monitor window after the SPUtable is closed,Week X, pig Y, yesis the value given for yes in the S? monitorwindow for the given week and pig,Change week X pig Y to Z Yesindicates, thatfor the given week and pig the Z last states is set to Yes.

During this test several problems were found. The value in the SPU table didnot match the value in the monitor window, and they should be identical. Theutility value (shown in the monitor window) after the SPU was lower than the onefound by keeping all pigs until week 12, which indicated that the strategy wasnot globally optimal, furthermore the strategy for week 11 was different for the 4pigs, which should not be the case since the pigs are identical before evidence isentered.

The “Esthauge LIMID software system” was checked by Anders Ringgaard Kris-tensen for errors that could cause this behaviour, but no errors were found, andthe problems seen in the PigLimid could not be found in other LIMIDs. Hencethe problems seems to be caused by the PigLimid itself.

By changing the strategies one state at a time it was shown, that the strategy givenby the SPU was not only not globally optimal but not locally optimal either. Theoptimal strategy was found to be to slaughter only pigs in the heaviest state inweek 11 and all other in week 12.

If the mortality rate was set to 0 the difference between the SPU table utilityvalue and the value in the monitor window disappeared. The PigLimid was re-programmed, so the options dead and delivered were split into two separate states,but as opposed to the expected effect none were seen. Although it did not have thedesired effect, the separate states for dead and delivered were kept in the modelsince it was considered more informative and correct. It was checked that the

Page 91: Optimization of delivery strategies for slaughter pigs

83

Table A.16: Operational validity checkAction resultsAll S? = NoUtility Value 407.43S? = yes, for t= 11Utility Value 369.35S? = yes, for t= 10Utility Value 287.13S? = yes, for t= 9Utility Value 154.77Single policy updatingUtility Value in table 473.34Utility Value in monitor window 396.26Week 9, pig 1, Yes 0.033Week 9, pig 2, Yes 0.033Week 9, pig 3, Yes 0.033Week 9, pig 4, Yes 0.033Week 10, pig 1, Yes 0.037Week 10, pig 2, Yes 0.037Week 10, pig 3, Yes 0.037Week 10, pig 4, Yes 0.037Week 11, pig 1, Yes 0.209Week 11, pig 2, Yes 0.450Week 11, pig 3, Yes 0.209Week 11, pig 4, Yes 0.318Change week 11 pig 2 to 4 YesUtility Value 398.58Change week 11 pig 2 to 3 YesUtility Value 400.51Change week 11 pig 4 to 3 YesUtility Value 402.45Change week 11 pig 4 to 2 YesUtility Value 403.65Change week 11 pig 3 to 2 YesUtility Value 404.86Change week 11 pig 2 to 2 YesUtility Value 406.07Change week 11 pig 1 to 2 YesUtility Value 407.29Change week 11 pig 1 to 1 YesUtility Value 407.57Change week 11 pig 2 to 1 YesUtility Value 407.85Change week 11 pig 3 to 1 YesUtility Value 408.14Change week 11 pig 4 to 1 YesUtility Value 408.42Change week 11 pig 4 to 0 YesUtility Value 408.17

Page 92: Optimization of delivery strategies for slaughter pigs

84 APPENDIX A. VERIFICATION LOG

affected potential tables looked correct, but no new verification was done.

Experiments were made with removing the termination value nodes from the net,the results are shown in table A.17 and A.18. This also illustrates the result ofsetting the mortality rate to 0. As it can be seen, the removal of the terminationvalue nodes eliminates the strategy problem. Since the removal of the terminationvalue nodes removes the interaction between pigs, the model could as well bemade for one pig only, thus the change is not implemented.

No further tests are performed during the validation.

Table A.17: No termination value, with mortalityName results4 pigs, 11 states, MR= 0.044Utility Value in table 475.51Utility Value in monitor window 398.58strategy week 11 pig 1 3 Yesstrategy week 11 pig 2 3 Yesstrategy week 11 pig 3 4 Yesstrategy week 11 pig 4 4 YesWithout TV nodesUtility Value in table 466.48Utility Value in monitor window 408.42strategy week 11 pig 1 1 Yesstrategy week 11 pig 2 1 Yesstrategy week 11 pig 3 1 Yesstrategy week 11 pig 4 1 Yes

Table A.18: No termination value, without mortalityName results4 pigs, 11 states, MR= 0.0Utility Value in table 485.16Utility Value in monitor window 485.17strategy week 11 pig 1 3 Yesstrategy week 11 pig 2 3 Yesstrategy week 11 pig 3 3 Yesstrategy week 11 pig 4 4 YesWithout TV nodesUtility Value in table 495.19Utility Value in monitor window 495.19strategy week 11 pig 1 1 Yesstrategy week 11 pig 2 1 Yesstrategy week 11 pig 3 1 Yesstrategy week 11 pig 4 1 Yes

Page 93: Optimization of delivery strategies for slaughter pigs

Appendix B

Code

PigLimid.javaCreated with JBuilderpackage dk.stenner.PigLimid;

import java.awt.Point;import java.util.*;import dk.esthauge.limid.gui.*;import dk.esthauge.limid.api.*;import dk.esthauge.limid.api.LabeledLimidChanceNode;import dk.esthauge.limid.api.BooleanLimidChanceNode;import dk.kvl.ihh.prodstyr.mlhmp.ArrayProbabilityProvider;import dk.esthauge.limid.api.NodeList;import dk.esthauge.limid.api.LimidDomain;

public class PigLimid{// class vars - accessible from all methods

//Pen related variablesstatic int NP = 2; //NP = number of pigs (minimum 2, maximum 16)static int NS = 5; //NS = Number of stagesstatic int SO = 9; //SO = Start week of observationstatic int DS = 3; //DS = Days from decision to slaughterstatic float MR = 0.0F; //MR = overall mortality ratestatic float MR0 = MR/(NS+SO-2)*SO; //MR0 = mortality rate for the weeks until start of observationstatic float MRT = MR/(NS+SO-2);//MRT = weekly mortality rate from start of observation until termination

//Price related variablesstatic float PI = 330F; //PI = Pig Price at insertion (DKK)static float FPR = 1.10F; //FPR = Feed price (DKK/FEsv)static float SPR = 8.70F; //SPR = base slaughter price (DKK/kg)static float GM = 100F; //GM = average gross margin (daekningsbidrag) per pig (DKK)

//Weight related variablesstatic float WI = 30; //WI = Average weight at insertion (kg)static int NWI = 11; //NWI = Number of weight intervals for each weight node (must be an unequal number).static float G = 6F; //G = Average weekly gain (kg)static float SigmaWI = 1.5F; //SigmaWI = Std.dev. for live weight at insertionstatic int WIMaxDev = 2; // WIMaxDev = the max number of std deviations to use in the LW t=0 node.static float MWI = 2*WIMaxDev*SigmaWI; //MWI = Maximum difference between pigs at insertion (kg)static float SigmaOW = 1.0F; //SigmaOW = Std.dev. for observed live weight (meassurement error)static float SigmaGC = 0.5F; //SigmaGC = Std.dev. for weekly gainstatic int GCMaxDev = 2; // GCMaxDev = the max number of std deviations to use in the GC, LW and OW nodes.static float MG = 2*GCMaxDev*SigmaGC; //MG = Maximum difference in weekly gain between fastest and slowestgrowing pig (kg)static float GF = 0.96F; //GF = Scaling factor for Weekly gain in the first weeks as percentage of Gstatic float GL = 1.07F; //GL = Scaling factor for Weekly gain in the last weeks as percentage of Gstatic float G0 = (G * GF); //G0 = Weekly gain in the first weeksstatic float GT = (G * GL); //GT = Weekly gain in the last weeksstatic float SF = 0.763F; //SF = Slaughter factorstatic float SigmaSW = 1.0F; //SigmaSW = Std.dev. for slaughter weight

//Feed related variables

85

Page 94: Optimization of delivery strategies for slaughter pigs

86 APPENDIX B. CODE

static float F = 2.9F; //F = Average feed efficiency (FEsv/kg)static float SigmaFC = 1.0F; //SigmaSW = Std.dev. for feed consumptionstatic float FF = 0.96F; //FF = Scaling factor for Feed efficiency in the first weeks as percentage of Fstatic float FL = 1.08F; //FL = Scaling factor for Feed efficiency in the last weeks as percentage of Fstatic float F0 = (F * FF); //F0 = Feed efficiency in the first weeksstatic float FT = (F * FL); //F0 = Feed efficiency in the last weeks

static LimidDomain domain = new LimidDomain("PigLimid");

static int[] nodeStates; //The number of states per node used in the creation of probability tables

static LabeledLimidChanceNode[][] LW = new LabeledLimidChanceNode[NS][NP]; // LW = Live weight (kg)static LabeledLimidChanceNode[][] SW = new LabeledLimidChanceNode[NS][NP]; // SW = slaughter weight (kg)static LabeledLimidChanceNode[][] FC = new LabeledLimidChanceNode[NS][NP]; // FC = feed consumption (FEsv)static LabeledLimidChanceNode[][] GC = new LabeledLimidChanceNode[NS][NP]; // GC = Growth capacity forthe pig (kg/week)static LabeledLimidChanceNode[][] OW = new LabeledLimidChanceNode[NS][NP]; // OW = Observed Live weight (kg)static LabeledLimidChanceNode[][] PC1 = new LabeledLimidChanceNode[NS][NP]; //PC1 = Pig counter 2 pigsstatic LabeledLimidChanceNode[][] PC2 = new LabeledLimidChanceNode[NS][NP]; //PC2 = Pig counter 4 pigsstatic LabeledLimidChanceNode[][] PC3 = new LabeledLimidChanceNode[NS][NP]; //PC3 = Pig counter 8 pigsstatic LabeledLimidChanceNode[][] PC4 = new LabeledLimidChanceNode[NS][NP]; //PC4 = Pig counter 16 pigsstatic LabeledLimidChanceNode[][] DA = new LabeledLimidChanceNode[NS][NP]; //DA = Dead or alive

static TimeUtilityNode[][] SP = new TimeUtilityNode[NS][NP]; //SP = Slaughter price (DKK per pig)static TimeUtilityNode[][] FP = new TimeUtilityNode[NS][NP]; //FP = Feed price (DKK)static TimeUtilityNode[][] PP = new TimeUtilityNode[1][NP]; //PP = Pig price at insertion (DKK)static TimeUtilityNode[][] TV = new TimeUtilityNode[NS][NP]; //TV = Termination value (DKK)

static LabeledDiscreteDecisionChanceNode[][] S = new LabeledDiscreteDecisionChanceNode[NS][NP];//S = Slaughter yes/nostatic Potential table; // assigned value in main()/**

* Creates the PigLimid*/

public static void main(String[] args) {try {

//Creation of nodes, edges and potential tablesfor (int s = 0; s < NS; s++) { //The entire amount of stages

for (int n = 0; n < NP; n++) { //All pigsInitGC( s,n );InitLW( s,n );InitOW( s,n );InitDA( s,n );InitFC( s,n );InitFP( s,n );InitS( s,n );InitSW( s,n );InitSP( s,n );InitPP( s,n );InitPC1( s,n );InitPC2( s,n );InitPC3( s,n );InitPC4( s,n );InitTV( s,n );

AssignGCProbs( s,n );AssignOWProbs( s,n );AssignDAProbs( s,n );AssignLWProbs( s,n );AssignSWProbs( s,n );AssignFCProbs( s,n );AssignPC1Probs( s,n );AssignPC2Probs( s,n );AssignPC3Probs( s,n );AssignPC4Probs( s,n );

} //end for n} // end for s

System.out.println("PigLimid created");

// Put labels equal to namesNodeList nodes = domain.getNodes();Iterator itera = nodes.iterator();while (itera.hasNext()) {

Node node = (Node) itera.next();node.setLabel(node.getName());

}//Defines decision node order as last -> firstNodeList ordering = new NodeList();for (int s = S.length-1; s > 0; s--) {

for (int n = 0; n < S[s].length; n++) {ordering.add(S[s][n]);

}

Page 95: Optimization of delivery strategies for slaughter pigs

87

}domain.compile(); //Compiles the LIMID before showing itdomain.setDefaultOrdering(ordering); //sets the decision node order

LimidFrame frame = new LimidFrame(); //Shows the LIMIDframe.addLimid(domain);frame.show();

} // end trycatch (Exception eh) {

System.out.println(eh.getMessage());eh.printStackTrace();

} // end catch} // end main

// initialisation of GCstatic void InitGC( int s, int n ){

try {GC[s][n] = new LabeledLimidChanceNode(domain); //Creates the Growth capacity chance nodeGC[s][n].setPosition(new Point(20 + 255 * s, 120 + 580*n));GC[s][n].setNumberOfStates(NWI);if( s != 0 ){

GC[s][n].setStateLabel( ( (NWI - 1) / 2), (GT) + " kg");int i;for( i = 1; i <= (NWI-1)/2; i++ ){

GC[s][n].setStateLabel( (NWI - 1) / 2 + i, (GT + i * MG / (NWI - 1)) + " kg");GC[s][n].setStateLabel( (NWI - 1) / 2 - i, (GT - i * MG / (NWI - 1)) + " kg");

}GC[s][n].setName((n+1) + ":GC t=" + (s + (SO - 1)));GC[s][n].setLabel((n+1) + ":GC t=" + (s + (SO - 1)));GC[s][n].addParent(GC[s - 1][n]); //adds parents for GC

}else{

GC[s][n].setStateLabel(((NWI - 1)/2), (G0) + " kg");int i;for( i = 1; i <= (NWI-1)/2; i++ ){

GC[s][n].setStateLabel((NWI - 1)/2 + i, (G0 + i * MG/(NWI - 1)) + " kg");GC[s][n].setStateLabel((NWI - 1)/2 - i, (G0 - i * MG/(NWI - 1)) + " kg");

}GC[s][n].setName((n+1) + ":GC t=0");GC[s][n].setLabel((n+1) + ":GC t=0");

}}catch (Exception eh) {

System.out.println(eh.getMessage());eh.printStackTrace();

}}

// initialisation of LWstatic void InitLW( int s, int n ){

try {if( s == 0 ) {

LW[s][n] = new LabeledLimidChanceNode(domain); //Creates the Live weight chance node at t = 0LW[s][n].setPosition(new Point(20 + 255 * s, 240 + 580*n));LW[s][n].setNumberOfStates(NWI);LW[s][n].setStateLabel(((NWI - 1)/2 -1), (WI + " kg"));int i;for( i = 0; i <= (NWI-1)/2; i++ ){

LW[s][n].setStateLabel((NWI - 1)/2 + i, (WI + (i * MWI/(NWI - 1))) + " kg");LW[s][n].setStateLabel((NWI - 1)/2 - i, (WI - i * MWI/(NWI - 1)) + " kg");

}LW[s][n].setName((n+1) + ":LW t=" + (s));LW[s][n].setLabel((n+1) + ":LW t=" + (s));

} // end if s == 0else if (s == 1){

LW[s][n] = new LabeledLimidChanceNode(domain); //Creates the Live weight chance node at t = SOLW[s][n].setPosition(new Point(20 + 255 * s, 240 + 580*n));LW[s][n].setNumberOfStates(NWI + 1);LW[s][n].setStateLabel(0, "Dead");LW[s][n].setStateLabel(((NWI + 1)/2), (WI + ((G0) * (SO))) + " kg");int i;for( i = 1; i <= (NWI-1)/2; i++ ){

LW[s][n].setStateLabel((NWI + 1)/2 + i, (WI + ((G0 + i * MG/(NWI - 1))*(SO))) + " kg");

Page 96: Optimization of delivery strategies for slaughter pigs

88 APPENDIX B. CODE

LW[s][n].setStateLabel((NWI + 1)/2 - i, (WI + ((G0 - i * MG/(NWI - 1))*(SO))) + " kg");}LW[s][n].setName((n+1) + ":LW t=" + (s + (SO -1)));LW[s][n].setLabel((n+1) + ":LW t=" + (s + (SO -1)));LW[s][n].addParent(GC[s -1][n]); //adds parents to LW node at s=1LW[s][n].addParent(LW[s - 1][n]);

} // end if s == 1else{

LW[s][n] = new LabeledLimidChanceNode(domain);//Creates the Live weight chance node at t>SOLW[s][n].setPosition(new Point(20 + 255 * s, 240 + 580*n));LW[s][n].setNumberOfStates(NWI + 2);LW[s][n].setStateLabel(0, "Dead");LW[s][n].setStateLabel(1, "Delivered");LW[s][n].setStateLabel(((NWI + 1)/2)+1, (WI + ((G0) * (SO)) + ((s - 1)*GT)) + " kg");int i;for( i = 1; i <= (NWI-1)/2; i++ ){

LW[s][n].setStateLabel((NWI + 1)/2 + i + 1, (WI + ((G0 + i * MG/(NWI - 1))*(SO)) +((GT + i*MG/(NWI - 1))*(s-1))) + " kg");

LW[s][n].setStateLabel((NWI + 1)/2 - i + 1, (WI + ((G0 - i * MG/(NWI - 1))*(SO)) +((GT - i*MG/(NWI - 1))*(s-1))) + " kg");

}LW[s][n].setName((n+1) + ":LW t=" + (s + (SO -1)));LW[s][n].setLabel((n+1) + ":LW t=" + (s + (SO -1)));LW[s][n].addParent(S[s - 1][n]);LW[s][n].addParent(GC[s -1][n]); //adds parents to LW node at s>1LW[s][n].addParent(LW[s - 1][n]);

} // end else (s > 1 )}catch (Exception eh) {

System.out.println(eh.getMessage());eh.printStackTrace();

}}

// initialisation of OWstatic void InitOW( int s, int n ){

try {if (s == 0) {

// do nothing}else if (s == 1) {

OW[s][n] = new LabeledLimidChanceNode(domain); //Creates the observed live weightchance node at t = SO

OW[s][n].setPosition(new Point(20 + 255 * s, 180 + 580*n));OW[s][n].addParent(LW[s][n]);OW[s][n].setNumberOfStates(NWI + 1);OW[s][n].setStateLabel(0, "Dead");OW[s][n].setStateLabel(((NWI + 1)/2), (WI + ((G0) * (SO))) + " kg");int i;for( i = 1; i <= (NWI-1)/2; i++ ){

OW[s][n].setStateLabel((NWI + 1)/2 + i, (WI + ((G0 + i * MG/(NWI - 1))*(SO))) + " kg");OW[s][n].setStateLabel((NWI + 1)/2 - i, (WI + ((G0 - i * MG/(NWI - 1))*(SO))) + " kg");

}OW[s][n].setName((n+1) + ":OLW t=" + (s + (SO - 1)));OW[s][n].setLabel((n+1) + ":OLW t=" + (s + (SO - 1)));

} //end if s==1else{

OW[s][n] = new LabeledLimidChanceNode(domain); //Creates the observed live weightchance node at t > SO

OW[s][n].setPosition(new Point(20 + 255 * s, 180 + 580*n));OW[s][n].addParent(LW[s][n]);OW[s][n].setNumberOfStates(NWI + 2);OW[s][n].setStateLabel(0, "Dead");OW[s][n].setStateLabel(1, "Delivered");OW[s][n].setStateLabel(((NWI + 1)/2) + 1, (WI + ((G0) * (SO)) + ((s - 1)*GT)) + " kg");int i;for( i = 1; i <= (NWI-1)/2; i++ ){

OW[s][n].setStateLabel((NWI + 1)/2 + i + 1, (WI + ((G0 + i * MG/(NWI - 1))*(SO)) +((GT + i*MG/(NWI - 1))*(s-1))) + " kg");

OW[s][n].setStateLabel((NWI + 1)/2 - i + 1, (WI + ((G0 - i * MG/(NWI - 1))*(SO)) +((GT - i*MG/(NWI - 1))*(s-1))) + " kg");

}OW[s][n].setName((n+1) + ":OLW t=" + (s + (SO -1)));OW[s][n].setLabel((n+1) + ":OLW t=" + (s + (SO -1)));

} // end s > 1} // end trycatch (Exception eh)

Page 97: Optimization of delivery strategies for slaughter pigs

89

{System.out.println(eh.getMessage());eh.printStackTrace();

}}// initialisation of DAstatic void InitDA( int s, int n ){

try {if (s == 0) {

// do nothing}else {

DA[s][n] = new LabeledLimidChanceNode(domain); //Creates the Dead/alive chance node at t > 0DA[s][n].setPosition(new Point(130 + 255 * s, 140 + 580*n));DA[s][n].addParent(OW[s][n]);DA[s][n].setNumberOfStates(2);DA[s][n].setStateLabel(0, "Dead");DA[s][n].setStateLabel(1, "Alive");DA[s][n].setName((n+1) + ":D/A? t=" + (s + (SO - 1)));DA[s][n].setLabel((n+1) + ":D/A? t=" + (s + (SO - 1)));

} //end if s > 0} // end trycatch (Exception eh){

System.out.println(eh.getMessage());eh.printStackTrace();

}}

// initialisation of FCstatic void InitFC( int s, int n ){

try {if( s == 0 ) {

// do nothing}else if( s == 1 ) {

FC[s][n] = new LabeledLimidChanceNode(domain);//Creates the Feed consumption chance node at t = 0 to t = SO

FC[s][n].setPosition(new Point(80 + 255 * s - 255, 400 + 580*n));FC[s][n].setNumberOfStates(NWI + 1);FC[s][n].setStateLabel(0, "0 FEsv");FC[s][n].setStateLabel(((NWI + 1)/2), (((G0) * (SO)) * F0 + DS/7.0F*GT*FT) + " FEsv");int i;for( i = 1; i <= (NWI-1)/2; i++ ){

FC[s][n].setStateLabel((NWI + 1)/2 + i, (((G0 + i * MG/(NWI - 1))*(SO))* F0 + DS/7.0F*GT*FT) + " FEsv");

FC[s][n].setStateLabel((NWI + 1)/2 - i, (((G0 - i * MG/(NWI - 1))*(SO))* F0 + DS/7.0F*GT*FT) + " FEsv");

}

FC[s][n].setName((n+1) + ":FC t=" + (s - 1) + "-" + (s - 1 + SO));FC[s][n].setLabel((n+1) + ":FC t=" + (s - 1) + "-" + (s - 1 + SO));

// FC[s][n].addParent(FE[s - 1][n]);//Adds FEP for t as parent to FC for t, for s=0FC[s][n].addParent(LW[s - 1][n]);FC[s][n].addParent(LW[s][n]);

} // end if s == 1else { // s > 1

FC[s][n] = new LabeledLimidChanceNode(domain);//Creates the Feed consumption chance node at t = SO to t = SO + NSFC[s][n].setPosition(new Point(80 + 255 * s - 255, 400 + 580*n));FC[s][n].setNumberOfStates(NWI + 1);FC[s][n].setStateLabel(0, "0 FEsv");FC[s][n].setStateLabel(((NWI + 1) / 2), (GT)*FT + " FEsv");int i;for( i = 1; i <= (NWI-1)/2; i++ ){

FC[s][n].setStateLabel((NWI + 1) / 2 + i, (GT + i * MG / (NWI - 1))*FT + " FEsv");FC[s][n].setStateLabel((NWI + 1) / 2 - i, (GT - i * MG / (NWI - 1))*FT + " FEsv");

}

FC[s][n].setName((n+1) + ":FC t=" + (s - 1 + (SO -1)) + "-" + (s - 1 + SO));FC[s][n].setLabel((n+1) + ":FC t=" + (s - 1 + (SO -1))+ "-" + (s - 1 + SO));FC[s][n].addParent(LW[s - 1][n]);FC[s][n].addParent(LW[s][n]);

}// end s > 1} // end trycatch (Exception eh) {

Page 98: Optimization of delivery strategies for slaughter pigs

90 APPENDIX B. CODE

System.out.println(eh.getMessage());eh.printStackTrace();

}}

// initialisation of FPstatic void InitFP( int s, int n ){

try {if( s == 0 ) {

// do nothing}else if( s == 1 ) {

FP[s][n] = new TimeUtilityNode(domain);//Creates the Feed price utility node at t = 0 to t = SO

FP[s][n].addParent(FC[s][n]);FP[s][n].setPosition(new Point(80 + 255 * s - 255, 450 + 580*n));FP[s][n].setName((n+1) + ":FP t=" + (s - 1) + "-" + (s - 1 + SO));FP[s][n].setLabel((n+1) + ":FP t=" + (s - 1) + "-" + (s - 1 + SO));table = FP[s][n].getTable();

//Creates the utility value table for PP as a function of PItable.setDataItem(0, 0);table.setDataItem(((NWI + 1)/2), (((G0) * (SO)) * F0 + DS/7.0F*FT) * FPR * (-1));int i;for( i = 1; i <= (NWI-1)/2; i++ ){

table.setDataItem((NWI + 1)/2 + i, (((G0 + i * MG/(NWI - 1))*(SO))* F0 + DS/7.0F*GT*FT) * FPR * (-1));

table.setDataItem((NWI + 1)/2 - i, (((G0 - i * MG/(NWI - 1))*(SO))* F0 + DS/7.0F*GT*FT) * FPR * (-1));

}

} // end if s == 1else { // s > 1

FP[s][n] = new TimeUtilityNode(domain);//Creates the Feed price utility node for t = SO to t = T-1

FP[s][n].addParent(FC[s][n]); //adds parent for FPFP[s][n].setPosition(new Point(80 + 255 * s - 255, 450 + 580*n));table = FP[s][n].getTable();FP[s][n].setName((n+1) + ":FP t=" + (s - 1 + (SO -1))+ "-" + (s - 1 + SO));FP[s][n].setLabel((n+1) + ":FP t=" + (s - 1 + (SO -1))+ "-" + (s - 1 + SO));table.setDataItem(0, 0);table.setDataItem(((NWI + 1) / 2), (GT)*FT * FPR * (-1));int i;for( i = 1; i <= (NWI-1)/2; i++ ){

table.setDataItem(((NWI + 1) / 2 + i), (GT + i * MG / (NWI - 1))*FT * FPR * (-1));table.setDataItem(((NWI + 1) / 2 - i), (GT - i * MG / (NWI - 1))*FT * FPR * (-1));

}

}// end s > 1} // end trycatch (Exception eh){

System.out.println(eh.getMessage());eh.printStackTrace();

}}

// initialisation of Sstatic void InitS( int s, int n ){

try {if( s == 0 ) {

// do nothing}else if( s == 1 ){

S[s][n] = new LabeledDiscreteDecisionChanceNode(domain);//Creates the Slaughter? decision node.

S[s][n].setNumberOfStates(2);S[s][n].addParent(OW[s][n]); //adds parents to SS[s][n].setPosition(new Point(70 + 255 * s, 210 + 580*n));S[s][n].setName((n+1) + ":S? t=" + (s + (SO -1)));S[s][n].setLabel((n+1) + ":S? t=" + (s + (SO -1)));S[s][n].setStateLabel(0, "Yes");S[s][n].setStateLabel(1, "No");

} // end s == 1else if(s == NS-1){

S[s][n] = new LabeledDiscreteDecisionChanceNode(domain);//Creates the Slaughter? decision node.

S[s][n].setNumberOfStates(1);S[s][n].addParent(OW[s][n]); //adds parents to S

Page 99: Optimization of delivery strategies for slaughter pigs

91

S[s][n].setPosition(new Point(70 + 255 * s, 210 + 580*n));S[s][n].setName((n+1) + ":S? t=" + (s + (SO -1)));S[s][n].setLabel((n+1) + ":S? t=" + (s + (SO -1)));S[s][n].setStateLabel(0, "Yes");

}else {

S[s][n] = new LabeledDiscreteDecisionChanceNode(domain);//Creates the Slaughter? decision node.

S[s][n].setNumberOfStates(2);S[s][n].addParent(OW[s][n]); //adds parents to SS[s][n].setPosition(new Point(70 + 255 * s, 210 + 580*n));S[s][n].setName((n+1) + ":S? t=" + (s + (SO -1)));S[s][n].setLabel((n+1) + ":S? t=" + (s + (SO -1)));S[s][n].setStateLabel(0, "Yes");S[s][n].setStateLabel(1, "No");

}} // end trycatch (Exception eh){

System.out.println(eh.getMessage());eh.printStackTrace();

}}

// initialisation of SWstatic void InitSW( int s, int n ){

try {if( s == 0 ) {

// do nothing}else {

SW[s][n] = new LabeledLimidChanceNode(domain);//Creates the Slaughter weight chance node at t = SO to t = SO + NS

SW[s][n].addParent(S[s][n]);SW[s][n].addParent(LW[s][n]); //adds parents for SWSW[s][n].addParent(GC[s][n]);SW[s][n].setPosition(new Point(200 + 255 * s, 280 + 580*n));SW[s][n].setNumberOfStates(NWI + 1);SW[s][n].setStateLabel(0, "0 kg");SW[s][n].setStateLabel(((NWI + 1)/2), (((WI + ((G0) * (SO))) + GT *((s - 1) +

(DS/7.0F)))*SF) + " kg");

int i;for( i = 1; i <= (NWI-1)/2; i++ ){

SW[s][n].setStateLabel( (NWI + 1)/2 + i, ((WI + ((G0 + i * MG/(NWI - 1))*(SO))) +(GT + i * MG/(NWI - 1)) *((s - 1) + DS/7.0F))*SF + " kg");

SW[s][n].setStateLabel( (NWI + 1)/2 - i, ((WI + ((G0 - i * MG/(NWI - 1))*(SO))) +(GT - i * MG/(NWI - 1)) *((s - 1) + DS/7.0F))*SF + " kg");

}

SW[s][n].setName((n+1) + ":SW t=" + (s + (SO -1)));SW[s][n].setLabel((n+1) + ":SW t=" + (s + (SO -1)));

} // end s > 0} // end trycatch (Exception eh) {

System.out.println(eh.getMessage());eh.printStackTrace();

}}

// initialisation of SPstatic void InitSP( int s, int n ){

try {if( s == 0 ) {

// do nothing}else {

float SlaughterWeight;

SP[s][n] = new TimeUtilityNode(domain); //Creates the slaughter price utility node fort = SO to t = SO + NS

SP[s][n].addParent(SW[s][n]); //adds parent for SPSP[s][n].setPosition(new Point(200 + 255 * s, 360 + 580*n));SP[s][n].setName((n+1) + ":SP t=" + (s + (SO -1)));SP[s][n].setLabel((n+1) + ":SP t=" + (s + (SO -1)));table = SP[s][n].getTable(); //Creates the utility value table for PP as a function of PItable.setDataItem(0, 0);

SlaughterWeight = ((WI + G0 * SO) + GT *((s - 1) + (DS/7.0F)))*SF;table.setDataItem( (NWI + 1)/2, SlaughterWeight * GetSlaughterPrice( SlaughterWeight ) );

Page 100: Optimization of delivery strategies for slaughter pigs

92 APPENDIX B. CODE

int i;for( i=1; i <= (NWI-1)/2; i++ ){

SlaughterWeight = ((WI + ((G0 + i * MG/(NWI - 1))*SO)) + (GT + i * MG/(NWI - 1)) *((s - 1) + DS/7.0F))*SF;

table.setDataItem( (NWI + 1)/2 + i, SlaughterWeight*GetSlaughterPrice( SlaughterWeight ));

SlaughterWeight = ((WI + ((G0 - i * MG/(NWI - 1))*SO)) + (GT - i * MG/(NWI - 1)) *((s - 1) + DS/7.0F))*SF;

table.setDataItem( (NWI + 1)/2 - i, SlaughterWeight*GetSlaughterPrice( SlaughterWeight ));

}}

} // end trycatch (Exception eh) {

System.out.println(eh.getMessage());eh.printStackTrace();

}}

// initialisation of PPstatic void InitPP( int s, int n ){

try {if( s == 0 ) {

PP[s][n] = new TimeUtilityNode(domain); //Creates the Pig Price utility nodePP[s][n].addParent(LW[s][n]);PP[s][n].setPosition(new Point(20 + 255 * s, 360 + 580*n));PP[s][n].setName((n+1) + ":PP");PP[s][n].setLabel((n+1) + ":PP");table = PP[s][n].getTable(); //Creates the utility value table for PP as a

function of PIint i;for( i = 0; i < NWI; i++ ){

table.setDataItem(i, - PI);}

}else {

// do nothing}

} // end trycatch (Exception eh) {

System.out.println(eh.getMessage());eh.printStackTrace();

}}// initialisation of PC1static void InitPC1( int s, int n ){

try {if (s == 0 ){

// do nothing}else {

if (n%2 == 1) {PC1[s][n] = new LabeledLimidChanceNode(domain); //Creates the Pig counter chance nodePC1[s][n].addParent(DA[s][n - 1]);PC1[s][n].addParent(DA[s][n]);PC1[s][n].setPosition(new Point(130 + 255 * s, 580 * n));PC1[s][n].setNumberOfStates(3);PC1[s][n].setStateLabel(0, 0 + " alive");PC1[s][n].setStateLabel(1, 1 + " alive");PC1[s][n].setStateLabel(2, 2 + " alive");PC1[s][n].setName( n + "-" + (n + 1) + ":PC1 t=" + (s + SO - 1));PC1[s][n].setLabel(n + "-" + (n + 1) + ":PC1 t=" + (s + SO - 1));

}else {

if (n == NP - 1) {PC1[s][n] = new LabeledLimidChanceNode(domain); //Creates the Pig counter chance node//PC1[s][n].addParent(OW[s][n - 1]);PC1[s][n].addParent(DA[s][n]);PC1[s][n].setPosition(new Point(130 + 255 * s, 580 * n));PC1[s][n].setNumberOfStates(2);PC1[s][n].setStateLabel(0, 0 + " alive");PC1[s][n].setStateLabel(1, 1 + " alive");//PC1[s][n].setStateLabel(2, 2 + " alive");PC1[s][n].setName( (n + 1) + ":PC1 t=" + (s + SO - 1));PC1[s][n].setLabel((n + 1) + ":PC1 t=" + (s + SO - 1));

}}

Page 101: Optimization of delivery strategies for slaughter pigs

93

}} // end trycatch (Exception eh) {

System.out.println(eh.getMessage());eh.printStackTrace();

}}

// initialisation of PC2static void InitPC2( int s, int n ){

try {if (NP > 2) {

if (s == 0 ){// do nothing

}else {

if ( (n + 1) % 4 == 0) {PC2[s][n] = new LabeledLimidChanceNode(domain); //Creates the Pig counter chance nodePC2[s][n].addParent(PC1[s][n - 2]);PC2[s][n].addParent(PC1[s][n]);PC2[s][n].setPosition(new Point(150 + 255 * s, 40 + 580 * n));PC2[s][n].setNumberOfStates(5);PC2[s][n].setStateLabel(0, 0 + " alive");PC2[s][n].setStateLabel(1, 1 + " alive");PC2[s][n].setStateLabel(2, 2 + " alive");PC2[s][n].setStateLabel(3, 3 + " alive");PC2[s][n].setStateLabel(4, 4 + " alive");PC2[s][n].setName((n - 2) + "-" + (n + 1) + ":PC2 t=" + (s + SO - 1));PC2[s][n].setLabel((n - 2) + "-" + (n + 1) + ":PC2 t=" + (s + SO - 1));

}else {

if (n == NP - 1 && (n+2)%4 == 0) {PC2[s][n] = new LabeledLimidChanceNode(domain); //Creates the Pig counter chance nodePC2[s][n].addParent(PC1[s][n - 1]);PC2[s][n].addParent(PC1[s][n]);PC2[s][n].setPosition(new Point(150 + 255 * s, 40 + 580 * n));PC2[s][n].setNumberOfStates(4);PC2[s][n].setStateLabel(0, 0 + " alive");PC2[s][n].setStateLabel(1, 1 + " alive");PC2[s][n].setStateLabel(2, 2 + " alive");PC2[s][n].setStateLabel(3, 3 + " alive");PC2[s][n].setName( (n - 1) + "-" + (n + 1) + ":PC2 t=" + (s + SO - 1));PC2[s][n].setLabel((n - 1) + "-" + (n + 1) + ":PC2 t=" + (s + SO - 1));

}}

}} // end NP > 2else{

//do nothing}

} // end trycatch (Exception eh) {

System.out.println(eh.getMessage());eh.printStackTrace();

}}

// initialisation of PC3static void InitPC3( int s, int n ){

try {if (NP > 4) {

if (s == 0 ){// do nothing

}else {

int i;int j;if ( (n + 1) % 8 == 0) {

PC3[s][n] = new LabeledLimidChanceNode(domain); //Creates the Pig counter chance nodePC3[s][n].addParent(PC2[s][n - 4]);PC3[s][n].addParent(PC2[s][n]);PC3[s][n].setPosition(new Point(170 + 255 * s, 80 + 580 * n));PC3[s][n].setName((n - 6) + "-" + (n + 1) + ":PC3 t=" + (s + SO - 1));PC3[s][n].setLabel((n - 6) + "-" + (n + 1) + ":PC3 t=" + (s + SO - 1));PC3[s][n].setNumberOfStates(9);for (i = 0; i < 9; i++) {

PC3[s][n].setStateLabel(i, i + " alive");}

}else

for (j = 0; j < 3 ; j++) {

Page 102: Optimization of delivery strategies for slaughter pigs

94 APPENDIX B. CODE

if (n == NP - 1 && (n + 4 - j) % 8 == 0) {PC3[s][n] = new LabeledLimidChanceNode(domain); //Creates the Pig counter chance nodePC3[s][n].addParent(PC2[s][n - 1 - j]);if (j < 2)

PC3[s][n].addParent(PC1[s][n]);else {

PC3[s][n].addParent(PC2[s][n]);}PC3[s][n].setPosition(new Point(170 + 255 * s,80 + 580 * n));PC3[s][n].setName( (n - 3 - j) + "-" + (n + 1) + ":PC3 t=" + (s + SO - 1));PC3[s][n].setLabel( (n - 3 - j) + "-" + (n + 1) + ":PC3 t=" + (s + SO - 1));PC3[s][n].setNumberOfStates(6 + j);for (i = 0; i < 6 + j; i++) {

PC3[s][n].setStateLabel(i, i + " alive");}

}else {

// do nothing}

}}

} // end NP > 4else{//do nothing

}} // end trycatch (Exception eh){

System.out.println(eh.getMessage());eh.printStackTrace();

}}

// initialisation of PC4static void InitPC4( int s, int n ){

try {if (NP > 8) {

if (s == 0 ){// do nothing

}else {

int i;if ( (n + 1) % 16 == 0) {

PC4[s][n] = new LabeledLimidChanceNode(domain); //Creates the Pig counter chance nodePC4[s][n].addParent(PC3[s][n - 8]);PC4[s][n].addParent(PC3[s][n]);PC4[s][n].setPosition(new Point(200 + 255 * s, 80));PC4[s][n].setNumberOfStates(17);for (i = 0; i < n + 2; i++) {

PC4[s][n].setStateLabel(i, i + " alive");}PC4[s][n].setName((n - 14) + "-" + (n + 1) + ":PC4 t=" + (s + SO - 1));PC4[s][n].setLabel((n - 14) + "-" + (n + 1) + ":PC4 t=" + (s + SO - 1));

}else if (n == NP - 1 && (n+8)%16 == 0) {

PC4[s][n] = new LabeledLimidChanceNode(domain); //Creates the Pig counter chance nodePC4[s][n].addParent(PC3[s][n - 1]);PC4[s][n].addParent(PC1[s][n]);PC4[s][n].setPosition(new Point(200 + 255 * s, 80));PC4[s][n].setNumberOfStates(n+2);for (i = 0; i < n + 2; i++) {

PC4[s][n].setStateLabel(i, i + " alive");}PC4[s][n].setName( (n - 7) + "-" + (n + 1) + ":PC4 t=" + (s + SO - 1));PC4[s][n].setLabel((n - 7) + "-" + (n + 1) + ":PC4 t=" + (s + SO - 1));

}else if (n == NP - 1 && (n+7)%16 == 0) {

PC4[s][n] = new LabeledLimidChanceNode(domain); //Creates the Pig counter chance nodePC4[s][n].addParent(PC3[s][n - 2]);PC4[s][n].addParent(PC1[s][n]);PC4[s][n].setPosition(new Point(200 + 255 * s, 80));PC4[s][n].setNumberOfStates(n+2);for (i = 0; i < n + 2; i++) {

PC4[s][n].setStateLabel(i, i + " alive");}PC4[s][n].setName( (n - 8) + "-" + (n + 1) + ":PC4 t=" + (s + SO - 1));PC4[s][n].setLabel((n - 8) + "-" + (n + 1) + ":PC4 t=" + (s + SO - 1));

}else if (n == NP - 1 && (n+6)%16 == 0) {

PC4[s][n] = new LabeledLimidChanceNode(domain); //Creates the Pig counter chance nodePC4[s][n].addParent(PC3[s][n - 3]);PC4[s][n].addParent(PC2[s][n]);

Page 103: Optimization of delivery strategies for slaughter pigs

95

PC4[s][n].setPosition(new Point(200 + 255 * s, 80));PC4[s][n].setNumberOfStates(n+2);for (i = 0; i < n + 2; i++) {

PC4[s][n].setStateLabel(i, i + " alive");}PC4[s][n].setName( (n - 9) + "-" + (n + 1) + ":PC4 t=" + (s + SO - 1));PC4[s][n].setLabel((n - 9) + "-" + (n + 1) + ":PC4 t=" + (s + SO - 1));

}else if (n == NP - 1 && (n+5)%16 == 0) {

PC4[s][n] = new LabeledLimidChanceNode(domain); //Creates the Pig counter chance nodePC4[s][n].addParent(PC3[s][n - 4]);PC4[s][n].addParent(PC2[s][n]);PC4[s][n].setPosition(new Point(200 + 255 * s, 80));PC4[s][n].setNumberOfStates(n+2);for (i = 0; i < n + 2; i++) {

PC4[s][n].setStateLabel(i, i + " alive");}PC4[s][n].setName( (n - 10) + "-" + (n + 1) + ":PC4 t=" + (s + SO - 1));PC4[s][n].setLabel((n - 10) + "-" + (n + 1) + ":PC4 t=" + (s + SO - 1));

}else if (n == NP - 1 && (n+4)%16 == 0) {

PC4[s][n] = new LabeledLimidChanceNode(domain); //Creates the Pig counter chance nodePC4[s][n].addParent(PC3[s][n - 5]);PC4[s][n].addParent(PC3[s][n]);PC4[s][n].setPosition(new Point(200 + 255 * s, 80));PC4[s][n].setNumberOfStates(n+2);for (i = 0; i < n + 2; i++) {

PC4[s][n].setStateLabel(i, i + " alive");}PC4[s][n].setName( (n - 11) + "-" + (n + 1) + ":PC4 t=" + (s + SO - 1));PC4[s][n].setLabel((n - 11) + "-" + (n + 1) + ":PC4 t=" + (s + SO - 1));

}else if (n == NP - 1 && (n+3)%16 == 0) {

PC4[s][n] = new LabeledLimidChanceNode(domain); //Creates the Pig counter chance nodePC4[s][n].addParent(PC3[s][n - 6]);PC4[s][n].addParent(PC3[s][n]);PC4[s][n].setPosition(new Point(200 + 255 * s, 80));PC4[s][n].setNumberOfStates(n+2);for (i = 0; i < n + 2; i++) {

PC4[s][n].setStateLabel(i, i + " alive");}PC4[s][n].setName( (n - 12) + "-" + (n + 1) + ":PC4 t=" + (s + SO - 1));PC4[s][n].setLabel((n - 12) + "-" + (n + 1) + ":PC4 t=" + (s + SO - 1));

}else if (n == NP - 1 && (n+2)%16 == 0) {

PC4[s][n] = new LabeledLimidChanceNode(domain); //Creates the Pigcounter chance node

PC4[s][n].addParent(PC3[s][n - 7]);PC4[s][n].addParent(PC3[s][n]);PC4[s][n].setPosition(new Point(200 + 255 * s, 80));PC4[s][n].setNumberOfStates(n+2);for (i = 0; i < n + 2; i++) {

PC4[s][n].setStateLabel(i, i + " alive");}PC4[s][n].setName( (n - 13) + "-" + (n + 1) + ":PC4 t=" +

(s + SO - 1));PC4[s][n].setLabel((n - 13) + "-" + (n + 1) + ":PC4 t=" +

(s + SO - 1));}else {

// do nothing}

}} // end NP > 8else{//do nothing

}} // end trycatch (Exception eh){

System.out.println(eh.getMessage());eh.printStackTrace();

}}

// initialisation of TVstatic void InitTV( int s, int n ){

try {if (NP > 1) {

if (s == 0) {// do nothing

}

Page 104: Optimization of delivery strategies for slaughter pigs

96 APPENDIX B. CODE

else {if (n == NP - 1) {

TV[s][n] = new TimeUtilityNode(domain); //Creates the Pig Priceutility node

TV[s][n].setPosition(new Point(200 + 255 * s, 20));TV[s][n].setName("TV" + (SO -1 + s));TV[s][n].setLabel("TV" + (SO -1 + s));if (NP < 3) {

TV[s][n].addParent(PC1[s][n]);table = TV[s][n].getTable(); //Creates the utility value table

for TV as a function of GMtable.setDataItem(0, GM * NP / (SO + NS - 2));

}else if (NP < 5) {

TV[s][n].addParent(PC2[s][n]);table = TV[s][n].getTable(); //Creates the utility value table

for TV as a function of GMtable.setDataItem(0, GM * NP / (SO + NS - 2));

}else if (NP < 9) {

TV[s][n].addParent(PC3[s][n]);table = TV[s][n].getTable(); //Creates the utility value table

for TV as a function of GMtable.setDataItem(0, GM * NP / (SO + NS - 2));

}else {

TV[s][n].addParent(PC4[s][n]);table = TV[s][n].getTable(); //Creates the utility value table

for TV as a function of GMtable.setDataItem(0, GM * NP / (SO + NS - 2));

}}else {

// do nothing}

}}else {

// do nothing}

} // end trycatch (Exception eh){

System.out.println(eh.getMessage());eh.printStackTrace();

}}// table look-up to find the slaughter price based on slaughter weightstatic float GetSlaughterPrice( float SlaughterWeight ){

int i;float[][] DataArray = {

{ 50.0F, -3.0F }, { 51.0F, -2.8F }, { 52.0F, -2.6F }, { 53.0F, -2.4F },{ 54.0F, -2.2F }, { 55.0F, -2.0F }, { 56.0F, -1.8F }, { 57.0F, -1.6F },{ 58.0F, -1.4F }, { 59.0F, -1.2F }, { 60.0F, -1.0F }, { 61.0F, -0.9F } ,{ 62.0F, -0.8F }, { 63.0F, -0.7F }, { 64.0F, -0.6F }, { 65.0F, -0.5F },{ 66.0F, -0.4F }, { 67.0F, -0.3F }, { 68.0F, -0.2F }, { 69.0F, -0.1F },{ 70.0F, 0.0F }, { 85.0F, -0.1F }, { 86.0F, -0.2F }, { 87.0F, -0.3F },{ 88.0F, -0.4F }, { 89.0F, -0.5F }, { 90.0F, -0.6F }, { 91.0F, -0.7F },{ 92.0F, -0.8F }, { 93.0F, -0.9F }, { 94.0F, -1.0F }, { 100.0F, -1.2F },{ 110.0F, -1.2F }

};for( i = 0; i < DataArray.length-1; i++ ){

if( SlaughterWeight > DataArray[i][0] && SlaughterWeight < DataArray[i+1][0] )return SPR+DataArray[i][1];

}// an errorreturn SPR+DataArray[DataArray.length-1][1];

}

// calculatiing and assigning GC probabilitiesstatic void AssignGCProbs( int s, int n){

// local varsint[] states = { 0, 0 };int i;int j;double ProbLeft, ProbRight;int LastGCix, ThisGCix;float DeltaGC, LastGC, ThisGC;// probability for GC tableDefaultProbabilityPotential Probs = (DefaultProbabilityPotential)

Page 105: Optimization of delivery strategies for slaughter pigs

97

GC[s][n].getTable();Probs.initialize();if( s == 0){

states[0] = 0;states[1] = (NWI-1)/2;// Calculating tailsProbLeft = CDF_Normal.normp( (float) GCMaxDev/(NWI-1) );ProbRight = CDF_Normal.normp( (float) -1*GCMaxDev/(NWI-1) );Probs.setDataItem( states, ProbLeft-ProbRight );for( i = 1; i < (NWI-1)/2; i++ ){

ProbLeft = CDF_Normal.normp( ((float) (2*i+1))*GCMaxDev/(NWI-1) );ProbRight = CDF_Normal.normp( ((float) (2*i-1))*GCMaxDev/(NWI-1) );

states[1] = (NWI-1)/2+i;Probs.setDataItem( states, ProbLeft-ProbRight );states[1] = (NWI-1)/2-i;Probs.setDataItem( states, ProbLeft-ProbRight );

}

ProbLeft = CDF_Normal.normp( ((float) (-2*i+1))*GCMaxDev/(NWI-1) );

states[1] = (NWI-1)/2+i;Probs.setDataItem( states, ProbLeft );states[1] = (NWI-1)/2-i;Probs.setDataItem( states, ProbLeft );

}else if (s == 1){

for (i = 0; i < NWI; i++) {for (j = 0; j < NWI; j++) {

// assigning statesstates[0] = i;states[1] = j;

// for readability (index values)LastGCix = i;ThisGCix = j;

// support calculationsDeltaGC = MG/(NWI-1);LastGC = (float) DeltaGC * (LastGCix - (NWI - 1) / 2) + G0;ThisGC = (float) DeltaGC * (ThisGCix - (NWI - 1) / 2) + GT;

ProbRight = CDF_Normal.normp( (float) ((ThisGC - DeltaGC/2) -LastGC*GL/GF)/SigmaGC);

ProbLeft = CDF_Normal.normp( (float) ((ThisGC + DeltaGC/2) -LastGC*GL/GF)/SigmaGC);

if (ThisGCix == 0)Probs.setDataItem(states, ProbLeft);

else if (ThisGCix == NWI - 1)Probs.setDataItem(states, 1 - ProbRight);

elseProbs.setDataItem(states, ProbLeft - ProbRight);

}}

}

else{

for( i = 0; i < NWI; i++ ){

for( j = 0; j < NWI; j++ ){

// assigning statesstates[0] = i;states[1] = j;

// Calculating tailsProbLeft = CDF_Normal.normp( ((float) (2*(j-i)+1))*GCMaxDev/(NWI-1) );ProbRight = CDF_Normal.normp( ((float) (2*(j-i)-1))*GCMaxDev/(NWI-1) );

// special case on borderif( j == 0 )

Probs.setDataItem( states, ProbLeft );else if( j == NWI-1 )

Probs.setDataItem( states, 1-ProbRight );else

Probs.setDataItem( states, ProbLeft-ProbRight );}

Page 106: Optimization of delivery strategies for slaughter pigs

98 APPENDIX B. CODE

}}

}

// calculating and assigning OW probabilitiesstatic void AssignOWProbs( int s, int n ){

// local varsint[] states = { 0, 0 };int i;int j;double ProbLeft, ProbRight;

if( s == 0){

// non-exist}else if (s == 1){

// probability for OLW tableDefaultProbabilityPotential Probs = (DefaultProbabilityPotential)OW[s][n].getTable();Probs.initialize();

// handling dead-deliveredfor( i = 0; i < NWI+1; i++ ){

if( i == 0 ){

// assigning statesstates[0] = 0;states[1] = 0;Probs.setDataItem( states, 1 );

}else{

// assigning statesstates[0] = i;states[1] = 0;Probs.setDataItem( states, 0 );// assigning statesstates[0] = 0;states[1] = i;Probs.setDataItem( states, 0 );

}}

for( i = 0; i < NWI; i++ ){

for( j = 0; j < NWI; j++ ){

// assigning statesstates[0] = i+1;states[1] = j+1;

// Calculating tailsProbLeft = CDF_Normal.normp( ((float) (2*(j-i)+1))*GCMaxDev/

(NWI-1)*SigmaGC/SigmaOW*(SO-1+s) );ProbRight = CDF_Normal.normp( ((float) (2*(j-i)-1))*GCMaxDev/

(NWI-1)*SigmaGC/SigmaOW*(SO-1+s) );

// special case on borderif( j == 0 )

Probs.setDataItem( states, ProbLeft );else if( j == NWI-1 )

Probs.setDataItem( states, 1-ProbRight );else

Probs.setDataItem( states, ProbLeft-ProbRight );}

}}

else{

// probability for OLW tableDefaultProbabilityPotential Probs = (DefaultProbabilityPotential)OW[s][n].getTable();Probs.initialize();

// handling dead-deliveredfor( i = 0; i < NWI+2; i++ ){

if( i == 0 )

Page 107: Optimization of delivery strategies for slaughter pigs

99

{// assigning statesstates[0] = 0;states[1] = 0;Probs.setDataItem( states, 1 );

states[0] = 0;states[1] = 1;Probs.setDataItem( states, 0);

}else if( i == 1 ){

// assigning statesstates[0] = 1;states[1] = 1;Probs.setDataItem( states, 1 );

states[0] = 1;states[1] = 0;Probs.setDataItem( states, 0);

}

else{

// assigning statesstates[0] = i;states[1] = 0;

Probs.setDataItem( states, 0 );// assigning statesstates[0] = 0;states[1] = i;

Probs.setDataItem( states, 0 );// assigning statesstates[0] = i;states[1] = 1;

Probs.setDataItem( states, 0 );// assigning statesstates[0] = 1;states[1] = i;

Probs.setDataItem( states, 0 );

}}

for( i = 0; i < NWI; i++ ){

for( j = 0; j < NWI; j++ ){

// assigning statesstates[0] = i+2;states[1] = j+2;

// Calculating tailsProbLeft = CDF_Normal.normp( ((float) (2*(j-i)+1))*GCMaxDev/(NWI-1)

*SigmaGC/SigmaOW*(SO-1+s) );ProbRight = CDF_Normal.normp( ((float) (2*(j-i)-1))*GCMaxDev/(NWI-1)

*SigmaGC/SigmaOW*(SO-1+s) );

// special case on borderif( j == 0 )

Probs.setDataItem( states, ProbLeft );else if( j == NWI-1 )

Probs.setDataItem( states, 1-ProbRight );else

Probs.setDataItem( states, ProbLeft-ProbRight );}

}}

}

// calculating and assigning DA probabilitiesstatic void AssignDAProbs( int s, int n){

// local varsint[] states = { 0, 0 };int i;int j;

Page 108: Optimization of delivery strategies for slaughter pigs

100 APPENDIX B. CODE

if( s == 0 ){

// no exist}else if ( s == 1) {

DefaultProbabilityPotential Probs = (DefaultProbabilityPotential)DA[s][n].getTable();

Probs.initialize();for (i = 0; i < NWI + 1; i++) {

for (j = 0; j < 2; j++) {// assigning statesstates[0] = i;states[1] = j;

if (i == 0) {if (j == 0) {

Probs.setDataItem(states, 1);}else {

Probs.setDataItem(states, 0);}

}else {

if (j == 1) {Probs.setDataItem(states, 1);

}else {

Probs.setDataItem(states, 0);}

}}

}}else {

DefaultProbabilityPotential Probs = (DefaultProbabilityPotential) DA[s][n].getTable();

Probs.initialize();for (i = 0; i < NWI + 2; i++) {

for (j = 0; j < 2; j++) {// assigning statesstates[0] = i;states[1] = j;

if (i == 0 || i == 1) {if (j == 0) {

Probs.setDataItem(states, 1);}else {

Probs.setDataItem(states, 0);}

}else {

if (j == 1) {Probs.setDataItem(states, 1);

}else {

Probs.setDataItem(states, 0);}

}}

}}

}

// calculatiing and assigning LW probabilities/**

* AssignLWProbs - Assigns probabilities to the live weight nodes** @param s int*/

static void AssignLWProbs( int s, int n ){

// local varsint[] states = { 0, 0, 0, 0 };int i, j, k;int LastGCix, LastLWTix, NextLWTix;double ProbLeft, ProbRight;float DeltaLWTs, DeltaGC, DeltaWI, DeltaGC0;float LastGC, LastLWT, NextLWT, LWTSO;

// probability for LW tableDefaultProbabilityPotential Probs = (DefaultProbabilityPotential)

Page 109: Optimization of delivery strategies for slaughter pigs

101

LW[s][n].getTable();Probs.initialize();if( s == 0){

states[0] = 0;states[3] = (NWI-1)/2;

// Calculating tailsProbLeft = CDF_Normal.normp( (float) WIMaxDev/(NWI-1) );ProbRight = CDF_Normal.normp( (float) -1*WIMaxDev/(NWI-1) );Probs.setDataItem( states, ProbLeft-ProbRight );

for( i = 1; i < (NWI-1)/2; i++ ){

ProbLeft = CDF_Normal.normp( ((float) (2*i+1))*WIMaxDev/(NWI-1) );ProbRight = CDF_Normal.normp( ((float) (2*i-1))*WIMaxDev/(NWI-1) );

states[3] = (NWI-1)/2+i;Probs.setDataItem( states, ProbLeft-ProbRight );states[3] = (NWI-1)/2-i;Probs.setDataItem( states, ProbLeft-ProbRight );

}

ProbLeft = CDF_Normal.normp( ((float) (-2*i+1))*WIMaxDev/(NWI-1) );

states[3] = (NWI-1)/2+i;Probs.setDataItem( states, ProbLeft );states[3] = (NWI-1)/2-i;Probs.setDataItem( states, ProbLeft );

}

else if( s == 1 ){

// handling dead-deliveredfor( i = 0; i < NWI; i++ ){

for (j = 0; j < NWI ; j++) {// assigning statesstates[0] = i;states[1] = j;states[3] = 0;Probs.setDataItem(states, MR0);

}}

// support calculationsDeltaGC = MG/(NWI-1); // GC interval sizeDeltaWI = MWI/(NWI-1); // WI interval sizeDeltaGC0 = DeltaGC;DeltaLWTs = SO*DeltaGC0 + (s-1)*DeltaGC;// handling dead-deliveredfor( i = 0; i < NWI; i++ ){

for (j = 0; j < NWI ; j++) {for (k = 1; k < NWI + 1; k++) {

// assigning statesstates[0] = i;states[1] = j;states[3] = k;// for readability (index values)LastGCix = i;LastLWTix = j;NextLWTix = k - 1;

// support calculationsLastGC = (float) DeltaGC * (LastGCix - (NWI - 1) / 2) + G0;LastLWT = (float) WI + (LastLWTix - (NWI - 1) / 2) * DeltaWI;NextLWT = (float) WI + (G0 + (NextLWTix - (NWI - 1) / 2) *

DeltaGC0) * SO;ProbLeft = CDF_Normal.normp(1 / SigmaGC *(NextLWT - LastLWT -

LastGC*SO - DeltaLWTs / 2));ProbRight = CDF_Normal.normp(1 / SigmaGC * (NextLWT - LastLWT -

LastGC*SO + DeltaLWTs / 2));

if (NextLWTix == 0)Probs.setDataItem(states, ProbRight * (1 - MR0));

else if (NextLWTix == NWI - 1)Probs.setDataItem(states, (1 - ProbLeft) * (1 - MR0));

elseProbs.setDataItem(states, (ProbRight - ProbLeft) * (1 - MR0));

}}

}

Page 110: Optimization of delivery strategies for slaughter pigs

102 APPENDIX B. CODE

}else if ( s == 2) // s = 2

{// support calculationsDeltaGC = MG/(NWI-1); // GC interval sizeDeltaGC0 = DeltaGC;DeltaLWTs = SO*DeltaGC0 + (s-1)*DeltaGC;// handling dead-deliveredfor( i = 0; i < NWI; i++ ){

for (j = 0; j < NWI + 1; j++){

for (k = 0; k < NWI + 2; k++){

// assigning statesstates[1] = i; states[2] = j; states[3] = k;

// first partstates[0] = 0;if (k == 1)

Probs.setDataItem( states, 1 );else

Probs.setDataItem( states, 0 );if (j == 0){

if (k == 0)Probs.setDataItem( states, 1 );

elseProbs.setDataItem( states, 0 );

}

// second partstates[0] = 1;if( j == 0 && k == 0 )

Probs.setDataItem( states, 1 );else if( j == 0 )

Probs.setDataItem( states, 0 );else if( k == 0 && j != 0 )

Probs.setDataItem( states, MRT );else if( k == 1 )

Probs.setDataItem( states, 0 );else{

// for readability (index values)LastGCix = i; LastLWTix = j-1; NextLWTix = k-2;

// support calculationsLastGC = (float) DeltaGC*(LastGCix-(NWI-1)/2) + GT;LastLWT = (float) WI + (G0 + (LastLWTix-(NWI - 1)/2)*Delta

GC0 )*SO + (DeltaGC*(LastLWTix-(NWI-1)/2) + GT) *(s-2);NextLWT = (float) WI + (G0 + (NextLWTix-(NWI - 1)/2)*Delta

GC0 )*SO + (DeltaGC*(NextLWTix-(NWI-1)/2) + GT) *(s-1);ProbLeft = CDF_Normal.normp( 1/SigmaGC*( NextLWT-LastLWT-

LastGC-DeltaLWTs/2 ) );ProbRight = CDF_Normal.normp( 1/SigmaGC*( NextLWT-LastLWT-

LastGC+DeltaLWTs/2 ) );

if( NextLWTix == 0 )Probs.setDataItem(states, ProbRight * (1 - MRT));

else if ( NextLWTix == NWI-1 )Probs.setDataItem(states, (1-ProbLeft) * (1 - MRT));

elseProbs.setDataItem(states, (ProbRight-ProbLeft) * (1 - MRT));

}}

}}

}

else // s > 2{

// support calculationsDeltaGC = MG/(NWI-1); // GC interval sizeDeltaGC0 = DeltaGC;DeltaLWTs = SO*DeltaGC0 + (s-1)*DeltaGC;// handling dead-deliveredfor( i = 0; i < NWI; i++ ){

for (j = 0; j < NWI + 2; j++){

for (k = 0; k < NWI + 2; k++){

// assigning statesstates[1] = i; states[2] = j; states[3] = k;

Page 111: Optimization of delivery strategies for slaughter pigs

103

// first partstates[0] = 0;if (k == 1)

Probs.setDataItem( states, 1 );else

Probs.setDataItem( states, 0 );if (j == 0){

if (k == 0)Probs.setDataItem( states, 1 );

elseProbs.setDataItem( states, 0 );

}

// second partstates[0] = 1;if( j == 0 && k == 0 )

Probs.setDataItem( states, 1 );else if( j == 0 )

Probs.setDataItem( states, 0 );

else if( j == 1 && k == 1 )Probs.setDataItem( states, 1 );

else if( j == 1 && k != 1 )Probs.setDataItem( states, 0 );

else if( k == 0 && j != 0 )Probs.setDataItem( states, MRT );

else if( k == 1 && j != 1 )Probs.setDataItem( states, 0 );

else{

// for readability (index values)LastGCix = i; LastLWTix = j-2; NextLWTix = k-2;

// support calculationsLastGC = (float) DeltaGC*(LastGCix-(NWI-1)/2) + GT;LastLWT = (float) WI + (G0 + (LastLWTix-(NWI - 1)/2)

*DeltaGC0 )*SO + (DeltaGC*(LastLWTix-(NWI-1)/2) + GT) *(s-2);NextLWT = (float) WI + (G0 + (NextLWTix-(NWI - 1)/2)*

DeltaGC0 )*SO + (DeltaGC*(NextLWTix-(NWI-1)/2) + GT) *(s-1);ProbLeft = CDF_Normal.normp( 1/SigmaGC*( NextLWT-LastLWT-

LastGC-DeltaLWTs/2 ) );ProbRight = CDF_Normal.normp( 1/SigmaGC*( NextLWT-LastLWT-

LastGC+DeltaLWTs/2 ) );

if( NextLWTix == 0 )Probs.setDataItem(states, ProbRight * (1 - MRT));

else if ( NextLWTix == NWI-1 )Probs.setDataItem(states, (1-ProbLeft) * (1 - MRT));

elseProbs.setDataItem(states, (ProbRight-ProbLeft) * (1 - MRT));

}}

}}

}

}

// calculatiing and assigning SW probabilitiesstatic void AssignSWProbs( int s, int n ){

// local varsint[] states = { 1, 0, 0, 0 };int i, j, k, l;int ThisGCix, ThisLWTix, ThisSWTix;double ProbLeft, ProbRight;float DeltaSWTs, DeltaGC, DeltaGC0;float ThisGC, ThisLWT, ThisSWT, LWTSO;

if( s == 0) {//do nothing

}else if (s == NS - 1){

// probability for SW tableDefaultProbabilityPotential Probs = (DefaultProbabilityPotential)

SW[s][n].getTable();Probs.initialize();

// support calculations

Page 112: Optimization of delivery strategies for slaughter pigs

104 APPENDIX B. CODE

DeltaGC = MG/(NWI-1); // GC interval sizeDeltaGC0 = DeltaGC;DeltaSWTs = (SO*DeltaGC0 + (s-1 + DS/7.0F)*DeltaGC)*SF;

// handling dead-deliveredfor( i = 0; i < NWI + 2 ; i++ ){

for (j = 0; j < NWI; j++) {for (k = 0; k < NWI + 1; k++) {

// assigning states

states[1] = i;states[2] = j;states[3] = k;states[0] = 0;if ((i == 0 || i == 1) && k == 0)

Probs.setDataItem(states, 1);else if (i == 0 || i == 1)

Probs.setDataItem(states, 0);else if (k == 0 && (i != 0 || i != 1) )

Probs.setDataItem(states, 0);

else {// for readability (index values)ThisLWTix = i - 2;ThisGCix = j;ThisSWTix = k - 1;

// support calculationsThisGC = (float) DeltaGC * (ThisGCix - (NWI - 1) / 2) + GT;ThisLWT = (float) WI + (G0 + (ThisLWTix - (NWI - 1) / 2) * DeltaGC0)

* SO +(DeltaGC * (ThisLWTix - (NWI - 1) / 2) + GT) * (s - 1);ThisSWT = (float) (WI + (G0 + (ThisSWTix - (NWI - 1) / 2) * DeltaGC0)

* SO + (DeltaGC * (ThisSWTix - (NWI - 1) / 2) + GT) * (s - 1) +(DeltaGC * (ThisSWTix - (NWI - 1) / 2) + GT) * DS / 7) * SF;

ProbRight = CDF_Normal.normp( (float) 1 / SigmaSW *(ThisSWT -(ThisLWT + ThisGC * DS / 7) * SF - DeltaSWTs / 2));

ProbLeft = CDF_Normal.normp( (float) 1 / SigmaSW *(ThisSWT -(ThisLWT + ThisGC * DS / 7) * SF + DeltaSWTs / 2));

if (ThisSWTix == 0)Probs.setDataItem(states, ProbLeft);

else if (ThisSWTix == NWI - 1)Probs.setDataItem(states, 1 - ProbRight);

elseProbs.setDataItem(states, ProbLeft - ProbRight);

}}

}}

}else if ( s == 1){

// probability for SW tableDefaultProbabilityPotential Probs = (DefaultProbabilityPotential)

SW[s][n].getTable();Probs.initialize();

// support calculationsDeltaGC = MG/(NWI-1); // GC interval sizeDeltaGC0 = DeltaGC;DeltaSWTs = (SO*DeltaGC0 + (s-1 + DS/7.0F)*DeltaGC)*SF;

// handling dead-deliveredfor( i = 0; i < NWI + 1 ; i++ ){

for (j = 0; j < NWI; j++){

for (k = 0; k < NWI + 1 ; k++){

// assigning statesstates[1] = i; states[2] = j; states[3] = k;// first partstates[0] = 1;

if (k == 0)Probs.setDataItem(states, 1);

elseProbs.setDataItem(states, 0);// second part

states[0] = 0;

Page 113: Optimization of delivery strategies for slaughter pigs

105

if (i == 0 && k == 0)Probs.setDataItem(states, 1);

else if (i == 0)Probs.setDataItem(states, 0);

else if (k == 0 && i != 0)Probs.setDataItem(states, 0);

else {// for readability (index values)ThisLWTix = i - 1;ThisGCix = j;ThisSWTix = k - 1;

// support calculationsThisGC = (float) DeltaGC * (ThisGCix - (NWI - 1) / 2) + GT;ThisLWT = (float) WI + (G0 + (ThisLWTix - (NWI - 1) / 2) * DeltaGC0)

* SO + (DeltaGC * (ThisLWTix - (NWI - 1) / 2) + GT) * (s - 1);ThisSWT = (float) (WI +(G0 + (ThisSWTix - (NWI - 1) / 2) * DeltaGC0)

* SO + (DeltaGC * (ThisSWTix - (NWI - 1) / 2) + GT) * (s - 1) +(DeltaGC * (ThisSWTix - (NWI - 1) / 2) + GT) * DS / 7) * SF;

ProbRight = CDF_Normal.normp( (float) 1 / SigmaSW * (ThisSWT -(ThisLWT + ThisGC * DS / 7) * SF - DeltaSWTs / 2));

ProbLeft = CDF_Normal.normp( (float) 1 / SigmaSW * (ThisSWT -(ThisLWT + ThisGC * DS / 7) * SF + DeltaSWTs / 2));

if (ThisSWTix == 0)Probs.setDataItem(states, ProbLeft);

else if (ThisSWTix == NWI - 1)Probs.setDataItem(states, 1 - ProbRight);

elseProbs.setDataItem(states, ProbLeft - ProbRight);

}}

}}

}else

{// probability for SW tableDefaultProbabilityPotential Probs = (DefaultProbabilityPotential)

SW[s][n].getTable();Probs.initialize();

// support calculationsDeltaGC = MG/(NWI-1); // GC interval sizeDeltaGC0 = DeltaGC;DeltaSWTs = (SO*DeltaGC0 + (s-1 + DS/7.0F)*DeltaGC)*SF;

// handling dead-deliveredfor( i = 0; i < NWI + 2 ; i++ ){

for (j = 0; j < NWI; j++){

for (k = 0; k < NWI + 1 ; k++){

// assigning statesstates[1] = i; states[2] = j; states[3] = k;// first partstates[0] = 1;

if (k == 0)Probs.setDataItem(states, 1);

elseProbs.setDataItem(states, 0);// second part

states[0] = 0;if ((i == 0 || i == 1) && k == 0)

Probs.setDataItem(states, 1);else if (i == 0 || i == 1)

Probs.setDataItem(states, 0);else if (k == 0 && (i != 0 || i != 1) )

Probs.setDataItem(states, 0);else {

// for readability (index values)ThisLWTix = i - 2;ThisGCix = j;ThisSWTix = k - 1;

// support calculationsThisGC = (float) DeltaGC * (ThisGCix - (NWI - 1) / 2) + GT;ThisLWT = (float) WI + (G0 + (ThisLWTix - (NWI - 1) / 2) * DeltaGC0)

* SO + (DeltaGC * (ThisLWTix - (NWI - 1) / 2) + GT) * (s - 1);ThisSWT = (float) (WI +(G0 + (ThisSWTix - (NWI - 1) / 2) * DeltaGC0)

* SO + (DeltaGC * (ThisSWTix - (NWI - 1) / 2) + GT) * (s - 1) +

Page 114: Optimization of delivery strategies for slaughter pigs

106 APPENDIX B. CODE

(DeltaGC * (ThisSWTix - (NWI - 1) / 2) + GT) * DS / 7) * SF;

ProbRight = CDF_Normal.normp( (float) 1 / SigmaSW * (ThisSWT -(ThisLWT + ThisGC * DS / 7) * SF - DeltaSWTs / 2));

ProbLeft = CDF_Normal.normp( (float) 1 / SigmaSW * (ThisSWT -(ThisLWT + ThisGC * DS / 7) * SF + DeltaSWTs / 2));

if (ThisSWTix == 0)Probs.setDataItem(states, ProbLeft);

else if (ThisSWTix == NWI - 1)Probs.setDataItem(states, 1 - ProbRight);

elseProbs.setDataItem(states, ProbLeft - ProbRight);

}}

}}

}

}

// calculatiing and assigning FC probabilitiesstatic void AssignFCProbs( int s, int n ){

// local varsint[] states = { 0, 0, 0 };int i, j, k;int ThisFEix, LastLWTix, NextLWTix, ThisFCix;double ProbLeft, ProbRight;float DeltaLWTs, DeltaGC, DeltaGC0, DeltaFE, DeltaWI, DeltaFC, DeltaFC0;float LastGC, LastLWT, NextLWT, ThisFE, ThisFC, LWTSO;

if( s == 0){//do nothing

}else if( s == 1 ){

// probability for FC tableDefaultProbabilityPotential Probs = (DefaultProbabilityPotential) FC[s][n].

getTable();Probs.initialize();

// handling dead-deliveredfor (i = 0; i < NWI; i++) {

for (j = 0; j < NWI + 1; j++) {for (k = 0; k < NWI + 1; k++) {

// assigning statesstates[0] = i;states[1] = j;states[2] = k;if (j == 0 && k == 0)

Probs.setDataItem(states, 1);else if (j == 0)

Probs.setDataItem(states, 0);else if (k == 0 && j != 0)

Probs.setDataItem(states, 0);

else {// for readability (index values)LastLWTix = i;NextLWTix = j - 1;ThisFCix = k - 1;// support calculationsDeltaGC = MG / (NWI - 1); // GC interval sizeDeltaGC0 = DeltaGC;DeltaLWTs = SO * DeltaGC0 + (s - 1) * DeltaGC;

// DeltaFE = MF / (NFEI - 1); // FE interval size

DeltaFC0 = DeltaGC0 * SO * F0;DeltaWI = MWI/(NWI-1); // WI interval sizeLastLWT = (float) WI + (LastLWTix - (NWI - 1) / 2) * DeltaWI;NextLWT = (float) WI + (G0 + (NextLWTix - (NWI - 1) / 2) * DeltaGC0) * SO;ThisFC = (float) (G0 + (ThisFCix - (NWI - 1) / 2) * DeltaGC0) *SO * F0

+ DS / 7 * GT * FT;ProbLeft = CDF_Normal.normp( (float) 1 / SigmaFC *(ThisFC - ((NextLWT -

LastLWT) * F0 + DS / 7 * GT * FT) - DeltaFC0 / 2));ProbRight = CDF_Normal.normp( (float) 1 / SigmaFC *(ThisFC - ((NextLWT -

LastLWT) * F0 + DS / 7 * GT * FT) + DeltaFC0 / 2));

if (ThisFCix == 0)Probs.setDataItem(states, ProbRight);

else if (ThisFCix == NWI - 1)Probs.setDataItem(states, 1 - ProbLeft);

Page 115: Optimization of delivery strategies for slaughter pigs

107

elseProbs.setDataItem(states, ProbRight - ProbLeft);

}}

}}

}else if (s == 2){

// probability for FC tableDefaultProbabilityPotential Probs = (DefaultProbabilityPotential) FC[s][n].getTable();Probs.initialize();

// handling dead-deliveredfor( i = 0; i < NWI + 1; i++ ) {

for (j = 0; j < NWI + 2; j++) {for (k = 0; k < NWI + 1; k++) {

// assigning statesstates[0] = i; states[1] = j; states[2] = k;

if ((j == 0 || j == 1) && k == 0)Probs.setDataItem( states, 1 );

else if ((j == 0 || j == 1) && k != 0)Probs.setDataItem( states, 0 );

else if (i == 0 && k == 0)Probs.setDataItem( states, 1 );

else if (i == 0 && k != 0)Probs.setDataItem( states, 0 );

else if (k == 0 && i != 0 && j != 0)Probs.setDataItem( states, 0 );

else{

// for readability (index values)LastLWTix = i - 1;NextLWTix = j - 2;ThisFCix = k - 1;// support calculationsDeltaGC = MG/(NWI-1); // GC interval sizeDeltaGC0 = DeltaGC;DeltaFC = DeltaGC*FT;LastLWT = (float) WI + (G0 + (LastLWTix - (NWI - 1) / 2) * DeltaGC0) *

SO + (DeltaGC * (LastLWTix - (NWI - 1) / 2) + GT) * (s - 2);NextLWT = (float) WI + (G0 + (NextLWTix-(NWI - 1)/2)*DeltaGC0 )*SO +

(DeltaGC * (NextLWTix - (NWI - 1) / 2) + GT) * (s - 1);ThisFC = (float) (GT + (ThisFCix-(NWI - 1)/2)*DeltaGC )* FT;ProbLeft = CDF_Normal.normp((float) 1 / SigmaFC * ( ThisFC - (NextLWT -

LastLWT)*FT - DeltaFC/2 ) );ProbRight = CDF_Normal.normp((float) 1 / SigmaFC * ( ThisFC - (NextLWT -

LastLWT)*FT + DeltaFC/2 ) );if (ThisFCix == 0)

Probs.setDataItem(states, ProbRight);else if (ThisFCix == NWI - 1)

Probs.setDataItem(states, 1 - ProbLeft);else

Probs.setDataItem(states, ProbRight - ProbLeft );}

}}

}}else //s>2

{// probability for FC tableDefaultProbabilityPotential Probs = (DefaultProbabilityPotential) FC[s][n].getTable();Probs.initialize();

// handling dead-deliveredfor( i = 0; i < NWI + 2; i++ ) {

for (j = 0; j < NWI + 2; j++) {for (k = 0; k < NWI + 1; k++) {

// assigning statesstates[0] = i; states[1] = j; states[2] = k;

if ((j == 0 || j == 1) && k == 0)Probs.setDataItem( states, 1 );

else if ((j == 0 || j == 1) && k != 0)Probs.setDataItem( states, 0 );

else if ((i == 0 || i == 1) && k == 0)Probs.setDataItem( states, 1 );

else if ((i == 0 || i == 1) && k != 0)Probs.setDataItem( states, 0 );

else if (k == 0 && i != 0 && j != 0)

Page 116: Optimization of delivery strategies for slaughter pigs

108 APPENDIX B. CODE

Probs.setDataItem( states, 0 );else{

// for readability (index values)LastLWTix = i - 2;NextLWTix = j - 2;ThisFCix = k - 1;// support calculationsDeltaGC = MG/(NWI-1); // GC interval sizeDeltaGC0 = DeltaGC;DeltaFC = DeltaGC*FT;LastLWT = (float) WI + (G0 + (LastLWTix - (NWI - 1) / 2) * DeltaGC0) * SO +

(DeltaGC * (LastLWTix - (NWI - 1) / 2) + GT) * (s - 2);NextLWT = (float) WI + (G0 + (NextLWTix-(NWI - 1)/2)*DeltaGC0 )*SO + (DeltaGC

* (NextLWTix - (NWI - 1) / 2) + GT) * (s - 1);ThisFC = (float) (GT + (ThisFCix-(NWI - 1)/2)*DeltaGC )* FT;ProbLeft = CDF_Normal.normp((float) 1 / SigmaFC * ( ThisFC - (NextLWT -

LastLWT)*FT - DeltaFC/2 ) );

ProbRight = CDF_Normal.normp((float) 1 / SigmaFC * ( ThisFC - (NextLWT -LastLWT)*FT + DeltaFC/2 ) );

if (ThisFCix == 0)Probs.setDataItem(states, ProbRight);

else if (ThisFCix == NWI - 1)Probs.setDataItem(states, 1 - ProbLeft);

elseProbs.setDataItem(states, ProbRight - ProbLeft );

}}

}}

}

}

// calculating and assigning PC1 probabilitiesstatic void AssignPC1Probs( int s, int n){

// local varsint[] states = { 0, 0, 0 };int i;int j;int k;

if( s == 0 || n == 0){

// no exist}else{

// probability for PC1 tableSystem.out.println( "s="+s+" -- n="+n);// Probs.initialize();if (n%2 == 1){

DefaultProbabilityPotential Probs = (DefaultProbabilityPotential) PC1[s][n].getTable();Probs.initialize();for (i = 0; i < 2; i++) {

for (j = 0; j < 2; j++) {for (k = 0; k < 3; k++) {

// assigning statesstates[0] = i;states[1] = j;states[2] = k;

if (i == 0){if (j == 0) {

if (k == 0) {Probs.setDataItem(states, 1);

}else {

Probs.setDataItem(states, 0);}

}else {

if (k == 1) {Probs.setDataItem(states, 1);

}else {

Probs.setDataItem(states, 0);}

}

Page 117: Optimization of delivery strategies for slaughter pigs

109

}else {

if (j == 0) {if (k == 1) {

Probs.setDataItem(states, 1);}else {

Probs.setDataItem(states, 0);}

}else {

if (k == 2) {Probs.setDataItem(states, 1);

}else {

Probs.setDataItem(states, 0);}

}}

}}

}}else {

if (n == NP - 1) {DefaultProbabilityPotential Probs = (DefaultProbabilityPotential) PC1[s][n].getTable();Probs.initialize();for (i = 0; i < 2; i++) {

// for (j = 0; j < NWI + 1; j++) {for (k = 0; k < 2; k++) {

// assigning statesstates[0] = i;// states[1] = j;states[2] = k;

if (i == 0){// if (j == 0) {if (k == 0) {

Probs.setDataItem(states, 1);}else {

Probs.setDataItem(states, 0);}

}else {

if (k == 1) {Probs.setDataItem(states, 1);

}else {

Probs.setDataItem(states, 0);}

}}

}}else {

//do nothing}

}}

}// calculating and assigning PC2 probabilitiesstatic void AssignPC2Probs( int s, int n){

// local varsint[] states = { 0, 0, 0 };int i;int j;int k;

if( s == 0 || n == 0){

// no exist}else{

// probability for PC2 tableSystem.out.println( "s="+s+" -- n="+n);

if ( (n + 1) % 4 == 0){

DefaultProbabilityPotential Probs = (DefaultProbabilityPotential) PC2[s][n].getTable();Probs.initialize();

Page 118: Optimization of delivery strategies for slaughter pigs

110 APPENDIX B. CODE

for (i = 0; i < 3; i++) {for (j = 0; j < 3; j++) {

for (k = 0; k < 5; k++) {// assigning statesstates[0] = i;states[1] = j;states[2] = k;

if (i == 0){if (k == j) {

Probs.setDataItem(states, 1);}else {

Probs.setDataItem(states, 0);}

}else if (i == 1) {

if (k == j + 1) {Probs.setDataItem(states, 1);

}else {

Probs.setDataItem(states, 0);}

}else {

if (k == j + 2) {Probs.setDataItem(states, 1);

}else {

Probs.setDataItem(states, 0);}

}}

}}

}else if (n == NP - 1 && (n+2)%4 == 0) {

DefaultProbabilityPotential Probs = (DefaultProbabilityPotential) PC2[s][n].getTable();Probs.initialize();for (i = 0; i < 3; i++) {

for (j = 0; j < 2; j++) {for (k = 0; k < 4; k++) {

// assigning statesstates[0] = i;states[1] = j;states[2] = k;

if (i == 0){if (k == j) {

Probs.setDataItem(states, 1);}else {

Probs.setDataItem(states, 0);}

}else if (i == 1) {

if (k == j + 1) {Probs.setDataItem(states, 1);

}else {

Probs.setDataItem(states, 0);}

}else {

if (k == j + 2) {Probs.setDataItem(states, 1);

}else {

Probs.setDataItem(states, 0);}

}}

}}

}

else {//do nothing

}}

}

// calculating and assigning PC3 probabilities

Page 119: Optimization of delivery strategies for slaughter pigs

111

static void AssignPC3Probs( int s, int n){

// local varsint[] states = { 0, 0, 0 };int i;int j;int k;if( s == 0 || n == 0){

// no exist}else{

// probability for PC3 tableSystem.out.println( "s="+s+" -- n="+n);if ( (n + 1) % 8 == 0){

DefaultProbabilityPotential Probs = (DefaultProbabilityPotential) PC3[s][n].getTable();Probs.initialize();

for (i = 0; i < 5; i++) {for (j = 0; j < 5; j++) {

for (k = 0; k < 9; k++) {// assigning statesstates[0] = i;states[1] = j;states[2] = k;

if (k == j + i) {Probs.setDataItem(states, 1);

}else {

Probs.setDataItem(states, 0);}

}}

}}else if (n == NP - 1 && (n+4)%8 == 0) {

DefaultProbabilityPotential Probs = (DefaultProbabilityPotential) PC3[s][n].getTable();Probs.initialize();for (i = 0; i < 5; i++) {

for (j = 0; j < 2; j++) {for (k = 0; k < 6; k++) {

// assigning statesstates[0] = i;states[1] = j;states[2] = k;

if (k == j + i) {Probs.setDataItem(states, 1);

}else {

Probs.setDataItem(states, 0);}

}}

}}else if (n == NP - 1 && (n+3)%8 == 0) {

DefaultProbabilityPotential Probs = (DefaultProbabilityPotential) PC3[s][n].getTable();Probs.initialize();for (i = 0; i < 5; i++) {

for (j = 0; j < 3; j++) {for (k = 0; k < 7; k++) {

// assigning statesstates[0] = i;states[1] = j;states[2] = k;

if (k == j + i) {Probs.setDataItem(states, 1);

}else {

Probs.setDataItem(states, 0);}

}}

}}else if (n == NP - 1 && (n+2)%8 == 0) {

DefaultProbabilityPotential Probs = (DefaultProbabilityPotential) PC3[s][n].getTable();Probs.initialize();

Page 120: Optimization of delivery strategies for slaughter pigs

112 APPENDIX B. CODE

for (i = 0; i < 5; i++) {for (j = 0; j < 4; j++) {

for (k = 0; k < 8; k++) {// assigning statesstates[0] = i;states[1] = j;states[2] = k;

if (k == j + i) {Probs.setDataItem(states, 1);

}else {

Probs.setDataItem(states, 0);}

}}

}}else {

//do nothing}

}}// calculating and assigning PC4 probabilitiesstatic void AssignPC4Probs( int s, int n){

// local varsint[] states = {0, 0, 0};int i;int j;int k;int x;

if (s == 0 || n == 0) {// no exist

}else {

// probability for PC4 tableSystem.out.println("s=" + s + " -- n=" + n);if ( (n + 1) % 16 == 0) {

DefaultProbabilityPotential Probs = (DefaultProbabilityPotential) PC4[s][n].getTable();Probs.initialize();

for (i = 0; i < 9; i++) {for (j = 0; j < 9; j++) {

for (k = 0; k < 17; k++) {// assigning statesstates[0] = i;states[1] = j;states[2] = k;

if (k == j + i) {Probs.setDataItem(states, 1);

}else {

Probs.setDataItem(states, 0);}

}}

}}else {

for (x = 0; x < 7; x++) {if (n == NP - 1 && (n + 8 - x) % 16 == 0) {

DefaultProbabilityPotential Probs = (DefaultProbabilityPotential)PC4[s][n].getTable();Probs.initialize();for (i = 0; i < 9; i++) {

for (j = 0; j < 2 + x; j++) {for (k = 0; k < 10 + x; k++) {

// assigning statesstates[0] = i;states[1] = j;states[2] = k;

if (k == j + i) {Probs.setDataItem(states, 1);

}else {

Probs.setDataItem(states, 0);}

}}

}

Page 121: Optimization of delivery strategies for slaughter pigs

113

}else {

//do nothing}

}}

}}

} // end class