Development of the precision feeding system for sows via a rule-based expert system

: To precisely meet the nutritional requirements of sows during the stages of pregnancy and lactation, a precision feeding system was developed by using the intelligent sow feeder combined with a rule-based expert system and the Internet of Things (IoTs). The model of uncertain knowledge representation was established for inference by using the certainty factor. The daily feeding amount of each sow was calculated by the expert system. An improved pattern matching algorithm Reused Degree Model-RETE (RDM-RETE) was proposed for the decision of daily feeding amount, which sped up inference by optimizing the RETE network topology. A prediction model of daily feeding amount was established by a rule-based expert system and the precision feeding was achieved by an accurate control technology of variable volume. The experimental results demonstrated that the HASH-RDM-RETE algorithm could effectively reduce the network complexity and improve the inference efficiency. The feeding amount decided by the expert system was a logarithmic model, which was consistent with the feeding law of lactating sows. The inferential feeding amount was adopted as the predicted feed intake and the coefficient of correlation between predicted feed intake and actual feed intake was greater than or equal to 0.99. Each sow was fed at different feeding intervals and different feed amounts for each meal in a day. The feed intake was 26.84% higher than that of artificial feeding during lactation days ( p <0.05). The piglets weaned per sow per year (PSY) can be increased by 1.51 compared with that of relatively high levels in domestic pig farms. This system is stable in feeding and lowers the breeding cost that can be applied in precision feeding in swine production.


Introduction
Precision feeding for sows can not only meet the nutrient requirements according to the predetermined target, maintain the healthy development of sows, and improve the fertility level and the health of newborn piglets, but also save labor and reduce feed waste.Especially, sows need to eat a sufficient amount of feed to meet the requirements of milk production during the post-farrowing period [1][2][3] .Nevertheless, due to weak body conditions, decreased appetite, and other factors, the feed intake of lactating sows does not increase.Generally, sow milk production will result in sow body weight loss during lactation.Increasing sow feed intake during lactation could reduce body weight loss and allow maintenance of body conditions [4] .However, excessive body condition consumption will lead to a long weaning-to-estrus interval [5] , a decrease in litter size at the next birth and in average weight [6,7] , and shortened sow longevity.To maximize sow feed intake and reduce sow body weight loss, a precise feeding concept was developed based on adjustment of both the quantity and quality of the diet delivered to each sow in the pen [8] .
The feeding patterns for sow include artificial feeding, automatic feeding, and intelligent feeding [9][10][11] .However, the first two are difficult to achieve an ideal feeding effect.Daily feeding amount is calculated individually according to the nutritional requirements of lactating sows and is fed by the intelligent sow feeder.Recently, intelligent feeding devices for sow include the computerized feeding system (Gestal Solo, JYGA Technologies, Quebec, Canada), the intelligent sow feeder (Shenzhen Runnong, Co., Ltd.China), the precision feeding system (Nanshang Nongke, Co., Ltd.China), and so on.Most of them have some disadvantages, such as easy arching of feed in the buffer bin, high costs of manufacture, and inconvenience of cleaning up the surplus feed.Moreover, on the premise of given feed intake, how to achieve the expected actual feed intake during the stages of gestation and lactation is the difficulty of precision feeding.Xiong et al. [12,13] developed an intelligent feeder characterized by accurate feeding with no surplus feed, an intelligent feeding pattern of 4 times/d was exploited to increase the feed intake.The curve of actual feed intake conformed to the feeding characteristics of the lactating sows.Wang et al. [14] exploited a Gestal intelligent feeder instead of an excellent stockman to reduce body weight losses and improve the growth performance of piglets.However, the previous research on sow feeding had not provided a customized nutritional program for each sow in consideration of feed palatability, indoor air quality, and individual body condition with expert systems.Meanwhile, the Internet of Things (IoTs) was not well used in the previous sow feeders.
Expert system is a kind of artificial intelligence tool that supports a decision-making process [15,16] .Knowledge representation and reasoning are important parts of an expert system.Herein, uncertainty reasoning rules based on credibility are exploited for knowledge representation.The RETE algorithm is a typical patternmatching algorithm for if-then rules.However, there are some problems such as complex network topology and low reasoning speed [17][18][19] .In this study, nutrient requirements and physiological characteristics of feeding behavior were fully considered and an efficient expert system was developed for sow feeding amount decision support [20] .RETE network topology was optimized to reduce network complexity and raise inference speed using reused degree model.An intelligent feeder prototype was developed based on the expert system and IoTs in this study to perform precision feeding for each sow equipped with a radio frequency identification (RFID) ear tag during the nursing and lactating stages of sows [21] .

