Keywords

1 Introduction

As part of its strategic plan for the next 20 years, the government of Thailand has launched the national policy on deploying modern technologies to help drive the nation to prosperity. One of the technologies being mentioned in the plan is artificial Intelligence. As it has been seen world wide that the adoption of AI has been widely successfully in many areas. Agriculture has been a successful area where AI has been increasingly deployed world wide. Based on this fact, the Thai government has been driving and hoping for the development on this area with the country.

The Department of Agricultural Extension (DOAE), Ministry of Agriculture, of Thailand has been quick to react to this call. DOAE has been maintaining large databases, collecting data from thousands of its personnel and millions of farmers all over the country for more than 40 years. It is keen to adopt AI technologies to utilize this massive amount of data to be personalized to help farmers make better decisions based on their interests. There are two main AI modules: machine learning-based for predicting prices, yields and costs of crops, and game theoretic modules, both cooperative and non-cooperative, for analyzing the derived data and help make better decision for both DOAE personnel and farmers. For cooperative game theory, there are three important solution concepts, namely, optimal coalition structure for global and individual optimality, Shapley value for fairness among coalition members, and Kernel for stability among coalition members.

This paper focuses on the stability issue of coalition formation among farmers. The Kernel is, one of, if not, the most widely adopted stability concepts. In general, the payoff configuration, a vector specifying how farmers form coalitions and their respective payoffs, will be provided. Then it will be examine whether the payoff configuration is in Kernel. This is not very easy to examine because the algorithm has to go to almost each coalition, out of \(2^n\) coalitions for n farmers, for each agent. This makes it almost \(2^{2n}\), which can be very large for small n. Although optimal coalition structure is likely to guarantee stability in most cases, particularly for superadditive environment, it is still important that we have to thoroughly examine to ensure stability. We thoroughly analyze the size of the search space and empirically investigate to ensure how large can n be such that the result can be achieved in reasonable, taking into account the reality that farmers and DOAE personnel are awaiting for the results. This paper’s contribution is to practically show how large search space can be and how long it takes to ensure stability among agents.

The paper is structured as follow. We review for progress in coalition formation in agricultural domain. We then briefly discuss the circumstance of this project. We discuss in details for fundamental concept of coalition formation and Kernel. We then discuss about experiments and results, then conclude, lastly.

2 Related Works

Game theory [5], both non-cooperative [4] and cooperative, has been widely adopted in AI research. Cooperative game, also known as coalition formation [3, 17], provides fundamental concepts for cooperation among decision making. Important solution concepts include efficiency (core [2] and optimal coalition structure [6]), stability [1], and fairness [7]. Here we shall review related work being deployed in agriculture and related domains.

Bistaffa et al.  [8] consider coalition formation among energy consumers in the smart grid applying stability concept. The peaks of demands are flatten. Blankernburg et al.  [9] investigate safety and privacy preservation in forming stable coalitions among informative agents. Yamamoto et al.  [10] propose a coalition formation scheme in e-commerce to buy as a group on a category of items. This system allows for buyers to post their needs and the system combine these needs a bunch. Sellers then bids for the request. Guthula et al.  [11] model a specific troubled agricultural sub-system in India as a Multi-Agent System and use it as a tool to analyze the impact of policies and recommend some policies based on simulation result. Zaryouli et al.  [12] help establish a predictive analysis on the impact of climatic change on red fruits by proposing solutions to optimize crop growth decisions by increasing yields and profitability of production for the farmer. Perez-ponz et al.  [13] help make decisions in the purchase of sustainable agricultural products by proposing a multiagent system choosing a supplier for agricultural future market price forecast. Chevalier et al.  [14] help achieve precision agriculture, combining quadrotor and tracked robots, by using coalition formation concept. Gonzalez et al.  [15] help reduce water usage and increase efficiency and effectiveness in automotive irrigation processes in rural areas by using cooperative game concept.

As we can see, there is almost none of stability concept has been deployed in agricultural domain in recent years. The concept has been used in theoretical work or e-commerce domain. Therefore, this Personalized Data is among the first to apply this concept to help farmers make better decisions.

3 Real World Domain

