Microgrid Group Trading Model and Solving Algorithm Based on Blockchain

With the development of the energy Internet and the integration of multi-type energy situations, it is of great significance to study the competition game of a multi-agent microgrid group system for its development. As an emerging distributed database technology, blockchain technology has great application potential in the field of energy trading. Firstly, blockchain technology is coupled with the microgrid group transaction, and the information flow transaction model of a microgrid group based on blockchain technology is established. Aiming at this complex multi-objective optimization problem, an improved ant colony optimization algorithm is proposed to solve the model. Finally, the competitive trading model and solving algorithm are simulated and analyzed. The relevant results show that the near global optimum price strategy of each time based on the proposed model can effectively balance the efficiency of each subject in the market. In addition, the model ensures that there is no high-income and low-cost phenomenon in the trading process, therefore the security and quality of the market are guaranteed.


Introduction
At present, primary energy consumption is too fast.With access to new forms of energy, the emergence of the energy Internet provides solutions for various kinds of energy access, environmental deterioration, and other issues [1].With the development of energy storage technology and diversification of energy forms, there will be new market subjects (such as distributed storage companies mentioned in this paper) in the power market of microgrid groups.This makes the market subjects participating in transaction competition diversified and multiple.The identity of each subject is no longer a single consumer or producer [2], but a "source-sale" integration.Because of the flexibility of the main types of power market involved in market trading, competitive trading in the power market is becoming more and more complex.In the new energy market environment, how to coordinate the relationship between the needs and benefits of various market subjects and improve the proportion of renewable energy use has become a problem that must be solved in the development of microgrid group system construction.Therefore, it is of great theoretical and practical significance for the development of distributed energy absorption and energy Internet technology to construct a market competition model for microgrid group.
The competition strategy of microgrids under the conditions of the power market was analyzed by using game theory in [3].The microgrid was regarded as a small low-voltage distribution network system, which was studied from two aspects of bidding strategy and economic operation.Reference [4] explored the multi-level microgrid structure in a distribution network.Users, investment developers represented by energy service companies, and power companies were selected as participants, and economic models based on different investors are established.Based on game theory, a multi-level microgrid optimal allocation model in distribution network was proposed.In [5], the electricity price function of the spot market was presented.Meanwhile, various bidding strategies in the microgrid power market were discussed.The spot market and electricity price mechanisms were considered comprehensively, and it was applied to predict and guarantee the economy of the microgrid.Based on the transaction impact between microgrid and distribution network, a non-cooperative game model and its solution process are established.Besides, the formation conditions and influencing factors of transactions between microgrid were solved [6].Reference [7] addressed a double-layer optimization model of multi-microgrid operators in the previous power market game competition model and the market operator's optimal economic scheduling model.In addition, the Nash equilibrium point of power market on distribution network side was calculated based on dynamic game method under complete information and double-layer optimization solution model.In [8], a multi-micro-network alliance control game model was proposed, and the formation process and algorithm of alliance cooperation were analyzed.The principal aim of reference [9] is to devise a combined market operator and a distribution network operator structure for multiple home-microgrids (MH-MGs) connected to an upstream grid.For modeling the interactions among partakers and implementing this comprehensive structure, a multi-objective function problem is solved by using a static, non-cooperative game theory.Reference [10] presents a smart Transactive energy framework.In addition, considering demand fluctuations, energy production based on renewable resources in the multiple H-MG can be accomplished by demand-side management strategies that try to establish mechanisms to allow for a flatter demand curve.
All of the above studies have achieved good results.However, most of them are limited to the transaction competition between the generation side or demand side.In addition, they have not yet been involved in the study of the trading competition between the multiple subjects in the microgrid group system.With the reform of the electricity market, along with the application of advanced metrology and information and communication technology, the frequency of energy trading will obviously increase.Hour-ahead or even real-time energy trading is emerging, peer-to-peer (P2P) energy trading offers a new option for decentralized energy market designs.
The idea of using blockchain technology to solve the transactions of the energy Internet is first proposed [11].The application prospect of blockchain in the energy field is proposed [12].A method to use blockchain technology for settlement in multi-energy complementary systems is proposed [13].
In the existing reference, most of the research on blockchain in the energy Internet stays at the theoretical research stage.As a distributed database storage technology, blockchain technology is the most typical application to reflect the characteristics of blockchain technology.In this paper, a P2P energy market is proposed, in which multi-directional energy trading of the multiple subjects in a microgrid group is achieved in the form of non-cooperative bidding supported by blockchain.
The rest of this paper is organized as follows.In Section 2, by introducing the definition and basic characteristics of the blockchain, the blockchain technology is coupled with the microgrid group transaction in three aspects, which proves the rationality and feasibility of establishing the microgrid group transaction system based on the blockchain technology.The establishment of the information flow transaction model based on blockchain technology is introduced in Section 3.Meanwhile, the establishment of physical flow transaction model depending on mathematical modeling are introduced.In Section 4, the algorithm for solving the transaction model of microgrid based on blockchain technology is introduced, that is, the improved ant colony algorithm is used to solve the near global optimum bidding strategy of the model.The model through a specific example is solved in Section 5 to verify the feasibility of the model.Conclusions and future work are given in Section 6.