Mechanical structure design for the intelligent feeder
Figure 1 shows the mechanical structure, which consists of an electrical box, a storage bin, a feed supply pipe, a quantitative bin, an electric actuator, a buffer spring, an upper plugging ball, and a lower plugging ball.Herein, the feed-supplying system and the discharging device are integrated through the storage bin.Cooperative feed delivery is performed by an electric push rod.
Figure 2 shows the feeding device.A direct current (DC) electric actuator drives an upper plugging ball and a lower plugging ball to reciprocate upward and downward.To ensure the consistency of each delivery, a high-precision screw is installed in the front end of the electric push-rod.A quantitative bin has a certain volume to ensure precise delivery.Each up-and-down reciprocating motion is called one cycle.When the electric push rod moves downward, the plugging ball plugs the storage bin and the plugging-down ball departs from the quantitative bin for quantitative feed delivery.On the contrary, when the electric push Figure 3 Structure of the proposed system rod moves upward, the plugging ball departs from the quantitative bin and the plugging down ball plugs the quantitative bin to store feed.Thus, the quantitative delivery is achieved without residual feed.Herein, the daily feeding amount of each sow is calculated by a rule-based expert system.Especially, the feed delivery amount is 200 g for each up-and-down reciprocating motion of the electric actuator.

Hardware design for experiment platform
Figure 3 shows the proposed system in this study.As observed, the system consists of intelligent feeders, environmental monitoring devices, a wireless data transmission module, and a remote monitoring terminal.An environmental monitoring device is capable of the collection and transmission of environmental parameters.An intelligent feeder achieves the precision feeding of concentrated feed.The Alibaba Cloud server is connected by the long-range radio (LoRa) module and the general packet radio service (GPRS) module to achieve long-distance transmission.Once the environmental parameters, sow body condition and feeding stages, and other information reach the Alibaba Cloud server, a rulebased expert system is exploited to decide the feeding amount.The remote monitoring terminal consists of the Alibaba Cloud server, the android client, and the host computer.
The hardware platform of an intelligent feeder consists of a programmable logic controller (PLC), a power supply, an electric pushing rod and its drive circuit, a LoRa module, a GPRS module, etc. Siemens central processing unit (CPU) was adopted as the dominant controller of the platform.The touch screen is the S-500A-V3.0produced by Zhongda, China.The working stroke and pushrod rate of the electric push-rod under the 24 V drive voltage are 40 mm and 60 mm/s, respectively.
The general packet radio service-data terminal unit (GPRS-DTU) module exploited the WG-8010 module (Beijing Tiantong Chengye Company, China).The reasons for choosing this module are automatic connection, transparent transmission, permanent support for transmission control protocol (TCP) communication, almost no data missing, only a configuration for a long period, and difficulty to be dropped.The system can upload environmental data and feeding amount data to the server through this module, then through the server set feeding amount and control the intelligent feeder.
The E32-DTU module adopted the SX1278 module (Chengdu Ebyte Company, China).LoRa module is chosen as a Low Power Wide Area Network (LPWAN) with the characteristics of low cost, long distance, and large capacity network.Therefore, there is no need to equip with a GPRS-DTU module for each intelligent feeder and each environmental monitoring device, respectively.When the system does not send collected data, this module goes into dormancy, which can effectively save power and flow costs.

Software design for the experiment system
The server system was the core of the whole system, which not only stored environmental data in MySQL database, decided daily feeding amount, but also sent it to PLC to control the intelligent feeder and record the feed intake per meal and the total amount per day and interact with clients.Visual Studio 2012 was adopted as a developing platform and programmed with NET language.
App software based on the Android system was also developed for the convenience of monitoring.The development environment was Android Studio 2.3, the programing language was Java, and the building tool was Gradle, communicating with a server through a socket.The programming steps were: Firstly, register in the manifest.xmlfile for access to the network and set the startup order of multiple activities, and then design the layout file activity_main.xml using a linear layout.Lastly, a program in the main_activity.java and other files.

Measurement of environmental indicators
The critical environmental indicators in an experimental swine house consist of temperature, humidity, concentrations of ammonia (NH 3 ), carbon dioxide (CO 2 ), and hydrogen sulfide (H 2 S).Herein, five measuring points were chosen to install environmental monitoring devices at a height of about 1.5 m from the ground.Indoor temperatures and humidity were measured with temperature and humidity transmitters (AW3485A, Aosong Electronics, Guangzhou, China).The concentrations of NH 3 , CO 2 , and H 2 S were measured with AP-G series fixed gas detectors (AP-G-NH 3 -02, AP-G-CO 2 -02, and AP-G-H 2 S-02, respectively, Empaer, Shenzhen, China).The water intake per sow per day was measured with intelligent water meters (DN20, Yongqiang, Ningbo, Zhejiang, China), installed 0.6 m above the floor in each pen. Figure 4 shows the layout of monitoring points, intelligent feeders, and water meters in an experimental swine house.