One of the reasons DOAE wants to use AI to help farmers is to leverage their hidden collective power on both producing and negotiating for higher prices when selling and lower prices when buying. This system allows for farmer to specify their needs for fertilizers, seeds, etc. and collectively gain discounts, which to be distributed among participating agents. Any farmer can submit her/his need for buying as a group to other farmers to participate. Interested farmers can choose to participate. Not interested agents can insist to be the group leader. Participating agents specify their needs and constraints, for example, 5 tons of fertilizers of a reserved price maximum. There could be many farmers submitting requests at the same time. The system will scan for farmers looking for the same thing and are located in close proximity. Figure 1 shows a set of screen snapshots of farmers.

Fig. 1.
figure 1

Screen snapshots of farmers looking for available groups (left), existing members (center), and confirming joining a group (right.)

3.1 Computing Values for a Group of Farmers

Farmers looking for values accruing from joining a group. The values can be discounts achieved from bulk buy, Typically bulk buy help save a fair amount of expenses for sellers. From sellers perspective, the saved amount can be shared to buyer in order to attract them. On the other hand, farmers can also sell as a group and ask for higher prices because they can save buyers, who look for a large amount of crops, time and expenses in order to collect the crops up to their need. From buyers perspective, the time and expenses they can save are to be shared to farmers in order to attract them. From the system point of view, with respect to cooperative game theory, the saved amount to be shared to farmers is the value of forming a group, or coalition, of farmers. This value is yet to be distributed to farmers. There are two steps involved in computing values: i) is to find coalition center, and ii) to find the net value for the group. For selling crops, there must be a center of the coalition where the crops will be collected from members. For buying goods, the center of the coalition is where the goods will be delivered to and distributed to members. The center is the location of farmer where the collective distances to other agents is minimal. This ensures that the cost for delivering goods/crops is collectively the cheapest. The net value is the discounted or increased total price subtracted by the collective cost.

3.2 Computing Payoffs for Farmers

There another very important step involved, computing payoffs for farmers. There are multiple solution concepts in cooperative game that can be adopted, for example, efficiency, fairness, stability, etc. This Personalized System is equipped with these features. From farmer perspective, efficiency is the discounted or increased price they will receive. However, they simply keen to know whether their shared value is fair. With this regard, the system adopts Shapley value. We have discuss in details about this in another work. The last one is stability, which can be ensured by Kernel solution concept. We shall discuss in details in section below.

4 Stability in Coalition of Farmers

This system adopts the concept of cooperative game, also known as coalition formation. Below, we shall discuss the fundamental concept of coalition formation and Kernel stable concept.

4.1 Coalition Formation

