A MATHEMATICAL MODEL TO DETERMINE THE OPTIMAL AGE FOR HARVESTING PIGS WHILE MAXIMISING PROFITABILITY

One of the challenges currently experienced in the agricultural environment is determining the optimal age for harvesting pigs while maximising profitability. The harvesting age selection policy affects the carcass weight and the meat quality of harvested animals and, therefore, the income generated from these harvesting activities. This decision also influences the total cost of managing an animal. Various factors influence the optimal age for harvesting pigs, including (but not limited to) genetics, feed, health, care


S 1. INTRODUCTION
The pork industry is a minor contributor to the South African agricultural sector, contributing 2.45% of the total sector [1].Challenges inherent in the pork industry have restricted the interest of some potential role players in becoming swineherds.The industry has been susceptible to diseases and phytosanitary issues [2].
Although much has been done to promote the health and quality of the meat as well as the pigs' living conditions, it is still widely considered an inferior product [3].Another problem is the availability of clean water for drinking and cleaning pens; a water shortage puts pigs' health at risk.
According to the Department of Agriculture, Land Reform and Rural Development [1], pig farming is more labour-intensive than red meat alternatives.Pig farmers have witnessed a steady increase in local demand despite the difficulties they face.However, over the last decade South Africa has been unable to produce enough pork.
South Africa has thus had to import meat to satisfy the increasing demand [1].Production has seen a 47% increase since 2010.Consumption has also increased by 33% for the same period.According to the Bureau for Food and Agricultural Policy [2], 10% of the pork that is consumed is imported.These results further emphasise the need and the opportunity for growth in the South African pork industry.The value of pork exports is progressively climbing, even though the number of exports is declining.This could primarily be owing to the fast turnaround production time and low feed costs compared with red meat alternatives.Moreover, the recent escalation in red meat prices and its unavailability has boosted pork's popularity.
A study was conducted on a particular pig farm that breeds a specific race of pigs and delivers them live to an abattoir in order to make a profit.The farmer has developed the procedure for each stage of his pigs' feeding regime.As a result, harvested pigs are delivering consistent back fat thickness measurements.This has also standardised the growth of the pigs in order to develop an accurate standard growth curve.Figure 1 shows the pigs' expected growth for the farm in the study.However, the farmer struggles with a complex problem: that of determining the optimal age to harvest their pigs.This crucial decision has a direct impact on the profitability of their pork production.However, owing to a range of factors, the farmer's decision-making process has become uncertain, leading to inconsistent harvesting decisions that harm both their income and the expectations of the abattoirs they supply.
Determining the best age to harvest pigs is complicated by conflicting factors.Lighter pigs secure higher prices per kilogram, tempting an early harvest.Moreover, younger pigs cost less because of reduced keeping costs.In contrast, older, heavier pigs can yield greater profit despite a lower price per kilogram, given their size and better dressing percentages.This paradox of opposing elements creates uncertainty.The farmer's changes in harvesting ages reflect a need for optimality.
Given this background, this study proposes a mathematical model -specifically, a mixed integer quadratic programming (MIQP) model -that could determine the optimal harvest age while considering the abovementioned constraints.This model would allow farmers to develop a harvesting policy that is best suited to their farm, resulting in consistent harvests and maximum profitability.
Following this introduction, the article briefly discusses the crucial findings of the literature review on optimisation theory in Section 2.1 and the critical factors to consider in the meat industry in Section 2.2.A mathematical model is proposed, verified, and validated in Sections 3 and 4. Last, the article concludes with a summary in Section 5 and a recommendation for further development in Section 6.