Feeding scheme
The breeding base of a pig farm selected for the paper was located in Zhenjiang City, Jiangsu, China, with a humid climate and four distinctive seasons.60 gestation sows with similar body conditions and farrowing at the same time were selected, which were divided into an experimental group and a control group, rearing in the restriction of pens after breeding.Each group occupied one column and was fed diets with the same nutrient content.Furthermore, the feed ingredients conformed to the nutritional requirements of swine compiled by the National Referral Center (NRC).The total feeding cycle consisted of three parts: pregnancy of 114 d, lactation of 23 d, and weaning of 6 d.A sow feeder based on an expert system was installed in the restriction of the pen of the experimental group.
Table 1 lists the feeding scheme of the gestation sows, which was divided into an experimental group (40 sows, fed by the intelligent sow feeder based on the expert system), and a control group (20 sows, fed by breeders).It should be pointed out that, "feed intake" means the actual feed amount that is consumed by sows, and "feeding amount" means the given feed amount that is decided by the stockman or the precision feeding system in this article.The "leftover" feed is measured and recorded before 6:00 on the next day.The electronic scale of ACS-18 is used to measure feed amount.Its measurement range is 0-3 kg with an accuracy of ±0.1 g.The daily "feed intake" equals the daily "feeding amount" minus the "leftover" feed amount.2.6 Rule-based expert system for the decision of sow feeding amount 2.6.1 Structure of the feeding system A rule-based expert system for the decision of sow feeding amount is a kind of intelligent computer program using prior knowledge and intelligent inference for a problem that can only be solved by husbandry experts [22][23][24] .It consists of a knowledge base, an integrated database, an inference engine, an interpretation tool, and a knowledge acquisition tool, as shown in Figure 5.
Human-machine interface for sow feeding

Farmer
Animal husbandman experts System maintenance Agency of interpretation for feeding Acquisition mechanism for feeding knowledge Feeding databases Inference engine for feeding

Knowledge base for feeding
Note: The boxes in the red dashed box mean the core components.

Figure 5 Decision system structure of sow feeding
The core of the sow-feeding expert system is the knowledge base and inference engine.The decision of sow feeding amount uses a forward inference.The inference process is as follows: facts are tested under the criteria of the rules; an unknown conclusion is deduced from known facts continuously; the intermediate result is exploited as a new known fact for inference; finally, the problem of feeding amount decision can be transformed from unknown to known.The inference results are provided to farmers through the human-machine interface in the process of operation.2.6.2Execution process of the feeding system The sow feeding expert system infers the daily feeding amount according to the environmental information and sows individual information collected by the environmental measurement and control device, combining the conditions input by the user, and feedback on the inferential results to the intelligent terminal.The execution process is as follows, including two stages.
The first stage is preparation for facts about sow feeding. 1) After the LoRa sensor node was powered on, the environmental measurement and control node collects environmental variables, body weight, breed, parity, and other individual information automatically, which was transmitted to the sink node through LoRa wireless sensor network.
2) Data was processed by the sink node, the GPRS-DTU module was exploited to establish a transmission control protocol/ internet protocol (TCP/IP) connection with the Alibaba Cloud server, and the data was sent to the server through the GPRS network.
3) The server resolved the data sent by the sink node and stored them in the fact database of the comprehensive database.
4) Through the man-machine interface, the farmers input auxiliary fact data for expert system decision-making such as piglet size, feeding equipment, feeding frequency, palatability, feed conversion ratio, rearing stage, and so on, and stored them in the fact database of a comprehensive database.
The second stage is the inference of the sow feeding amount and the feedback on results.
1) The inference engine called the rule matching algorithm inferred the daily feeding amount by searching the knowledge base.The inference results were stored in the result database of the comprehensive database.
2) The explanation engine displayed the inferential daily feeding amount in the comprehensive database through humanmachine interaction and provided guidance to farmers.
3) The Alibaba Cloud server read the inferential daily feeding amount and sent the feeding data to sink nodes through the GPRS network.
4) The sink node received the daily feeding amount and checked whether it is correct, and then sends the data to the intelligent feeder node through the LoRa wireless sensor network.
5) The intelligent feeder node received and resolved the daily feeding data, and the feeding action is completed by controlling the electric actuator according to the inferential daily feeding amount.

Credibility factor (CF) model of knowledge representation
Rule-based knowledge representation in the knowledge base was employed for feeding amount decisions.The knowledge in the form of a rule was defined by Equation (1).
where, E 1 , E 2 , E 3 , ..., En is the feeding evidences; H is the feeding amount of sow; CF refers to a certainty factor of rule.
For the feeding evidences, E=E 1 AND E 2 AND E 3 AND ... AND E n .
The certainty factor of feeding evidence (CF(E)) was calculated in Equation (2).
where, CF(E i ) is the certainty factor of feeding evidence, the value was specified by the animal husbandman.For the objective evidence, such as sow breed and parity, indoor temperature, and humidity, CF(E i )=1; For the subjective evidences, such as feed palatability, CF(E i ) ranges from 0 to 1.
The certainty factor of feeding amount (CF(H, E)) was calculated in Equation (3).
Once the feeding evidences were met, the rule was used for the feeding amount decision and the result showed a certain feeding amount.