Definition of Blockchain
In 2008, the concept of blockchain is first proposed in a groundbreaking paper on cryptography: "Bitcoin: A Peer-to-Peer Electronic Cash System".Hereafter, the technology of Bitcoin's digital cryptocurrency system which uses blockchain as the fundamental element was widely provided.
In a narrow sense, blockchain is a decentralized distributed database which makes different data blocks into the form of a 'chain' in a chronological order.Then, relying on asymmetric cryptography, it could be ensured that the data in the blockchain cannot be forged and cannot be falsified.Additionally, the transaction process, transaction data and information of the blockchain are fully and safely recorded.In addition, the transaction data can be traced back in timestamp and be verified in the system [14].In a generalized sense, blockchain technology is a new distributed paradigm for computing and a 'decentralized' basic architecture.It relies on the consensus algorithm of distributed nodes to generate or update data.At the same time, it can realize verifying and storing data by using the encrypted chain block structure.Blockchain technology relies on automated script code (smart contract) to program and manipulate data [15].

Characteristic of the Blockchain
The key technologies of blockchain involves data blocks, chain structure, P2P network, timestamp, Merkel tree, hash function, asymmetric encryption propagation mechanism, consensus mechanism (PoW, Pos, DPos), etc. [16].Combining the definition, technology, and basic architecture of the blockchain, its basic characteristics could be summarized as follows: (1) Decentralization By using distributed storage and computing methods, the blockchain system can build up mutual trust through mathematical methods rather than mandatory centralized hardware or management structures.Consequently, the data modules in the network are maintained by all nodes with maintenance functions in the entire system.In this situation, the incompleteness of the entire network caused by the loss of data in a single node cannot happen.Hence, decentralized distributed network systems can greatly enhance the network's anti-interference ability.
(2) Information Security and Transparency As the core technology to ensure information security, the data encryption technology of blockchain originates from asymmetric encryption technology.A pair of asymmetric passwords: "Public Key" and "Private Key" are used in it to meet the security and ownership verification requirements [17].Although the information is secure and reliable as it has been effectively encrypted, the network can still be open and transparent.Except the private information of the transaction parties which is protected by the encryption mechanism, data is disclosed to all nodes (users), which means that every node on the entire blockchain network can query data and supervise the generation of new blocks [12].
(3) Intelligent Contract Blockchain has a transformable programming system.The efficient smart contract mechanism which satisfies the execution conditions of both parties could be established at each node.When both transaction parties meet the execution conditions and are willing to perform the 'contract' obligation, the 'contract' can be automatically executed without the mutual trust of the transaction parties, nor the need of a supervisor or a third-party's restriction.Since both transaction parties can complete the transaction anonymously, the efficiency could be improved and the waste of resources could be reduced.

(4) Verifiability
The verifiability and traceability of the data stored in the blockchain are mainly derived from the 'timestamp' technique.Since the time nodes can be added to the blockchain by this technique, which means all the recorded transactions and data are encoded with time information.The verifiability of the information recorded on the database could be guaranteed for every transaction has trading time [18].Therefore, the 'timestamp' technology is also called as proof-of-existence of the block data.The existence of this technology makes the blockchain database unforgeable and falsified.Besides, any node (user) can obtain detailed information of any transaction data in history through the chain structure.

Basic Architecture Model of Blockchain
The basic architecture of blockchain consists of six levels: data layer, network layer, consensus layer, incentive layer, contract layer, and application layer, which is shown in Figure 1.verifiability of the information recorded on the database could be guaranteed for every transaction has trading time [18].Therefore, the 'timestamp' technology is also called as proof-of-existence of the block data.The existence of this technology makes the blockchain database unforgeable and falsified.Besides, any node (user) can obtain detailed information of any transaction data in history through the chain structure.

Basic Architecture Model of Blockchain
The basic architecture of blockchain consists of six levels: data layer, network layer, consensus layer, incentive layer, contract layer, and application layer, which is shown in Figure 1.

Subject Coupling
In the market environment, all the entities will generate a large amount of electricity purchase and sale information, such as the system's power generation, demand, bidding strategy, etc.For the traditional market trading model, all the information will be packaged and fed back to the control center of grid trading, and then be sorted and published to the market.After that, bidding begins in each market and the dispatching center will unify the economic dispatching when the bidding is finished [19].This process is cumbersome and time-consuming, which badly affects the timeliness of information transmission.At the same time, rights of the consumers are limited to purchasing electricity, and the electricity price market is completely controlled by the power grid center.
However, the 'decentralization' of the blockchain can effectively improve this problem for it provides a peer-to-peer platform for electricity market transactions.Each market entity can openly bid.Therefore, the fairness of market competition and the rationality of electricity price quotes could be improved.Also, the direct trade between each entity means that the information can be processed quickly and in time, which means that the efficiency of information circulation can be promoted.Since blockchain technology and the distributed management of microgrid group information resources are proposed based on the idea of decentralization, the information exchange rights and information storage rights of each transaction subject are equal, and the same obligations are also required.Therefore, it could be seen that there is a coupling relationship between the blockchain technology and microgrid group transaction, which is shown in Figure 2.

Subject Coupling
In the market environment, all the entities will generate a large amount of electricity purchase and sale information, such as the system's power generation, demand, bidding strategy, etc.For the traditional market trading model, all the information will be packaged and fed back to the control center of grid trading, and then be sorted and published to the market.After that, bidding begins in each market and the dispatching center will unify the economic dispatching when the bidding is finished [19].This process is cumbersome and time-consuming, which badly affects the timeliness of information transmission.At the same time, rights of the consumers are limited to purchasing electricity, and the electricity price market is completely controlled by the power grid center.
However, the 'decentralization' of the blockchain can effectively improve this problem for it provides a peer-to-peer platform for electricity market transactions.Each market entity can openly bid.Therefore, the fairness of market competition and the rationality of electricity price quotes could be improved.Also, the direct trade between each entity means that the information can be processed quickly and in time, which means that the efficiency of information circulation can be promoted.Since blockchain technology and the distributed management of microgrid group information resources are proposed based on the idea of decentralization, the information exchange rights and information storage rights of each transaction subject are equal, and the same obligations are also required.Therefore, it could be seen that there is a coupling relationship between the blockchain technology and microgrid group transaction, which is shown in Figure 2. be improved.Also, the direct trade between each entity means that the information can be processed quickly and in time, which means that the efficiency of information circulation can be promoted.Since blockchain technology and the distributed management of microgrid group information resources are proposed based on the idea of decentralization, the information exchange rights and information storage rights of each transaction subject are equal, and the same obligations are also required.Therefore, it could be seen that there is a coupling relationship between the blockchain technology and microgrid group transaction, which is shown in Figure 2.