Foundation of Coalition. A set of n agent is denoted by \(A =\{a_1, a_2, \ldots , a_n\}\). A coalition, denoted by S of A, \(S \subseteq A, S \ne \emptyset \), is a non-empty subset of of A. Therefore, the size of coalition, or the number of agents in S, also known as cardinality, \(1 \le |S| \le n\), ranges between 1 and n. In practice, a coalition is formed once agents agree to cooperate and are abiding to their respective coalitions. The smallest coalition, \(|S| = 1\), is the singleton coalition. Obviously, there are n singleton coalitions. The set A itself is the largest coalition, \(|S| = n\), namely the grand coalition, The power set of A is the set of all coalitions, denoted by \({\textbf {S}}\), where \({\textbf {S}}\) is \(2^{n}-1.\). Given a set of 3 agents, \(A = \{a_1, a_2, a_3\}\), there are \(2^3-1=7\) coalitions. All the coalition \(\{a_1\}, \{a_2\}, \{a_3\}, \{a_1, a_2\}, \{a_1, a_3\},\{a_2, a_3\} \text { and } \{a_1, a_2, a_3\}\). Once all agents in a give game agree to form coalitions, they are regarded as being mutually exclusive and exhaustive partitioned to m coalitions. Such a partitioned set of agents, A, is known as a coalition structure, denoted by \(CS = \{S_{1}, S_{2}, \ldots , S_{m}\}\). The following mathematical definition defines mutual and exhaustive conditions: 1) \(S_{j} \ne \emptyset , j = 1, 2, \ldots , m,\), 2) \(S_{i} \cap S_{j} = \emptyset \text { for all } i \ne j, \text { and }\) 3) \(\bigcup S_{j} = N.\) For example, given \(A = \{a_1, a_2, a_3\}\), all CS in \(\mathcal{C}\mathcal{S}\) are \(\{\{a_1\},\{a_2\},\{a_3\}\}, \{\{a_1, a_2\},\{a_3\}\}, \{\{a_1, a_3\},\{a_2\}\}, \{\{a_2,a_3\},\{a_1\}\},\) \(\{\{a_1\},\{a_2\},\) \(\{a_3\}\}\). We denote the set of all CSs of A by \(\mathcal{C}\mathcal{S}\). The benefit jointly accruing from a coalition is known as coalition value. In general, coalition value can be anything valuable to agents. In game theory, coalition values are mostly money value, which can be dollars, pounds, etc. Whereas coalitions in real world need to do real business to achieve their values, we assume the \(characteristic function, \upsilon : S \rightarrow \mathbb {R}^+\), associates to each coalition a non-negative value as its coalition value. The coalition value of a coalition S is denoted by \(\upsilon (S)\). A coalitional game defined by a characteristic function is known as a characteristic function game. Here is an example of such a game of three agents defined by a characteristic function: \(\upsilon (\{a_1\}) = \upsilon (\{a_2\}) = \upsilon (\{a_3\}) = 0;\) \(\upsilon (\{a_1, a_2\}) = 90; \upsilon (\{a_1, a_3\}) = 80; \upsilon (\{a_2, a_3\}) = 70;\) \(\upsilon (\{a_1, a_2, a_3\}) = 105.\)

Payoff and Payoff Configuration. The ultimate reason each agent decides to join a coalition is the share of the joint benefit it receives from that coalition. This share is known as the payoff of the agent. Mathematically, agent \(a_i\) in its respective coalition is given a payoff, \(U_{i}\). The payoff vector, \(U = (U_{1}, U_{2}, \ldots , U_{n})\), specifies the payoff for each agent. Generally, the payoff of each agent and the coalition structure are always associated to decide for the outcome. This association is known as the payoff configuration [16], (UCS) specifying payoffs of agents and how agents form coalitions. Considering the game mention above, the payoff configuration, \((45, 0, 35; \{a_1, a_3\}, \{a_2\})\) specifies that agents decide to form two coalition \(\{a_1, a_3\}\) and \(a_1\), \(a_1\) receives payoff 45, \(a_2\) receives payoff 0, and \(a_3\) receives payoff 35, respectively.

Solution Concept. The state which leads to the final and stable state of each game is known as equilibrium. The principles which agents can use to decide for equilibrium of each game is known as solution concept. There are three important solution concepts in coalition formation: i) fairness which helps agents receive fair payoffs based on agents’ contribution to the coalition values, ii) efficiency which helps agents receive highest possible payoffs both individually and globally, and iii) stability which helps agents receive satisfactory payoffs such that there is no need for agents to deviate from their current payoffs for higher payoffs. In the next solution, we shall discuss a stability solution concept, namely, the Kernel.

4.2 Kernel Solution Concept