Overview of optimisation theory
According to Chong and Zak [4], optimisation is the theory and method of selecting the optimal solution from different possibilities.Various mathematical programming techniques, such as linear and integer programming, have been developed to solve different problems [5].Therefore, it is crucial to classify the optimisation problem appropriately to select the best technique to solve the problem.
Optimisation theory is typically divided into deterministic optimisation and stochastic optimisation, the second of which is also called decision-making under uncertainty.Deterministic optimisation excludes uncertainty or randomness in the decision-making process, whereas stochastic optimisation includes uncertainty [6].This study mainly focuses on deterministic optimisation.
Prominent applications of LP include (but are not limited to) the finance industry [7], energy [8], and scheduling [9].Linear programming problems that restrict the decision variables to integers are called integer linear programming problems (ILP) [10].The standard formulation of an ILP problem is shown in equations (2.4) to (2.7): Maximise where Typical ILP applications in the literature include investment problems [7], the travelling salesman problem [11], and the knapsack problem [13].The values that the variables are allowed to take on will determine whether a programming problem is classified as an integer or a real-valued programming problem [5].However, if only some design values are limited to discrete values, the problem is called a mixed integer programming problem (MIP).
If any function used to state the optimisation problem is non-linear, the problem is classified as a nonlinear programming (NLP) problem [5].All other problems are considered exceptional cases of the NLP problem.If the objective function of an NLP problem is quadratic and all of the constraints are linear, the problem becomes a quadratic programming problem [5].If at least one of the constraints is quadratic as well, the problem becomes a quadratically constrained programming (QCP) problem.The standard formulation of a quadratic problem can be formulated as follows [14]: Minimise () =  is defined as the symmetric  ×  matrix.The indices in this model are defined as  and  respectively.The variables , x and {  },  ∈  ∪  are defined as vectors in ℝ  .Quadratic programming and QCP have also been useful in the energy [14,15] and finance industries [16].

The meat and pork industry
Like any other business, a farm operates to earn a profit -that is, the financial gain from subtracting the amount spent (cost) from the amount earned (revenue) in a business operation.Therefore, farming in meat production industries has cost and revenue elements that need to be considered.The weight of a carcass and the purchasing price per kilogram will determine the revenue per carcass.Thus the elements to be considered for the revenue function are the influencers of carcass weight and the influencers of the carcass price per kilogram.Feeding (quantity and quality), pig genetics, age, and dressing percentage influence the weight of a carcass at harvest [17].Carcass class, weight category, and market prices influence the purchasing price [18,19].Each of these is explained in the sections below.

Pig feeding, genetics, and growth
Diet and feeding regimes largely determine the growth of the animals, and can be formulated to optimise the growth of pigs [20].Feed utilisation is another factor affecting pigs' growth, which is determined by the pigs' genetics [20,21].Feeding regimes are developed or chosen by the farmer.Likewise, the farmer chooses which animal breed(s) to farm.Thus the farmer can control the growth rate and carcass quality.This emphasises the fact that every farm will have a unique growth curve.A farmer should be able to determine the standard growth curve of their farm animals.

Pig age and live weight
Plotting the growth of the pigs in respect of live weight and age delivers a curve with an S-shape.Kusec et al. [22] modelled the growth dynamics using an asymmetric S-function with one flexible inflexion point as the generalised form of the logistic function to predict the live weights of pigs. Figure 2 presents the growth S-curve of the investigation by Kusec et al. [22].
The curves in Figure 2 display the characteristic S-shape.Kusec et al. [22] also mentioned a stage of retardation that begins at the saturation point.This point can be predicted, and the stage of retardation is observed as the curve flattens over time.Traditionally, this point is assumed to be the optimal harvest age since, from this point on, the cost of maintaining an animal remains constant, whereas the increase in weight and size has ceased to increase.The cost of keeping an animal past this point is considered a loss.Some farmers do not know their animals' standard curve under their specific circumstances, and make harvesting decisions based on assumptions or their own experience.Although this method has aided in estimating better harvest ages for increased profit, other factors could contribute to finding the optimal age.

Dressing percentage
'Dressing' is the process of removing an animal's internal organs and inedible parts, and the 'dressing percentage' is the percentage of the live animal weight that remains after dressing.Jensen et al. [23] note that older and heavier pigs usually have higher dressing percentages.Breed, diet, gender (castration of male piglets reduces this effect), and harvest time in relation to the biological growth curve are all factors that affect the dressing percentages of animals [24].This could cause the model to select an age past the point of saturation.However, this would again require the farmer to find the trend of dressing percentage changes across the ages of his animals.

Carcass quality and market price
Meat prices are not constant, and have been vulnerable to unforeseen events, including the listeriosis outbreak in 2018 and the COVID-19 pandemic in 2020, that affect the pork industry in South Africa [18].Figure 3 shows the weekly price of pig carcasses in South Africa from 2017 until mid-2021.
Figure 3 shows that purchasing prices are constantly changing and are affected by events that are out of a farmer's control.The price per kilogram of a pig depends on the weight category and the back fat classification of the carcass [19].

Figure 3: Weekly price of pig carcasses [16]
As previously mentioned, the farmer has some control over the back fat thickness and carcass weight by selecting the appropriate feeding regime, genetics, and, ultimately, the harvest age.It is then necessary for the farmer to know at what age the animals will have the optimal weight category and class for harvesting to be most profitable.These prices are not constant.The harvest age will have to be repeatedly determined, as optimality will change as the market pricing changes.