Trading Mechanism Coupling
There are many competitions between various market subjects in the microgrid group.Problems such as opportunity cost and information leakage could be made due to the lack of trust, transparent information transmission, and unsafe transaction process.However, the decentralized information mechanism in blockchain technology can realize transaction recorded accurately and reduce opportunity cost due to lack of trust.
Additionally, blockchain technology uses asymmetric encryption mechanism to ensure the security and reliability of data transmission.An asymmetric encryption mechanism not only makes the transaction data real and effective but also reduces the rent-seeking behavior.Security issues such as leakage of transaction data can be solved.At the same time, the chain can be used to check the traceback transaction information at any time because of timestamp, which provides the maximum price selection for each subject.It can be seen that there is a coupling relationship between the two on the trading mechanism, as shown in Figure 3.

Trading Mechanism Coupling
There are many competitions between various market subjects in the microgrid group.Problems such as opportunity cost and information leakage could be made due to the lack of trust, transparent information transmission, and unsafe transaction process.However, the decentralized information mechanism in blockchain technology can realize transaction recorded accurately and reduce opportunity cost due to lack of trust.
Additionally, blockchain technology uses asymmetric encryption mechanism to ensure the security and reliability of data transmission.An asymmetric encryption mechanism not only makes the transaction data real and effective but also reduces the rent-seeking behavior.Security issues such as leakage of transaction data can be solved.At the same time, the chain can be used to check the traceback transaction information at any time because of timestamp, which provides the maximum price selection for each subject.It can be seen that there is a coupling relationship between the two on the trading mechanism, as shown in Figure 3.

Smart Contract Coupling
It is possible that every two subjects in the microgrid market can trade.When the transactions meet the preset conditions, the contract executes automatically using smart contract.Malicious factors that interfere with the normal execution of the contract can be avoided and execution efficiency can be increased.
In addition, there is a punishment mechanism in the blockchain technology.Microgrid group trading is a competitive game market.It can improve the utilization rate of clean energy and maximize the utilization of renewable energy.Meanwhile, carbon emissions and environmental pollution can be reduced.It can be seen that there is a coupling relationship between the two on the smart contract, as shown in Figure 4.

Information Flow Trading Model
The trading system of the microgrid group includes many market entities.The each of them has its corresponding purchase and sale information and bidding strategy for each period.Hence, it could be seen that for this system which has a large amount of information and strong timeliness, ensuring

Smart Contract Coupling
It is possible that every two subjects in the microgrid market can trade.When the transactions meet the preset conditions, the contract executes automatically using smart contract.Malicious factors that interfere with the normal execution of the contract can be avoided and execution efficiency can be increased.
In addition, there is a punishment mechanism in the blockchain technology.Microgrid group trading is a competitive game market.It can improve the utilization rate of clean energy and maximize the utilization of renewable energy.Meanwhile, carbon emissions and environmental pollution can be reduced.It can be seen that there is a coupling relationship between the two on the smart contract, as shown in Figure 4.

Trading Mechanism Coupling
There are many competitions between various market subjects in the microgrid group.Problems such as opportunity cost and information leakage could be made due to the lack of trust, transparent information transmission, and unsafe transaction process.However, the decentralized information mechanism in blockchain technology can realize transaction recorded accurately and reduce opportunity cost due to lack of trust.
Additionally, blockchain technology uses asymmetric encryption mechanism to ensure the security and reliability of data transmission.An asymmetric encryption mechanism not only makes the transaction data real and effective but also reduces the rent-seeking behavior.Security issues such as leakage of transaction data can be solved.At the same time, the chain can be used to check the traceback transaction information at any time because of timestamp, which provides the maximum price selection for each subject.It can be seen that there is a coupling relationship between the two on the trading mechanism, as shown in Figure 3.

Smart Contract Coupling
It is possible that every two subjects in the microgrid market can trade.When the transactions meet the preset conditions, the contract executes automatically using smart contract.Malicious factors that interfere with the normal execution of the contract can be avoided and execution efficiency can be increased.
In addition, there is a punishment mechanism in the blockchain technology.Microgrid group trading is a competitive game market.It can improve the utilization rate of clean energy and maximize the utilization of renewable energy.Meanwhile, carbon emissions and environmental pollution can be reduced.It can be seen that there is a coupling relationship between the two on the smart contract, as shown in Figure 4.

Information Flow Trading Model
The trading system of the microgrid group includes many market entities.The each of them has

