Natural gas supply and demand matching method based on intelligent contract
By applying machine learning algorithms and oracle technology in smart contracts, combining state channels for dual evaluation and off-chain transactions, the problems of low flexibility, high transaction costs and insufficient security in natural gas supply and demand matching are solved, and a more efficient, secure and transparent supply and demand matching is achieved.
Patent Information
- Application Number
- CN202411502070.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-25
- Publication Date
- 2025-02-28
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing smart contracts have problems such as low flexibility, high transaction costs, insufficient security and transparency in the matching of natural gas supply and demand, especially in the credibility verification of off-chain transactions.
By using machine learning algorithms to establish prediction models and optimize smart contracts, and using oracles to transmit external data to smart contracts, double evaluation is conducted to verify the applicability and real-time nature of transaction matching. When the applicability or real-time is insufficient, a status channel is introduced for off-chain transactions and verification and settlement is carried out through smart contracts.
It improves the flexibility of smart contracts and the accuracy and speed of supply and demand matching, reduces transaction costs, enhances transaction security and transparency, and expands the scope of application of smart contracts.
Smart Images

Figure CN119539342A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain technology, and more specifically, to a natural gas supply and demand matching method based on smart contracts. Background Art
[0002] A smart contract is an automatically executed contract based on blockchain technology, which allows the terms of the contract to be controlled and executed programmatically without the need for a third-party trusted institution. The key to using blockchain technology to use smart contracts to automatically execute natural gas matching lies in the execution applicability of smart contracts. On-chain transactions based on blockchain have the advantages of security and transparency, but at the same time increase transaction costs and matching difficulty. Traditional smart contracts traverse and match both parties to the transaction according to preset rules, which has low flexibility, and there is a high cost to modify the smart contract itself. Therefore, transactions based on smart contracts exist both on and off the chain. The cost of off-chain transactions is lower, but there are defects in security and transparency. Therefore, verifying the credibility of off-chain transactions and ensuring the security and reliability of transactions under the premise of low-cost transactions have become challenges that smart contracts need to solve urgently.
[0003] In order to solve the above defects, a technical solution is now proposed. Summary of the invention
[0004] The purpose of the present invention is to provide a natural gas supply and demand matching method based on smart contracts to address the deficiencies in the background technology.
[0005] In order to achieve the above object, the present invention provides the following technical solution: a natural gas supply and demand matching method based on smart contracts, the specific steps of which include:
[0006] Use machine learning algorithms to build prediction models and optimize smart contracts based on the prediction models;
[0007] By integrating the oracle to transmit external data to the smart contract, an assessment is performed based on the external data to verify the suitability conditions for transaction matching. When the smart contract meets the preset suitability restrictions, the smart contract is used to match supply and demand and execute transactions based on market data;
[0008] When the applicability conditions do not meet the preset applicability restrictions, the smart contract is re-evaluated to verify the real-time performance of the smart contract. When the real-time performance of the smart contract is insufficient, the state channel is introduced to conduct off-chain transactions and the transaction results are transferred to the chain for verification and settlement through smart contracts.
[0009] The natural gas supply and demand are matched based on the introduced status channel, and after the matching is completed, the transaction is paid and settled through the chain.
[0010] Preferably, the method of using machine learning algorithms to establish a prediction model and optimize smart contracts is:
[0011] Collect market data, including natural gas prices, supply and demand, trading volume, external economic indicators, and organize the data in chronological order;
[0012] Collect smart contract execution data, including transaction success rate, settlement time, transaction volume, transaction time window, transaction price fluctuation, and mark whether the smart contract execution is successful or not;
[0013] Use feature selection techniques to perform feature engineering on execution data;
[0014] After the market data is standardized, it is used as input to build a time series model, and the time series model is trained. When the loss converges or reaches the preset training cycle, the training of the time series model is stopped and the prediction results are output;
[0015] The features after feature engineering processing based on the execution data and the smart contract execution results are used as input to build a classification model, train the classification model, and stop training when the preset training rounds are reached;
[0016] The prediction results of the time series model are used as input features and input into the classification model to predict the success probability of smart contract execution;
[0017] The smart contract is dynamically adjusted based on the success probability output by the classification model.
[0018] Preferably, the specific application method of using feature selection technology to perform feature engineering processing is:
[0019] Each decision tree in the random forest is constructed based on randomly selected features and samples. Different features are used to split each node of the decision tree, and the feature that can minimize impurity is selected as the basis for splitting.
[0020] For each feature, calculate the reduction in impurity brought by the feature when splitting all decision tree nodes;
[0021] Average the impurity reduction of each feature in all decision trees to obtain the average impurity reduction value of the feature;
[0022] The features are sorted from large to small according to the average impurity reduction value, and the feature with the largest average impurity reduction value is output. The feature with the largest average impurity reduction value is used as the input of the random forest to build a classification model.
[0023] Preferably, the method for standardizing market data is:
[0024] The original market data is calibrated as X, and the standardized data is X norThe maximum and minimum values in the original data are X max and X min , then the standardized formula is
[0025] Preferably, the logic for dynamically adjusting the smart contract based on the success probability output by the classification model is:
[0026] Based on the prediction results of the random forest model, the parameters of the smart contract are dynamically adjusted, including price limits, matching rules, etc.
[0027] When the predicted success probability is lower than the preset probability limit, the smart contract automatically adjusts the transaction matching strategy and starts the state channel to execute the transaction off-chain;
[0028] Monitor the market trends predicted by the time series model in real time, make adjustments based on the forecast results, and take protective measures when price fluctuations exceed the preset fluctuation range. Protective measures include suspending transactions and renegotiation.
[0029] Preferably, the rules for matching based on external data are:
[0030] Define the base supply as Q s , the basic demand is Q d , the weather influence coefficient is C w , the transport risk threshold is T r , the actual delay time of the transport line is Δt, and the transport adjustment factor is F a , then the supply-demand difference is calculated as ΔQ = Q d *C w -Q s *f(Δt,T r ), where f(Δt,T r ) is calculated as Where, T thr is the tolerance time threshold of transport line delay, T max is the maximum time threshold of transportation line delay, T max Greater than T thr And T max , T thr All are positive numbers, and the weather influence coefficient C w The calculation expression is C w =a(TT base )+1, where T is the current temperature, T base is the reference temperature, a is the temperature influence coefficient, and a is a positive number.
[0031] Preferably, the logic for verification and judgment according to the preset rules is:
[0032] Preset the first imbalance threshold I f and the second imbalance threshold I s , and the first imbalance threshold I f Less than the second imbalance threshold I s , the calculated supply-demand difference ΔQ and the first imbalance threshold I f and the second imbalance threshold I s When the supply-demand difference ΔQ is less than the first imbalance threshold I f When the smart contract is marked as applicable and the natural gas supply and demand are balanced;
[0033] When the first imbalance threshold I f Less than or equal to the supply-demand difference ΔQ Less than or equal to the second imbalance threshold I s When the smart contract is marked as applicable and the natural gas supply and demand are unbalanced, it is prompted to allocate natural gas from other reserves or start emergency supply to match supply and demand;
[0034] When the supply-demand difference ΔQ is greater than the second imbalance threshold I s When the smart contract is marked as invalid and the gas supply and demand are unbalanced, the transaction will be stopped and renegotiated.
[0035] Preferably, the logic for secondary evaluation of smart contracts is:
[0036] Define the evaluation value as S t , the transaction frequency is T f , the average transaction fee on the chain is c on , the average cost of off-chain transactions is c off , the average processing time of on-chain transactions is m on , the average processing time of off-chain transactions is m off , then the transaction frequency value is The transaction fee is Then the calculation expression of the evaluation value is S t =ω h *S h +ω c *S c , where ω h and ω c are the weight coefficients of transaction frequency value and transaction fee value respectively, and ω h and ω c All are positive numbers;
[0037] The preset evaluation threshold is T hr , the calculated evaluation value S t With the evaluation threshold T hr For comparison, when the evaluation value S t Greater than or equal to the evaluation threshold T hrWhen the state channel is not introduced, the transaction is carried out by renegotiating and adjusting the smart contract;
[0038] When the evaluation value S t Less than the evaluation threshold T hr When the state channel is introduced, off-chain transactions are carried out, and the off-chain transactions are verified and settled through smart contracts.
[0039] In the above technical solution, the technical effects and advantages provided by the present invention are:
[0040] This application designs smart contracts through a blockchain network to optimize the matching of natural gas supply and sales. It optimizes the flexibility of smart contracts by combining time series models and classification models, and adopts a double evaluation method to flexibly match the demand conditions of both supply and demand parties, thereby enhancing the scope of application of smart contracts and improving the matching accuracy and speed of both parties. At the same time, it reduces the transaction costs of both parties by introducing state channels, avoids increasing transaction risks while reducing transaction costs, and expands the universality of smart contracts. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present invention. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.
[0042] Figure 1 The present invention is a flow chart of the method. DETAILED DESCRIPTION
[0043] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0044] Example 1: Please refer to Figure 1 As shown, the present invention is a natural gas supply and demand matching method based on smart contracts, and the specific steps include:
[0045] Use machine learning algorithms to build prediction models and optimize smart contracts based on the prediction models;
[0046] By integrating the oracle to transmit external data to the smart contract, an assessment is performed based on the external data to verify the suitability conditions for transaction matching. When the smart contract meets the preset suitability restrictions, the smart contract is used to match supply and demand and execute transactions based on market data;
[0047] When the applicability conditions do not meet the preset applicability restrictions, the smart contract is re-evaluated to verify the real-time performance of the smart contract. When the real-time performance of the smart contract is insufficient, the state channel is introduced to conduct off-chain transactions and the transaction results are transferred to the chain for verification and settlement through smart contracts.
[0048] The natural gas supply and demand are matched based on the introduced status channel, and after the matching is completed, the transaction is paid and settled through the chain.
[0049] Machine learning algorithms can optimize the execution logic and decision-making efficiency of smart contracts by analyzing large amounts of data and learning patterns and regularities in the data;
[0050] The method of using machine learning algorithms to build prediction models and optimize smart contracts is:
[0051] Collect market data, including natural gas prices, supply and demand, trading volume, external economic indicators, and organize the data in chronological order;
[0052] Collect smart contract execution data, including transaction success rate, settlement time, transaction volume, transaction time window, transaction price fluctuation, and mark whether the smart contract execution is successful or not;
[0053] Use feature selection techniques to perform feature engineering on execution data;
[0054] After the market data is standardized, it is used as input to build a time series model, and the time series model is trained. When the loss converges or reaches the preset training cycle, the training of the time series model is stopped and the prediction results are output;
[0055] The features after feature engineering processing based on the execution data and the smart contract execution results are used as input to build a classification model, train the classification model, and stop training when the preset training rounds are reached;
[0056] The prediction results of the time series model are used as input features and input into the classification model to predict the success probability of smart contract execution;
[0057] The smart contract is dynamically adjusted based on the success probability output by the classification model.
[0058] Through real-time data analysis and prediction, smart contracts can adapt to market changes more quickly and adjust supply and demand strategies in a timely manner, thereby improving market response speed; machine learning algorithms learn and identify market rules based on a large amount of historical data, provide intelligent decision-making support for smart contracts, and reduce human intervention and misjudgment; smart contracts can automatically adjust resource allocation according to supply and demand forecasts, ensure the rational allocation of natural gas in different regions and time periods, and improve resource utilization efficiency; through automated transactions and the execution of smart contracts, reduce human operations and intermediary links, thereby reducing transaction costs and improving transaction efficiency; the transparency and immutability of smart contracts, combined with the prediction results of machine learning algorithms, enhance market transparency and promote fair competition and trust building.
[0059] It should be noted that the prediction model established using the machine learning algorithm is a composite model that includes a time series model and a classification model. In the composite model, the time series model is a long short-term memory network model, and the classification model is a random forest model.
[0060] Feature selection technology is a method of selecting features that affect model performance by evaluating features. The specific application method of feature selection technology for feature engineering is:
[0061] Each decision tree in the random forest is constructed based on randomly selected features and samples. Different features are used to split each node of the decision tree, and the feature that can minimize impurity is selected as the basis for splitting.
[0062] For each feature, calculate the reduction in impurity brought by the feature when splitting all decision tree nodes;
[0063] Average the impurity reduction of each feature in all decision trees to obtain the average impurity reduction value of the feature;
[0064] The features are sorted from large to small according to the average impurity reduction value, and the feature with the largest average impurity reduction value is output. The feature with the largest average impurity reduction value is used as the input of the random forest to build a classification model.
[0065] Random forest is an ensemble learning method that constructs multiple decision trees and combines the prediction results of the decision trees to obtain the final prediction. Each decision tree is trained based on randomly selected samples and feature subsets. Random selection helps reduce overfitting of the model. In the feature selection process, by eliminating features with weak prediction ability for the target variable or highly correlated with other features, the interference of the model during training is reduced, thereby improving the generalization ability and accuracy of the model; by using a small number of features, it helps to reduce the complexity of the model, that is, the model needs to learn fewer parameters, making the model easier to train and reducing the risk of overfitting; in the data preprocessing and model training stages, processing a small number of features reduces the amount of calculation, thereby accelerating the training process. At the same time, a small number of highly explanatory features make the model easier to understand and explain;
[0066] Features that are highly correlated with other features are noisy and redundant features.
[0067] The method to standardize market data is:
[0068] The original market data is calibrated as X, and the standardized data is X nor The maximum and minimum values in the original data are X max and X min , then the standardized formula is
[0069] Standardization eliminates the differences in dimensions, magnitudes, and properties between different variables, making the data suitable for mathematical model analysis. Too large values can lead to numerical calculation problems, such as floating-point overflow or underflow. The logarithmic normalization method compresses the values within a certain range, thereby improving numerical stability. The standardized data has better distribution characteristics, which helps optimization algorithms such as gradient descent to converge faster to obtain the optimal solution.
[0070] The logic of dynamically adjusting the smart contract based on the success probability output by the classification model is as follows:
[0071] Based on the prediction results of the random forest model, the parameters of the smart contract are dynamically adjusted, including price limits, matching rules, etc.
[0072] When the predicted success probability is lower than the preset probability limit, the smart contract automatically adjusts the transaction matching strategy and starts the state channel to execute the transaction off-chain;
[0073] Monitor the market trends predicted by the time series model in real time, make adjustments based on the forecast results, and take protective measures when price fluctuations exceed the preset fluctuation range. Protective measures include suspending transactions and renegotiation.
[0074] By integrating the oracle to transmit external data to the smart contract, an assessment is performed based on the external data to verify the suitability conditions for transaction matching. When the smart contract meets the preset suitability restrictions, the smart contract is used to match supply and demand and execute transactions based on market data;
[0075] Call the oracle service through smart contracts to regularly request updates of external data, including weather data, transportation route data, and policy fluctuation information;
[0076] The evaluation indicators include price fluctuation range and supply and demand balance status. The smart contract matches the real-time external data provided by the oracle with the pre-set rules. If the supply and demand are balanced, the current supply and demand status will be maintained. If the supply and demand are unbalanced, adjustments will be made based on the degree of imbalance and the preset rules.
[0077] The rules for matching based on external data are:
[0078] Define the base supply as Q s , the basic demand is Q d , the weather influence coefficient is C w , the transport risk threshold is T r , the actual delay time of the transport line is Δt, and the transport adjustment factor is F a , then the supply-demand difference is calculated as ΔQ = Q d *C w -Q s *f(Δt,T r ), where f(Δt,T r ) is calculated as Where, T thr is the tolerance time threshold of transport line delay, T max is the time limit threshold of transport line delay, T max Greater than T thr And T max , T thr All are positive numbers, and the weather influence coefficient C w The calculation expression is C w =a(TT base )+1, where T is the current temperature, T base is the reference temperature, a is the temperature influence coefficient, and a is a positive number.
[0079] It should be noted that when the line delay time is less than or equal to the tolerance time threshold T thr is the acceptable delay time. When the line delay time exceeds the limit time threshold T max , then the supply will be reduced to zero or the minimum acceptable level;
[0080] At the base temperature, natural gas demand is not affected by weather. The temperature impact coefficient represents the percentage change in natural gas demand for every unit change in temperature and is set by professional and technical personnel in this field.
[0081] Preset the first imbalance threshold I f and the second imbalance threshold I s , and the first imbalance threshold I f Less than the second imbalance threshold I s , the calculated supply-demand difference ΔQ and the first imbalance threshold I f and the second imbalance threshold I s When the supply-demand difference ΔQ is less than the first imbalance threshold I f When the smart contract is marked as applicable and the natural gas supply and demand are balanced;
[0082] When the first imbalance threshold I f Less than or equal to the supply-demand difference ΔQ Less than or equal to the second imbalance threshold I s When the smart contract is marked as applicable and the natural gas supply and demand are unbalanced, it is prompted to allocate natural gas from other reserves or start emergency supply to match supply and demand;
[0083] When the supply-demand difference ΔQ is greater than the second imbalance threshold I s When the smart contract is marked as invalid and the gas supply and demand are unbalanced, the transaction will be stopped and renegotiated.
[0084] When the applicability conditions do not meet the preset applicability restrictions, the smart contract is re-evaluated to verify the real-time performance of the smart contract. When the real-time performance of the smart contract is insufficient, the state channel is introduced to conduct off-chain transactions and the transaction results are transferred to the chain for verification and settlement through smart contracts.
[0085] When the smart contract fails, the natural gas supply and demand matching is re-evaluated to verify the real-time performance. The logic of the re-evaluation of the smart contract is as follows:
[0086] Define the evaluation value as S t , the transaction frequency is T f , the average transaction fee on the chain is c on , the average cost of off-chain transactions is c off , the average processing time of on-chain transactions is m on , the average processing time of off-chain transactions is m off , then the transaction frequency value is The transaction fee is Then the calculation expression of the evaluation value is S t =ω h *S h +ω c *S c , where ω h and ωc are the weight coefficients of transaction frequency value and transaction fee value respectively, and ω h and ω c All are positive numbers;
[0087] The preset evaluation threshold is T hr , the calculated evaluation value S t With the evaluation threshold T hr For comparison, when the evaluation value S t Greater than or equal to the evaluation threshold T hr When the state channel is not introduced, the transaction is carried out by renegotiating and adjusting the smart contract;
[0088] When the evaluation value S t Less than the evaluation threshold T hr When the state channel is introduced, off-chain transactions are carried out, and the off-chain transactions are verified and settled through smart contracts.
[0089] Transaction frequency refers to the number of transactions completed per unit time. The smart contract platform records detailed information for each transaction, including transaction time, transaction type, and transaction amount. The total number of transactions within a certain period of time is calculated by analyzing the system log, thereby obtaining the transaction frequency. The on-chain transaction fee is calculated through the Gas fee in the blockchain network. Each transaction includes the Gas price and the Gas limit. The actual transaction fee is the product of the Gas price and the actual amount of Gas consumed. The off-chain transaction fee is defined by the specific off-chain solution or protocol. The on-chain processing time is the time from the initiation of a transaction to the confirmation and recording of the transaction on the blockchain. The off-chain processing time is the time required from the initiation of a transaction to the completion of the off-chain status update. The processing time of the transaction can be queried through the blockchain platform transaction log.
[0090] Match gas supply and demand based on the introduced state channel, and after the matching is completed, the transaction will be paid and settled on the chain;
[0091] The state channel allows both parties to a transaction to interact and update the status off-chain without having to conduct expensive transactions on the blockchain every time. At the same time, the state channel reduces the burden on the blockchain network and increases the transaction speed. Based on market dynamic data and the conditions set in the contract, the smart contract automatically matches supply and demand. When the market conditions meet the thresholds set by both parties, the match is deemed successful. After the supply and demand parties reach an agreement on the transaction details, the transaction results are submitted to the blockchain and confirmed by the smart contract. After the transaction is confirmed on the blockchain, the smart contract automatically executes the payment and settlement process. All transactions are recorded on the blockchain. The smart contract updates the status information in the state channel based on the transaction results to ensure that both parties have a consensus on the transaction status.
[0092] This application designs smart contracts through a blockchain network to optimize the matching of natural gas supply and sales. It optimizes the flexibility of smart contracts by combining time series models and classification models, and adopts a double evaluation method to flexibly match the demand conditions of both supply and demand parties, thereby enhancing the scope of application of smart contracts and improving the matching accuracy and speed of both parties. At the same time, it reduces the transaction costs of both parties by introducing state channels, avoids increasing transaction risks while reducing transaction costs, and expands the universality of smart contracts.
[0093] The above formulas are all dimensionless and numerical calculations. The formula is a formula for the most recent real situation obtained by collecting a large amount of data and performing software simulation. The preset parameters in the formula are set by technicians in this field according to actual conditions.
[0094] The above embodiments can be implemented in whole or in part by software, hardware, firmware or any other combination. When implemented by software, the above embodiments can be implemented in whole or in part in the form of computer program goods. The computer program goods include one or more computer instructions or computer programs. When the computer instructions or computer programs are loaded or executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that contains one or more available media sets. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium. The semiconductor medium can be a solid-state hard disk.
[0095] It should be understood that in the various embodiments of the present application, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0096] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0097] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0098] If the functions are implemented in the form of software functional units and sold or used as independent goods, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can essentially or in other words, the part that contributes to the prior art or the part of the technical solution can be embodied in the form of software goods, and the computer software goods are stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, and other media that can store program codes.
[0099] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A natural gas supply and demand matching method based on smart contracts, characterized in that: The specific steps include: Use machine learning algorithms to build prediction models and optimize smart contracts based on the prediction models; By integrating the oracle to transmit external data to the smart contract, an assessment is performed based on the external data to verify the suitability conditions for transaction matching. When the smart contract meets the preset suitability restrictions, the smart contract is used to match supply and demand and execute transactions based on market data; When the applicability conditions do not meet the preset applicability restrictions, the smart contract is re-evaluated to verify the real-time performance of the smart contract. When the real-time performance of the smart contract is insufficient, the state channel is introduced to conduct off-chain transactions and the transaction results are transferred to the chain for verification and settlement through smart contracts. The natural gas supply and demand are matched based on the introduced status channel, and after the matching is completed, the transaction is paid and settled through the chain.
2. The natural gas supply and demand matching method based on smart contracts according to claim 1 is characterized in that: The method of using machine learning algorithms to build prediction models and optimize smart contracts is: Collect market data, including natural gas prices, supply and demand, trading volume, external economic indicators, and organize the data in chronological order; Collect smart contract execution data, including transaction success rate, settlement time, transaction volume, transaction time window, transaction price fluctuation, and mark whether the smart contract execution is successful or not; Use feature selection techniques to perform feature engineering on execution data; After the market data is standardized, it is used as input to build a time series model, and the time series model is trained. When the loss converges or reaches the preset training cycle, the training of the time series model is stopped and the prediction results are output; The features after feature engineering processing based on the execution data and the smart contract execution results are used as input to build a classification model, train the classification model, and stop training when the preset training rounds are reached; The prediction results of the time series model are used as input features and input into the classification model to predict the success probability of smart contract execution; The smart contract is dynamically adjusted based on the success probability output by the classification model.
3. The natural gas supply and demand matching method based on smart contracts according to claim 2 is characterized in that: The specific application method of feature engineering processing using feature selection technology is: Each decision tree in the random forest is constructed based on randomly selected features and samples. Different features are used to split each node of the decision tree, and the feature that can minimize impurity is selected as the basis for splitting. For each feature, calculate the reduction in impurity brought by the feature when splitting all decision tree nodes; Average the impurity reduction of each feature in all decision trees to obtain the average impurity reduction value of the feature; The features are sorted from large to small according to the average impurity reduction value, and the feature with the largest average impurity reduction value is output. The feature with the largest average impurity reduction value is used as the input of the random forest to build a classification model.
4. The natural gas supply and demand matching method based on smart contracts according to claim 2 is characterized in that: The method to standardize market data is: The original market data is calibrated as X, and the standardized data is X nor The maximum and minimum values in the original data are X max and X min , then the standardized formula is 5. The natural gas supply and demand matching method based on smart contracts according to claim 2 is characterized in that: The logic of dynamically adjusting the smart contract based on the success probability output by the classification model is as follows: Based on the prediction results of the random forest model, the parameters of the smart contract are dynamically adjusted, including price limits, matching rules, etc. When the predicted success probability is lower than the preset probability limit, the smart contract automatically adjusts the transaction matching strategy and starts the state channel to execute the transaction off-chain; Monitor the market trends predicted by the time series model in real time, make adjustments based on the forecast results, and take protective measures when price fluctuations exceed the preset fluctuation range. Protective measures include suspending transactions and renegotiating.
6. The natural gas supply and demand matching method based on smart contracts according to claim 1 is characterized in that: The rules for matching based on external data are: Define the base supply as Q s , the basic demand is Q d , the weather influence coefficient is C w , the transport risk threshold is T r , the actual delay time of the transport line is Δt, and the transport adjustment factor is F a , then the supply-demand difference is calculated as ΔQ = Q d *C w -Q s *f(Δt,T r ), where f(Δt,T r ) is calculated as Where, T thr is the tolerance time threshold of transport line delay, T max is the maximum time threshold of transportation line delay, T max Greater than T thr And T max , T thr All are positive numbers, and the weather influence coefficient C w The calculation expression is C w =a(TT base )+1, where T is the current temperature, T base is the reference temperature, a is the temperature influence coefficient, and a is a positive number.
7. The natural gas supply and demand matching method based on smart contracts according to claim 6 is characterized in that: The logic of verification and judgment based on preset rules is: Preset the first imbalance threshold I f and the second imbalance threshold I s , and the first imbalance threshold I f Less than the second imbalance threshold I s , the calculated supply-demand difference ΔQ and the first imbalance threshold I f and the second imbalance threshold I s When the supply-demand difference ΔQ is less than the first imbalance threshold I f When the smart contract is marked as applicable and the natural gas supply and demand are balanced; When the first imbalance threshold I f Less than or equal to the supply-demand difference ΔQ Less than or equal to the second imbalance threshold I s When the smart contract is marked as applicable and the natural gas supply and demand are unbalanced, it is prompted to allocate natural gas from other reserves or start emergency supply to match supply and demand; When the supply-demand difference ΔQ is greater than the second imbalance threshold I s When the smart contract is marked as invalid and the gas supply and demand are unbalanced, the transaction will be stopped and renegotiated.
8. The natural gas supply and demand matching method based on smart contracts according to claim 7 is characterized in that: The logic of secondary evaluation of smart contracts is: Define the evaluation value as S t , the transaction frequency is T f , the average transaction fee on the chain is c on , the average cost of off-chain transactions is c off , the average processing time of on-chain transactions is m on , the average processing time of off-chain transactions is m off , then the transaction frequency value is The transaction fee is Then the calculation expression of the evaluation value is S t =ω h *S h +ω c *S c , where ω h and ω c are the weight coefficients of transaction frequency value and transaction fee value respectively, and ω h and ω c All are positive numbers; The preset evaluation threshold is T hr , the calculated evaluation value S t With the evaluation threshold T hr For comparison, when the evaluation value S t Greater than or equal to the evaluation threshold T hr When the state channel is not introduced, the transaction is carried out by renegotiating and adjusting the smart contract; When the evaluation value S t Less than the evaluation threshold T hr When the state channel is introduced, off-chain transactions are carried out, and the off-chain transactions are verified and settled through smart contracts.