Cost aspects
The total cost of pig production can be divided into total feed cost, total fixed cost, total reproduction cost, and total drug and vaccine cost [25].The main cost is the feed cost, which increases as the pig ages and naturally becomes larger and consumes more daily feed.The age of harvest also determines the total cost of production.These costs can be used to set up the standard cost curve of the specific farm, as costs are also very farm-specific.Each cost aspect has various factors that are specific to the farm's location and environment.
Considering that the income and cost from meat production operations are affected by the age at which animals are harvested, the profit depends on the farmer's decision.The mathematical model proposed in Section 3 could aid in selecting an age when the difference between the income and the costs of production is most significant, allowing the farmer certainty in decision-making and resulting in more consistent harvests.This model could benefit both the farmer and the abattoir.The model will select among the different category-class combinations for the optimal price per kilogram, resulting in maximum profitability.

Mathematical programming in the meat production industry
Mathematical programming and optimisation have extended to many sectors, and are already prevalent in agriculture.Morrison et al. [26] used mathematical programming to develop an MIP model that represents a crop-livestock farm's biological, technological, and financial relationships.Their study aimed to investigate the positive interactions between enterprises and their influence on profit and on the optimal farm plan.
Ohmann and Jones [27] developed a mixed integer linear program to model a decision-making problem for pork marketing for optimal profit.Case et al. [28] used a deterministic optimisation model to determine the optimal slaughter weights of turkeys for maximum profit in a turkey production system.
These are a few examples of the many studies and projects that add value to the meat production industry.However, a model that determines the optimal age for harvesting pigs while maximising profitability is scarce in the literature, and would benefit farmers looking to direct their efforts towards precision farming.

MATHEMATICAL MODEL DEVELOPMENT
The mathematical model was developed and implemented using CPLEX, since it provides a free licence for academic purposes and is popular in the authors' educational institutions.The model was coded and solved in CPLEX using its general-purpose optimisation programming language (OPL).Microsoft Excel was used to provide data to CPLEX for the optimisation model.
In this section, the notations and assumptions are discussed first, followed by the model's formulation.

Notations and assumptions
The indices, parameters, and variables are defined in Sections 3.1.1 to 3.1.3.

Indices used:
•  ∈  is the index of classes according to the classification done by an abattoir by measurement of the back fat thickness of a carcass.
•  ∈  is the index of categories according to an abattoir's categorisation by measuring a carcass's dressed weight.
•  ∈  is the index of the number of weeks considered.

Parameters used:
• A is the matrix of purchasing prices per kilogram of size  × .
•   is a single entry in A: a purchasing price per kilogram of a carcass with class  and category .
•   is the dressing percentage of a pig aged  weeks.
•   is the cost of keeping a pig aged  weeks.
•   is the standard weight of a pig aged  weeks.
•   is the minimum weight limit of category .
•   is the maximum weight limit of category .

Variables used:
•   is the binary decision variable that allocates the purchasing price per kilogram with class  and category .
•   is the binary decision variable used to allocate the age  of the pig in weeks.The objective function (3.1) finds the optimal age (in weeks) that maximises profitability.The selected age determines the live weight, dressing percentage, and cost of keeping a pig, which results in the maximum difference between income and cost.Constraint (3.2) ensures that only one purchasing price is selected.Constraint (3.3) ensures that only one age (in weeks) is selected.Constraint (3.4) is a conditional constraint that assigns the weight category  to the pig if the product of the dressing percentage and weight of a pig at week  is above the minimum weight limit and below the maximum weight limit of weight category .Constraints (3.5) and (3.6) respectively define (  ) and (  ) as binary variables.

VERIFICATION AND VALIDATION
According to the formulation of the objective function and the constraints, CPLEX resolved to solve the problem as a mixed integer quadratic programming (MIQP) problem.Thacker et al. [29] gave the following descriptions for verifying and validating models.Verification ensures that the model has been implemented correctly and accurately represents the conceptual description and design specifications [29].Verification is typically performed by running a series of tests to confirm that the model behaves as expected.On the other hand, validation refers to evaluating the model's performance according to the perspective of its intended use.Validation is typically performed by testing the model against a set of test or real-world data to evaluate its performance [29].Model verification is described in Section 4.1, and validation in Section 4.2.