Information Flow Trading Model
The trading system of the microgrid group includes many market entities.The each of them has its corresponding purchase and sale information and bidding strategy for each period.Hence, it could be seen that for this system which has a large amount of information and strong timeliness, ensuring the transaction data and the transaction records are accurate is of prime importance.Based on the basic framework of the blockchain, an information flow transaction model is established.Transaction information is passed between points in the form of a blockchain and is permanently entered.In the basic awareness data layer, each block on the blockchain represents a market entity.The system nodes are linked into a network to form the data path.In this situation, even part of the data path is attacked by malicious factors, the information can still be transferred through the transfer.In the network layer, the nodes are responsible for finding the next block, and the next linked block body could only be truly generated after the verifications of the entire network nodes are accepted by the node with authorization.In the consensus layer, the agreement between distributed data and block data is efficiently made.In the incentive layer, the using ratio of clean energy has been improved by the reward and punishment mechanism of the blockchain.In the contract layer, the efficiency of the execution is enhanced for the transactions could be automatically made in the form of smart contract.Besides, the microgrid group system which is the field applied in this paper, belongs to the application layer.Therefore, it is clear that the blockchain-based microgrid group information flow transaction model has the characteristics of security, confidentiality, anti-interference, timeliness, etc.The information flow microgrid transaction model based on the blockchain is shown as Figure 5.
Energies 2019, 12, x FOR PEER REVIEW 6 of 19 basic framework of the blockchain, an information flow transaction model is established.Transaction information is passed between points in the form of a blockchain and is permanently entered.In the basic awareness data layer, each block on the blockchain represents a market entity.The system nodes are linked into a network to form the data path.In this situation, even part of the data path is attacked by malicious factors, the information can still be transferred through the transfer.In the network layer, the nodes are responsible for finding the next block, and the next linked block body could only be truly generated after the verifications of the entire network nodes are accepted by the node with authorization.In the consensus layer, the agreement between distributed data and block data is efficiently made.In the incentive layer, the using ratio of clean energy has been improved by the reward and punishment mechanism of the blockchain.In the contract layer, the efficiency of the execution is enhanced for the transactions could be automatically made in the form of smart contract.Besides, the microgrid group system which is the field applied in this paper, belongs to the application layer.Therefore, it is clear that the blockchain-based microgrid group information flow transaction model has the characteristics of security, confidentiality, anti-interference, timeliness, etc.The information flow microgrid transaction model based on the blockchain is shown as Figure 5.

Physical Flow Trading Model
The power market structure of the microgrid group studied in this paper is as shown in the Figure 6.In that structure, the market entity mainly includes microgrid operators (MOs), distributed

Basic Structure of Microgrid
The power market structure of the microgrid group studied in this paper is as shown in the Figure 6.In that structure, the market entity mainly includes microgrid operators (MOs), distributed storage (DS), and power consumers (PCs).The entities are independent of each other and they all want to maximize their own interests by competition.It could be seen from Figure 6 that the market entities are connected by physical flow to realize energy transfer and transaction.In this figure, each entity has its own function.For the microgrid operators, generating and trading power is their main responsibility.When a power shortage occurs with other entities and the operator's power is abundant, the electricity is sold to obtain profits.For the distributed storage operators, the power provided by distributed users is collected and when the system is short of power, they can still act as power sellers and earn profits through the price difference.For the large power users, 'consumers' are the only role they play.According to their own conditions, getting the maximum power at the lowest cost is the most preferable transaction.In this model, large power users do not sell electricity.Based on Figure 6, it could be seen that each market entity is treated as a block.Consequently, the transactions made between market entities in different periods are equivalent to the new blocks' searching and linking.Ultimately, a large blockchain network will be formed.In the large energy blockchain network, each market entity's identity information, the purchasing and selling situation of the electricity, energy form, and bidding strategy will be released to the network.In the wider environment, when the markets begin to trade, every market entity could select the trading object in view of the information released on the internet provided by other entities.In this situation, according to the quotation, the trading object could be determined during the competition.For example, if the sales information is published on a blockchain network at a certain time by a distributed storage company, and other market entities are notified by broadcasting.After a period of time, the immediate electricity quantity and electricity price of other market entities will also be published on the network to make the information of each block transparent.Then, each entity could judge whether or not to make the transaction according to its own demand and the acceptable value of the electricity price.If the transaction requirements of the both sides are satisfied, the contract and transaction will be automatically made and recorded.
Energies 2019, 12, x FOR PEER REVIEW 7 of 19 responsibility.When a power shortage occurs with other entities and the operator's power is abundant, the electricity is sold to obtain profits.For the distributed storage operators, the power provided by distributed users is collected and when the system is short of power, they can still act as power sellers and earn profits through the price difference.For the large power users, 'consumers' are the only role they play.According to their own conditions, getting the maximum power at the lowest cost is the most preferable transaction.In this model, large power users do not sell electricity.
Based on Figure 6, it could be seen that each market entity is treated as a block.Consequently, the transactions made between market entities in different periods are equivalent to the new blocks' searching and linking.Ultimately, a large blockchain network will be formed.In the large energy blockchain network, each market entity's identity information, the purchasing and selling situation of the electricity, energy form, and bidding strategy will be released to the network.In the wider environment, when the markets begin to trade, every market entity could select the trading object in view of the information released on the internet provided by other entities.In this situation, according to the quotation, the trading object could be determined during the competition.For example, if the sales information is published on a blockchain network at a certain time by a distributed storage company, and other market entities are notified by broadcasting.After a period of time, the immediate electricity quantity and electricity price of other market entities will also be published on the network to make the information of each block transparent.Then, each entity could judge whether or not to make the transaction according to its own demand and the acceptable value of the electricity price.If the transaction requirements of the both sides are satisfied, the contract and transaction will be automatically made and recorded.

Mathematical Model of Microgrid Group Subject
In this paper, the microgrid group consists of three main bodies and each of them will make great efforts to maximize its own interests according to the practical situation.In the process of electricity trading, decentralization, and transparency of the blockchain are the most significant technologies.For the former one, decentralization guarantees that during the bidding and trading process, monitoring from third parties is not needed.For the latter one, transparency could make the transactions fair and reasonable to protect the rights of the consumers by making the previous transaction price and transacted electricity quantity be searchable.For every entity, how to maximize their own interests in the competition is the most paramount issue.Therefore, the building of the mathematical model of the microgrid group main body is of great significance.

