Artificial intelligence-based method and system for automatically generating a feed plan for a breeding farm
Patent Information
- Application Number
- CN202611502438.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-24
- Publication Date
- 2026-10-30
AI Technical Summary
现有人工方式难以对每头猪逐头跟踪状态变化并计算饲料需求
本发明将预测和计算的基本单元从群体下沉到每一头猪,从根本上消除了平均值偏差。其次,本发明利用时序模型从历史数据中自动学习多维特征的组合规律,这种组合数是指数级的,人工枚举规则无法穷举,从而实现对每头猪状态的精确预测。确定性生理约束规则仅作为安全边界兜底,预测主体始终是AI模型。本发明将配种计划、转群计划、引种计划作为模型的输入信号,通过注意力机制让每头猪动态匹配其所在生产线和日期的计划安排,使预测不仅反映生理节律,还能预判人为生产安排对猪群结构的影响。本发明从数据读取→状态预测→饲料需求量计算→计划生成→格式化输出,全流程由系统自动串联完成,无需人工干预。在存栏2000头的规模下,从发起计划到输出结果显著快于人工方式。最后,随着时间推移和历史数据积累,模型可通过多场联合训练或迁移学习持续优化,适应猪场生产节律的变化。计划生成后,系统可周期性地将预测需求量与实际消耗量(需接入实际饲喂记录表)进行比对,将偏差反馈至模型训练管道,形成预测→验证→优化的闭环。
Smart Images