Principle. To help define a stable condition, Davis et al. [1] propose that agents do not need to deviate from their respective coalitions for higher payoffs if they have already achieved the highest possible payoffs. This solution concept is named the Kernel. that stabilizes coalition structure by balancing each pair of agents payoffs in every coalition. Given a payoff configuration (UCS) for a game \((N;\upsilon )\), there may be a group of agents contemplate leaving their respective coalitions to form a new coalition R for more payoff. The excess: \(e(R;U) = \upsilon _{R} - U_{R}\) is difference between the value of R and the sums of the collective payoffs, \(U_{R}\), of the agents. Considering any pair of agents \(a_i \in S\) and \(a_j \in S\), and \(S \in CS\). Agent \(a_i\) may join R alone, \(R \notin CS\) and \(a_j \notin R\). Coalition R, any similar coalitions, will have excess (UCS). The largest excess is the maximum surplus of \(a_i\) over \(a_j\) with respect to (UCS), e.g., \( \mathcal {S}_{i,j} = max_{R|i \in R, j \notin R} \quad e(R;U). \) Agent, \(a_i\) can potentially gain that higher payoff. Similarly, \(a_j\) can do the same, with maximum surplus \(\mathcal {S}_{a_j, a_i}\). If both \(a_i\)’s maximum surplus is greater than that of \(a_j\) and \(a_j\)’s payoff is greater than its singleton coalition’s value, \( \mathcal {S}_{i,j}> \mathcal {S}_{j,i} \text { and } U_{j} > \upsilon _{j} \text {,} \) then \(a_i\) outweighs \(a_j\), with regards to (UCS) [1]. Agent \(a_i\) ask for compensation from \(a_j\) because of its higher maximal surplus otherwise it could join R for higher payoff. However, \(a_i\) can ask for up to a certain value because \(a_j\) can only accept payoff at least \(\upsilon _j\) It is said that an equilibrium between each pair of agents exists when one of the following holds: i) \(\mathcal {S}_{i,j} = \mathcal {S}_{j,i}\); each agent cannot ask for compensation be their maximum surpluses are equal, ii) \(\mathcal {S}_{i,j} > \mathcal {S}_{j,i}\) and \(U_{j} = V_{j}\); agent \(a_i\) cannot ask for compensation from \(a_j\) because agent \(a_j\) can be in its \(\{a_j\}\) iii) \(\mathcal {S}_{j,i} < \mathcal {S}_{i,j}\) and \(U_{i} = V_{i}\); agent \(a_j\) cannot ask for compensation from \(a_i\) because agent \(a_i\) can be in its \(\{a_i\}\). The global equilibrium is defined as the set K [1] of all payoff configurations (UCS), namely “Kernel”, such that every pair of agents \(a_i, a_j \in S \in CS\) are in equilibrium. Given this global equilibrium, it is said that the coalitions are stable.

Example. Let us consider the game defined in Sect. 4.1. Suppose we are given payoff configuration \((U;CS) = (45, 0, 35;\{1, 3\}, \{2\})\) to examine if it is in Kernel. Firstly, we consider coalition \(\{a_1, a_3\}\). For \(a_1\), it may join, excluding \(a_3\), two coalitions, e.g., \(\{a_1\}\) and \(\{a_1, a_2\}\). The excesses and maximum surplus are \(e(a_1;U) = \upsilon _{1} - U_{1} = 0 - 45 = -45\), \(e(\{a_1, a_2\};U) = \upsilon _{1,2} - U_{1} = 90 - 45 = 45\), and \(mathcal{S}_{1,3} = max(-45, 45) = 45.\) Similarly, \(\mathcal {S}_{a_3,a_1} = 35\). Hence, \(a_1\) outweighs \(a_3\) because \(\mathcal {S}_{a_1,a_3} = 45 > \mathcal {S}_{a_3,a_1} = 35\). Therefore, payoff configuration \((U;C) = (45, 0, 35 : \{a_1, a_3\}, a_2)\) is not in the Kernel. Consider another payoff configuration \((U;CS) = (50, 30, 25; \{a_1, a_2, a_3\})\). The excesses and maximum surplus between agent \(a_2\) and \(a_3\) are: \(\mathcal {S}_{2,3} = max(\upsilon _{2} - U_{2}, \upsilon _{1,2} - U_{2}) = max(0 - 30, 90 - 30) = 60\) and \(\mathcal {S}_{3,2} = max(\upsilon _{3} - U_{3}, \upsilon _{1,3} - U_{3}) = max(0 - 25, 80 - 25) = 55.\) Hence, \(a_2\) outweighs \(a_3\), or \((50,30,25;\{a_1,a_2,a_3\})\) is not in Kernel. Given another payoff configuration \((U;C) = (45, 35, 25;\{a_1, a_2, a_3\})\), we consider balance between each pair of them. Agent \(a_1\) and \(a_2\) are in equilibrium because \(\mathcal {S}_{1,2} = max(0 - 45, 80 - 70) = 10 = max(0 - 35, 70 - 60) = \mathcal {S}_{2,1}.\) Agent \(a_1\) and \(a_3\) are in equilibrium because \(\mathcal {S}_{1,3} = max(0 - 45, 90 - 80) = 10 = max(0 - 25, 70 - 60) = \mathcal {S}_{3,1}.\) Agent \(a_2\) and \(a_3\) are in equilibrium because \(\mathcal {S}_{2,3} = max(0 - 35, 90 - 80) = 10 = max(0 - 25, 80 - 70) = \mathcal {S}_{3,2}.\) Therefore, the \((U;C) = (45, 35, 25; \{1, 2, 3\})\)is in the Kernel.