Mathematical Model of Microgrid Group Subject
In this paper, the microgrid group consists of three main bodies and each of them will make great efforts to maximize its own interests according to the practical situation.In the process of electricity trading, decentralization, and transparency of the blockchain are the most significant technologies.For the former one, decentralization guarantees that during the bidding and trading process, monitoring from third parties is not needed.For the latter one, transparency could make the transactions fair and reasonable to protect the rights of the consumers by making the previous transaction price and transacted electricity quantity be searchable.For every entity, how to maximize their own interests in the competition is the most paramount issue.Therefore, the building of the mathematical model of the microgrid group main body is of great significance.
(1) Mathematical Model of the Microgrid Operators (MO S ) There are many new energy resources among microgrid operators, such as wind energy, solar energy, etc. Accordingly, it cannot be guaranteed that there would be excess electricity to be sold at any time.However, as the main body of electricity sales, when surplus power exists, microgrid operators will sell the surplus power to the other subjects who need electricity during such periods to obtain the profit P MO sell (t).When the operation cannot be supplied by itself, electricity purchasing is needed and the cost is C MO buy (t).Besides, the strict punishment mechanism is embedded in the incentive.Later, extra bonus R MO bonus (t) will made available when the clean energy utilization ratio increases, and extra punishment PC MO extra (t) will be applied when the pollutant emissions increase.The mathematical description is as follows: (a) The profit from selling electricity to other subjects P MO sell (t): where, P where, c M i toM buy (t) and c S j toM buy (t) respectively represent the unit cost of electricity purchase from ith MO, and jth DS at t time.Also, q M i toM buy (t) and q S j toM buy (t) respectively represent the purchased electric quantity from ith MO and jth DS at t time.
(c) Incentive rewards and penalty costs where, R Mo bonus (t), i, i 0 , and R bonus (t) respectively represent the value of incentive rewards, instant use ratio of new energy, standard use ratio of new energy and the system incentive reward value per unit of clean energy.The unit of R to produce and sell electricity.Consequently, its power purchase target is microgrid operators (MOs) and distributed storage vendors (DS).The specific mathematical expressions are as follows: (a) Purchase cost (from MOs) Among them, c M i toC buy (t) and Q M i toC buy (t) respectively represent the unit cost of electricity purchase and value of it at t time from ith microgrid operator.
(b) Purchase cost (from DS) where, c S j toC buy (t) and q S j toC buy respectively represent the unit cost of electricity purchase and value of it at t time from jth distributed storage vendors.
(3) Mathematical Model of Distributed Storage Vendors (DS) By signing smart contract agreements with distributed energy users, distributed storage vendors (DS) can centralize, integrate, re-manage, and store the distributed renewable energy to maximize the reuse of energy.In this situation, not only the use ratio of renewable energy could be increased but also a large amount of 'chicken rib' energy can be reserved, thereby providing more energy sources and purchasing channels for the market.Therefore, profits could be obtained by distributed storage vendors through the price difference.When the large market lacks electricity, the stored electric energy will be sold to obtain profits P A sell (t).Simultaneously, electricity will be purchased at the lowest cost C out buy (t).The mathematical form is described as follows: (a) Purchase cost Purchase cost (from MOs): where, c M i toS buy (t) and q M i toA buy (t) respectively represent the unit cost and volume of electricity purchase from ith MOs at t time.
Purchase cost (from DS): where, c S j toS buy (t) and q S j toS buy (t) respectively represent the unit cost and volume of electricity purchase from jth DC at t time.

(b) Electricity selling profit
Electricity selling profit (to MO S ): where, p StoM i sell (t) and q StoM i sell (t) respectively represent the price and volume of electricity selling to microgrid operators i at t time.Electricity selling profit (to MO S ): where, P AtoC m sell (t) and Q AtoC m sell (t) respectively represent the price and volume of electricity selling to BUs m at t time.
Electricity selling profit (to other DS): where, p StoS j sell (t) and q StoS j sell (t) respectively represent the price and volume of electricity selling to other DS j at t time.

Traditional Ant Colony Algorithm
Using the ant colony optimization algorithm to solve the multi-objective problem has the same characteristics as using blockchain technology to achieve 'decentralization'.
For the ant colony algorithm, individual ant finds the city in a special way to achieve the near global optimum path.Similarly, the blockchain ensures the security of the transmission process through the information communication among the blocks.It could be seen clearly that both of them are 'point-to-point' communication and that through the collaborative communication between individuals or between modules, the system's overall optimization could be achieved.Therefore, it is feasible to use the ant colony algorithm to solve the microgrid group trading model based on blockchain technology.The schematic diagram is shown as Figure 7. StoS sell q t respectively represent the price and volume of electricity selling to other DS j at t time.