Verification
The mathematical model's objective function (3.1) was verified, followed by verification of the individual constraints (3.2) to (3.7).After that, parameter changes were made in different scenarios to complete the model's verification.Equations (4.1) to (4.6) represent the respective returned values of the decision variables z (purchasing price) and x (age in weeks).

The objective function
The objective function (3.1) maximises the profit and selects an optimal age and purchasing price per kilogram.Running the model with no constraint on the number of ages and purchasing prices that can be selected, the model should select multiple purchasing prices and ages.If the model selects one in the matrix Z, the model performs as expected, since no restriction is provided on the model.The following results were obtained: All purchasing prices are selected (z), as well as all of the available ages (x).The model returned a solution value of R309 014,62.

Constraint 1
The first constraint (3.2) limits the total purchasing price per kilogram.The model should select the most significant purchasing price value (z) while still selecting multiple ages (x) to maximise the profit.Furthermore, the solution value should decrease with the addition of this constraint.The following results were obtained: Only one purchasing price per kilogram (z) and multiple ages (x) are selected.The purchasing price that was selected was the highest.A lower value of R3 594,65 was returned.

Constraint 2
The third constraint limits the total number of ages.The model should select only the highest purchasing price and only one age.Furthermore, the solution value should decrease with the addition of this constraint.The following results were obtained:

Constraint 3
Constraint (3.4) categorises the weight.These constraints should categorise the dressed weights, linking specific purchasing prices to specific dressed weights.The model should select the appropriate purchasing price for the age that will result in the dressed weight of the pig being priced in line with the method used in an abattoir.The solution value should decrease.The following results were obtained: A single purchasing price and a single age, where the weight associated with the age of the pig falls within the range specified by the category of the selected purchasing price per kilogram, is selected.A lower solution value of R505,25 was returned.A scenario analysis was conducted to verify further and evaluate the model's behaviour.

Scenario 1
This scenario aims to verify the model's ability to function properly with randomly changing markets.To simulate this, matrix A (the matrix of the purchasing price) was populated with randomly generated values.The model should select the harvest age in weeks, resulting in the maximum weight × purchasing price combination for maximum profit.The model should correctly comment on the age and back fat thickness that would deliver the maximum profit according to the values defined in the new matrix A. The following results were obtained: R1 041,05 was obtained with a back fat thickness between 13mm and 18mm.The optimal age in weeks was 23.The selected age had a standard weight within the range required for the selected purchasing price.
The model further correctly commented on the solution value, back fat thickness, and optimal age in weeks.The selected age had a standard weight within the range required for the selected purchasing price.
The model further correctly commented on the solution value, back fat thickness, and optimal age in weeks.

Scenario 2
The purpose of this scenario is to verify that the model can be applied to farms with different growth rates.
To simulate this, a different standard growth curve and a different range of considerable ages are given.The model should select the harvest age in weeks, resulting in the maximum weight × purchasing price combination for maximum profit.According to the values defined in matrix A, the model should correctly comment on the age and back fat thickness that would deliver the maximum profit.The optimal weight multiplied by the purchasing price combination should be different from the previous tests, as a new standard growth curve is used along with a larger set of ages to choose from.The following results were obtained: R389,43 was obtained, with a back fat thickness between 13mm and 18mm.The optimal age in weeks was 18.The selected age had a standard weight within the range required for the selected purchasing price.
The model further correctly commented on the solution value, back fat thickness, and optimal age in weeks.Note that X had more variables, which indicates that more weeks were considered.
From the above information, there is evidence to verify the correctness of the mathematical formulation of this optimisation model and the correctness of the coding of the model in CPLEX using OPL.

Validation
For the validation of the model, a single delivery of pigs to an abattoir was chosen to compare the actual decision-making results of the farm with the hypothetical results of the model.The delivery provided information on each carcass's dressed weight and back fat classification.The animals' ages were determined using the dressed weights of the pigs (comparable to live weights after compensating for loss from dressing) with the standard growth curve of the animals bred on the farm.
Applying the standard cost curve of the animals on the farm to the ages of the animals, the cumulative cost of each pig was determined.The purchasing prices used to calculate the income from pig carcasses were the same ones used to develop the model, and were obtained from the South African Pork Producers' Organisation carcass price report for March 2021 [30].Thus the circumstances assumed in the model were exactly the same circumstances for the pigs delivered to the abattoir.It resulted in similar costs, growth rates, and dressing percentages.Table 2 summarises the information that was needed to calculate the comparable profit from the delivery of 20 pigs to an abattoir.From the information in Table 2, the total purchasing price for the delivery of all 20 pigs was R40 737,57.
The combined costs of keeping the pigs until their harvest came to R31 965,00.Thus the profit was calculated to be R8 772,57.
The optimisation model had the same prices, growth rate, costs, and estimated dressing percentages as the pigs in Table 2.The model was used to find the optimal age of harvest.The results given by the model were: • Solution (optimal) with the objective value of R505.25