Pattern matching algorithm 2.8.1 Analysis of RETE algorithm
The RETE algorithm is an efficient pattern-matching algorithm for implementing production rule system [17,25] .It converts a rule set to the RETE network for rule matching.The RETE network consists of a root node, and Alpha and Beta networks.Herein, the Root node is created as the entrance of the network, while Alpha and Beta networks are built for fact filtering and pattern matching, respectively.
The RETE algorithm is different from the traditional patternmatching algorithms, when different rules contain the same conditions, the same node can be reused.However, in the analysis of the creation process of the RETE network, the reused degree between nodes was not considered, which resulted in lots of space taken up during the generation and storage of the RETE network.
Different orders of conditions in the rules lead to different numbers of reused nodes in RETE network [26] .The pattern consists of some conditions and it is the IF part of a rule.Suppose that there are two rules R 1 and R 2 , and the corresponding patterns 1 and 2 are (A 1 , A 2 , A 3 , …, A n , A s1 , A s2 , …, A sp ) and (A 1 , A 2 , A 3 , …, A n , A t1 , A t2 , …, A tq ), respectively.Herein, A represents the same type of conditions.Obviously, there are n same conditions in the two patterns.Figure 6a shows that a total of n nodes are reused in the Alpha network.Once the condition orders of pattern 2 are changed, a new pattern (A 2 , A 3 , A 4 , …, A n , A 1 , A t1 , A t2 , …, A tq ) arises.When constructing a RETE network, despite n same nodes, no nodes are reused for the different order of conditions.Figure 6b illustrates that there are no reused nodes.In summary, the orders of rule conditions have a great impact on the shared performance of nodes in Alpha and Beta networks.Improper order of conditions will increase the complexity of network topology.Hence, the inference speed is affected.

An improved RETE algorithm for sow feeding expert system
To obtain a more reasonable order of conditions and improve the reused performance of the RETE network, a reused degree model is proposed.It is quantified by the number of times a condition has been cited in the rule and represents the reused degree of a node in the rule set.For instance, if one condition is cited by n rules, then reused degree of its node is n.Suppose that d c is reused degree of node c, then, where, Ideally, there is no same node existing in the RETE network.Hence, the reused degree of a node is the number of times a condition occurs.Additionally, the greater the d c the more times a condition occurs and reused degree of its node is higher.The conditions with different reused degrees are arranged in descending order, and the nodes with higher reused degrees join the network and are reused preferentially.However, conditions with the same reused degree need to be further arranged.
Herein, the reused degree of a pattern is defined by the sum of reused degrees of all conditional nodes.Suppose that pattern M consists of n conditions (c 1 , c 2 , c 3 , …, c n ), then the reused degree of a pattern can be obtained by Equation (6).
Indeed, the reused degrees of patterns reflect the reused degree of the entire patterns in the RETE network: the greater the d M the higher the reused degree.As a pattern consists of conditions, reused degree of a pattern is high, and so are its conditions.Therefore, the conditions with the same reused degrees can be further arranged in descending order according to the reused degree of a pattern.Suppose that condition c appears in k patterns (M 1 , M 2 , …, M k ), the reused degrees of patterns are (d M1 , d M2 , d M3 , …, d Mk ), then the reused degree of patterns for condition c is defined by Equation (7).
Herein, the greater the d cM the more dependent on condition c.Thus, the reused degree is higher and this conditional node ranks forward.
In summary, rule conditions were arranged once according to reused degrees of nodes.If the reused degree is identical, then arrange rule conditions twice according to the reused degree of a pattern.Herein, the reused degree of a node is exploited as a primary basis, yet the reused degree of a pattern is employed as a secondary basis.Therefore, the nodes in the rule set can be arranged and a high-quality network topology is produced according to a reused degree model.