Traditional Ant Colony Algorithm
Using the ant colony optimization algorithm to solve the multi-objective problem has the same characteristics as using blockchain technology to achieve 'decentralization'.
For the ant colony algorithm, individual ant finds the city in a special way to achieve the near global optimum path.Similarly, the blockchain ensures the security of the transmission process through the information communication among the blocks.It could be seen clearly that both of them are 'point-to-point' communication and that through the collaborative communication between individuals or between modules, the system's overall optimization could be achieved.Therefore, it is feasible to use the ant colony algorithm to solve the microgrid group trading model based on blockchain technology.The schematic diagram is shown as Figure 7. Ant colony algorithm is a process to solve the problem that how does the ants in the natural world use pheromones to effectively search for food and find the shortest path.The ant colony releases a kind of pheromone called 'biologic incretion' in the process of finding the next path, and determines the choice based on the pheromone concentration.If one of the various paths is repeatedly selected by different ants, then the pheromone volatilization rate cannot keep up with the accumulation speed.Therefore, the transition probability of moving to this path will become larger, which also means that this path will be continuously selected by different ants.In this situation, a positive feedback loop will be built and eventually all ants will choose a near global optimum path to find food [20].
The algorithmic mechanism of the ant colony algorithm will be illustrated by using it to deal with the traveling salesman problem (TSP) which is the most typical application of the ant colony algorithm.The traveler needs to travel all the given cities without repeating and go back to the starting city in the shortest path.Assuming that m ants are randomly assigned to one of the n cities as the starting point, the specific rules are shown as follows: Each ant will release the pheromone according to the length of the selected path, and then select the next city to visit based on the corresponding transition probability.Besides, ants have the ability Ant colony algorithm is a process to solve the problem that how does the ants in the natural world use pheromones to effectively search for food and find the shortest path.The ant colony releases a kind of pheromone called 'biologic incretion' in the process of finding the next path, and determines the choice based on the pheromone concentration.If one of the various paths is repeatedly selected by different ants, then the pheromone volatilization rate cannot keep up with the accumulation speed.Therefore, the transition probability of moving to this path will become larger, which also means that this path will be continuously selected by different ants.In this situation, a positive feedback loop will be built and eventually all ants will choose a near global optimum path to find food [20].
The algorithmic mechanism of the ant colony algorithm will be illustrated by using it to deal with the traveling salesman problem (TSP) which is the most typical application of the ant colony algorithm.The traveler needs to travel all the given cities without repeating and go back to the starting city in the shortest path.Assuming that m ants are randomly assigned to one of the n cities as the starting point, the specific rules are shown as follows: Each ant will release the pheromone according to the length of the selected path, and then select the next city to visit based on the corresponding transition probability.Besides, ants have the ability to remember and do not repeat the same path.Finally, the pheromone will be updated when every ant completes a loop.
It could be assumed that between the city i and j at t moment, τ ij (t) is the pheromone and d ij is the distance.When t = 0, the pheromone concentration on each path is the same, which means τ ij (0) = c (c is an arbitrary constant).For any ant k, the concentration of the pheromone on each path determines the direction of the transfer during the movement.In this case, p k ij (t) is the transition probability of the ant k to transfer from the city i to the city j at t moment.
where, allowed k = { 0, 1, 2, . . .n − 1} is the collection of the next city that could be chosen by the ant.Also, α and β are the accumulation of the pheromone released by the ant in the movement process.Besides, and when all ants complete a cycle, the pheromone concentration will be updated as where, ρ is the volatilization factor, 1 − ρ indicates the degree of residue and ρ ∈ (0, 1).∆τ ij (t, t + n) is the pheromone increment between the city i and j from t to t + n.Therefore, at the initial moment (∆τ ij (0) = 0), ∆τ k ij (t, t + n) is the volume of the pheromone released by ant k between the city i and j from t to t + n and its expression is where, Q is a constant and L k is the total length of the path taken by the ant in this cycle.After all the ants complete a cycle, the near global optimum path and the shortest distance of the cycle will be recorded.Then, this process will be repeat and iterated to the predetermined number of times.During this process, the near global optimum path and the shortest distance obtained in each cycle will be compared to select the optimal value which will finally converge to the ultimately near global optimum path and the shortest distance.