•
Optimal back fat thickness: between 13mm and 18mm • Optimal age in weeks = 24 The model selected the age of 24 weeks to be the optimal age to harvest a single pig for maximum profit.If all 20 pigs in Table 2 were harvested at 24 weeks, where the profit on a single pig was the solution value stated above, the total profit would have been 20 × R505.25.This would have totalled R10 105,13.
Comparing the above profit calculations, the optimisation model improved the profit by 13%.This information shows that the optimisation model could improve the decision-making policies for this specific farm regarding the harvest age.

CONCLUSIONS AND SUMMARY
The study was introduced with background to the pork meat production industry and a case study done on a pig farm that needed greater certainty in its harvesting policies.The pig farm producing pigs for harvest was uncertain of the optimal age at which to harvest them to maximise profit.The farmer had become unsure of the harvesting policies he had adopted, and was convinced that a more specific way of determining the harvest age specific to his operation had to be possible.
Therefore, this project aimed to propose a suitable decision-making model that considers the constraints that influence the maximum profit and returns the optimised age in weeks for harvesting pigs.The literature study provided information to select an environment in which to construct the optimisation model, select a mathematical programming technique, and understand the different elements of the problem in order to design the objective function and the constraints.The literature study also identified existing models to compare with the problem identified in this study.The mathematical model was developed and coded in CPLEX using OPL.Microsoft Excel was used to provide the data to the CPLEX model.The completed model was verified and validated to prove that the model was both correct and effective in improving the profitability of the farmer's harvesting policies.
The optimisation model was designed and developed to achieve the goal of selecting the optimal age of harvest to maximise profit.It was proven that the model could increase profit for the farm in the study.The model considered different parameters that are user adjustable.The results obtained in this study show that the study yielded an acceptable final deliverable and successfully solved the problem.This study solved the farmer's dilemma by proving that it could determine a policy that results in increased profit.
This optimisation model provides the pork meat industry with a novel alternative to the traditional decisionmaking approach by considering adjustable parameters, enabling the identification of an age for optimal harvest that maximises profitability.
By achieving a substantial increase in the farm's profit margin, this study addresses the original dilemma faced by the farmer.The successful resolution of the problem emphasises the model's practical significance, offering an approach that appropriately merges agricultural insight with advanced optimisation techniques.As a result, this study should not only enrich the understanding of decision-making in agribusiness, but should also provide a noteworthy contribution to the theoretical and practical dimensions of optimisation methodologies.

RECOMMENDATION FOR FUTURE RESEARCH
The solution discussed in this paper has been applied to a specific pig farm.The model should be tested on farms of varying sizes, feeding regimes, pig races, and harvesting policies.This model uses a standard growth curve to estimate age instead of considering all of the variables that could influence the growth of the animals.To improve upon this method, growth data could be collected for individual pigs each week.With enough data, machine learning could be applied to develop a prediction model for pig growth according to piglet measurements at certain ages.Such a prediction model could make the current model pig-specific, and help farmers to make better decisions in the future at earlier stages.
With further studies, the model could be extended to find the optimal harvesting ages of other livestock, and not be limited to pigs.The programming of the model could be better optimised and improved.An interface could be developed to increase its user-friendliness for farmers.CPLEX and many other solvers do not allow strict inequalities (<, >) when mixed integer programming is used to create the optimisation model.A more effective method of designing the constraints could be applied that might improve the program's efficiency and even the model's effectiveness.
If successfully implemented on a broader scale, the simplicity and effectiveness of this model could have a transformative impact on the pork production industry in South Africa.By providing farmers with a userfriendly tool for determining the optimal harvesting age, tailored to their specific operational constraints, the model could increase the overall profitability of pork production.The potential extends beyond individual farms, fostering industry-wide improvements in financial outcomes, supply chain predictability, and resource optimisation.Moreover, because of the potential cross-industry innovation, the model's adaptable design could lead to its integration into decision-making processes in other meat-producing agricultural sectors throughout the nation.This model could reshape traditional practices in a new era of data-driven, optimised agriculture, ultimately contributing to increased sustainability and economic growth.

Figure 1 :
Figure 1: Standard growth and weight gain of pigs from the case study