5 Algorithms

5.1 Overview

As presented above, it takes a payoff configuration to determine whether the payoffs for agents are in the Kernel. There are three algorithms involved in verifying stability of coalitions. i) Generate Coalitions Since a coalition is merely a subset, any algorithm for generating subset can be applied for this purpose. The additional requirement is to associate a coalition value to each coalition. ii) Generate Coalition Structure This is quite a complex algorithm. There are two strong constraints, i.e. exclusiveness and exhaustiveness. iii) Verify Kernel This is also a complex algorithm because it has to iterate through a lot of coalitions. Because of limited space, we choose to demonstrate only algorithms for generating coalitions and verifying Kernel. This is based on the theoretical principle described above that a certain coalition structure is given as the input, along with payoff vector, in the payoff configuration. On the other hand, all coalitions must be repeatedly generated for examining whether it is in the Kernel.

5.2 Algorithm to Generate Coalitions

The coalitions are to be created in lexicographical order as shown in previous section, i.e. the coalition member at the right most position is the highest and the most value of the next member to the left is less by 1. We generate coalitions in form of array of integer, starting from size 1 to n. There is a main for loop where array coal of the respective size is created. Each cell of the array is initialized with its corresponding index. The algorithm enters the second loop where array coal is output. Another array, temp, is then created and initialized with the value of coal. For each position in temp, the algorithm checks within the current size \(i \le n\) if its value can be increased. If it has reached the maximum value allowed, it moves to the next left position until there is nothing left.

figure a

Although there are many ways to generate subsets or coalitions, our algorithm is suitable for verifying if a payoff configuration is in Kernel. According to the principle, each pair of agents in every coalition in the coalition structure of the given payoff configuration must be examined against almost coalitions for stability. Therefore generating a list of coalitions of the given set A and storing it for later referencing is suitable for our purpose.

5.3 Algorithm to Verify Kernel

At presented above, the concept of Kernel requires that we have to explore a lot of possible coalitions, i.e. up to \(2^n\), for every pair of agents in each coalition. In order to complete the search, at least, the algorithm needs a payoff configuration, a characteristic function (from game theory perspective, or a list of coalition values), of a given game. Firstly, the payoff configuration is assumed to be in Kernel, inKernel is set to true. The algorithm enters the main loop which goes through each S in the CS of the given payoff configuration. The second loop is to goes through each \(a_i\). The third loop is to go through each \(a_j, i \ne j\), checking for each pair \(a_i, a_j\) in the coalition. The forth loop is to go through all possible coalitions R, then determine their excesses and maximum surpluses. After that, the algorithm verifies the three conditions. If one of them is violated, the algorithm returns false. It is required by the principle that the verification must be done exhaustively. While the algorithm proceeds, the algorithm returns false whenever it finds that the one the three conditions is violated. We illustrate the algorithm below.

figure b

As mentioned, this algorithm strictly follow the principle of examining Kernel. One may use the figures provided in the previous section to learn and further understand Kernel algorithm.

6 Experiments and Results

There are two parts we consider about using the solution concept Kernel in real world setting. The first part is to analyze how large the search space can be. Due to the fact that the algorithm has to exhaustively search for all possible cases whether any agent can deviate for better payoffs, it is important to know how large the search space can be. As we have already mentioned in the review, Kernel is hardly adopted. We therefore present statistical results of our experiments. We conducted the experiments on a Ryzen 9 CPU, 16 core 32 thread and 32GB ram computer. Since coalition values can be varied, we divide the search space into 10 ranges, i.e. 10%, 20%, \(\ldots \), 100%, of the number of coalitions. We consider cases, where \(10\le n\le 30\), whose number of coalitions are defined by \(2^n\), e.g., \(1,024, 2,048, \ldots , 1,073,741,824\). Then we calculate, how large is the search space by multiply the number of coalitions for each n by \(10\%, 20\%,\ldots ,\%100\), respectively.