Improvement of Pheromone Concentration
The studies and analyses provided by predecessors indicate that the ant colony algorithm is liable to fall into the local optimal solution and the problem of stagnation in the search process is also likely to happen.This situation could be mainly attributed to the actual path information not accurately being reflected by the pheromone concentration [21].
To solve the problem provided above, the original ant colony algorithm is improved from the aspects of initial pheromone and pheromone volatilization based on the basic ant colony algorithm.The specifics will be illustrated as follows: In the classical ant colony algorithm, for all the initial pheromone concentrations are equal, the ants have no target direction when they start searching.Accordingly, a large number of unrelated paths will be produced in the search which could mislead the local update of the pheromone concentration.
In this case, not only the initial search time will become longer, because of the pheromone concentration of the irrelevant path is strengthened, the search process of the near global optimum path will also be hindered to make the algorithm move into local optimum.Therefore, in this paper, directional guidance is added at the initial pheromone concentration, and the formula of the initial pheromone information is modified as: where, d Si and d jE are the linear distance from node j to the starting point S and the ending point E (the paths between j and S(E) are not necessarily exist), and Q is a given parameter which represents the total pheromone allocated for each search.It is obvious that the shortest distance between the initial point S and the end point E is the line distance between them.From ( 15), it could be seen that when the node j tends to the line SE, (d Si +d jE will become smaller which means τ ij (0) will be larger.When τ ij (0) becomes larger, the ant will tend to select this node as the moving direction.With the help of the improvement of the algorithm, different weights are introduced to the node at the beginning of the search, therefore, a reasonable direction guidance could be produced for the search and the search for unrelated paths could also be suppressed.Thus, the process of finding the near global optimum solution will be accelerated.

Amendment of Parameters
In power network planning, if the parameters are not selected properly, it will directly affect the speed and effect of solving the model.In order to improve the efficiency of ant colony algorithm, the parameters can be defined as [22] α = 1 + e −0.1N max ( 16) where,N max is the maximum number of iterations.Two parameters can be controlled by controlling one parameter, which increases the linkage between parameters.

Algorithm Implementation
When using ant colony algorithm to solve the microgrid group transaction model and traveling salesman problem (TSP) respectively, the differences could be specifically reflected in two aspects.

"Closed Problem"
In that model, when the bidding strategies are selected by the market entities (from 1 to n), only one kind of bidding strategies could be chosen by each of them.In this case, a decision set which contains all bidding strategies will be formed and called as a "closed path" [23].

Calculation of Heuristic Function η ij
Unlike the basic ant colony algorithm, the problem solved by this model is to achieve the goal maximization rather than the goal minimization.
In this model, let η ij (t) = d ij (t), d ij (t) denotes the total transaction price of the bidding strategy selected by the market subject.

Analysis of Examples
In order to verify the relevant characteristics of the constructed model, a microgrid group trading system based on the blockchain technology is built by PyCharm software and Python 3.6 language.Also, three microgrid operators (MO S ), two distributed storage vendors (DS), and three power consumers (PC S ) are integrated to make up this system.
Besides, to simplify the setting of the bidding strategy matrix, it is regulated that the purchased electricity price is consistent with the selling price of the subject.The bidding strategy interval for each type of market subject is shown in Table 1 [24].In this paper, it is stipulated that the power consumers can only buy electricity but not sell electricity.For each subject, the 24-h power demand is shown in Figure 8.In addition, the electricity sales of the microgrid operators and distributed storage vendors are shown in Figure 9. Besides, to simplify the setting of the bidding strategy matrix, it is regulated that the purchased electricity price is consistent with the selling price of the subject.The bidding strategy interval for each type of market subject is shown in Table 1 [24].In this paper, it is stipulated that the power consumers can only buy electricity but not sell electricity.For each subject, the 24-hour power demand is shown in Figure 8.In addition, the electricity sales of the microgrid operators and distributed storage vendors are shown in Figure 9.   Besides, to simplify the setting of the bidding strategy matrix, it is regulated that the purchased electricity price is consistent with the selling price of the subject.The bidding strategy interval for each type of market subject is shown in Table 1 [24].In this paper, it is stipulated that the power consumers can only buy electricity but not sell electricity.For each subject, the 24-hour power demand is shown in Figure 8.In addition, the electricity sales of the microgrid operators and distributed storage vendors are shown in Figure 9.In this transaction, maximizing the profit of the distributed storage vendors should be first consideration.Similarly, the electricity price of power consumers to purchase electricity from two major power subjects at 12:00 p.m. is taken as an example.It can be seen from the Figure 11, the price of power consumers purchasing electricity from distributed storage vendors are higher than the price of electricity purchased from microgrid operators.That is, (p(B_D) = 0.95) >p(B_M) = 0.87).Distributed storage vendors use this bidding strategy to maximize their own interests.
From the analysis results of the example 1 and the example 2, it can be clearly seen that the near global optimum bidding strategy obtained is completely different when the objective function is different.

Pareto Near Global Optimum Scatter Diagram
In order to prove to prove that the model is a competitive game model, the Pareto near global optimum value scatter diagram generated after each iteration of the improved ant colony algorithm is shown in Figure 12.As can be seen from Figure 12, there is no Pareto near global optimum point in the areas where both microgrid operators and distributed storage vendors are high benefit, and power consumers are low-cost.The results show that interest conflict between the three types of market subjects is explained, and the objective function is contradictory.What is more, there is only a competitive game relationship among the subjects, and there is no collusion cooperation.There is no near global As can be seen from Figure 12, there is no Pareto near global optimum point in the areas where both microgrid operators and distributed storage vendors are high benefit, and power consumers are low-cost.The results show that interest conflict between the three types of market subjects is explained, and the objective function is contradictory.What is more, there is only a competitive game relationship among the subjects, and there is no collusion cooperation.There is no near global optimum bidding strategy that allows the three parties to meet the conditions in high-income and low-cost regions.In this kind of competitive game trading model, mutual restriction in the relationship among the various market subjects can be realized.In the 'decentralized' blockchain environment, it is still able to maintain market harmony and effectively eliminate the use of low cost to complete high income.Thus, the safety and reasonableness of market operations can be guaranteed, and the operational efficiency of the market can be improved.

Discussion
When the pairing of each subject in the transaction model is successful, transaction settlement link begins.The purchaser signs the electricity selling information with the private key using the public key address as the flow account of electricity using the blockchain technology.Then the purchaser uploads the signed contract to the blockchain.The electricity purchase agreement is reached between the seller and the buyer once the confirmation is completed.After that, the smart contract stage is entered.Its transaction information is recorded in the form of a Merkle tree in the blockchain.Transactions are stored in new blocks in the form of Merkle tree and linked to the end of the blockchain through security checking.The untouchable modification of the Merkle tree ensures the security and credibility of transactions.

Peer-to-Peer Network in Trading System
The peer-to-peer(P2P) network works relying on the computing power and broadband of each participant in the network.It is not controlled by only a few servers.The distributed feature of a P2P network increases the reliability of fault prevention by replicating data on multiple nodes.In addition, there will be no single point crash because the P2P network does not need to rely on a central index server to discover data.When it refers to the microgrid group trading system proposed in this paper, peer-to-peer trading is supervised by the market participants to ensure the reliability and integrity of data.

