## 3 Mechanism and Algorithm
### The Stable Trading Matching Algorithm  
This paper has designed the deferred acceptance algorithm for stable matching between coal mining and power generation companies. From the rankings that are put forth by the coal mining and power generation companies to the interactive selection of partners on both sides of the trading relationship to the pursuit of stable trading partners by the coal mining and power generation companies, this algorithm supplements and improves upon the traditional deferred acceptance algorithm. The deferred acceptance algorithm in this paper was designed based on the general algorithms in [PERSON] et al. (2017) [20], [PERSON] et al. (2020) [22], and [PERSON] (2022) [15], but it differs from the existing studies. Based on the typical stable matching model, this paper builds a stable matching algorithm of coal-power trading considering the trading volume and obtains a more general matching trading framework. It has certain theoretical innovation significance from  
Figure 1: The stable trading matching mechanism. the matching problem of non-separable commodities to that of separable commodities considering the trading volume between the coal mining and power generation companies. It is a better solution to the medium- and long-term trading problems between the coal mining and power generation companies on the electronic trading platform. This algorithm comprises the following aspects: variable initialization, initiating requests, rejecting requests, and termination conditions (as shown in Figure 2). Figure 2: The stable trading matching algorithm. * Variable initialization _PLcop_ records the coal mining companies' preferences for power generation companies; _PLproc_ records the power generation companies' preferences for coal mining companies. _PLcop(i,j)_ denotes a power generation company that ranks _j_th in the order of preferences of coal mining company \(i\) and _PLproc(j,i)_ denotes a coal mining company that ranks _i_th in the order of preferences of power generation company \(j\). The variables _quotaC_ and _quotaP_ record each coal mining company's total coal supply capacity and each power generation company's total demand for coal, respectively. At each stage of the algorithm, the coal mining companies' residual supply capacities and the power generation companies' unmet demands for coal are denoted by _leftC_ and _leftP_, where _leftC_(_i_) denotes the residual coal supply capacity of the coal mining company \(i\) and _leftP_(_j_) denotes the unmet demand for coal of the power generation company \(j\). The residual coal supply capacity and unmet demand for coal are then initialized as the total supplied by coal mining companies and the total demanded by power generation companies, respectively. Then, _proplag_ is used to indicate the place on the order of preferences at which the power generation companies begin to initiate requests; _proplag_(_j_) = \(r\) denotes that power generation company \(j\) initiated a request to a coal mining company that ranks _r_th on its order of preferences for coal mining companies; _newp_ records each of the power generation companies and is initialized as a new request. * Initiating requests When a power generation company receives requests, the requests are reviewed one by one in order to determine whether they are new requests. If a request is not new, then the power generation company looks to the next coal mining company to initiate a request. If that request is new, then the request to supply coal is added to the unmet demand for coal _leftP_(_p_) and the unmet demand is reduced to zero. Then the next power generation company continues to initiate requests until all of the companies have competed their requests. * Rejecting requests Step 1: Determine, in turn, whether each coal mining company has received new requests (sum(_cReci_(_;_c_)) \(\geq\) 1). Step 2: If it has, then the total residual coal supply capacity, _leftC_(_c_) = _quota_(_c_), is reallocated.