Figure CN123014629A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of pig breeding technology, and in particular to an automatic feed plan generation method and system for pig farms based on artificial intelligence. Background Technology
[0002] Breeding pig farms are a core link in the pig farming industry chain. The farm's herd includes multiple categories such as gilts, pregnant sows, lactating sows, non-pregnant sows, and boars. Each type of pig is at a different production stage and is constantly changing. After mating, they go through gestation and farrowing, followed by lactation and weaning. After weaning, they are mated again after a period of interval. Meanwhile, gilts are continuously added to the production herd, inefficient sows are culled, and some pregnant sows become non-pregnant, abort, or return to estrus. The different conditions and ages of the pigs result in different daily standard feed intakes and feed types, which constitutes the core challenge of feed requirement planning.
[0003] Currently, pig farms mainly rely on the following methods to plan their feed demand: (1) Estimation by human experience Pig farm managers manually estimate future feed requirements based on the number of pigs in stock and established feed standards. This method is highly dependent on individual experience, and estimates vary significantly among different managers.
[0004] (2) Fixed template calculation Some pig farms use pre-set templates in spreadsheets to perform rough calculations based on pig herd type and average feed consumption. However, these templates lack dynamic tracking of changes in the condition of each pig, resulting in calculations that deviate significantly from actual needs.
[0005] (3) Simple statistical functions of aquaculture management software Some commercial livestock management software offers livestock inventory statistics, but generally does not include the ability to predict future feed demand, and only provides historical data query capabilities.
[0006] Problems with the above-mentioned existing technologies (1) Lack of refined prediction capability for each pig The core management unit of a breeding pig farm is the individual pig. Each pig's production status (non-pregnant, pregnant, lactating, etc.) and age (in days) are constantly changing, and the standard feed intake varies depending on the status and age. Current manual methods make it difficult to track these changes and calculate feed requirements for each pig individually.
[0007] (2) Lack of forward-looking prediction of state evolution The number of days in the production cycle (e.g., gestation period of approximately 114 days, lactation period of approximately 21-28 days, and weaning-to-breeding interval of approximately 5-7 days) determines the evolutionary pattern of the pig herd's condition. Existing methods cannot use these patterns to systematically predict the condition of each pig at any future point in time.
[0008] (3) Planning is delayed and the supply chain response is passive. Manual calculations are labor-intensive and time-consuming, and can usually only be completed hastily near the reporting deadline. This results in poor planning accuracy, leading to passive responses in feed procurement and supply, and easily causing feed shortages or excessive stockpiling.
[0009] (4) Lack of automatic verification between theoretical values and actual reported values There is often a discrepancy between the feed requirements reported by pig farms and the theoretical requirements calculated by the system. Current methods lack automated discrepancy comparison and early warning mechanisms, and cannot automatically complete discrepancy verification during the reporting process. Summary of the Invention
[0010] This invention overcomes the shortcomings of the prior art and provides an automatic generation method and system for feed plans in pig farms based on artificial intelligence.
[0011] To achieve the above objectives, the technical solution adopted by the present invention is as follows: The first aspect of this invention provides a method for automatically generating feed plans for breeding pig farms based on artificial intelligence, comprising the following steps: Read basic data such as pig records, standard feed amount, time configuration, return to estrus rate, and difference threshold; load mating plan, group transfer plan, and introduction plan data; and verify and exclude abnormal records. The data of mating plan, group transfer plan, and introduction plan are converted into numerical inputs that the model can accept. Through the attention mechanism, the individual physiological characteristics of each pig are dynamically fused with the production plan signals of its production line and the corresponding date according to the attention weight. The fusion directly participates in the calculation of the state probability of each pig during the model inference process. Using a temporal deep neural network, the daily state sequence of the next N days is output, and deterministic physiological rules are used to perform posterior correction on the model output. The head-by-head and day-by-day state prediction results output by the time-series deep neural network are summarized into an intermediate result set. Each record in the intermediate result set is traversed, and a standard feed amount table is matched according to the breeder pig's nature, predicted state, and age to obtain feed type and feed intake. The results are then summarized and aggregated according to four dimensions: date, pig house, production line, and feed type. The summarized results are entered into the preset plan template, and the plan document is output according to the target format.
[0012] Furthermore, in the AI-based automatic feed plan generation method for breeding pig farms, basic data such as pig records, standard feed quantity, time configuration, return-to-estrus ratio, and difference threshold are read; mating plan, regrouping plan, and introduction plan data are loaded; and abnormal records are verified and excluded. Specifically: Record the identity information and current status of each pig in the current stock, the standard daily feed intake for different production statuses and age ranges, the standard number of days for each state transition in the pig herd, the actual state change events that have occurred in the historical production and operation of each pig, the time configuration, the return to estrus ratio, and the basic data of the difference threshold. Receive the number of replacement breeding pigs bred, the number of weaned pigs bred, and the number of empty return pigs bred on each date, and construct a breeding plan; receive the type of herd transfer, the number of herd transfers, and the number of pigs to be marketed reported by pig farms within a preset time, and construct a herd transfer plan. The system receives information from pig farms regarding the breed, quantity, and age of introduced pigs within a preset timeframe, constructs an introduction plan, and verifies and excludes abnormal records from the mating plan, regrouping plan, and introduction plan data.
[0013] Furthermore, in the AI-based automatic feed plan generation method for pig farms, a cross-attention mechanism is used to fuse the individual physiological characteristics of each pig with the production line and corresponding date's production plan signals according to attention weights. Specifically: For the breeding plan data, for each production line and each planned date, the number of weaned pigs to be bred, the number of reserve pigs to be bred, and the number of empty return pigs to be bred are encoded into a three-dimensional vector, which is expanded into a time-series vector of length N×3 by date, and then deeply fused with the pig features of the corresponding production line through a cross-attention mechanism. For the data on the regrouping plan, the regrouping type, original production line, target production line, regrouping quantity, and market quantity are encoded into structured vectors, which are then expanded by date and fused with the characteristics of the affected pigs. For the data on the introduction plan, after encoding the breed, quantity, and age, a prediction unit is added to the model on the corresponding date. The prediction unit includes the initial state, breed, and age of the introduced pigs.
[0014] Furthermore, in the AI-based automatic feed plan generation method for pig farms, the state prediction process of the temporal deep neural network is as follows: The numerical inputs that the model can accept are mapped to vector representations and merged with continuous features into a unified feature vector, while the production planning signal is fused with pig features after being independently encoded. The fused feature vector is received to extract the temporal context. The sequence generation network outputs the state prediction for each future day in an autoregressive manner. When predicting the state on day t+1, the predicted state on day t is fed back as the input for the next time step, capturing the temporal dependency of state evolution. Each time step is mapped to the probability distribution of all possible states through a fully connected layer and Softmax. The state with the highest probability is taken as the prediction result. For mating and empty return flow states, an additional binary classifier is output to predict the probability of the return flow event. The training data is constructed from the historical state change record table. For each pig in history, an arbitrary time point t is selected. The pig's state characteristics at that time point and the production plan signal at the same time are used as the model input. The daily state sequence that actually occurs in N days after t is used as the supervision label. The model outputs a daily state sequence for the next N days, and the model output is then corrected posteriorly using deterministic physiological rules.
[0015] Furthermore, in the AI-based automatic feed plan generation method for pig farms, deterministic physiological rules are used to perform posterior correction on the model output, specifically: The state evolution must follow a unidirectional sequence: backup → mating → (empty return flow → mating) → parturition → weaning → mating, and cannot be reversed; The number of days from mating to delivery must not exceed the reasonable range defined in the time allocation table; The number of days from delivery to weaning must not exceed the reasonable range defined in the time allocation table; If the model output violates the constraints, it will be automatically corrected to the closest approximation state allowed by the constraints.
[0016] Furthermore, in the AI-based automatic feed plan generation method for pig farms, the temporal deep neural network is trained in the following manner: The federated learning strategy is adopted, where each pig farm trains the model and calculates the gradient locally, and only uploads the model parameters to the central server for aggregation. The original data is kept locally and does not go out. An adaptive parameter weighting algorithm is introduced in the federated learning aggregation process to dynamically adjust the weight of parameter updates based on the amount and quality of data from each pig farm, in order to solve the problem of non-independent and identically distributed data from each pig farm and generate a basic model with generalization ability. The model optimizes the cross-entropy loss between the predicted state sequence and the actual state sequence. The binary classifier head that predicts the return event additionally calculates the binary cross-entropy loss, and the total loss is the weighted sum of the two.
[0017] Furthermore, in the AI-based method for automatically generating feed plans for pig farms, the training of the temporal deep neural network also includes transfer learning and data augmentation: After pre-training the basic model on data from multiple pig farms, it is then fine-tuned using historical data from a single pig farm. Based on known physiological rules, small random perturbations are made to real data to generate enhanced samples, thereby expanding the coverage of the training samples.
[0018] Furthermore, in the AI-based automatic feed plan generation method for breeding pig farms, each record in the intermediate result set is traversed, and a standard feed quantity table is matched according to the breeding pig's nature, predicted status, and age to obtain feed type and feed intake. This information is then aggregated and summarized according to four dimensions: date, pig house, production line, and feed type. Specifically: When a feed plan needs to be generated, the current data of all pigs in stock is read from the pig file table, the pigs in the group with the departure type empty are filtered, and the mating plan, transfer plan and introduction plan are loaded. For each pig, input features are constructed and input into the trained prediction model to obtain the state prediction sequence for the next N days. Deterministic constraints are applied for correction, and the prediction results of all pigs are summarized into an intermediate result set. Each record includes: pig identifier, date, predicted state, predicted age, production line, breed, and parity. The calculation results for all pigs are aggregated and summarized in four dimensions: by date, by date + pig house, by date + production line, and by date + feed type.
[0019] Furthermore, in the AI-based method for automatically generating feed plans for pig farms, the output plan document also includes: The summarized results are filled into the preset plan template to generate a structured feed demand plan table. The template includes: the start and end dates of the plan period, the name of the pig farm, an overview of the generation time, the total daily demand and the demand by breed, the daily demand details of each production line, the total number of pigs covered by the plan and the distribution of each status. After the feed demand plan is generated, the theoretical demand is automatically compared with the actual reported demand, and the difference ratio is calculated by variety. The system compares the data with a difference threshold and automatically triggers an alert when the threshold is exceeded. This serves as an optional auxiliary function after the plan is generated and outputs the plan document in the target format.
[0020] The second aspect of this invention provides an automatic feed plan generation system for pig farms based on artificial intelligence, comprising a data layer, an algorithm layer, and an application layer: the data layer includes a pig file table, a standard feed quantity table, a time configuration table, a historical state change record table, a production plan data table, and an actual feeding record table, used to provide data for the algorithm layer; the algorithm layer is a state prediction engine, including: a feature encoding unit, used to vectorize the discrete and continuous features of pigs; and a feature extraction and sequence generation unit, used for time-series modeling and fusing production plan signals and individual physiological characteristics of pigs through a cross-attention mechanism, and outputting a state prediction sequence for the next N days in a daily autoregressive manner; The output classification unit is used to output the probability distribution of each state through Softmax and take the state with the highest probability as the prediction result, as well as output the probability of the return to estrus event; the deterministic constraint correction unit is used to make a fallback correction to the prediction result with physiological rules; the application layer includes: a feed demand calculation module, which is used to match the head-by-head daily state prediction results output by the algorithm layer with the standard feed amount table, and summarize and aggregate them according to four dimensions: date, pig house, production line, and feed type; a plan generation and deviation verification module, which is used to fill the summary results into the plan template and perform threshold comparison and early warning; and a multi-format output module, which is used to output the plan document according to the target format.
[0021] This invention addresses the shortcomings of the prior art and has the following beneficial effects: This invention decentralizes the basic unit of prediction and calculation from the entire herd to each individual pig, fundamentally eliminating the bias of average values. Secondly, it utilizes a time-series model to automatically learn the combination patterns of multi-dimensional features from historical data. The number of such combinations is exponential, exceeding the exhaustive nature of manual rule enumeration, thus achieving accurate prediction of each pig's condition. Deterministic physiological constraints serve only as a safety margin; the AI model remains the primary predictor. This invention uses breeding plans, relocation plans, and introduction plans as input signals to the model. Through an attention mechanism, each pig dynamically matches its production line and date's schedule, enabling predictions to not only reflect physiological rhythms but also anticipate the impact of human production arrangements on the herd structure. From data reading to condition prediction, feed requirement calculation, plan generation, and formatted output, the entire process is automatically completed by the system without human intervention. At a scale of 2000 pigs, the time from plan initiation to output is significantly faster than manual methods. Finally, with the passage of time and the accumulation of historical data, the model can be continuously optimized through multi-field joint training or transfer learning to adapt to changes in the pig farm's production rhythm. After the plan is generated, the system can periodically compare the predicted demand with the actual consumption (which needs to be connected to the actual feeding record table), and feed the deviation back to the model training pipeline, forming a closed loop of prediction → verification → optimization. Attached Figure Description
[0022] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other embodiments can be obtained from these drawings without creative effort.
[0023] Figure 1 A system block diagram of an AI-based automatic feed plan generation system for pig farms is shown. Figure 2 A flowchart is shown for an AI-based method for automatically generating feed plans for pig farms. Detailed Implementation
[0024] To better understand the above-mentioned objectives, features, and advantages of the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that, unless otherwise specified, the embodiments and features described in these embodiments can be combined with each other.
[0025] Many specific details are set forth in the following description in order to provide a full understanding of the invention. However, the invention may also be practiced in other ways different from those described herein, and therefore the scope of protection of the invention is not limited to the specific embodiments disclosed below.
[0026] Example 1
[0027] The first aspect of this invention provides a method for automatically generating feed plans for breeding pig farms based on artificial intelligence, comprising the following steps: Read basic data such as pig records, standard feed amount, time configuration, return to estrus rate, and difference threshold; load mating plan, group transfer plan, and introduction plan data; and verify and exclude abnormal records. The data of mating plan, group transfer plan, and introduction plan are converted into numerical inputs that the model can accept. Through the attention mechanism, the individual physiological characteristics of each pig are dynamically fused with the production plan signals of its production line and the corresponding date according to the attention weight. The fusion directly participates in the calculation of the state probability of each pig during the model inference process. Using a temporal deep neural network, the daily state sequence of the next N days is output, and deterministic physiological rules are used to perform posterior correction on the model output. The head-by-head and day-by-day state prediction results output by the time-series deep neural network are summarized into an intermediate result set. Each record in the intermediate result set is traversed, and a standard feed amount table is matched according to the breeder pig's nature, predicted state, and age to obtain feed type and feed intake. The results are then summarized and aggregated according to four dimensions: date, pig house, production line, and feed type. The summarized results are entered into the preset plan template, and the plan document is output according to the target format.
[0028] It should be noted that this invention lowers the basic unit of prediction and calculation from the herd to each individual pig, fundamentally eliminating the bias of average values. Secondly, this invention utilizes a time-series model to automatically learn the combination patterns of multi-dimensional features from historical data. The number of such combinations is exponential, exceeding the exhaustive nature of manual rule enumeration, thus achieving accurate prediction of each pig's state. Deterministic physiological constraints serve only as a safety margin; the prediction entity remains the AI model. This invention uses breeding plans, relocation plans, and introduction plans as input signals to the model. Through an attention mechanism, each pig dynamically matches its production line and date's schedule, enabling predictions to not only reflect physiological rhythms but also anticipate the impact of human production arrangements on the pig herd structure. From data reading to state prediction, feed requirement calculation, plan generation, and formatted output, the entire process is automatically completed by the system without human intervention. At a scale of 2000 pigs, the time from plan initiation to output is significantly faster than manual methods. Finally, with the passage of time and the accumulation of historical data, the model can be continuously optimized through multi-field joint training or transfer learning to adapt to changes in the pig farm's production rhythm. After the plan is generated, the system can periodically compare the predicted demand with the actual consumption (which needs to be connected to the actual feeding record table), and feed the deviation back to the model training pipeline, forming a closed loop of prediction → verification → optimization.
[0029] Furthermore, in the AI-based automatic feed plan generation method for breeding pig farms, basic data such as pig records, standard feed quantity, time configuration, return-to-estrus ratio, and difference threshold are read; mating plan, regrouping plan, and introduction plan data are loaded; and abnormal records are verified and excluded. Specifically: Record the identity information and current status of each pig in the current stock, the standard daily feed intake for different production statuses and age ranges, the standard number of days for each state transition in the pig herd, the actual state change events that have occurred in the historical production and operation of each pig, the time configuration, the return to estrus ratio, and the basic data of the difference threshold. This record contains the identity information and current status of each pig currently in stock. Each record includes the following fields, as shown in Table 1 below: Table 1
[0030] Record the standard daily feed intake for different production states and age ranges. The table is organized separately according to the nature of the breeding pigs (replacement breeding pigs / production breeding pigs), and production breeding pigs are further divided into tabs according to their status (mating, empty return, weaning, farrowing, production boars). Under each status tab, the corresponding feed type and feed intake are defined according to the age range.
[0031] The structure of Table 2 is as follows: Table 2
[0032] The standard for recording the duration of each state transition in a pig herd is a fundamental rule parameter for state prediction, as shown in Table 3 below: Table 3
[0033] Secondly, the actual state change events that occurred in the historical production and operation of each pig are recorded for use in training the artificial intelligence model. Each record includes information such as: pig ID, state before the change, state after the change, age at which the change occurred, and date of the change.
[0034] Receive the number of replacement breeding pigs bred, the number of weaned pigs bred, and the number of empty return pigs bred on each date, and construct a breeding plan; receive the type of herd transfer, the number of herd transfers, and the number of pigs to be marketed reported by pig farms within a preset time, and construct a herd transfer plan. The system receives information from pig farms regarding the breed, quantity, and age of introduced pigs within a preset timeframe, constructs an introduction plan, and verifies and excludes abnormal records from the mating plan, regrouping plan, and introduction plan data.
[0035] It should be noted that the actual daily feed consumption of each pig or pigsty is recorded for comparison with the theoretical prediction, and the deviation is fed back to the model training pipeline. Each record includes the following fields: date, pig ID or pigsty number, feed type, actual consumption (kg), person filling in the record, and remarks. In addition, the system operation relies on the following preset configuration parameters: return-to-estrus ratio (the statistical mean of the group that returns to estrus after mating, used as a priori reference for the prediction model); difference ratio threshold (upper and lower limits of total difference and breed-specific difference, used for deviation verification and triggering early warning judgment).
[0036] Furthermore, in the AI-based automatic feed plan generation method for pig farms, a cross-attention mechanism is used to fuse the individual physiological characteristics of each pig with the production line and corresponding date's production plan signals according to attention weights. Specifically: For the breeding plan data, for each production line and each planned date, the number of weaned pigs to be bred, the number of reserve pigs to be bred, and the number of empty return pigs to be bred are encoded into a three-dimensional vector, which is expanded into a time-series vector of length N×3 by date, and then deeply fused with the pig features of the corresponding production line through a cross-attention mechanism. For the data on the regrouping plan, the regrouping type, original production line, target production line, regrouping quantity, and market quantity are encoded into structured vectors, which are then expanded by date and fused with the characteristics of the affected pigs. For the data on the introduction plan, after encoding the breed, quantity, and age, a prediction unit is added to the model on the corresponding date. The prediction unit includes the initial state, breed, and age of the introduced pigs.
[0037] Furthermore, in the AI-based automatic feed plan generation method for pig farms, the state prediction process of the temporal deep neural network is as follows: The numerical inputs that the model can accept are mapped to vector representations and merged with continuous features into a unified feature vector, while the production planning signal is fused with pig features after being independently encoded. The fused feature vector is received to extract the temporal context. The sequence generation network outputs the state prediction for each future day in an autoregressive manner. When predicting the state on day t+1, the predicted state on day t is fed back as the input for the next time step, capturing the temporal dependency of state evolution. Each time step is mapped to the probability distribution of all possible states through a fully connected layer and Softmax. The state with the highest probability is taken as the prediction result. For mating and empty return flow states, an additional binary classifier is output to predict the probability of the return flow event. The training data is constructed from the historical state change record table. For each pig in history, an arbitrary time point t is selected. The pig's state characteristics at that time point and the production plan signal at the same time are used as the model input. The daily state sequence that actually occurs in N days after t is used as the supervision label. The model outputs a daily state sequence for the next N days, and the model output is then corrected posteriorly using deterministic physiological rules.
[0038] It should be noted that the state prediction model is the core of this invention. The problem it aims to solve is: given current inventory data, production rhythm rules, and future production plans, predict the production status of each pig every day for the next N days. This is a prerequisite for achieving precise feed demand calculation per pig.
[0039] The evolution of the production status of breeding pigs follows a clear biological rhythm: for example, replacement → mating (replacement to production), mating → farrowing (about 114 days), mating → return to estrus → empty return flow (occurring according to probability, about 21-42 days after mating), farrowing → weaning (about 21 days), weaning → next mating (about 5-7 days), empty return flow → next mating.
[0040] The typical duration of each state provides a baseline for prediction. However, in actual production, the precise timing of state transitions is influenced by various factors such as breed, parity, and body condition, fluctuating around the typical value. More importantly, there are complex interaction effects among these factors—for example, the impact of high parity × breed A × summer on gestational age is not a simple additive effect, but a non-linear combination effect, which cannot be covered by manual enumeration rules.
[0041] The model's innovation lies in its ability to automatically learn individualized shift patterns under the interaction of multiple factors from massive historical data, rather than relying on a fixed offset on a baseline. For example: Breed A × Parity 3 → Gestation days tend to be 1-2 days shorter; Breed B × Parity 1 × Body condition lean → Weaning-to-mating interval tends to be 2-3 days longer. These interaction patterns are impossible for any rule engine to exhaustively enumerate due to combinatorial explosion; only the AI model can automatically extract them from the data.
[0042] Deterministic constraints serve only as safety boundaries (preventing model outputs from exceeding biologically plausible ranges, such as gestation periods less than 100 days or greater than 130 days), not as the main predictor. Simultaneously, the model uses production arrangements such as mating plans, relocation plans, and introduction plans as external input signals, incorporating plan-driven state changes into the prediction. This forms a hybrid prediction method of "soft prediction based on physiological patterns + hard constraints based on planning interventions." The model first outputs a basic state prediction probability based on physiological characteristics. Subsequently, it interactively fuses production plan signals with physiological characteristics through a cross-attention mechanism (solving the causal inversion problem during inference), and uses deterministic physiological rules to perform posterior correction on the model output (ensuring the results do not exceed biologically reasonable ranges), rather than replacing prediction with planning, ensuring that the prediction results conform to both biological patterns and actual production arrangements. It should be noted that this invention is not limited to a specific neural network architecture; its core innovation lies in using individual physiological characteristics and production plan signals as input features, and utilizing a cross-attention mechanism to achieve deep fusion of planning signals and physiological predictions. Any machine learning model capable of realizing this input-output mapping relationship (including but not limited to LSTM, Transformer, TCN, support vector machine, and rule engine with probability correction) falls within the protection scope of this invention.
[0043] The model's prediction unit is each pig in stock. For a single pig, the input information is shown in Table 4 below: Table 4
[0044] Among these, production planning signals are a key input that distinguishes them from purely physiological predictions—they represent human intervention in the trajectory of the pig herd. For example, when weaned sows are bred depends partly on natural processes (estrus occurs approximately 5-7 days later) and partly on the specific arrangements of the breeding plan.
[0045] Production planning signals are converted into numerical inputs that the model can accept in the following ways: Breeding Plan: For each production line and each planned date, the (number of weaned pigs to be bred, number of reserve pigs to be bred, and number of empty return pigs to be bred) are encoded into a three-dimensional vector, which is then expanded into a time-series vector of length N×3 by date. This vector is deeply fused with the pig features of the corresponding production line through a cross-attention mechanism—this mechanism allows the production plan signal to serve as contextual prior knowledge, directly participating in the calculation of each pig's state probability during model inference, rather than being post-processed and corrected after model output. Specifically, each pig's feature vector dynamically focuses on the breeding plan signal of its production line for the corresponding date, so that the planning arrangement influences the state prediction distribution in a way that uses attention weights, thereby achieving integrated modeling of planned intervention and physiological prediction.
[0046] Herd transfer plan: (Herd transfer type, original production line, target production line, number of transferred herds, number of pigs to market) are encoded as structured vectors, expanded by date, and fused with the characteristics of the affected pigs. For herd transfers involving production line changes, the model switches the characteristics of the pig's original production line to the target production line code on the corresponding date.
[0047] Introduction Plan: After encoding (breed, quantity, age), a new prediction unit is added to the model on the corresponding date. The initial state (reserve), breed, and age of these introduced pigs are known, and the model predicts their state evolution within the remaining planning period based on this. The number of pigs to be marketed in the regrouping plan will have their "departure type" set to "marketed" on the corresponding date and will be removed from subsequent prediction units. The introduction plan must include target production line information, and the system assigns a "production line" code accordingly.
[0048] The model outputs the predicted production status of each pig for each day within the planning cycle.
[0049] Age increases by natural days, requiring no model prediction. The core task of the model is to determine the state of each pig on each day by integrating physiological rhythms, individual characteristics, and production plans.
[0050] This invention employs a temporal deep neural network to achieve the aforementioned prediction function, and the overall process consists of three stages: Feature encoding stage: Discrete features of pigs (status, breed, breeding pig characteristics, sex, production line, etc.) are mapped into vector representations and merged with continuous features (age, duration, parity, etc.) into a unified feature vector. Production planning signals are fused with pig features after independent encoding.
[0051] The temporal modeling layer includes a feature extraction network for extracting temporal dependencies of input features, and a sequence generation network for generating future state sequences based on historical states and production plans. The feature extraction network receives the fused feature vectors to extract the temporal context; the sequence generation network autoregressively outputs the state prediction for each future day—when predicting day t+1, the predicted state for day t is fed back as the input for the next time step, capturing the temporal dependencies of state evolution. It should be noted that the aforementioned feature extraction network and sequence generation network are not limited to specific architectures: preferably, LSTM, GRU, the encoder layer of a Transformer, TCN, etc., can be used as the feature extraction network, and an autoregressive decoder or a Transformer with one-time decoding can be used as the sequence generation network. Any model capable of learning temporal dependencies and generating state sequences falls within the scope of protection.
[0052] Output classification layer: At each time step, the probability distribution of all possible states is mapped through a fully connected layer and a softmax layer, and the state with the highest probability is taken as the prediction result. For mating and empty return flow states, an additional binary classifier is output to predict the probability of the return flow event.
[0053] Furthermore, in the AI-based automatic feed plan generation method for pig farms, the temporal deep neural network is trained in the following manner: The federated learning strategy is adopted, where each pig farm trains the model and calculates the gradient locally, and only uploads the model parameters to the central server for aggregation. The original data is kept locally and does not go out. An adaptive parameter weighting algorithm is introduced in the federated learning aggregation process to dynamically adjust the weight of parameter updates based on the amount and quality of data from each pig farm, in order to solve the problem of non-independent and identically distributed data from each pig farm and generate a basic model with generalization ability. The model optimizes the cross-entropy loss between the predicted state sequence and the true state sequence. An additional binary cross-entropy loss is calculated for the binary classifier head used to predict recurrence events. The total loss is a weighted sum of the two losses. An early stopping strategy is employed during training to prevent overfitting.
[0054] Furthermore, in the AI-based method for automatically generating feed plans for pig farms, the training of the temporal deep neural network also includes transfer learning and data augmentation: After pre-training the basic model on data from multiple pig farms, it is then fine-tuned using historical data from a single pig farm. Based on known physiological rules, small random perturbations are made to real data to generate enhanced samples, thereby expanding the coverage of the training samples.
[0055] It should be noted that the training data is constructed from a historical state change record table. For each pig in history, an arbitrary time point t is selected, and the pig's state characteristics at that time point and the production plan signal for the same period are used as model inputs. The daily state sequence that actually occurs within N days after t is used as supervision labels.
[0056] Given the limited amount of data from a single pig farm, the following strategies can be used to ensure training effectiveness: Multi-farm joint training: Employing a federated learning strategy, each pig farm trains its model locally and calculates gradients. Only model parameter updates are uploaded to the central server for aggregation, while the original data remains locally and is not processed. Due to differences in hardware (e.g., ear tag reader models), environmental parameters (temperature and humidity range), and management habits (recording granularity) among different pig farms, the data from each farm exhibits non-independent and identically distributed (Non-IID) characteristics. This invention introduces an adaptive parameter weighting algorithm during the federated learning aggregation process, dynamically adjusting the weights of parameter updates based on the amount and quality of data from each pig farm. This solves the problem of cross-farm data heterogeneity and generates a basic model with generalization capabilities.
[0057] Transfer learning: After the base model is pre-trained on multiple datasets, it is fine-tuned using historical data from a single pig farm.
[0058] Data augmentation: Based on known physiological rules (such as the number of days of pregnancy following a normal distribution with a mean of 114), small random perturbations are applied to the real data to generate augmented samples.
[0059] It should be noted that the historical training data implicitly includes physical variables such as environmental temperature and humidity, and feed nutrient levels (even if they are not explicitly labeled in the model input). By capturing the statistical correlation between state changes and these implicit factors, the model essentially learns causal chains that follow natural laws, such as "high temperature → shortened gestation days" and "nutrient level → body condition → extended weaning interval". This is the key difference between this model and purely statistical data methods.
[0060] Furthermore, in the AI-based automatic feed plan generation method for breeding pig farms, each record in the intermediate result set is traversed, and a standard feed quantity table is matched according to the breeding pig's nature, predicted status, and age to obtain feed type and feed intake. This information is then aggregated and summarized according to four dimensions: date, pig house, production line, and feed type. Specifically: When a feed plan needs to be generated, the current data of all pigs in stock is read from the pig file table, the pigs in the group with the departure type empty are filtered, and the mating plan, transfer plan and introduction plan are loaded. For each pig, input features are constructed and input into the trained prediction model to obtain the state prediction sequence for the next N days. Deterministic constraints are applied for correction, and the prediction results of all pigs are summarized into an intermediate result set. Each record includes: pig identifier, date, predicted state, predicted age, production line, breed, and parity. The calculation results for all pigs are aggregated and summarized in four dimensions: by date, by date + pig house, by date + production line, and by date + feed type.
[0061] It should be noted that the prediction results for all pigs are aggregated into an intermediate result set. Each record includes: pig identifier, date, predicted status, predicted age, production line, breed, and parity. When the model predicts that a pig will undergo a state transition on date t, the system automatically updates the pig's "current status" to the predicted new status, resets the "latest status date" to t, and recalculates the age in days for subsequent dates based on the new status. When a pig is transitioned from weaning to breeding, the parity is incremented by 1; when a pig is transitioned from a gilt to breeding, the parity is set to 1.
[0062] To ensure that the prediction results conform to the basic laws of pig reproductive physiology, deterministic constraint rules are superimposed on the model output: The state evolution must follow a unidirectional sequence: backup → mating → (empty return flow → mating) → parturition → weaning → mating, and cannot be reversed; The number of days from mating to delivery must not exceed the reasonable range defined in the time allocation table; The number of days from delivery to weaning must not exceed the reasonable range defined in the time allocation table; If the model output violates the above constraints, it is automatically corrected to the closest approximation allowed by the constraints. This mechanism combines the statistical learning capabilities of AI with known physiological rules to ensure that the prediction results are both accurate and reasonable.
[0063] Furthermore, in the AI-based method for automatically generating feed plans for pig farms, the output plan document also includes: The summarized results are filled into the preset plan template to generate a structured feed demand plan table. The template includes: the start and end dates of the plan period, the name of the pig farm, an overview of the generation time, the total daily demand and the demand by breed, the daily demand details of each production line, the total number of pigs covered by the plan and the distribution of each status. After the feed demand plan is generated, the theoretical demand is automatically compared with the actual reported demand, and the difference ratio is calculated by variety. The system compares the data with a difference threshold and automatically triggers an alert when the threshold is exceeded. This serves as an optional auxiliary function after the plan is generated and outputs the plan document in the target format.
[0064] For each pig's predicted condition and predicted age on each day within the planning period, the feed requirement is calculated according to the following logic: (1) Calculation of daily feed requirement for a single pig When selecting replacement breeding pigs, age in days = planned date - date of birth + 1 (inclusive is counted as day 1, the same applies below). Locate the age range in the standard feed ration table according to the pig's nature, and select the corresponding feed type and standard feed intake. If the replacement pig's status changes on the planned date based on the mating or regrouping plan (transferred to a production breeding pig for mating, or regrouped / marketed), deductions or adjustments will be made according to the corresponding rules.
[0065] When producing sows, the age in days of condition = planned date - latest condition date + 1 (including the current day, which is counted as day 1, the same below). In the standard feed table, find the corresponding feed type and standard feed intake by breeder type, corresponding condition tab, age range, applicable season, and parity.
[0066] When producing boars, the process involves searching by breeder type, boar tab, and age range (total age of the boar used for production, i.e., planned date - date of birth + 1), and then retrieving the corresponding feed type and standard feed intake. The logic is relatively simple.
[0067] Special handling for lactating pigs: If the predicted stage is farrowing or early weaning, the feed intake should be increased by adding an additional feed based on the number of suckling piglets on top of the basic feed intake. Actual feed intake = basic feed intake + number of suckling piglets × feed increment per piglet The number of pigs in each state is determined by the results of the state prediction model. The daily inflow (transfer from other states) and outflow (transfer to the next state) of pigs in each state are automatically counted based on the model's head-by-head prediction results, without the need for manual addition or subtraction rules.
[0068] The calculation results for all pigs are summarized according to the following dimensions: Summarize by date: Obtain the total daily feed requirement for the entire farm.
[0069] Summarize by date and pigsty: Get the daily demand for each pigsty.
[0070] Summarize by date and production line: Get the daily demand for each production line.
[0071] Summarize by date and feed type: Obtain the daily demand for each feed type, which can be used for category-based procurement and reconciliation.
[0072] Plan Generation: The system will input the summarized results into a preset plan template to generate a structured feed demand plan. The template includes: overview information such as the start and end dates of the plan period, pig farm name, and generation time; daily total demand and demand by breed; daily demand details for each production line; and the total number of pigs covered by the plan and their distribution across different statuses.
[0073] Deviation Validation: After the feed demand plan is generated, the system supports automatic comparison between theoretical demand and actual reported demand, calculates the difference ratio by breed (difference ratio = (actual reported demand - theoretical demand) / theoretical demand × 100%), and compares it with the difference threshold. Exceeding the threshold automatically triggers an alert, serving as an optional auxiliary function after plan generation. The system supports comparing the theoretical demand aggregated by pig house with the actual reported demand at the pig house level, and also supports direct comparison at the pig level; the granularity depends on the pig farm's reporting method.
[0074] Multiple output formats: Supports three output methods: structured files (CSV or Excel format), RESTful API push, and front-end chart display.
[0075] In addition, this method also includes: Real-time image features of pigs are extracted, and identification is performed based on these features to obtain the body condition score, backfat thickness estimate, and body posture information of the breeding pigs. Mel frequency cepstral coefficients are used to extract sound features, and a classification model is used to identify normal feeding sounds and abnormal noises. Simultaneously, behavioral information within a preset time period is identified, activity intensity index and feeding efficiency index are calculated, mean body temperature and variability index are calculated using statistical methods, and a self-attention mechanism is used to weightedly fuse features of all modalities. Based on the fused multimodal features, a health status assessment model for breeding pigs is constructed, which outputs an individual health status vector, including body condition score, stress level, health risk level, and reproductive status. The feed planning optimization problem is modeled as a Markov decision process. The state space includes individual characteristics of breeding pigs, current body condition, health state vector, environmental parameters, and historical feeding records. Individual characteristics of breeding pigs include breed, age, gestation days, and number of piglets born; current body condition includes weight and backfat; environmental parameters include temperature and humidity. The operational space includes daily feed intake, feed formulation adjustment plan, feeding frequency, and feeding time; the feed formulation adjustment plan includes energy level, protein level, and amino acid ratio; Set a reward function, train the decision strategy using a deep deterministic policy gradient algorithm or a proximal policy optimization algorithm, and generate a personalized daily feed plan for each breeding pig based on the output of the deep reinforcement learning model, including feed formula, feeding amount, and feeding time sequence, and continuously optimize the strategy based on real-time feedback.
[0076] It should be noted that R = w1·Reproductive performance improvement + w2·Feed conversion rate + w3·Health maintenance - w4·Feed cost, where w1-w4 are weighting coefficients. This solution collects visual, auditory, behavioral, and physiological data of breeding pigs through a multimodal intelligent sensing system, and combines it with deep reinforcement learning algorithms to achieve dynamic optimization of individual feed plans, thereby improving the rationality of feed plan generation.
[0077] In addition, this method also includes: Acquire feeding log data, environmental temperature and humidity data, and basic production data from the target breeding pig farm, and construct key time-series data under a unified date index; the feeding log data of the target breeding pig farm includes the amount of feed given to each breeding pig per meal and the amount remaining; the environmental temperature and humidity data includes the indoor temperature, relative humidity, and temperature and humidity index; the basic production data includes the number of days of gestation, the number of days of lactation, and the number of piglets born to the breeding pigs; Perform missing value imputation, outlier detection and correction, and data smoothing on key time-series data to obtain cleaning time-series data. Calculate the nighttime feeding ratio based on the total daily feeding amount and hourly feeding amount. Calculate the average feeding amount based on the total daily feeding amount and the number of animals in stock at the end of the day. Calculate the feed reduction intensity based on the median of the average feeding amount within the historical window. The proportion of nighttime feeding and the intensity of feed reduction are combined to form an action feature sequence that characterizes the intensity of stress feed reduction and nighttime feeding movement. Based on the action feature sequence and the average feeding residual sequence, an input-driven three-state switching state space model is constructed, wherein the three states are: normal state, heat stress warning state, and heat stress response state. The forward-backward algorithm or Viterbi algorithm is used to reason about the state space model, determine the output hidden state estimate and the probability of each state, and recursively generate the feed demand forecast and forecast interval for the next multiple steps based on the current state estimate and state transition probability. Online bias updates are performed on the prediction error based on the action index to output a corrected feed demand forecast. When the prediction error exceeds a preset threshold, dynamic adjustment of the feed plan is automatically triggered. Based on the corrected feed demand forecast and combined with nutritional regulation strategies under heat stress conditions (increasing the proportion of anti-stress nutrients such as vitamin E, vitamin C, and electrolytes), a graded feed plan for heat stress is generated.
[0078] It should be noted that nutritional regulation strategies under heat stress conditions include increasing the proportion of anti-stress nutrients such as vitamin E, vitamin C, and electrolytes. This scheme constructs a three-state switching state-space model to quantify the intensity of strategy switching actions under heat stress conditions, enabling dynamic prediction and planning adjustment of feed demand, and further optimizing feed demand planning.
[0079] Example 2
[0080] In this embodiment, "mating status" refers to the complete gestation period from the date of mating confirmation to the day before delivery; "empty reflux status" is the unified code of this model for the three non-pregnant and non-lactating statuses of empty pregnancy, estrus return, and miscarriage, and the internal differences are distinguished by the number of days the status lasts and historical events; "empty pregnancy feed" is the standard feed variety in the empty reflux status.
[0081] A large-scale pig farm has 2,000 sows and operates on four production lines. This Friday (May 15, 2026), the farm needs to generate a feed demand plan for the following week (May 16-22, 2026, a total of 7 days) and submit it to the supply chain management department. The daily demand for each feed type must be provided during submission, and the system will automatically verify the discrepancy between the theoretical and reported values.
[0082] Model Construction and Training: A temporal deep neural network comprising a feature extraction network and a sequence generation network is employed. The feature extraction network receives a vector representation that integrates pig features and production plan signals (through a cross-attention mechanism) and extracts the temporal context. The sequence generation network autoregressively outputs the predicted state for each of the next 7 days. Training data utilizes a federated learning architecture to aggregate historical state change records from multiple pig farms over the past 2 to 5 years (the original data from each farm is kept locally, and only the model gradient parameters are uploaded to the cloud for aggregation). This forms a pre-trained basic model, which is then fine-tuned based on the farm's data. Cross-entropy loss is used to optimize model parameters, and an early shutdown strategy is employed to prevent overfitting. This historical data includes latent variables such as environmental temperature and humidity, and feed nutrient composition (even if not explicitly listed in the input features of this embodiment, they are part of the model's historical training). This allows the model to learn implicit physical laws such as 'breed A tends to have a shorter gestation period of 1-2 days under high temperature conditions' from the data, rather than simply statistical correlations.
[0083] Predictive Execution The model's innovation lies in learning the individualized shift patterns of each pig under the interaction of multiple factors. This is illustrated below through five typical scenarios.
[0084] Scenario 1: Early stage of mating (no state transition) P0001, current status: mated, age 2, parity 3. Since the delivery threshold has not yet been reached, the model predicts the mated status for the next 7 days, with the age increasing daily. The fixed rules in this scenario are consistent with the AI prediction results.
[0085] Scenario 2: Late mating stage (cross-state transition, demonstrating AI's individualized prediction) P0002, current status: mated, age 111 days, parity 3, breed A. The typical timeframe for mating to farrowing is 114 days.
[0086] Fixed rule prediction: Transition occurs when the state age = 114 days, that is, on the 3rd day, labor begins.
[0087] AI model prediction: After inputting features such as breed A and parity 3, the model learns from historical data that the gestation days of high-parity sows of this breed tend to be 1-2 days shorter, and predicts that the gestation will occur on the 2nd day (age=113).
[0088] Scenario 3: Individualized prediction of return probability P0003, currently in the breeding stage, 20 days old, parity 1, return-to-estrus rate is 8% (population average).
[0089] Fixed rule: Whether to return to the state is determined randomly with an 8% probability, which cannot distinguish individual risks.
[0090] AI model prediction: After inputting the feature of parity = 1, the model learns that the probability of primiparous sows returning to estrus is significantly higher than that of multiparous sows (about 12%), and adjusts the probability of the sow returning to estrus upward; if estrus is determined, the model further predicts the specific age at which estrus occurs (the peak period of estrus in primiparous sows is 21-24 days after mating). Scenario 4: Early Childbirth (No State Transition) P0004 is on day 7 of farrowing (10 suckling piglets). It will remain in farrowing state for the next 7 days. The daily suckling feed requirement is 5.5 + 10 × 0.5 = 10.5 kg. No model is needed to predict the state transition.
[0091] Scenario 5: Production Plan-Driven State Changes P0005 is currently weaned, on day 2 of age, parity 2, and located on production line 1. The breeding plan shows that line 1 will schedule 3 weaned pigs for mating between May 20th and 20th. The typical interval between weaning and mating for P0005 is 5 days, meaning it should be mated between May 18th according to the natural rhythm. However, the mating plan is scheduled for May 20th—the model, after considering both physiological rhythms and planning signals, predicts that P0005 will be mated between May 20th, changing its parity from 2nd to 3rd, instead of the natural May 18th. Meanwhile, P0006 (a replacement gilt, approximately 226 days old) is within line 1's replacement gilt mating quota between May 20th and 20th—the model determines that its age has exceeded the replacement gilt production threshold and that the mating plan has a quota, predicting that P0006 will be mated between May 20th, changing its parity from 0th to 1st.
[0092] The five scenarios above illustrate the core value of AI models: fixed rules can only provide the population mean, while AI models can provide individualized predictions under the interaction of multiple factors and can integrate production plan signals to make judgments that conform to actual production arrangements. The larger the pig herd, the more significant the cumulative effect of individual deviations.
[0093] Feed requirement calculation: Taking the above-mentioned pigs as an example, the standard feed amount table is matched for each pig: P0001 (early mating stage): 7 days in mating state, age 2~8 days → 1-30 days → parity 3 (≥2) → 2.2kg gestation feed per day.
[0094] P0002 (mating → farrowing transfer): Day 1 mating / age 112 days → 85-114 days interval → 3.5kg gestation feed; Day 2 onwards, transfer to farrowing (AI predicts 1 day earlier), assuming 10 suckling piglets → basic 5.5kg + 10×0.5=10.5kg suckling feed.
[0095] P0003 (If estrus is determined): Mating on days 1-2 / Age 20-21 → 1-30 day interval → Pregnancy feed; After estrus, it turns into empty estrus → Matching empty estrus tab → Empty pregnancy feed.
[0096] P0004 (Early Farrowing Stage): 7 days in the farrowing stage → 1-21 day interval → 10 suckling piglets → Basic feed 5.5kg + 10 × 0.5 = 10.5kg suckling feed.
[0097] P0005 (Weaning → Breeding Change): Weaning status from 05-16 to 05-19 → 2.5kg empty pregnancy feed; from 05-20 onwards, the model predicts a change to breeding → 1-30 day interval → parity 3 (≥2) → 2.2kg gestation feed.
[0098] P0006 (Reserve → Breeding Change): From May 16 to May 20, reserve status / age 226~230 days → 150-240 days → 2.2kg reserve feed; From May 20 onwards, the model predicts a change to breeding → parity becomes 1 → 1-30 days → 2.0kg gestation feed.
[0099] After calculating each of the 2000 heads individually, the data is summarized by date and feed type (example data to illustrate changes in feed composition due to status transition): Key change points: May 18th—P0002 and other late-stage breeding pigs transitioned to farrowing, resulting in a decrease in gestation feed and an increase in lactation feed. May 20th—The day the breeding plan was implemented, weaned pigs such as P0005 and replacement gilts such as P0006 were transferred to breeding, resulting in an increase in gestation feed, a decrease in non-pregnant feed, and a decrease in replacement feed. This change was entirely driven by production plan signals and could not be predicted by purely physiological rules.
[0100] Deviation verification and output: After the pig farms submit the actual data, the system automatically compares it breed by breed: Theoretical amount of gestation feed: 4,200 kg; reported amount: 4,500 kg → difference of 300 kg → difference ratio of 7.14% If the difference ratio threshold is ±10%, the threshold is not exceeded and the process proceeds normally; if the threshold is exceeded, a warning will be issued.
[0101] The final output is an Excel-formatted feed demand plan or system spreadsheet, containing theoretical quantities, reported quantities, and difference comparison data.
[0102] Degraded operating mode: A simplified solution based on a rules engine (not a core protection scope; this only illustrates the adaptability of this solution in scenarios with limited computing power). It should be noted that the rule engine-based solution described herein is existing technology and is only used in this embodiment to illustrate the compatibility of the invention in scenarios with limited computing power, and is not the core innovation of the invention. The core protection point of the invention lies in "state evolution prediction based on multi-dimensional feature interaction". In contrast, common rule engine solutions in the prior art (not within the core protection scope of this invention) can be used as a degraded operation mode in scenarios with limited computing power resources.
[0103] State transition rules are established based on time configuration parameters, defining the typical duration and transition target for each state. A lightweight statistical model is introduced, taking individual pig characteristics as input and outputting the posterior probability distribution of the state duration. For example, the weaning-to-mating interval of high-parity sows may shift towards higher values. The return-to-estrus ratio is used to randomly remove some pigs from the mating state and transfer them to an empty return flow based on probability. The mating plan, regrouping plan, and introduction plan serve as deterministic external inputs, directly implementing state changes or quantity adjustments for the corresponding pigs on the corresponding dates. This degradation mode has low computational cost and is simple to deploy, making it a temporary transitional solution for small and medium-sized breeding pig farms or edge computing devices. However, its prediction accuracy is significantly lower than that of AI-driven hybrid prediction modes, and it lacks the ability for continuous model evolution.
[0104] The second aspect of this invention provides an automatic feed plan generation system for pig farms based on artificial intelligence, comprising a data layer, an algorithm layer, and an application layer: the data layer includes a pig file table, a standard feed quantity table, a time configuration table, a historical state change record table, a production plan data table, and an actual feeding record table, used to provide data for the algorithm layer; the algorithm layer is a state prediction engine, including: a feature encoding unit, used to vectorize the discrete and continuous features of pigs; and a feature extraction and sequence generation unit, used for time-series modeling and fusing production plan signals and individual physiological characteristics of pigs through a cross-attention mechanism, and outputting a state prediction sequence for the next N days in a daily autoregressive manner; The output classification unit is used to output the probability distribution of each state through Softmax and take the state with the highest probability as the prediction result, as well as output the probability of the return to estrus event; the deterministic constraint correction unit is used to make a fallback correction to the prediction result with physiological rules; the application layer includes: a feed demand calculation module, which is used to match the head-by-head daily state prediction results output by the algorithm layer with the standard feed amount table, and summarize and aggregate them according to four dimensions: date, pig house, production line, and feed type; a plan generation and deviation verification module, which is used to fill the summary results into the plan template and perform threshold comparison and early warning; and a multi-format output module, which is used to output the plan document according to the target format.
[0105] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or units can be electrical, mechanical, or other forms.
[0106] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units. They may be located in one place or distributed across multiple network units. Some or all of the units may be selected to achieve the purpose of this embodiment according to actual needs.
[0107] In addition, in the various embodiments of the present invention, each functional unit can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be implemented in hardware or in the form of hardware plus software functional units.
[0108] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0109] Alternatively, if the integrated units of this invention are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this invention, or the parts that contribute to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROM, RAM, magnetic disks, or optical disks.
[0110] The above are merely specific embodiments of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. An AI-based method for automatically generating feed plans for pig farms, characterized in that, Includes the following steps: Read basic data such as pig records, standard feed amount, time configuration, return to estrus rate, and difference threshold; load mating plan, group transfer plan, and introduction plan data; and verify and exclude abnormal records. The data of mating plan, group transfer plan, and introduction plan are converted into numerical inputs that the model can accept. Through the attention mechanism, the individual physiological characteristics of each pig are dynamically fused with the production plan signals of its production line and the corresponding date according to the attention weight. The fusion directly participates in the calculation of the state probability of each pig during the model inference process. Using a temporal deep neural network, the daily state sequence of the next N days is output, and deterministic physiological rules are used to perform posterior correction on the model output. The head-by-head and day-by-day state prediction results output by the time-series deep neural network are summarized into an intermediate result set. Each record in the intermediate result set is traversed, and a standard feed amount table is matched according to the breeder pig's nature, predicted state, and age to obtain feed type and feed intake. The results are then summarized and aggregated according to four dimensions: date, pig house, production line, and feed type. The summarized results are entered into the preset plan template, and the plan document is output according to the target format.
2. The method for automatically generating feed plans for breeding pig farms based on artificial intelligence according to claim 1, characterized in that, Read basic data such as pig records, standard feed quantity, time configuration, return-to-estrus ratio, and difference threshold; load mating plan, regrouping plan, and introduction plan data; and verify and exclude abnormal records. Specifically: Record the identity information and current status of each pig in the current stock, the standard daily feed intake for different production statuses and age ranges, the standard number of days for each state transition in the pig herd, the actual state change events that have occurred in the historical production and operation of each pig, the time configuration, the return to estrus ratio, and the basic data of the difference threshold. Receive the number of replacement breeding pigs bred, the number of weaned pigs bred, and the number of empty return pigs bred on each date, and construct a breeding plan; receive the type of herd transfer, the number of herd transfers, and the number of pigs to be marketed reported by pig farms within a preset time, and construct a herd transfer plan. The system receives information from pig farms regarding the breed, quantity, and age of introduced pigs within a preset timeframe, constructs an introduction plan, and verifies and excludes abnormal records from the mating plan, regrouping plan, and introduction plan data.
3. The method for automatically generating feed plans for breeding pig farms based on artificial intelligence according to claim 1, characterized in that, The cross-attention mechanism integrates the individual physiological characteristics of each pig with the production line and the production plan signal for the corresponding date according to attention weights. Specifically: For the breeding plan data, for each production line and each planned date, the number of weaned pigs to be bred, the number of reserve pigs to be bred, and the number of empty return pigs to be bred are encoded into a three-dimensional vector, which is expanded into a time-series vector of length N×3 by date, and then deeply fused with the pig features of the corresponding production line through a cross-attention mechanism. For the data on the regrouping plan, the regrouping type, original production line, target production line, regrouping quantity, and market quantity are encoded into structured vectors, which are then expanded by date and fused with the characteristics of the affected pigs. For the data on the introduction plan, after encoding the breed, quantity, and age, a prediction unit is added to the model on the corresponding date. The prediction unit includes the initial state, breed, and age of the introduced pigs.
4. The method for automatically generating feed plans for breeding pig farms based on artificial intelligence according to claim 1, characterized in that, The state prediction process of a temporal deep neural network is as follows: The numerical inputs that the model can accept are mapped to vector representations and merged with continuous features into a unified feature vector, while the production planning signal is fused with pig features after being independently encoded. The fused feature vector is received to extract the temporal context. The sequence generation network outputs the state prediction for each future day in an autoregressive manner. When predicting the state on day t+1, the predicted state on day t is fed back as the input for the next time step, capturing the temporal dependency of state evolution. Each time step is mapped to the probability distribution of all possible states through a fully connected layer and Softmax. The state with the highest probability is taken as the prediction result. For mating and empty return flow states, an additional binary classifier is output to predict the probability of the return flow event. The model outputs a daily state sequence for the next N days, and the model output is then corrected posteriorly using deterministic physiological rules.
5. The method for automatically generating feed plans for breeding pig farms based on artificial intelligence according to claim 4, characterized in that, The model output is then posteriorly corrected using deterministic physiological rules, specifically as follows: State evolution must follow a unidirectional sequence: backup → mating → empty return flow → mating → parturition → weaning → mating, and cannot be reversed; The number of days from mating to delivery must not exceed the reasonable range defined in the time allocation table; The number of days from delivery to weaning must not exceed the reasonable range defined in the time allocation table; If the model output violates the constraints, it will be automatically corrected to the closest approximation state allowed by the constraints.
6. The method for automatically generating feed plans for breeding pig farms based on artificial intelligence according to claim 1, characterized in that, Iterate through each record in the intermediate result set, match the standard feed amount table according to the breeder pig's nature, predicted status, and age, obtain the feed type and feed intake, and summarize and aggregate them according to four dimensions: date, pig house, production line, and feed type. Specifically: When a feed plan needs to be generated, the current data of all pigs in stock is read from the pig file table, the pigs in the group with the departure type empty are filtered, and the mating plan, transfer plan and introduction plan are loaded. For each pig, input features are constructed and input into the trained prediction model to obtain the state prediction sequence for the next N days. Deterministic constraints are applied for correction, and the prediction results of all pigs are summarized into an intermediate result set. Each record includes: pig identifier, date, predicted state, predicted age, production line, breed, and parity. The calculation results for all pigs are aggregated and summarized in four dimensions: by date, by date + pig house, by date + production line, and by date + feed type.
7. The method for automatically generating feed plans for breeding pig farms based on artificial intelligence according to claim 6, characterized in that, When outputting the plan document, it also includes: Load the actual data entered, use the summarized results as the theoretical demand, and automatically compare them with the actual data entered by variety to calculate the difference ratio; compare it with the difference threshold, and generate an early warning message when the threshold is exceeded.
8. The method for automatically generating feed plans for breeding pig farms based on artificial intelligence according to claim 1, characterized in that, The temporal deep neural network is trained in the following way: The training data is constructed from the historical state change record table. For each pig in history, an arbitrary time point t is selected. The pig's state characteristics at that time point and the production plan signal at the same time are used as the model input. The daily state sequence that actually occurs in N days after t is used as the supervision label. The federated learning strategy is adopted, where each pig farm trains the model and calculates the gradient locally, and only uploads the model parameters to the central server for aggregation. The original data is kept locally and does not go out. An adaptive parameter weighting algorithm is introduced in the federated learning aggregation process to dynamically adjust the weight of parameter updates based on the amount and quality of data from each pig farm, in order to solve the problem of non-independent and identically distributed data from each pig farm and generate a basic model with generalization ability. The model optimizes the cross-entropy loss between the predicted state sequence and the actual state sequence. The binary classifier head that predicts the return event additionally calculates the binary cross-entropy loss, and the total loss is the weighted sum of the two.
9. The method for automatically generating feed plans for breeding pig farms based on artificial intelligence according to claim 8, characterized in that, The training of the temporal deep neural network also includes transfer learning and data augmentation: After pre-training the basic model on data from multiple pig farms, it is then fine-tuned using historical data from a single pig farm. Based on known physiological rules, small random perturbations are made to real data to generate enhanced samples, thereby expanding the coverage of the training samples.
10. An AI-based automatic feed planning generation system for pig farms, characterized in that: It includes the data layer, algorithm layer, and application layer; The data layer includes a pig file table, a standard feed amount table, a time configuration table, a historical status change record table, a production plan data table, and an actual feeding record table, which are used to provide data for the algorithm layer; The algorithm layer is a state prediction engine, comprising: a feature encoding unit for vectorizing discrete and continuous features of pigs; a feature extraction and sequence generation unit for time-series modeling and fusing production plan signals with individual physiological characteristics of pigs through a cross-attention mechanism, and outputting a state prediction sequence for the next N days in a daily autoregressive manner; an output classification unit for outputting the probability distribution of each state through Softmax and taking the state with the highest probability as the prediction result, and outputting the probability of the return to estrus event; and a deterministic constraint correction unit for making a fallback correction to the prediction result based on physiological rules. The application layer includes: a feed demand calculation module, used to match the daily status prediction results output by the status prediction engine with the standard feed amount table, and summarize and aggregate them according to four dimensions: date, pig house, production line, and feed type; a plan generation and deviation verification module, used to fill the summary results into the plan template and perform threshold comparison and early warning; and a multi-format output module, used to output the plan document according to the target format.