Transaction Settlement Based on Blockchain
When the buyer and the seller have reached a transaction in the microgrid electricity trading, the transaction funds need to be settled.In order to avoid the problem of untimely and unfair settlement of electricity charges, the smart contract can be used to complete the settlement of electricity charges between the buyer and the seller based on blockchain technology.The smart contract is a kind of transaction protocol that uses a computer to deal with executable contract terms.It can cooperate well with blockchain technology to realize the unification of energy flow, information flow, and capital flow in the process of power transaction [25].Figure 13 is a model of smart contract for transaction settlement of a microgrid.Its implementation steps are as follows: (1) Contract signing: Each power selling and purchasing transaction node predefines an electronic commitment, which includes the electronic signature of both subjects, the amount of electricity and virtual tokens needed by power exchanges, power trading rules, and a complete state machine.(2) Writing block: smart contracts with electronic signatures spread to the whole network through P2P in the process of transaction.After consensus verification, they are written into distributed accounts of each node in the blockchain.(3) Trigger conditions: judging whether all triggering conditions are met in power trading.
(4) Contract execution: If a power transaction meets the conditions in (3), it will be verified by pushing out of the blockchain to the queue.When it passes the verification as well as agreed by most nodes, the smart contract is activated and executed to complete the settlement of the transaction funds automatically.
(1) Contract signing: Each power selling and purchasing transaction node predefines an electronic commitment, which includes the electronic signature of both subjects, the amount of electricity and virtual tokens needed by power exchanges, power trading rules, and a complete state machine.(2) Writing block: smart contracts with electronic signatures spread to the whole network through P2P in the process of transaction.After consensus verification, they are written into distributed accounts of each node in the blockchain.(3) Trigger conditions: judging whether all triggering conditions are met in power trading.(4) Contract execution: If a power transaction meets the conditions in (3), it will be verified by pushing out of the blockchain to the queue.When it passes the verification as well as agreed by most nodes, the smart contract is activated and executed to complete the settlement of the transaction funds automatically.

Prospect
A new type of microgrid market competition game model is constructed in this paper, which realizes the power trading within the microgrid group.The model is a multi-agent and multiobjective optimization model.This paper uses ant colony algorithm to solve the model, and the correctness and rationality of the model have been verified.However, there are many other optimization algorithms besides the ant colony algorithm.In the future work, other algorithms will be chosen to solve and improve the model.
In the paper, we attempted to find the solution with the strongest global search ability, the best convergence performance, and the highest operational efficiency through comparative analysis.

Conclusions
Based on the analysis of the characteristics and structure of the blockchain technology, this paper couples microgrid group transaction and blockchain technology to establish a microgrid group information flow transaction model based on blockchain technology.By analyzing the needs of the three major types market subjects, the microgrid group physical flow transaction model is constructed, and the competition relationship and respective goals between the three subjects are

Prospect
A new type of microgrid market competition game model is constructed in this paper, which realizes the power trading within the microgrid group.The model is a multi-agent and multi-objective optimization model.This paper uses ant colony algorithm to solve the model, and the correctness and rationality of the model have been verified.However, there are many other optimization algorithms besides the ant colony In the future work, other algorithms will be chosen to solve and improve the model.
In the paper, we attempted to find the solution with the strongest global search ability, the best convergence performance, and the highest operational efficiency through comparative analysis.

Conclusions
Based on the analysis of the characteristics and structure of the blockchain technology, this paper couples microgrid group transaction and blockchain technology to establish a microgrid group information flow transaction model based on blockchain technology.By analyzing the needs of the three major types market subjects, the microgrid group physical flow transaction model is constructed, and the competition relationship and respective goals between the three subjects are fully considered.At the same time, a method based on improved ant colony algorithm for solving the microgrid group transaction model is proposed by using the decentralization feature shared by blockchain technology and ant colony algorithm.Finally, by plotting the Pareto near global optimum scatter diagram, there is a contradiction between the three, and there is obvious competition.A win-win relationship among them cannot be realized.

Figure 7 .
Figure 7. Analogy diagram of ant colony algorithm and microgrid group trading model.

Figure 7 .
Figure 7. Analogy diagram of ant colony algorithm and microgrid group trading model.

Energies 2019 ,
12,  x FOR PEER REVIEW 13 of 19 language.Also, three microgrid operators ( S MO ), two distributed storage vendors ( DS ), and three power consumers ( S PC ) are integrated to make up this system.

Figure 8 .
Figure 8. Electricity demand of various market players.

Figure 9 .
Figure 9. Electricity supply of various market subjects.In this model, set the maximum number of iterations max 100 N =( through repeated testing), the

Figure 8 .
Figure 8. Electricity demand of various market players.

Figure 8 .
Figure 8. Electricity demand of various market players.

Figure 9 .
Figure 9. Electricity supply of various market subjects.In this model, set the maximum number of iterations max 100 N =( through repeated testing), the

Figure 9 .
Figure 9. Electricity supply of various market subjects.In this model, set the maximum number of iterations N max = 100 (through repeated testing), the number of market subject n = 8, the minimum volatilization coefficient ρ min = 0.1, and the constant Q = 1.Beyond that, each subject randomly generates ant numbers in the scope of the bidding strategy m = 10 (10 kinds of bidding strategy).As the model belongs to the multigoal and multistage optimization problem, the microgrid operators and the distributed storage vendors are taken as examples to verify the feasibility of the model in this paper.Since the power consumers are similar to the microgrid operators and the distributed storage vendors, the feasibility of this model will be verified by the latter two of them.

Figure 11 .
Figure 11.Power bidding of various market subject in 24-h.

Figure 12 .
Figure 12.Pareto near global optimum scatter diagram of various subjects.

Figure 13 .
Figure 13.Model diagram of a smart contract for transaction and settlement of a microgrid

Figure 13 .
Figure 13.Model diagram of a smart contract for transaction and settlement of a microgrid respectively represent the sales volume of electricity to ith MO, jth DS, and mth PC at t time.Besides, n 1 + 1, n 2 and n 3 respectively represent the number of MO, DS, and PC.
sell(t) respectively represent the selling price of electricity to ith MO, jth DS, and mth PC at t time; similarly, q sell (t) Distributed big users are the consumers in large microgrid group systems.Its goal is to solve the energy demand problems with the minimum cost.In this paper, that entity does not have the capacity

Table 1 .
Bidding strategy interval for each type of market subject

Table 1 .
Bidding strategy interval for each type of market subject

Table 1 .
Bidding strategy interval for each type of market subject