## 3 Optimization Model for Energy Purchase and Sale of the Electric-Gas Interconnection System
### Treatment of Uncertain Factors  
When the electric-gas interconnection system participates in the bidding of the multi-energy market, the uncertain variables involved include the clearing price of the power market, the average clearing price of the natural gas market, the penalty price of unbalanced electric quantity, and the actual output power of the system in the next day. Two kinds of uncertain variables, price and output power, are dealt with by the scenario analysis method and cardinal uncertainty set method respectively.  
The clearing price of the power market, the clearing price of the natural gas market, and the penalty price of unbalanced electricity quantity will directly affect the income of the electric-gas interconnection system, while the clearing price is affected by the bidding behavior of the market subjects, load fluctuation and other factors, which has considerable volatility and uncertainty. When using the scenario analysis method to describe the uncertainty of these factors, it can deal with uncertainty factors and carry out risk analysis by calculating the maximum (or minimum) expectation of the model objective function in various scenarios.  
First of all, according to the historical data of clearing price in the power market and the natural gas market, a specific probability distribution can be obtained by data fitting. Then, a large number of scenes are obtained by sampling. The larger the number of scenes are, the more accurate the results are, but the larger the calculation amount is. In order to balance the calculation amount and accuracy, firstly, according to the probability distribution of market clearing price, a large number of scenarios are generated by Latin hypercube sampling (LHS). Then, the k-means algorithm is used to reduce and merge the scene, and the probability of the scene after merging is calculated. The flow of the k-means algorithm is shown in the Figure 3.  
For the uncertainty of the next day's actual output power of the electric-gas interconnection system, select the appropriate 'uncertainty set' to be expressed. At present, the uncertain sets are often described in the form of box type, polyhedron type, ellipsoid type, cardinal type, etc. The characteristic of the cardinal uncertainty set used in this paper is that it can control the relative value of the uncertainty  
Figure 3: The process of k-means algorithm clustering.  
parameter offset and measure the parameter fluctuation accurately. The cardinal uncertainty set of the next day's actual output power of the electric-gas interconnection system is expressed as follows:  
\[\Omega=\{\widetilde{P^{\text{real}}_{\text{E,$t$}}}:P^{\text{real,min}}_{\text{E,$t $},k}\leq\widetilde{P^{\text{real}}_{\text{E,$t$}}}\leq P^{\text{real,max}}_{ \text{E,$t$},k},\quad\sum_{t=1}^{T}\frac{\widetilde{P^{\text{real}}_{\text{E,$t $}}}\cdot\frac{\rho_{\text{E,$t$}}}{\Delta}}{\frac{\rho_{\text{E,$t$}}}{\Delta} \widetilde{P^{\text{real}}_{\text{E,$t$}}}}\leq\Gamma\} \tag{13}\]  
where, \(\Omega\) represents the uncertainty set of the next day's actual output power of the electric-gas interconnection system. \(P^{\text{real,max}}_{\text{E,$t$},k}\)(Unit: MW) and \(P^{\text{real,min}}_{\text{E,$t$},k}\)(Unit: MW) represent the upper and lower limits of the next day's actual output power of the electric-gas interconnection system respectively. \(\widetilde{P^{\text{real}}_{\text{E,$t$}}}\)(Unit: MW) is the midpoint of the confidence interval of the next day's actual output power. \(P^{\text{real}}_{\text{E,$t$}}\)(Unit: MW) represents the maximum deviation.