1) An algorithm for constructing Alpha network
The alpha network is composed of conditions in rule patterns.The order of conditions affects the reused performance of nodes.The ordering algorithm using a reused degree model is as follows: Step 1 Read a rule R i one by one from rule set Q and create a rule array G; Step 2 Traverse the rule array G once, calculate the reused degrees of conditional nodes, and save them into condition set C; Step 3 Arrange conditional array F in descending order according to reused degrees of conditional nodes; Step 4 If there are no conditions with the same reused degrees, then turn to Step 6.Otherwise, traverse rule array G twice, calculate the reused degrees of patterns, and store them in the condition set C; Step 5 According to the reused degree of the pattern, partial conditions with the same reused degree are arranged in descending order; Step 6 Return condition set C. Without reading the rule set Q, Alpha network is constructed directly using the ordering condition set C. Thus, an improved Alpha network construction algorithm steps include: Step 1 Create a root node; Step 2 Read condition c i from condition set C; Step 3 Determine whether a type node exists, if not, create a new type node; Step 4 Create Alpha nodes; Step 5 Execute Step 2 until all conditions in condition set C are processed.
Step 6 Return Beta network.
2) Algorithm for constructing Beta network The RETE algorithm needs to classify the Alpha nodes when constructing Alpha network.However, the reused degree model of nodes can only guarantee the ordering of the same type of nodes, which leads to an influence on the reused performance of nodes and an increase in the number of matching calculations.Therefore, Alpha classifications need to be arranged.Suppose that there are m Alpha nodes (α 1 , α 2 , α 3 , …, α m ) in the k-th Alpha classification and the reused degrees are (d 1 , d 2 , d 3 , …, d m ), then the reused degree of Alpha classification is .Generally, the Alpha classification with a high reused degree ranks forward.While that with the same reused degree will also affect the reused performance of the Beta network for its order, mainly influenced by the number of nodes in Alpha classification on the number of join connections of Beta network nodes.For the two Alpha classifications with the same reused degree, the one with a small number of nodes and a topranked position requires fewer join connections.To reflect the impact of the number of nodes in Alpha classification on the reused performance, the average reused degree is introduced.
Therefore, for the Alpha classifications with the same reused degree, the high average reused degree ranks forward.The ordering optimization algorithm steps for type nodes include: Step 1 Create a classification array T; Step 2 Traverse Alpha network, calculate the reused degrees of Alpha classifications and save them in the classification array T; Step 3 Arrange the Alpha classifications in descending order; Step 4 For the Alpha classifications with the same reused degree, arrange them in descending order using the average reused degree; Step 5 Return well ordering Alpha network.On the basis of the above optimization algorithm, an improved Alpha network was constructed, in which the Alpha classifications are arranged in descending order.Therefore, the high reused degree of Alpha classifications is ensured to be preferentially connected and the reused performance of the Beta network is improved.Thereby, an improved Beta network construction algorithm steps include:

R i
Step 1 Read a rule from the rule set Q; Step 2 In the well-ordering Alpha network, record the number of Alpha nodes corresponding to all conditions of the rule; Step 3 Define j=2 and create Beta(j) node, the left and right parent nodes of Beta(j) are Beta(j−1) and Alpha(j); j=j+1; Step 4 If j<n, then create Beta node according to Step 3; Step 5 Encapsulate the conclusion of rule R i into a terminal node as the leaf node of Beta(n); Step 6 Execute Step 1 until all rules in rule set Q are processed; Step 7 Return Beta network.
3) Evaluation indexes Suppose that there are s rules r 1 , r 2 , …, r s in rule set Q and the numbers of conditions contained in each rule pattern are c 1 , c 2 , c 3 , …, c t , then total number of conditions is .The respective reused performances of nodes in Alpha, Beta, and RETE networks are calculated as follows: where, Node(α) and Node(β) refer to the total nodes of Alpha and Beta networks, respectively; S α , S β ∈(0, 1], S∈(0, 2].For any RETE network, the smaller S the better-reused performance of nodes, and vice versa.

