A digital currency transaction method, medium and system based on genetic algorithm
By applying genetic algorithms in the digital currency trading system to optimize coin collecting and minting solutions, the problems of high complexity, low efficiency and security risks of the existing system have been solved, efficient and automated digital currency transactions and inventory management have been achieved, and the system has been improved. stability and security.
Patent Information
- Application Number
- CN202410804236.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-21
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2044-06-21
AI Technical Summary
The existing digital currency trading system has high complexity, low efficiency and security risks during the transaction process, especially due to frequent coin minting and coin selling operations, which leads to a waste of system resources and security risks.
Adopting a digital currency transaction method based on genetic algorithms, by setting the initial digital currency stock, receiving transaction requests, using genetic algorithms to optimize the coin collection plan, selecting the optimal combination from the existing stock, executing transactions, and performing coin minting operations when necessary. Replenish inventory, monitor and optimize system operations in real time.
It realizes fully automated processing of digital currency transactions, improves transaction efficiency, reduces delay risks caused by manual intervention, dynamically adjusts inventory to adapt to market demand, enhances the intelligence level of inventory management, and reduces security risks.
Smart Images

Figure CN118379059B
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of digital currency transaction methods, and in particular, relates to a digital currency transaction method, medium and system based on genetic algorithm. Background Art
[0002] The emergence of digital currency has brought revolutionary changes to modern finance. Unlike traditional paper money and coins, digital currency is a virtual currency based entirely on digital technology. It has many advantages, such as no geographical restrictions, fast transaction speed, low cost, etc., and has attracted much attention from all walks of life. However, with the popularization of digital currency, its security and transaction efficiency have also become a hot topic in the industry.
[0003] In the transaction process, the traditional digital currency coding system requires a large number of coin minting and coin cancellation processes in order to meet the traceability of digital currency. Specifically, when a user makes a transaction, the system needs to piece together a currency combination equal to the transaction amount from the existing digital currency stock, and disassemble and remit the change after the transaction is completed. This primitive disassembly and assembly method has many problems:
[0004] 1. High complexity, requiring a lot of computing power. In the case of disordered splitting and combination, the level of coins becomes deeper and deeper, making it difficult to trace.
[0005] 2. Low efficiency. A large number of coin minting and minting operations will cause a waste of system resources and reduce transaction efficiency.
[0006] 3. Security risks. Due to the need for frequent coin minting and cancellation, the system is vulnerable to attacks and poses security risks. Summary of the invention
[0007] In view of this, the present invention provides a digital currency transaction method, medium and system based on genetic algorithm, which can solve the technical problems of high complexity and low efficiency in the digital currency transaction process in the prior art.
[0008] The present invention is achieved in that:
[0009] A first aspect of the present invention provides a digital currency transaction method based on a genetic algorithm, which comprises the following steps:
[0010] S10. Set the initial digital currency stock, including the number of digital currencies of each denomination;
[0011] S20, receiving the transaction request and determining the amount of digital currency required to be paid for this transaction;
[0012] S30, using a genetic algorithm to select a combination from the existing digital currency stock, so that the total amount of the selected combination is close to or equal to the required payment amount, thereby determining the currency collection plan for this transaction;
[0013] S40, execute this transaction, and deduct the corresponding amount and denomination of digital currency from the existing digital currency stock according to the coin collection plan;
[0014] S50, determining whether the number of digital currencies of certain denominations in the existing digital currency stock is less than a preset threshold value, if so, using a genetic algorithm to determine a minting scheme for the denomination and quantity of new digital currencies to be minted; if not, the minting step S60 directly proceeds to step S70;
[0015] S60, execute coinage, mint new digital currency according to the coinage plan, and add it to the existing digital currency stock;
[0016] S70. Update the statistical information of the digital currency stock;
[0017] S80. Repeat steps S20-S70 to complete the processing of subsequent transaction requests.
[0018] The preset threshold is 1000.
[0019] Wherein, the step S10 specifically includes:
[0020] Step 201, determine the type of digital currency denomination to be used in the system;
[0021] Step 202, setting an initial quantity for each denomination of digital currency, and determining the initial quantity based on the actual situation when the system is started;
[0022] Step 203, record the initial quantity of digital currency of each denomination in the system's digital currency inventory ledger.
[0023] Wherein, the step S20 specifically includes:
[0024] Step 301, receiving a digital currency transaction request initiated by a user, including transaction amount and transaction object information;
[0025] Step 302, verify the legitimacy of the transaction request and check whether the transaction parameters meet the system requirements;
[0026] Step 303, determine the total amount of digital currency required to be paid for this transaction, which will serve as the basis for subsequent coin collection optimization.
[0027] Wherein, the step S30 specifically includes:
[0028] Step 401, read the current digital currency inventory data of the system to obtain the actual inventory quantity of digital currencies of various denominations;
[0029] Step 402, constructing a decoding method of a genetic algorithm, treating each denomination of digital currency as a gene, and using a gene string to represent a coin-collecting scheme;
[0030] Step 403, designing a fitness function, the goal is to make the total amount of the selected coin-collecting scheme close to the amount required to pay for the transaction;
[0031] Step 404, using a genetic algorithm to optimize and solve, to find the best coin collection scheme that maximizes the fitness function value.
[0032] Wherein, the step S40 specifically includes:
[0033] Step 501, according to the coin-collecting scheme determined in step S30, deduct the corresponding amount and denomination of digital currency from the digital currency stock ledger of the system;
[0034] Step 502, update the digital currency inventory ledger to ensure that the ledger data is consistent with the actual inventory;
[0035] Step 503, record the relevant information of this transaction, including the transaction amount, transaction parties, and transaction time, and save it in the system transaction log.
[0036] Wherein, the step S50 specifically includes:
[0037] Step 601, read the current digital currency inventory data of the system to obtain the actual inventory quantity of digital currencies of various denominations;
[0038] Step 602, determining whether the inventory quantity of digital currency of each denomination is lower than a preset threshold;
[0039] Step 603, if the denomination of some digital currencies is lower than the preset threshold, a genetic algorithm is used to determine the denomination and quantity of new digital currencies to be minted;
[0040] Step 604: If all denominations of digital currencies are higher than the preset threshold, proceed directly to step S70 without minting coins.
[0041] Wherein, the step S60 specifically includes:
[0042] Step 701, according to the casting scheme determined in step S50, prepare new digital currency of corresponding quantity and denomination;
[0043] Step 702: Add the newly minted digital currency to the digital currency inventory ledger of the system and update the inventory quantity of each denomination;
[0044] Step 703, record the relevant information of this coin minting operation, including the minting quantity, time, and cost, and save it in the system coin minting log.
[0045] Wherein, the step S70 specifically includes:
[0046] Step 801, counting the total number of digital currencies of various denominations in the current system;
[0047] Step 802, calculating the total value of the current digital currency in the system;
[0048] Step 803, record the statistical results in the system's digital currency inventory statistics table;
[0049] Step 804, regularly back up the digital currency inventory statistics table and save historical data.
[0050] The step S80 specifically includes:
[0051] Step 901, looping through steps S20 to S70 to complete the processing of each subsequent transaction request;
[0052] Step 902, during the execution of the transaction processing flow, continuously monitor the operating status of the system, such as transaction processing speed, digital currency inventory level, etc.;
[0053] Step 903, according to the system operation status, timely optimize the algorithm and parameter settings of each step to improve the processing efficiency and stability of the system.
[0054] A second aspect of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores program instructions, and when the program instructions are executed, they are used to execute the above-mentioned digital currency transaction method based on genetic algorithm.
[0055] The third aspect of the present invention provides a digital currency trading system based on a genetic algorithm, which includes the above-mentioned computer-readable storage medium.
[0056] Compared with the prior art, the present invention firstly, in terms of transaction processing, the method of the present invention can automatically receive and verify the user's transaction request, and then use the genetic algorithm to select the optimal coin-adding scheme from the existing digital currency stock, so that the total amount of the selected denomination currency is as close as possible to the amount required to pay for the transaction. This can not only greatly improve the efficiency of transaction processing, but also reduce transaction delays caused by manual coin-adding. At the same time, the system can automatically execute transactions and deduct the corresponding amount and denomination of digital currency from the user's account, further improving the overall transaction automation level.
[0057] Secondly, in terms of digital currency inventory management, the method of the present invention can monitor the inventory of digital currencies of various denominations in real time. When the inventory of certain denominations is insufficient, the genetic algorithm is used to automatically determine the optimal casting scheme and perform coin casting operations to replenish the inventory. This dynamic adjustment mode can enable the system to better adapt to changes in market demand and avoid affecting the smooth progress of subsequent transactions due to shortages of certain denominations. At the same time, the system can also regularly count and record various indicators of digital currency inventory to provide support for financial management and supervision.
[0058] Compared with the prior art, the method of the present invention has the following significant advantages:
[0059] 1. It realizes the fully automated processing of digital currency transactions, greatly improves transaction efficiency, and reduces the risk of transaction delays caused by human intervention.
[0060] 2. Using genetic algorithms to dynamically optimize coin collection plans and minting plans can better adapt to changes in market demand and ensure the rationality of digital currency stocks.
[0061] 3. A complete digital currency stock management mechanism has been established, including real-time monitoring, automatic replenishment, statistical analysis and other functions, which has improved the intelligence level of stock management.
[0062] Therefore, the solution of the present invention solves the technical problems of high complexity and low efficiency in the digital currency transaction process in the prior art. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments of the present invention will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative labor.
[0064] Figure 1 A flow chart of the method provided by the present invention;
[0065] Figure 2 Schematic diagram of an individual population of a genetic algorithm in Example 1 of the present invention;
[0066] Figure 3 It is a step flow chart of Example 1 of the present invention. DETAILED DESCRIPTION
[0067] In order to make the purpose, technical solution and advantages of the embodiments of the present invention more clear, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0068] like Figure 1 FIG. 1 is a flow chart of a digital currency transaction method based on a genetic algorithm provided by the present invention. The method comprises the following steps:
[0069] S10. Set the initial digital currency stock, including the number of digital currencies of each denomination;
[0070] S20, receiving the transaction request and determining the amount of digital currency required to be paid for this transaction;
[0071] S30, using a genetic algorithm to select a combination from the existing digital currency stock, so that the total amount of the selected combination is close to or equal to the required payment amount, thereby determining the currency collection plan for this transaction;
[0072] S40, execute this transaction, and deduct the corresponding amount and denomination of digital currency from the existing digital currency stock according to the coin collection plan;
[0073] S50, determining whether the number of digital currencies of certain denominations in the existing digital currency stock is less than a preset threshold value, if so, using a genetic algorithm to determine a minting scheme for the denomination and quantity of new digital currencies to be minted; if not, the minting step S60 directly proceeds to step S70;
[0074] S60, execute coinage, mint new digital currency according to the coinage plan, and add it to the existing digital currency stock;
[0075] S70. Update the statistical information of the digital currency stock;
[0076] S80. Repeat steps S20-S70 to complete the processing of subsequent transaction requests.
[0077] The specific implementation methods of the above steps are described in detail below:
[0078] Step S10 - Set the initial digital currency stock
[0079] In order to achieve this step, it is necessary to first determine the various denominations of digital currencies that will be used in the system. This can be achieved through the following sub-steps:
[0080] 1. Determine the denominations of digital currency to be used in the system. Select appropriate denominations based on actual needs, such as 1, 5, 10, 50, 100, etc.
[0081] 2. Set the initial quantity for each denomination of digital currency. According to the actual situation when the system is started, set a certain initial quantity for each denomination of digital currency. These initial quantities can be determined based on experience or market research data. For example, the initial quantity of digital currency with a denomination of 100 can be set to 10,000, the initial quantity of digital currency with a denomination of 50 to 20,000, and so on.
[0082] 3. Record the initial quantity of digital currency of each denomination in the system's digital currency inventory ledger. This ledger needs to save the quantity information of each denomination of digital currency to provide a basis for subsequent transaction processing and coinage.
[0083] 4. Regularly monitor the digital currency inventory ledger to promptly understand the actual inventory status of digital currencies of various denominations.
[0084] Through the above sub-steps, the initial stock of digital currencies of various denominations in the system can be set, providing a basis for subsequent transaction processing and coin minting. The main purpose of this step is to build the initial inventory status of digital currencies in the system, providing a basis for subsequent transaction processing and coin minting.
[0085] Step S20 - Receive the transaction request and determine the amount of digital currency required for this transaction
[0086] To achieve this step, the following sub-steps are required:
[0087] 1. Receive transaction requests from users. Receive digital currency transaction requests initiated by users through the Internet and other channels, including transaction amount, transaction object and other information.
[0088] 2. Verify the legitimacy of the transaction request. Check whether the parameters in the transaction request meet the system requirements, such as whether the transaction amount exceeds the user's disposable balance, whether the transaction object exists, etc.
[0089] 3. Determine the amount of digital currency required for this transaction. According to the transaction amount information in the transaction request, the total amount required for this transaction is obtained. This amount will serve as the basis for the genetic algorithm to optimize the coin collection scheme in the subsequent steps.
[0090] Through the above sub-steps, the user's transaction request can be received and verified, the total amount required for this transaction can be determined, and basic data can be provided for subsequent coin optimization. The main purpose of this step is to obtain transaction request information and prepare for subsequent coin optimization processing.
[0091] Step S30 - Use genetic algorithms to select combinations from the existing digital currency stock so that the total amount of the selected combination is close to or equal to the required payment amount, thereby determining the currency collection plan for this transaction
[0092] To achieve this step, the following sub-steps are required:
[0093] 1. Read the current digital currency inventory data of the system. From the digital currency inventory ledger established in step S10, read the actual inventory quantity of digital currencies of various denominations in the system.
[0094] 2. Construct a decoding method for the genetic algorithm. Treat each denomination of digital currency as a gene, and use a gene string to represent a coin-collecting scheme. The length of the gene string is equal to the number of digital currency denominations in the system, and each gene bit represents the number of corresponding denominations.
[0095] 3. Define the fitness function. The goal of the fitness function is to make the total amount of the selected coin-collecting scheme as close to or equal to the amount required to pay for the transaction as possible. The following fitness function can be designed:
[0096]
[0097] Among them, Total_Amount represents the total amount of the selected coin-raising scheme, and Required_Amount represents the amount required to pay for the transaction. The larger the value of the fitness function (the closer to 0), the closer the selected coin-raising scheme is to the amount required to pay for the transaction.
[0098] 4. Use genetic algorithm for optimization and solution. According to the above decoding method and fitness function, use genetic algorithm to optimize the search for possible coin-collecting schemes and find the coin-collecting scheme with the maximum fitness function value. The specific implementation of genetic algorithm can include population initialization, selection, crossover, mutation and other steps.
[0099] 5. Output the optimal coin collection scheme. After optimization by the genetic algorithm, output a coin collection scheme that makes the total amount close to the amount required to pay for the transaction, including the number of digital currencies of each denomination.
[0100] Through the above sub-steps, the genetic algorithm can be used to select the optimal coin-collecting scheme from the existing digital currency stock, providing a basis for subsequent transaction execution. The main purpose of this step is to find an optimal coin-collecting scheme so that the total amount of the selected digital currency is as close as possible to the amount required to pay for the transaction.
[0101] Step S40 - Execute this transaction and deduct the corresponding amount and denomination of digital currency from the existing digital currency stock according to the coin collection plan
[0102] To achieve this step, the following sub-steps are required:
[0103] 1. Deduct the stock of digital currency. According to the coin collection scheme determined in step S30, deduct the corresponding amount and denomination of digital currency from the digital currency stock ledger of the system.
[0104] 2. Update the digital currency inventory ledger. After deducting digital currency, update the digital currency inventory ledger in a timely manner to ensure that the data in the ledger is consistent with the actual inventory.
[0105] 3. Record transaction information. Record relevant information of this transaction, such as transaction amount, transaction parties, transaction time, etc., in the transaction log of the system to provide a basis for subsequent account verification and audit.
[0106] Through the above sub-steps, the corresponding digital currency can be deducted from the system's digital currency inventory according to the previously determined optimal coin collection plan, the transaction can be completed, and the system's digital currency inventory ledger and transaction records can be updated simultaneously. The main purpose of this step is to execute the transaction and update the system's digital currency balance and transaction records.
[0107] Step S50 - Determine whether the number of digital currencies of certain denominations in the existing digital currency stock is less than a preset threshold. If so, use a genetic algorithm to determine the minting plan for the denomination and number of new digital currencies to be minted; if not, the minting step S60 directly enters step S70
[0108] To achieve this step, the following sub-steps are required:
[0109] 1. Read the current digital currency inventory data of the system. From the digital currency inventory ledger established in step S10, read the actual inventory quantity of digital currencies of various denominations in the system.
[0110] 2. Determine whether the inventory quantity of digital currencies of each denomination is lower than the preset threshold. Set a preset inventory lower limit threshold, such as 1,000, and check whether the inventory quantity of digital currencies of each denomination is lower than the threshold.
[0111] 3. If the inventory quantity of certain denominations of digital currency is lower than the threshold, a genetic algorithm is used to determine the denomination and quantity of new digital currency to be minted. A genetic algorithm optimization method similar to step S30 can be used to find a solution that makes the total inventory quantity after minting meet the demand while minimizing the minting cost. The minting cost can be represented by a weighted function, such as minting cost = ,in is the number of denominations to be minted, It is the unit minting cost of the denomination.
[0112] 4. If the inventory quantity of digital currencies of all denominations is higher than the preset threshold, proceed directly to step S70 without performing coin minting operations.
[0113] Through the above sub-steps, the inventory of digital currencies of various denominations in the system can be monitored in real time. When the inventory of certain denominations is insufficient, the genetic algorithm is used to determine the optimal casting plan to replenish the digital currency inventory of the system. The main purpose of this step is to maintain a reasonable inventory of digital currencies of various denominations in the system to ensure the smooth progress of subsequent transactions.
[0114] Step S60 - Execute coin minting, mint new digital currency according to the minting plan, and add it to the existing digital currency stock
[0115] To achieve this step, the following sub-steps are required:
[0116] 1. According to the casting scheme determined in step S50, prepare new digital currency of corresponding quantity and denomination. Technical means such as digital signatures can be used to generate new digital currency with uniqueness and traceability.
[0117] 2. Add the newly minted digital currency to the system's digital currency inventory ledger. Update the inventory quantity of digital currency of each denomination in the ledger to ensure that the ledger data reflects the actual inventory status.
[0118] 3. Record relevant information of this coin minting operation, such as minting quantity, time, cost, etc., and save it in the system's coin minting log to provide a basis for subsequent auditing and analysis.
[0119] Through the above sub-steps, the minting operation can be actually performed according to the previously determined minting plan, new digital currency can be generated, and added to the system's digital currency stock to meet the needs of subsequent transactions. The main purpose of this step is to implement the minting plan and replenish the system's digital currency stock.
[0120] Step S70 - Update the statistics of digital currency stock
[0121] To achieve this step, the following sub-steps are required:
[0122] 1. Count the total number of digital currencies of each denomination in the current system. Count the total number of digital currencies of each denomination from the digital currency inventory ledger established in step S10.
[0123] 2. Calculate the total value of the current digital currency in the system. Calculate the total value of the current digital currency in the system based on the number and face value of digital currencies of each denomination.
[0124] 3. Record the statistical information of digital currency stock. Record the statistical results of steps 1 and 2 in the digital currency stock statistics table of the system to provide a basis for subsequent financial analysis and supervision.
[0125] 4. Regularly back up the digital currency inventory statistics table. To avoid data loss, it is necessary to regularly back up the digital currency inventory statistics table and save historical data.
[0126] Through the above sub-steps, the statistical information of the digital currency stock in the system can be updated regularly, including the total number and total value of digital currencies of various denominations. These statistical data will provide an important basis for subsequent financial management and supervision. The main purpose of this step is to record and maintain the statistical information of the digital currency stock in the system in a timely and accurate manner.
[0127] Step S80 - Repeat steps S20-S70 to complete the processing of subsequent transaction requests
[0128] To achieve this step, the following sub-steps are required:
[0129] 1. Execute steps S20 to S70 in a loop. For each new transaction request, repeat the aforementioned steps S20 to S70 to complete transaction processing, coin collection optimization, coin minting, etc.
[0130] 2. Monitor the system operation status. During the repeated execution of the transaction processing process, continuously monitor the system operation status, such as key indicators such as transaction processing speed and digital currency inventory level, to promptly identify and resolve problems.
[0131] 3. Optimize system performance. According to the system operation status, timely optimize the algorithm and parameter settings of each step to improve the processing efficiency and stability of the system. For example, you can adjust the population size, crossover probability, mutation probability and other parameters of the genetic algorithm to obtain a better coin collection solution.
[0132] Through the above sub-steps, transaction requests in the system can be continuously processed, while the system's operating status can be monitored and optimized to ensure stable and efficient operation of the system. The main purpose of this step is to achieve continuous operation and performance optimization of the system.
[0133] In general, this digital currency trading method based on genetic algorithm realizes the automatic processing of digital currency transactions and the dynamic maintenance of digital currency stocks through a series of steps such as setting the initial digital currency stock, receiving transaction requests, optimizing the coin-collecting plan using genetic algorithm, executing transactions and updating the stock, monitoring the stock level, performing coin-minting operations, and counting stock information. Among them, genetic algorithm plays an important role in the optimization of coin-collecting and the determination of coin-minting plans, and can find a near-optimal solution.
[0134] A second aspect of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores program instructions, and when the program instructions are executed, they are used to execute the above-mentioned digital currency transaction method based on genetic algorithm.
[0135] The third aspect of the present invention provides a digital currency trading system based on a genetic algorithm, which includes the above-mentioned computer-readable storage medium.
[0136] Specifically, the principle of the present invention is:
[0137] Genetic algorithm, a computer intelligent optimization algorithm, is fully utilized. Genetic algorithm is a random search algorithm that simulates the natural evolution process. By simulating the mechanism of biological evolution, such as selection, crossover, mutation, etc., it can efficiently find the optimal solution or near-optimal solution to the problem. In scenarios such as digital currency trading and inventory management, genetic algorithms have shown their unique advantages.
[0138] First, in the transaction processing phase, the system needs to select the best coin combination scheme from the existing digital currency stock according to the user's transaction request, so that the total amount of the selected denomination currency is as close as possible to the amount required to pay for the transaction. This problem can be modeled as a combinatorial optimization problem, that is, to select an optimal denomination combination from the limited digital currency stock to meet the transaction needs. Genetic algorithms are very suitable for solving such problems. They can find a near-optimal solution within a limited computing time.
[0139] Specifically, the system treats each denomination of digital currency as a gene, and uses a gene string to represent a coin-collecting scheme. Then a fitness function is defined, with the goal of making the total amount of the selected coin-collecting scheme as close as possible to the amount required to pay for the transaction. Next, the system uses a genetic algorithm to iteratively optimize possible coin-collecting schemes, and through operations such as selection, crossover, and mutation, it finally finds the optimal coin-collecting scheme that maximizes the fitness function value. This optimization method based on the principle of evolution can quickly converge to a solution close to the global optimal solution with limited computing resources.
[0140] Secondly, in the digital currency inventory management link, the system needs to dynamically adjust the issuance of digital currencies of various denominations according to market demand to ensure the rationality of the overall inventory. When the inventory of certain denominations is insufficient, it is also necessary to use genetic algorithms to quickly determine the optimal casting plan to replenish the inventory. This problem can also be modeled as a combinatorial optimization problem, that is, to find an optimal casting plan under limited casting costs and inventory requirements.
[0141] The advantages of genetic algorithms in this problem are also very obvious. First, it can automatically determine the denomination and quantity that needs to be replenished based on the current inventory level and the preset lower limit threshold. Second, when determining the casting plan, the genetic algorithm can consider the unit casting cost of various denominations and find a plan that minimizes the total casting cost. This optimization process that takes into account both cost and inventory requirements can help the system better adapt to market changes and ensure the rationality of digital currency supply.
[0142] The above description is only a specific implementation mode of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.
[0143] In order to better understand the present invention, a specific embodiment 1 of the present invention is provided below: The operation steps of this embodiment 1 are as follows Figure 3 The specific description is as follows:
[0144] Initialize the population:
[0145] Create an initial population, each individual represents a coin-collecting scheme. This scheme includes the selected digital currency set and their permutation and combination. The present invention uses 01 encoding to encode individual schemes.
[0146] The initial population should cover as many different coin-collecting strategies as possible to ensure the diversity of the algorithm.
[0147] like Figure 2 As shown, the individual initialization process is divided into two steps:
[0148] Step 1: Initiate the transaction by sorting the digital collection of the user's wallet by digital currency code to form a one-dimensional array as the original gene.
[0149] Step 2: Expand the original gene into a two-dimensional array and mark whether each currency element in the gene is selected, with 1 for selected and 0 for unselected.
[0150] Fitness function design:
[0151] Design a fitness function to evaluate the pros and cons of each coin-collecting scheme. The function considers multiple factors, such as whether the coin-collecting amount meets the transaction requirements, handling fees, the degree of fragmentation of digital currency (i.e. the number and size distribution of output digital currency), etc.
[0152] The fitness function should be able to reflect the impact of the coin-pooling scheme on transaction processing efficiency and security.
[0153] The constraint formula is as follows:
[0154] Where T represents the transaction amount. is the number of digital currencies in an individual, and x represents the amount of each digital currency.
[0155] The formula must meet the following conditions:
[0156]
[0157] xi is a 0-1 decision variable, indicating whether digital currency i is selected, if yes xi=1, if not xi=0.
[0158] During the entire fitness selection process, gene combinations with results equal to the transaction amount are prioritized among genes with higher suitability. If there is no gene combination that meets this condition, the one with fewer currency levels (fewer split times) is selected. If the levels are the same, the one with the lowest excess amount is selected.
[0159] Select an action:
[0160] The individuals in the population are sorted according to the fitness function, and individuals with higher fitness are selected as parents.
[0161] Strategies such as tournament selection can be used to ensure that superior genes are retained.
[0162] Crossover operation:
[0163] The selected parent individuals are crossovered to generate new offspring individuals.
[0164] Crossover operations can include exchanging some of the digital currency selections of the parent individuals, rearranging the order of digital currencies, etc.
[0165] Mutation operation:
[0166] Mutation operations are performed on offspring individuals to introduce new genetic information.
[0167] Mutation operations may include randomly adding or deleting digital currencies, adjusting the amount of digital currencies, etc.
[0168] Evaluate and Iterate:
[0169] Evaluate the fitness of the newly generated offspring individuals and place them into the new population together with the parent individuals.
[0170] According to the new fitness ranking, new parents are selected for the next round of crossover and mutation operations.
[0171] This process is repeated until the termination condition is met (such as reaching a preset number of iterations or the fitness reaches a preset standard).
[0172] Coinage and Coinage:
[0173] After finding the optimal coin-collecting scheme, the minting operation is performed according to the scheme to generate the digital currency required for transaction output.
[0174] At the same time, the selected digital currency is marked as spent, completing the coin disposal process.
[0175] Through the optimization of genetic algorithms, more efficient coin-collecting schemes can be found, transaction fees and the degree of digital currency fragmentation can be reduced, and the efficiency of transaction processing can be improved. At the same time, the algorithm can also consider factors such as transaction security and privacy protection to ensure the safety and reliability of transactions.
[0176] In order to implement the present invention more easily, a specific embodiment 2 of the present invention is provided below based on specific formulas and algorithms: In embodiment 2, step S10 - setting the initial digital currency stock
[0177] In this step, it is necessary to determine the initial stock of digital currencies of various denominations to be used in the system. The specific implementation is as follows:
[0178] Assume that there are There are digital currencies with different denominations, The initial inventory quantity of each denomination of digital currency is These initial inventory quantities are recorded in the system's digital currency inventory ledger as the basis for subsequent transaction processing and coin minting operations.
[0179] The structure of the digital currency stock ledger is as follows:
[0180]
[0181] In order to ensure the stable operation of the system, it is necessary to regularly monitor the actual inventory of digital currencies of various denominations, timely understand the inventory level, and provide a basis for subsequent decision-making. The specific monitoring methods are as follows:
[0182] set up Indicates The denomination of digital currency at the moment The actual inventory quantity can be calculated regularly (such as daily or weekly) The value of When making comparisons, if it is found that the inventory of certain denominations is significantly low, it is necessary to consider minting to replenish the inventory.
[0183] Step S20 - Receive the transaction request and determine the amount of digital currency required for this transaction
[0184] In this step, it is necessary to receive the user's transaction request, verify the legitimacy of the request, and determine the total amount of digital currency required to pay for this transaction. The specific implementation is as follows:
[0185] Assume that the transaction request submitted by the user contains the following information:
[0186] Transaction Amount:
[0187] Trading Object:
[0188] First, the legitimacy of the transaction request needs to be verified, including:
[0189] 1. Check the transaction amount Whether it exceeds the user's available balance
[0190] 2. Verify the transaction object Is it present in the system
[0191] If the transaction request is legal, the total amount of digital currency required to pay for this transaction is determined to be , as the basis for subsequent coin optimization.
[0192] Step S30 - Use genetic algorithms to select combinations from the existing digital currency stock so that the total amount of the selected combination is close to or equal to the required payment amount, thereby determining the currency collection plan for this transaction
[0193] In this step, a genetic algorithm is used to select the best coin-collecting scheme from the existing digital currency stock, so that the total amount of the selected denomination currency is as close as possible to the amount required to pay for the transaction. The specific implementation is as follows:
[0194] 1. Read the current digital currency inventory information of the system, that is
[0195]
[0196] 2. Construct a decoding method for the genetic algorithm. Consider each denomination of digital currency as a gene, and use a length of The gene string To represent a coin-collecting scheme, Indicates selection The number of digital currencies of different denominations.
[0197] 3. Define the fitness function. The total amount of the selected coin scheme is expected to be As close as possible to the amount you will pay for the transaction , so the fitness function can be set as:
[0198]
[0199] in
[0200] 4. Use genetic algorithm to optimize the solution. The specific steps of genetic algorithm include:
[0201] Population initialization: Randomly generate a population containing The initial population of individuals
[0202] Selection: Roulette selection is used to select individuals with higher fitness to enter the next generation
[0203] Crossover: Perform crossover operations on selected individuals to generate new individuals
[0204] Mutation: Gene mutation of newly generated individuals with a certain probability
[0205] Fitness evaluation: Calculate the fitness value of the new generation population
[0206] Iteration: Repeat the above steps until the termination condition is met (such as reaching the maximum number of iterations or fitness convergence)
[0207] 5. Output the optimal coin-collecting scheme. After optimization by the genetic algorithm, the individual with the largest fitness function value is obtained. , which is the optimal coin collection scheme for this transaction.
[0208] Step S40 - Execute this transaction and deduct the corresponding amount and denomination of digital currency from the existing digital currency stock according to the coin collection plan
[0209] In this step, it is necessary to deduct the corresponding amount and denomination of digital currency from the system's digital currency stock according to the optimal coin collection scheme determined in step S30, complete this transaction, and simultaneously update the system's digital currency stock ledger. The specific implementation is as follows:
[0210] 1. Deduct from the system's digital currency inventory The corresponding amount of digital currency will be Updated to .
[0211] 2. Update the digital currency inventory ledger to ensure that the ledger data reflects the actual inventory situation.
[0212] 3. Record relevant information of this transaction, such as transaction amount , both parties to the transaction , transaction time, etc., are saved in the system's transaction log to provide a basis for subsequent account verification and auditing.
[0213] Step S50 - Determine whether the number of digital currencies of certain denominations in the existing digital currency stock is less than a preset threshold. If so, use a genetic algorithm to determine the minting plan for the denomination and number of new digital currencies to be minted; if not, the minting step S60 directly enters step S70
[0214] In this step, it is necessary to monitor the inventory of digital currencies of various denominations in the system in real time. When the inventory of certain denominations is insufficient, a genetic algorithm is used to determine the optimal casting plan to replenish the digital currency inventory of the system. The specific implementation method is as follows:
[0215] 1. Read the actual inventory quantity of digital currencies of each denomination from the digital currency inventory ledger .
[0216] 2. Set a preset minimum inventory threshold ,like . Check the inventory quantity of digital currency of each denomination Is it below this threshold:
[0217] like , then a minting operation is required to replenish the inventory of that denomination;
[0218] If all denominations , then go directly to step S70 without minting coins.
[0219] 3. For the denominations that need to be minted, use genetic algorithms to determine the optimal minting plan. The goal of the genetic algorithm is to find a minting plan , making the casting cost Minimum, while meeting the total inventory after casting The casting cost can be expressed as:
[0220]
[0221] in Indicates The unit minting cost of digital currency of different denominations.
[0222] 4. After genetic algorithm optimization, the optimal casting solution is obtained , as the basis for this coin minting operation.
[0223] Step S60 - Execute coin minting, mint new digital currency according to the minting plan, and add it to the existing digital currency stock
[0224] In this step, according to the casting scheme determined in step S50 , actually performs the minting operation, generates new digital currency, and adds it to the digital currency stock of the system. The specific implementation is as follows:
[0225] 1. Using digital signature and other technical means, generate a number of No. These newly generated digital currencies are unique and traceable.
[0226] 2. Add the newly minted digital currency to the system's digital currency inventory ledger and update the actual inventory quantity of digital currency of each denomination .
[0227] 3. Record relevant information of this coin minting operation, such as the number of coins minted , time, cost, etc., are saved in the system's minting log to provide a basis for subsequent auditing and analysis.
[0228] Step S70 - Update the statistics of digital currency stock
[0229] In this step, it is necessary to regularly update the statistical information of the digital currency stock in the system, including the total number and total value of digital currencies of various denominations. The specific implementation is as follows:
[0230] 1. The total number of digital currencies of various denominations currently in the statistical system ,in Indicates the system Total issuance batches of digital currencies of various denominations, Indicates Batch The inventory quantity of digital currency of this denomination.
[0231] 2. Calculate the total value of the current digital currency in the system .
[0232] 3. Record the statistical results in the system's digital currency inventory statistics table for subsequent financial analysis, supervision, etc. The structure of the inventory statistics table is as follows:
[0233]
[0234] in Indicates The total value of digital currencies of various denominations.
[0235] 4. Regularly back up the digital currency inventory statistics table to prevent data loss.
[0236] Through the above steps, the statistical information of the digital currency stock in the system can be recorded and maintained in a timely and accurate manner, providing an important basis for subsequent financial management and supervision.
[0237] In general, this digital currency transaction method based on genetic algorithm makes full use of computer algorithm technology, and realizes the automatic processing of digital currency transactions and dynamic maintenance of stocks through a series of steps such as setting the initial stock, receiving transaction requests, optimizing the coin collection plan, executing transactions to update the stock, monitoring and minting new coins. Among them, genetic algorithms play an important role in the optimization of coin collection and the determination of coin minting plans, and can find a near-optimal solution.
[0238] In order to better illustrate the implementation details and technical effects of the method of the present invention, an embodiment 3 is provided below in combination with a specific usage scenario.
[0239] Assume that a digital currency trading platform is ready to adopt the digital currency trading method based on genetic algorithm proposed in this invention. The platform is initially prepared to support 5 denominations of digital currency, namely 1, 5, 10, 50, and 100 units. The initial digital currency inventory of the system is shown in Table 1:
[0240] Table 1 System initial digital currency stock
[0241] Denomination Initial inventory quantity 1 50,000 5 20,000 10 10,000 50 5,000 100 2,000
[0242] As can be seen from Table 1, the system initially sets up five denominations of digital currency, and the initial inventory quantity of each denomination is also different. These initial parameters will be recorded in the system's digital currency inventory ledger as the basis for subsequent transaction processing and coin minting operations.
[0243] Next, we simulated the system running for a week, including steps such as transaction processing, inventory monitoring and coin minting, and observed the system operation during the whole process.
[0244] On the first day, the system received the following transaction request:
[0245] - Transaction amount: 278 units
[0246] - Transaction object: User A
[0247] According to step S20, the system first verifies the legitimacy of the transaction request and confirms that the available balance of user A is sufficient to pay the transaction amount of 278 units.
[0248] Then, the system uses genetic algorithms to find the best solution to collect coins from the existing inventory to meet the transaction needs of 278 units. The specific process is as follows:
[0249] 1. Read the current digital currency inventory ledger to obtain the actual inventory quantity of each denomination.
[0250] 2. Construct a genetic algorithm decoding method, treat each denomination of digital currency as a gene, and use the gene string represents a coin-collecting scheme, where Respectively represent the selection of 1, 5, 10, 50, and 100 unit denomination quantities.
[0251] 3. Define the fitness function ,in Indicates the total amount of the selected coin-raising scheme.
[0252] 4. Genetic algorithm is used for optimization and solution. After 200 iterations, the algorithm converges to the optimal solution. , the corresponding total amount .
[0253] According to step S40, the system deducts from user A's digital currency account The corresponding digital currency completes this transaction and updates the digital currency inventory ledger. The transaction log records are as follows:
[0254] Transaction amount: 278 units
[0255] Transaction object: User A
[0256] Coin collection scheme: 50 1-unit coins + 6 5-unit coins + 2 10-unit coins
[0257] In addition, the system also regularly monitors the inventory level of digital currencies of various denominations. Assuming the preset inventory lower limit threshold After one day of trading, the system finds that the inventory of 50-unit denominations has dropped to 800, which is below the threshold.
[0258] Then according to step S50, the system uses a genetic algorithm to determine the number of new 50-unit digital currencies that need to be minted. The specific process is as follows:
[0259] 1. Read the current digital currency inventory ledger to obtain the actual inventory quantity of each denomination.
[0260] 2. Set up the gene string for the casting scheme ,in Represents the first The number of digital currencies of various denominations.
[0261] 3. Define the fitness function , of which casting cost , assuming that the unit casting cost of each denomination is They are 0.1, 0.5, 1, 5 and 10 respectively.
[0262] 4. Genetic algorithm is used for optimization and solution. After 150 iterations, the algorithm converges to the optimal solution. , which means that 200 new digital currencies of 50 units need to be minted.
[0263] According to step S60, the system performs the minting operation, generates 200 new digital currencies of 50 units, and adds them to the stock account. The minting log records are as follows:
[0264] - Minting denomination: 50 units
[0265] - Casting quantity: 200
[0266] - Casting cost: 1,000 units
[0267] After a week of operation, the system processed 10,000 transactions with a total amount of 250,000 units. At the same time, the system also performed three coin minting operations, minting 200 50-unit, 300 10-unit and 100 5-unit new digital currencies to replenish inventory.
[0268] In order to comprehensively evaluate the technical effect of the method of the present invention, a detailed analysis was conducted on the system in terms of transaction processing efficiency, inventory management effect and operating costs, and a comparison was made with the traditional manual processing method.
[0269] 1. Transaction processing efficiency: The method of the present invention uses genetic algorithms to automatically optimize the coin-collecting scheme, which greatly improves the transaction processing speed. Statistics show that the average processing time for each transaction is only 5 seconds, while the traditional manual coin-collecting method takes more than 30 seconds. During peak hours (such as 12:00-2:00 on weekdays), the transaction processing capacity of the method of the present invention can reach 100 transactions per minute, while the manual processing method can only handle 20 transactions. This greatly improves the system's responsiveness and user experience.
[0270] 2. Inventory management effect: By real-time monitoring of the inventory levels of digital currencies of various denominations and using genetic algorithms to dynamically determine the casting plan, the method of the present invention can effectively maintain the system's digital currency inventory within a reasonable range.
Claims
1. A digital currency trading method based on genetic algorithm, characterized in that: The following steps are involved: S10. Set the initial digital currency stock, including the number of digital currencies of each denomination; S20, receiving the transaction request and determining the amount of digital currency required to be paid for this transaction; S30, using a genetic algorithm to select a combination from the existing digital currency stock, so that the total amount of the selected combination is close to or equal to the required payment amount, thereby determining the currency collection plan for this transaction; S40, execute this transaction, and deduct the corresponding amount and denomination of digital currency from the existing digital currency stock according to the coin collection plan; S50, determining whether the number of digital currencies of certain denominations in the existing digital currency stock is less than a preset threshold value, if so, using a genetic algorithm to determine a minting scheme for the denomination and quantity of new digital currencies to be minted; if not, the minting step S60 directly proceeds to step S70; S60, execute coinage, mint new digital currency according to the coinage plan, and add it to the existing digital currency stock; S70. Update the statistical information of the digital currency stock; S80. Repeat steps S20-S70 to complete the processing of subsequent transaction requests.
2. A digital currency transaction method based on genetic algorithm according to claim 1, characterized in that: The step S10 specifically includes: Step 201, determine the type of digital currency denomination to be used in the system; Step 202, setting an initial quantity for each denomination of digital currency, and determining the initial quantity based on the actual situation when the system is started; Step 203, record the initial quantity of digital currency of each denomination in the system's digital currency inventory ledger.
3. A digital currency transaction method based on genetic algorithm according to claim 1, characterized in that: The step S20 specifically includes: Step 301, receiving a digital currency transaction request initiated by a user, including transaction amount and transaction object information; Step 302, verify the legitimacy of the transaction request and check whether the transaction parameters meet the system requirements; Step 303, determine the total amount of digital currency required to be paid for this transaction, which will serve as the basis for subsequent coin collection optimization.
4. A digital currency transaction method based on genetic algorithm according to claim 1, characterized in that: The step S30 specifically includes: Step 401, read the current digital currency inventory data of the system to obtain the actual inventory quantity of digital currencies of various denominations; Step 402, constructing a decoding method of a genetic algorithm, treating each denomination of digital currency as a gene, and using a gene string to represent a coin-collecting scheme; Step 403, designing a fitness function, the goal is to make the total amount of the selected coin-collecting scheme close to the amount required to pay for the transaction; Step 404, using a genetic algorithm to optimize and solve, to find the best coin collection scheme that maximizes the fitness function value.
5. A digital currency transaction method based on genetic algorithm according to claim 1, characterized in that: The step S40 specifically includes: Step 501, according to the coin-collecting scheme determined in step S30, deduct the corresponding amount and denomination of digital currency from the digital currency stock ledger of the system; Step 502, update the digital currency inventory ledger to ensure that the ledger data is consistent with the actual inventory; Step 503, record the relevant information of this transaction, including the transaction amount, transaction parties, and transaction time, and save it in the system transaction log.
6. A digital currency transaction method based on genetic algorithm according to claim 1, characterized in that: The step S50 specifically includes: Step 601, read the current digital currency inventory data of the system to obtain the actual inventory quantity of digital currencies of various denominations; Step 602, determining whether the inventory quantity of digital currency of each denomination is lower than a preset threshold; Step 603, if the denomination of some digital currencies is lower than the preset threshold, a genetic algorithm is used to determine the denomination and quantity of new digital currencies to be minted; Step 604: If all denominations of digital currencies are higher than the preset threshold, proceed directly to step S70 without minting coins.
7. A digital currency transaction method based on genetic algorithm according to claim 1, characterized in that: The step S60 specifically includes: Step 701, according to the casting scheme determined in step S50, prepare new digital currency of corresponding quantity and denomination; Step 702: Add the newly minted digital currency to the digital currency inventory ledger of the system and update the inventory quantity of each denomination; Step 703, record the relevant information of this coin minting operation, including the minting quantity, time, and cost, and save it in the system coin minting log.
8. A digital currency transaction method based on genetic algorithm according to claim 1, characterized in that: The step S70 specifically includes: Step 801, counting the total number of digital currencies of various denominations in the current system; Step 802, calculating the total value of the current digital currency in the system; Step 803, record the statistical results in the system's digital currency inventory statistics table; Step 804, regularly back up the digital currency inventory statistics table and save historical data.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores program instructions, which, when executed, are used to execute a digital currency transaction method based on a genetic algorithm as described in any one of claims 1 to 8.
10. A digital currency trading system based on genetic algorithm, characterized in that: A computer-readable storage medium comprising the computer-readable storage medium of claim 9.