Fig. 2.
figure 2

Progresses of contribution values of 24 (left) and 25 (right) agents

As shown in Fig. 2, the search space can be very large. Since the search space is large, we herein will consider the degree of magnitude. The largest one is degree 20, existing in two cases, 90% and 100%, where \(n=30\). There are Given that most CPUs existing today runs at a few GHz. Let us assume, at the very best case, that it completes one case per a clock cycle. We may complete cases of magnitude degree 9 in a matter of seconds. In the worst case scenarios, to complete cases of magnitude degree 12, it may take minutes or hours. To complete cases of magnitude degree 13, 14, and 15, it will take hours, days, weeks and months, respectively. If we use 10 CPUs to handle magnitude degree 13, it will approximately bring down the search time to hours. If we use 100 CPUs to handle magnitude degree 14 (or 15), it will approximately bring down the search time to hours. Magnitude degree 15 is found in when \(n=24\)(10%–30%), \(n=23\)(20%–100%), and \(n = 22\)(60%–100%). These are the worst cases where we can finish the search at the best possibile within hours, using hundreds of CPUs. Note that we are not searching the maximal or minimal points. Instead we must be able to exhaustively search the whole search space to ensure the correct results should the worst case scenario exist (Fig. 3).

Fig. 3.
figure 3

Elapsed time of exhaustive search through 10–19 agents.

The second part is to carry out a set of experiments to investigate the execution time it might take to exhaustively examine stability, given the above analysis, in the best case scenarios. According to the definition of Kernel that for each agent in each coalition of a given payoff configuration, we have to exhaustively search by constructing nested loops to cover all the possibilities. Note that we assume that the actual elapsed time for comparison for each pair of coalitions is minimal. We have completed the experiment of 18 agents, all ranges, 10%–100% with magnitude degree 11–12. It took 383,752 milliseconds, over 6 min, to complete the -100% range. For the cases of 19 agents, range 100%, and magnitude degree 13, it took 1,626,389 milliseconds or almost 30 min to complete. At the time of writing this report, we can finish 60% range of 20 agents with magnitude degree 13 by 5,028,333 milliseconds, over 83 min, or 1 h and 23 min. This means the 100% range of 10 agents with magnitude degree 14 could easily takes days. If we take the problems of 15 \(^\circ \)C of magnitude, 30% of 24 agents, 20%–100% of 23 agents, and 60%–100% of 22 agents, it may take up to months. In this case, we might need hundreds of CPUs to finish the search in hours.

7 Conclusion

Based on the Personalized Data system, developed by the Department of Agricultural Extension, Ministry of Agriculture, Thailand. Among many AI libraries and concepts used, the stability concept, Kernel, is needed when farmers cooperate and do not deviate for other alternative groups for better payoffs. We must be ensured that given any worst case scenario in real world environment, we can still deliver the answer in reasonable time This means the number of agents participating in forming coalitions must not be too large. We firstly analyze how large the search space can be. We found that with up to 30 agents, the largest space is \(1.2\times 10^{20}\). By approximation with typical GHz CPUs, we may finish the search with minutes for 18 agent, hours for 19 agents, and days for 20 agents. We may bring down these figures by adding more CPUs by 10 s or 100 s of them. We have also carried out the approximate search time, assuming that the exact comparison between each pair of coalitions can be done at minimal time, for up to 60% of 20 agents. This takes almost an hour and a half. This implies that by using single CPU for 20 agents we may need merely hours. For 21 and 22 agents it might take days or weeks for a single CPU. By adding 10 s or 100 s CPUs, it may take hours or days for 23 or 24 agents. Therefore, we can use this system in practice to verify if a payoff configuration is in Kernel. In the future, more advanced techniques can be developed to search for a payoff configuration that is in Kernel.