4) Optimization of the inference process
To speed up the search of Alpha and Beta nodes during the inference process, a hash table is established to store the position mapping of Alpha and Beta nodes in the RETE network.Therefore, the efficiency of fact matching is improved.
It should be pointed out that, the conditions in the rules were reordered according to the reused degree, which did not have any effect on the rules themselves.No matter how the orders of conditions change in the rule, provided that the rule contains all the conditions, then the inference result will not change.Thus, the inference result using the improved RETE algorithm is entirely consistent with that using the traditional RETE algorithm.2.9 Application of the improved RETE algorithm 2.9.1 Characteristics of RETE network in the feeding amount decision system In the feeding knowledge base, there are many rules and high repeatability of patterns, with many identical Alpha nodes and Beta nodes.improved strategy for sharing network nodes is feasible in the decision system of sow feeding amount.There are many rules and facts in the decision system, and the size of the storage area grows exponentially with the number of rules and facts.It is necessary to establish indexes for search and join.
Generally, there may be multiple independent and nonintersecting RETE networks in a rule base.However, there is only one RETE network in the decision system of sow feeding amount, and all facts and rules are attached to this network.An increase in the number of facts and rules in the feeding knowledge base results in an increase in join operations.Moreover, unreasonable order of nodes will generate a lot of intermediate matching information, leading to a large number of redundant join operations.Therefore, the RETE network topology directly affects the efficiency of the inference engine for feeding amount decisions.
Based on the reused degree model, the node reused degree and pattern reused degree are calculated by using Equation (4) and Equation ( 7), respectively.Table 3 lists the calculation results.The above conditions are sorted according to the node reused degree (primary sort basis) and pattern reused degree (secondary sort basis), and the ordered sequence of conditions are (C 1 , C 2 , C 3 , The Alpha network is established according to the construction method, as shown in Figure 8.Moreover, based on the Alpha classification in the sort algorithm, the average node reused degree of each category is calculated by using Equation ( 8), as listed in Table 4. Figure 9 shows the improved Alpha network by the sort algorithm.

Figure 8 Construction method of Alpha network
Finally, the Beta network can be established according to the construction method, as shown in Figure 10.
It can be seen from Figure 10, there are four reused Alpha nodes of C 1 , C 2 , C 3 , and C 7 , and three reused Beta nodes of (C 1 , C 2 ), (C 1 , C 2 , C 3 ) and (C 1 , C 2 , C 3 , C 7 ).Therefore, the redundant nodes have been greatly reduced.In addition, put rearing stage and lactation age in front of other conditions, the expert system only needs to search for the conclusion of sow feeding amount of the lactation period and lactation age 15 in the knowledge base.Thus, the scope of rule matching can be narrowed and the matching time can be greatly reduced.Furthermore, when more rules including more facts are added to the RETE network, unreasonable orders of conditions result in the increase of redundant nodes, and the network topology will become more complicated.However, the optimal network topology can be obtained by using the reused degree model.

Preparation for the RETE network construction and inference for feeding amount
In this study, 20 000 facts were selected from the actual sow feeding expert system and 1784 rules were established, and then the RETE network was constructed.Table 5 lists the conditions classification table of the feeding rule set.Hardware condition: CPU of 2.7 GHz, memory of 8 G, and Java language was used to build the RETE network.

Experiment results and discussion of inference testing and analysis
To verify the improvement of reused performance and inference speed in RETE network, the improved RETE algorithm and standard RETE algorithm were compared.The algorithms of standard RETE (SRETE) and reused degree model RETE (RDM-RETE) were employed to construct RETE network and the conditions were arranged at random in the feeding rule set.Each experiment was repeated three times and average results were obtained.The respective construction time of SRETE and RDM-RETE was 19.6 ms and 26.9 ms.And the respective reused performance of SRETE and RDM-RETE was 0.116 and 0.087.Although the construction time was more by 37.2%, mainly due to the ordering of rule conditions and Alpha classifications, the cost is minimal as the reused performance of RETE network was increased by 25%.The rule set was generally stable and the RETE network was required to construct once only.Therefore, construction time was not an important indicator to measure the performance of the inference engine.
To investigate the inference efficiency, a comparison experiment of fact matching was performed.The experiment was divided into four groups.4000, 8000, 12 000, and 16 000 facts were selected in the fact set to form groups 1 to 4. Each experiment was also repeated three times and average results were shown.Figure 11 shows the results of inference efficiency.Compared with SRETE, the inference time of RDM-RETE and HASH-RDM-RETE were shortened.By adjusting the order of rule conditions and Alpha Figure 10 RETE network for the decision of sow feeding amount classifications, the reused performance of nodes was improved and the redundant nodes were reduced.Thus, the inference time was reduced and the inference efficiency was improved.In addition, the HASH-RDM-RETE algorithm could quickly locate fact classifications through HASH table index, and therefore the inference efficiency was further improved.Especially, the deviation rate of the inference results was 0, which indicated that the rule conditions were merely rearranged and the rules themselves were not affected.Thus, the HASH-RDM-RETE algorithm is more sufficient.Combined with the conditions input by the user and the environmental information and sow individual information collected by the environmental measurement and control device, the inference engine called rule matching algorithm infers daily feeding amount by searching the knowledge base.Although a consistent feeding amount can be obtained when using SRETE, RDM-RETE, and HASH-RDM-RET algorithms, the HASH-RDM-RET algorithm is the most efficient and the inference time is the shortest.

Experiment results and discussion of multiple environmental parameters measurement
Table 6 lists the monitoring results of multiple environmental parameters in a swine house with artificial lighting.Various environmental indicators in a lactating swine house will affect feed intake [27] .Herein, the suitable air temperatures range from 18°C to 22°C, with a maximum threshold value of 27°C; the suitable humidity ranges from 60% to 70%, with a maximum threshold value of 80%; the respective concentrations of NH 3 , CO 2 , and H 2 S were less than 15 mg/L, 1300 mg/L, and less than 2 mg/L.The monitoring results demonstrate that the respective concentrations of NH 3 , CO 2 , and H 2 S in a swine house adhere to the standards mentioned above.While the average temperature is slightly higher and the average humidity is a little lower.However, the lactation performance of sows is almost unaffected.As the test groups were in the same swine house, it can be concluded that there is no difference in the effects of environmental parameters on lactating sows between groups.

Results and discussion on the intelligent sow feeder
Additionally, the performance of a sow feeder was evaluated by using the coefficient of variation and relative error.The smaller coefficient of variation indicates better stability of the feeding device.Meanwhile, the smaller relative error indicates higher feeding accuracy.
Herein, a high precision screw was installed in the front end of an electric actuator, and a feeding pattern of a small amount several times was exploited, that is 200 g once.The relationship was obtained between set feeding amounts and actual feeding amounts after lots of experiments.It can be seen from Figure 12 that the actual feeding amounts were consistent with set feeding amounts on the whole and the maximum relative error was 2%.Thus, it indicates that the feeder system is stable and the requirements for precision feeding can be met.

Results and discussion on the feeding effect of gestation sows
The gestational age of daily feed intake of 1-107 d was selected for analysis.Table 7 lists the average daily feed intake of gestation sows under different feeding methods.As can be seen from Table 7, there were significant differences in feed intake, which is the actual amount of feed that is consumed by sows among different pregnant stages (p<0.05),mainly because energy and nutrient requirements varied at different stages of gestation, and incremental feeding was required.The average daily feed intake of gestation sow in the experimental group was 5.13%, 3.60%, and 3.49% higher than that of the control group at different stages of gestation.The average daily feed intake of gestation sow was calculated under two feeding methods per day.Figure 13 shows the daily feed intake of gestation sow under two feeding methods.The daily feed intake also showed an increasing trend.To keep the evenness of newborn piglet birth weight, there was a significant increase in daily feeding amount during late gestation, and so was the daily feed intake.Figure 13 Daily feed intake of gestation sow under two feeding methods

Results and discussion on the feeding effect of lactating sows
At Days 1-7 of lactation, daily feed intake is mainly low.However, adequate feed should be supplied from 8 d of lactation.The daily feeding amounts of experimental groups 1 and 2 were decided by a rule-based expert system under intelligent feeding mode, while that of the control group was given by an experienced breeder under a manual feeding pattern.Table 8 lists the average daily feeding amount and feed intake using mean±standard deviation for lactating sows with three feeding methods.Herein, "feeding amount" means the given amount of feed that is decided by the stockman or the precision feeding system.
As can be seen from Table 8, among the average daily feeding amounts, experimental group 1 occupies first place (5.96 kg), experimental group 2 comes second (5.59 kg), and the control group takes third (4.84 kg), in Days 1-23 of full lactation days.During Days 8-23 and Days 1-23, the average daily feeding amounts of experimental groups 1 and 2 were significantly higher than that of the control group.However, there was no significant difference between experimental groups 1 and 2.
During Days 1-7, Days 8-23, and Days 1-23, the difference in feed intakes between experimental groups 1 and 2 was not significant.However, during Days 8-23 and Days 1-23, the average daily feed intakes of experimental groups 1 and 2 were significantly higher than that of the control group.During Days 1-23, the average daily feed intakes of experimental groups 1 and 2 and the control group were 5.86 kg, 5.43 kg, and 4.62 kg, respectively.In addition, the average daily feed intakes of experimental groups 1 and 2 were 26.84% and 17.53% higher than that of the control group, respectively.The experimental results demonstrate that, due to the intelligent sow feeder exploited by experimental groups 1 and 2, the daily feeding amount determined by an expert system was regarded as a predicted value, it is basically consistent with the actual feed intake, and thus the daily feed intakes are improved.
Figure 14 and Figure 15 show the average daily feeding amount and daily feed intake in three feeding methods according to daily statistical data, respectively.Logarithmic curve-fit models were obtained by simulating daily feeding amounts data or daily feed intake.As can be seen from Figure 14, during Days 1-7, the variation trends of daily feeding amounts among the three treatments were basically the same.During Days 8-23, daily feeding amounts of experimental groups 1 and 2 showed an increasing trend, and the former was higher than the latter, which may be related to sow live weights and litter sizes.However, that of the Figure 15 Average daily feed intake with three feeding patterns control group fluctuated greatly, which was lower than experimental groups 1 and 2. In addition, as can be seen from Figure 15, the variation trends of daily feed intake curves among the three treatments are increasing slightly, which is consistent with daily feeding amount curves.Nevertheless, the daily feed intake was slightly less than the daily feeding amount.Compared with the two intelligent feeding methods, the feed intakes are obviously improved.Moreover, the daily feed intake was higher in experimental group 1 ((5.86±1.74)kg) than in experimental group 2 ((5.43±1.71)kg).Therefore, a sow will eat 9.89 kg more feed in 23 days of lactation, which indicate that the changed feeding frequency and feeding amount will further conform to the feeding behavior of sows.Table 9 illustrates the fitting models of daily feeding amount and daily feed intake.As can be seen from Table 9, both of the determination coefficients R 2 of experimental groups 1 and 2 for daily feeding amount and daily feed intake are higher than 0.95, which indicates that the credibility of inference by an expert system is high and the logarithmic model is basically consistent with the feeding behavior of lactating sow.In this study, the decision value of daily feeding amount was exploited as a predicted value of daily feed intake.Figures 16 and  17 illustrate the scatterplot of predicted and measured daily feed intakes of experimental groups 1 and 2, respectively.Herein, prediction results for daily feed intake were compared with actual data by a scatterplot, and the correlation coefficient reached 0.9995 and 0.9989, respectively.The experimental results demonstrate that a rule-based expert system is capable of accurately inferring the daily nutrient requirements of each sow for ensuring adequate feed intake during lactation days.Table 10 lists sow reproductive performance under different modes.As can be seen from Table 10, due to the use of an intelligent sow feeder combined with an expert system, the reproduction performance of the gestation sow is better than that of the control group with manual feeding.There was no significant difference in litter size between the two feeding methods (p>0.05).However, the Experimental group was significantly higher than the control group in terms of live litter size, healthy litter size, and average quality of newborn piglets (p<0.05), which increased by 9.91%, 13.38%, and 16.91%, respectively.Thus, the evenness of newborn piglets was improved.The PSY is an important indicator measuring farm efficiency and sows reproductive performance, and it is calculated in Equation (12).PSY = LSY × Average live born pigs per birth litter × Survival rate of pre-starter (12)   where, litters per sow per year (LSY)=(365−non-productive days)/ (gestation days+lactating days).Through multiple parity experiments of the experimental herd, production statistics were an average gestation length of 114 d, an average lactating length of 23 d, an average non-productive length of 75 d, and an average LSY of 2.12.Combining with the average number of live-born pigs per birth a litter of 11.80 and a 90% survival rate of pre-starter, then the PSY of 22.51 can be obtained from Equation (12).Compared with presently a higher level of PSY of 21 in domestic pig farms, the PSY is increased by 1.51 when using the proposed precision feeding system.
Indeed, the feeding system is not the only variable affecting PSY.Other factors include breed, lactation period, weaning to service interval, rearing environment, and so on.In this paper, excellent breeding sows were selected and culling standards were established for sows.In addition, the lactation period was shortened from 28 days to 23 days, and thus reproductive sows quickly entered the next estrus period and production cycle.Adequate nutrition, estrus management, and breeding technology were needed to reduce the weaning to service interval.Furthermore, new environmental monitoring and control devices were developed by our research team and applied in nursing sow houses.New models were also developed by our research team for multi-factor evaluation and control of the sow house environment, so as to provide a comfortable rearing environment for sows and piglets [28] .

Conclusions
The following conclusions can be drawn from this paper: 1) A customized nutritional program was implemented for each sow by using a rule-based expert system.To improve the deficiencies of the traditional RETE algorithm, a reused degree model was proposed to optimize the topology of RETE network.Through the sorting of rule conditions and Alpha classifications, the reused degree of nodes was improved and a RETE network with a high reused degree was constructed.Thus, the network complexity was effectively reduced.The daily feeding amount was automatically determined using the credibility uncertainty inference method based on probability theory.Furthermore, the hash index was exploited and the execution efficiency of the inference engine was further improved.
2) The intelligent sow feeder based on the Internet of Things (IoTs) was developed and the feeding amount decided by a rulebased expert system was achieved through the variation of bin content volume, and the maximum error of feeding was 2%.Therefore, the intelligent sow feeder was good in feeding stability and reliable in operation.
3) Compared with artificial feeding, the feed intake was significantly increased when the sow was fed by the intelligent sow feeder during stages of pregnancy and lactation.The maximal feed intake was achieved when the sow was fed at different post-feeding intervals and different feed amounts in a day.Thus, the effect of feed intake was perfect.Especially, maximizing feed intakes for maximum milk production during lactation.Precision feeding might be a suitable way for improving sow welfare and health.
4) Piglets weaned per sow per year (PSY) is an important indicator to measure the benefits of intensive pig breeding and sow reproductive performance.Through multiparity experiments, the PSY was calculated as 22.51.However, the relatively high level of PSY in domestic pig farms is 21 at present.Therefore, the PSY can be increased by 1.51 when using the intelligent sow feeder combined with an expert system and the evenness of newborn piglets was improved.

Figure 4
Figure 4 Layout of environmental monitoring points, intelligent feeders, and water meters in an experimental swine house

IF E 1
AND E 2 AND E 3 AND . . .AND E n THEN H, CF

Figure 6 Figure 7
Figure 6 Reused nodes in Alpha network Suppose also that there are two rules R 3 and R 4 and the corresponding patterns 3 and 4 are (A, B, C) and (A, B, C, D), respectively.Herein, A, B, C, and D represent different types of color on C 1 -C 10 means different attribute values of facts.Same below.

10 Figure 9
Figure 9 Improved Alpha network by sort algorithm

Figure 11
Figure 11 Experimental results of pattern matching

Figure 12
Figure 12 Comparisons of different feeding amounts

Figure 16
Figure 16 Scatterplot of prediction results for daily feed intake (Experimental group 1)

Figure 17
Figure 17 Scatterplot of prediction results for daily feed intake (Experimental group 2)

Table 3 Node reused degree and pattern reused degree of conditions
C 2 C 3 C 4 C 5 C 6 C 7 C 8 C 9 C 10

Table 7 Average daily feed intake of gestation sow under different feeding methods
Note: Different letters of the same gestational age indicate significant differences in data among treatments (p<0.05).

Table 8 Average daily feeding amount and feed intake for lactating sows with different feeding methods
Note: Different letters of the same lactation day indicate significant differences in data among treatments (p<0.05).

Table 9 Fitting models of daily feeding amount and daily feed intake
x Note: y i (i= 1, 2, 3) is daily feeding amount or daily feed intake, kg; is lactation day, d.

Table 10 Sow reproductive performance under different modes
Note: Different letters of the same index indicate significant differences in data among treatments (p<0.05).