Research on Bidding Mechanism for Power Grid with Electric Vehicles Based on Smart Contract Technology

To promote coordinated development of electric vehicles (EVs) and power grid under open power selling, a bidding mechanism using blockchain smart contract technology was proposed. By demand respone management (DRM) on and off the blockchain, based on different driving characteristics of EV subgroups, various charging–discharging demands and constraints were fully considered between EV user subgroups and agent. Purchase–sale transaction relationship and unit commitment plan were fully considered between the EV agent and power dispatching center under economic dispatching. Aiming at the lowest power purchase cost of EV users, the highest profit of EV agent and the lowest cost of power economic dispatching, smart contract models with optimal benefits were established among the three. The smart contract models were solved by combining the internal and external optimization relationship of particle swarm and genetic algorithms. The charging–discharging price was optimized by DRM to realize the reasonable allocation of charging–discharging resources of EVs. An example analysis shows that this bidding mechanism can achieve peak–cutting and valley–filling for power load. At the same time, it can effectively protect the benefits of EV users, agent, and power dispatching center. This result can provide a reference for the application of smart contract in bidding of EVs to the power grid.


Introduction
In the recent years, the opening of the electricity side and the deepening of the concept of the energy Internet have further promoted the integration of various energy systems and the allocation of plug-in energy resources [1]. A large number of distributed power generators, distributed energy storage systems, intelligent electrical equipments, and other players participate in the power market [2]. Through smart grid technology, traditional subjects have transformed from mere energy consumers into 'energy prosumers' that integrate energy production and consumption. They are capable of generating new energy, responding to power demand and participating in active distribution network [3]. Especially, in a diversified market structure, large-scale EVs with flexible charging-discharging characteristics will become an important component of smart grid construction [4].
EVs can be regarded as load when they are being charged and can be used as distributed power sources when they are idle. EVs can be connected to the grid and send the energy back to the grid by V2G (vehicle-to-grid). Appropriate charging-discharging control cannot only restrain the adverse impact of EVs on the power grid but also support peak shifting, frequency modulation, rotary standby, and other services to coordinate the development of EVs and the power grid [5]. Therefore, EV agent can act as a mediation between users and the power grid. It can facilitate centrally dispatch the achieved with the goal of minimum electricity purchase cost for the users and maximum revenue for the agent. On the other hand, the smart contract model between the agent and the power dispatching center is achieved with the aim of minimizing the load variance of the power grid and the cost of power economic dispatching. After that, the combination of particle swarm and genetic algorithm is used to realize the above two aspects of smart contract models. Then, the results are recorded in the blockchain distributed ledger. Finally, an example is given to verify the effectiveness of the bidding mechanism and DRM, which achieves economic win-win among several aspects.
The contributions and innovations of this paper are as follows: (a) Different from the traditional blockchain trading architecture with a single chain, this paper innovatively proposes the on and off chain architecture considering the applicability and bottleneck of smart contract technology. The bidding relationship among market subject is only used as the logic of contract on the chain to realize distributed trading. Off the chain, EV cluster classification and unit commitment still adopt centralized dispatching. (b) Different from the traditional centralized bidding of EVs, this paper classifies EVs with different driving characteristics in a unified cluster and adopts a different DRM. This method fully excavates the diverse charging-discharging demands of different users and provides a more real demand response for bidding in the market. (c) Based on the literatures [16,17], the traditional user-side and grid-side DRM have been extended to introduce the concept of EV agent. The smart contract interaction between EV users and agent is taken as the user side in a broad sense. The smart contract interaction between EV agent and power dispatching center is taken as the power grid side in a broad sense. On the whole, this paper will achieve economic win-win results based on the demand response of the three parties. (d) Based on the traditional EV charging bidding, the demand response and economic impact brought by discharging are considered. Moreover, a reasonable and effective bidding mechanism and algorithm are designed, which obtains better optimal scheduling and economic benefit than bidding only containing charging.

Relationship between Blockchain and Smart Contract
Blockchain is a series of data in the block list, and each block is recorded within a certain period of time based on the transaction data. This technology uses the asymmetric encryption technology between the public and private key of an account, Merckle tree data structure guaranteed by Hash algorithm, peer-to-peer distributed network architecture, consensus mechanism for building trust between blocks, and other technologies. However, smart contract was put forward earlier than blockchain, which is a computer-processed automatic trading protocol that can execute the contract terms required by each trader [18]. Due to the lack of corresponding supporting system and technology, smart contract was not previously carried out. With the birth of blockchain technology, smart contract has gained support and gradually become an important extension of blockchain technology. The two are complementary: The underlying blockchain technology provides a practical, safe, and fair platform for the application of smart contract. Smart contract provides procedural guarantee for the legal execution of a trader's rights and obligations. On the whole, it constitutes a decentralized trading system. On the premise of no third-party central institution participating, on the one hand, it fully guarantees the privacy and data security of each market subject. On the other hand, it gives all subjects a flexible and diverse smart contract logic, which can realize the maximization of resources and interests in a balanced way based on the DRM. Smart contract is mostly embedded in transaction logic with automated scripting language, which is insufficient for dealing with large-scale complex optimization problems in the power system [19]. Therefore, in order to give full play to the advantages of smart contract, this paper combines distributed transactions on the chain with centralized scheduling off the chain. Its overall framework is shown in Figure 1.
Considering driving demand, discharging compensation, and other requests, the users' layer and the agent layer reach a smart contract with the goal of minimizing the electricity purchase cost of the users and maximizing the charging-discharging profit of the agent. Considering the power grid of the company's interests in purchase-sale, unit state, and other requested information, the agent layer and the power dispatching center layer reach a smart contract with the goal of the minimum variance of power grid load and cost of power economic dispatching. Through the process of the two smart contracts reached, DRM is realized in both.
EVs are connected to the network through smart charging piles to participate in DRM, forming a data collection and classification layer off the chain. A variety of user subgroups are formed based on the remaining power of EVs and the driving time of users. Then, corresponding smart contracts are reached with the agent in turn. According to the power generation plan issued by the power dispatching center on the chain, the operation state of units is dispatched centrally to participate in DRM, forming the unit commitment layer off the chain.  On the whole, the optimal scheduling load containing EV charging-discharging resources is embedded between each market subject and on-off the hierarchy of blockchain. With EV charging-discharging electricity price as the economic dispatching lever, smart contracts containing charging-discharging contract volume and price information are mutually achieved as the result of DRM. The corresponding transactions of charging-discharging resource are automatically executed and recorded in the underlying blockchain distributed ledger to form a mutually agreed, tamper-proof, secure, and transparent block data structure. From on to off, this framework realizes the dynamic balance of supply-demand DRM and guarantees the security, trust, and transparency of the whole bidding process. Market subjects participate in the transaction mechanism on the chain including EV users, agent, and power dispatching center. They form independent node layers in the blockchain, and then form a point-to-point distributed transaction network as each node layer. Each market subject, according to their own interest, requests to the blockchain network trading pool based on the node that contains encrypted information such as IP address, public key, and private key [20]. Considering driving demand, discharging compensation, and other requests, the users' layer and the agent layer reach a smart contract with the goal of minimizing the electricity purchase cost of the users and maximizing the charging-discharging profit of the agent. Considering the power grid of the company's interests in purchase-sale, unit state, and other requested information, the agent layer and the power dispatching center layer reach a smart contract with the goal of the minimum variance of power grid load and cost of power economic dispatching. Through the process of the two smart contracts reached, DRM is realized in both.

Classification Method of EVs
EVs are connected to the network through smart charging piles to participate in DRM, forming a data collection and classification layer off the chain. A variety of user subgroups are formed based on the remaining power of EVs and the driving time of users. Then, corresponding smart contracts are reached with the agent in turn. According to the power generation plan issued by the power dispatching center on the chain, the operation state of units is dispatched centrally to participate in DRM, forming the unit commitment layer off the chain.
On the whole, the optimal scheduling load containing EV charging-discharging resources is embedded between each market subject and on-off the hierarchy of blockchain. With EV charging-discharging electricity price as the economic dispatching lever, smart contracts containing charging-discharging contract volume and price information are mutually achieved as the result of DRM. The corresponding transactions of charging-discharging resource are automatically executed and recorded in the underlying blockchain distributed ledger to form a mutually agreed, tamper-proof, secure, and transparent block data structure. From on to off, this framework realizes the dynamic balance of supply-demand DRM and guarantees the security, trust, and transparency of the whole bidding process.

Classification Method of EVs
EVs with different driving characteristics have different charging-discharging demand. If similar charging-discharging control is carried out on large-scale EVs one by one, it will not only fail to provide personalized scheduling for users with different electricity demands, but also cause a computational dimension disaster [21]. Therefore, it is particularly important to make a reasonable classification and scheduling system.
The randomness of a single EV is strong, but the driving characteristics of a large number of EVs are regular. The travel rule of the users is the moment when the EVs are connected and detached from the charging piles, which determines the schedulable duration and the time when the EVs start dispatching. Meanwhile, the initial state of charge (SOC) also has a key impact on the charging-discharging. Therefore, this paper takes the time for EVs to access and leave the charging piles as a clustering feature, and takes EVs with similar SOC as another classification standard. Finally, charging piles connected to EVs with similar driving characteristics will be taken as the unified user node to integrate large-scale charging-discharging resources. Thus, users can participate in the realization of the agent's smart contracts and optimal scheduling.

Constraints of EV Users
In the process of reaching smart contracts with the agent, users should first consider different constraints of each user subgroup to match different demand responses. Its specific analysis is as follows.
1. Constraints of users travel demand.
where, S need (k, i) is the power demand SOC of the vehicle i in the user subgroup k; S exp,min and S exp,max are the minimum and maximum power demand SOC expected by the users, respectively.
where, x(k, i, t) is the charging-discharging state of the vehicle i in the user subgroup k in time period t: 1 is charging and 0 is idle and −1 is discharging; T s (k, i) and T e (k, i) are respectively the starting and ending scheduling time of the vehicle i in the user subgroup k, namely the time when the EVs arrive and leave the charging piles.
where, t ∈ [T s (k, i), T e (k, i)]; S(k, i, t) is the SOC of the vehicle i in the user subgroup k at the end of time period t;p ch (k, i, t) and p dc (k, i, t) are the charging and discharging power of the vehicle i in the Energies 2020, 13, 390 6 of 17 user subgroup k in time period t, respectively; B is the capacity of the battery; ∆t is the length of a scheduling period.

Analysis of Demand Contract for EV Users
Users mainly buy electricity volume from power grid company through an agent. The battery will be charged and discharged several times, which will cause additional cost. Its specific analysis is as follows.
1. Cost of electricity purchasing for users.
where, C AtoU buy (k) is the purchasing power cost of the user subgroup k from the agent; T ev is the total number of scheduling hours in a day; W ch (t) is the contract charging price within time period t; N k is the number of EVs in the user subgroup k.

Cost of battery loss for users.
where, C U loss (k) is the battery loss cost of the user subgroup k; W loss (t) is the unit loss cost of the battery in time period t; p dch (k, i, t) is the charging or discharging power of the vehicle i in the user subgroup k in time period t.
3. Employment cost of the agent entrusted by the users.
where, C UtoA agent (k) is the cost of hiring agent for the user subgroup k; W agent is the dispatch hire fee that the users gives the agent per vehicle.

Analysis of Demand Contract for EV Agent
As the intermediate layer, the agent purchases the electricity demand on behalf of the users and feeds the volume back to the grid under certain constraints to obtain part of the discharging revenue. At the same time, the cost of energy storage and operation should be considered. Therefore, the users should be compensated economically for the discharging part. Its specific analysis is as follows.
where, R AtoG sell (k) is the agent's revenue from discharging electricity into the grid through the user subgroup k; W dc (t) is the contract discharging price within time period t. where, C A run (k) is the energy storage and operation cost of agent after purchasing electricity for the user subgroup k; W run (t) is the unit cost of energy storage and operation of agent after purchasing electricity in time period t.

Energy storage and operation cost of agent.
3. Discharging compensation of agent.
where, C AtoU comp (k) is the agent's discharging compensation for the user subgroup k; W comp (t) is the unit compensation of discharging within time period t.

Analysis of Target Contract
In order to fully mobilize the enthusiasm of users, a certain proportion of profit sharing is introduced between the agent and the users' target contract. Therefore, both parties can develop a flexible benefit distribution plan while maximizing the benefits. Its specific analysis is as follows.
1. Target contract of agent.
where, R A total (k) is the agent's total revenue to the user subgroup k; r is the profit sharing proportion that the agent gives to the users. If the agent loses money, there will be no profit sharing.
2. Target contract of users.
where, C U total (k) is the total power purchase cost of the user subgroup k; R AtoU bonus (k) is the profit sharing that the agent gives to the user subgroup k.

Analysis of Target Contract
Agent integrates the users' various demands and interacts with the power grid through the power dispatching center. The goal of the power dispatching center is to optimize the power grid load and the power grid company's interests.
The charging-discharging resources of the EVs can not only be used as an important scheme for load peak-cutting and valley-filling, but also provide flexible dispatching response for the unit commitment under load optimization. This mechanism can reduce the cost of system operation, and realize the optimal cost of the whole economic dispatching. The specific analysis is as follows.
1. Target contract 1 of power dispatching center.
Take the minimum variance of power grid load as the target contract: where, D load (k) is the grid load variance containing the user subgroup k; P base (t) is the load value of the basic power grid excluding EVs in time period t; P av is the average load value of the grid containing EVs in the total time period.
2. Target contract 2 of power dispatching center.
On the one hand, the power dispatching center protects the interests of the power grid company and agent from being damaged. On the other hand, by assigning a power generation load plan, it minimizes the increased cost of unit commitment due to the entry of EVs into the network. It will achieve the optimal cost of overall economic dispatching. In order to simplify the model and highlight the transactions on the distribution side of blockchain, the electricity purchase cost of the power grid company from the power generation market is simplified. It is expressed as the increased cost because of the unit commitment in the analysis off the chain, regardless of the specific relationship between the units and the power grid company.
Taking the lowest cost of power economic dispatching as the target contract, that is where, C E is cost of the whole power economic dispatching; C G is the unit commitment cost of the power system excluding EVs; C G is the unit commitment cost of the power system containing EVs; C AtoG buy (k) is the cost of the grid company by purchasing discharging volume from the user subgroup k through the agent; R GtoA sell (k) is the revenue of the grid company by selling the charging volume to the user subgroup k through the agent.

Analysis of Demand Contract
The unit commitment layer of the blockchain is extended based on the traditional unit commitment model [22]. According to the load generation plan issued by the power dispatching center, the model of centralized optimal dispatching of each unit is adopted. The cost of unit commitment containing EVs is expressed as where, C G is the system total cost of the unit commitment, consisting of fuel cost and startup cost; T uc is the total optimization time of the unit commitment; N G is the number of thermal power units involved in optimization; F j [Y j (t)] is the fuel cost function of the unit j. Y j (t) is the unit output of the unit j in the time period t; a j , b j , c j is the fuel cost coefficient of the unit j; S j is the startup cost of the unit j, which consists of hot start cost and cold start cost; T Loff where, P ch (t) and P dc (t) are the total charging and discharging loads of all EVs in time period t, respectively.
2. Constraints of system reserve.
where, Y max j (t) is the maximum output of unit j in the time period t; Q(t) is the standby demand of the system in time period t.
3. Constraints of unit output.
where, Y min j (t) is the minimum output of the unit j in time period t. 4. Constraints of unit downtime.
where, T Aon j (t) and T Aoff j (t) respectively represents the cumulative startup time and shutdown time of the unit j in time period t; T Mon j is the allowed minimum running time of unit j.

Solution of Smart Contract Model
Firstly, k-means algorithm and quartile method are used to cluster the travel time of users, and the initial residual power of EVs is classified. The user subgroups with different driving characteristics are formed. Then, particle swarm optimization is used as the outer layer optimization and genetic algorithm as the inner layer optimization to solve the smart contract models. Each chromosome represents the volume of electricity left in each vehicle in a user subgroup. The inner layer algorithm first optimizes the residual power of each user subgroup one by one to obtain the optimal charging-discharging control state. What's more, based on the optimization results of the inner layer, the outer layer algorithm optimizes the overall charging-discharging electricity price and unit commitment. So that the market subjects can reach a smart contract with each other. The specific solution process is shown in Figure 2.
Among them, the transaction information in the three objective functions of agent, user benefit maximization, and grid load variance minimization influence each other. In order to achieve comprehensive optimization, this paper adopts a linear weighting method to convert multi-objective functions into a single-objective function. Due to the different dimensions between the objective functions, normalization is required: Energies 2020, 13, 390 10 of 17 where, O(k) is the single objective function of the user subgroup k after multi-objective normalization.
In order to highlight the advantages of the scheduling in this paper, the corresponding characteristics of unordered charging are taken as the normalized proportional objects. C U uc (k) is the purchase cost of electricity when the user subgroup k is unordered charging without agent. D uc (k) is the grid load value when the user subgroup k is unordered charging. λ 1 , λ 2 , and λ 3 are the weight coefficients of each objective function, respectively, indicating the degree of relative importance, meeting λ 1 + λ 2 + λ 3 = 1, λ m > 0(m = 1, 2, 3).

Results and Discussion
The deployment and application of smart contracts are mostly based on Ethereum, Hyperledger, and other blockchain development platforms. As a distributed ledger data architecture, blockchain technology is packaged at the bottom of the platform to support the embedding of smart contracts with various logics [23]. Based on the overall framework of smart contracts in blockchain, this example uses Matlab to verify the effectiveness and feasibility of the EVs into bidding mechanism under the realization of smart contracts. This mechanism illustrates the advantages of realizing the logic of the smart contracts designed in this paper.

The Example Data
Based on the statistical results of the 2017 national household travel survey [24], this paper extracts the starting time, ending time, and daily mileage of private cars in a day to study the random driving characteristics of EVs. Making the following assumptions:

•
The total number of cars is 1 million, and the penetration rate of EVs is 5%. All users participate in day-ahead market bidding through the V2G dispatching of agent. Specific EV parameters are shown in Table 1.

Results and Discussion
The deployment and application of smart contracts are mostly based on Ethereum, Hyperledger, and other blockchain development platforms. As a distributed ledger data architecture, blockchain technology is packaged at the bottom of the platform to support the embedding of smart contracts with various logics [23]. Based on the overall framework of smart contracts in blockchain, this example uses Matlab to verify the effectiveness and feasibility of the EVs into bidding mechanism under the realization of smart contracts. This mechanism illustrates the advantages of realizing the logic of the smart contracts designed in this paper.

The Example Data
Based on the statistical results of the 2017 national household travel survey [24], this paper extracts the starting time, ending time, and daily mileage of private cars in a day to study the random driving characteristics of EVs. Making the following assumptions:

•
The total number of cars is 1 million, and the penetration rate of EVs is 5%. All users participate in day-ahead market bidding through the V2G dispatching of agent. Specific EV parameters are shown in Table 1.

•
The ending and starting time of the user's travel is taken as the starting and ending time of the schedule. EVs are charged once a day. Also, 15 min is one dispatching period, and 1 h is one electricity price period. Peak-valley time-of-use price without EV bidding is shown in Table 2.
The range of charging price containing bidding of EV is shown in Table 3. Considering the cost of storage, transportation, and loss of energy, the discharging price range is 1.3 times of the charging price range [25].

•
According to the charging-discharging power, the agent pays CNY 0.5/(kW·h) for the unit discharging compensation. According to the charging-discharging depth of the EVs in this example, the unit loss cost of the battery is CNY 0.14/(kW·h) [26]. The unit energy storage and operation cost of the agent is CNY 0.1/(kW·h).

•
The profit sharing ratio given by agent to users is 0.1; the employment fee provided by the users to the agent is CNY 0.1/one vehicle/a day.

•
Since the smart contract relationship is based on the flexible charging-discharging resources, the optimal scheduling control based on the total load peak-cutting and valley-filling is particularly important. The weight coefficients of the three objective functions in the smart contracts between the users and the agent are λ 1 = λ 2 = 0.25, λ 3 = 0.5: Objective functions of users and agent have the same importance; the target with the smallest load variance is the most important. • The power system units are composed of 10 thermal power units, and detailed parameters are shown in [27]. The base load of the grid excluding EVs is shown in Figure 3. The ending and starting time of the user's travel is taken as the starting and ending time of the schedule. EVs are charged once a day. Also, 15 min is one dispatching period, and 1 h is one electricity price period. Peak-valley time-of-use price without EV bidding is shown in Table 2.
The range of charging price containing bidding of EV is shown in Table 3. Considering the cost of storage, transportation, and loss of energy, the discharging price range is 1.3 times of the charging price range [25].  According to the charging-discharging power, the agent pays CNY 0.5/(kW·h) for the unit discharging compensation. According to the charging-discharging depth of the EVs in this example, the unit loss cost of the battery is CNY 0.14/(kW·h) [26]. The unit energy storage and operation cost of the agent is CNY 0.1/(kW·h).

•
The profit sharing ratio given by agent to users is 0.1; the employment fee provided by the users to the agent is CNY 0.1/one vehicle/a day.

•
Since the smart contract relationship is based on the flexible charging-discharging resources, the optimal scheduling control based on the total load peak-cutting and valley-filling is particularly important. The weight coefficients of the three objective functions in the smart contracts between the users and the agent are λ1 = λ2 = 0.25, λ3 = 0.5: Objective functions of users and agent have the same importance; the target with the smallest load variance is the most important. • The power system units are composed of 10 thermal power units, and detailed parameters are shown in [27]. The base load of the grid excluding EVs is shown in Figure 3.

Results of Smart Contract between EV Users and Agent
The k-means clustering method is adopted to cluster 3 main clusters at the time when the users start scheduling and end scheduling. The final clustering centers are shown in Table 4. The number of main clusters accounts for 30%, 20%, and 50% of the total number, respectively. The initial SOC of EVs is divided into four subclusters by the quartile method from low to high. Therefore, the whole EVs are divided into 12 user subgroups. Based on the travel rules of different users and different initial SOC, smart contracts are reached with the agent according to demands of subgroups. All four subclusters in main cluster 3 are taken as an example, and the contract charging-discharging volume reached at each moment is shown in Figure 4.

Results of Smart Contract between EV Users and Agent
The k-means clustering method is adopted to cluster 3 main clusters at the time when the users start scheduling and end scheduling. The final clustering centers are shown in Table 4. The number of main clusters accounts for 30%, 20%, and 50% of the total number, respectively. The initial SOC of EVs is divided into four subclusters by the quartile method from low to high. Therefore, the whole EVs are divided into 12 user subgroups. Based on the travel rules of different users and different initial SOC, smart contracts are reached with the agent according to demands of subgroups. All four subclusters in main cluster 3 are taken as an example, and the contract charging-discharging volume reached at each moment is shown in Figure 4. According to Figure 4, it describes the starting and ending moment of the charging-discharging schedule of the EVs on the whole. The charging-discharging scheduling period of this main cluster is about from 7:00 p.m. to 8:00 a.m. on the next day. Since this is an example by main cluster 3, its starting and ending scheduling moment are consistent with the final cluster results of main cluster 3, as shown in Table 4: Final cluster center of starting time of scheduling is 19.03 h, and final cluster center of ending time of scheduling is 7.60 h.
In specific analysis, charging period is mainly from the early morning to the time before starting travel, and discharging period is concentrated around 9:00 p.m. Due to the volume of residual power of each subcluster, the subcluster 1 has less residual power. So, it charges more but discharges less power. Subcluster 4, on the contrary, has the largest volume of electricity remaining and shows the opposite charging-discharging behavior. The analysis of the rest of the subclusters are similar and will not be repeated.

Results of Smart Contract between EV Agent and Power Dispatching Center
The charging-discharging volume and price reached by the agent and the power dispatching center at each moment are shown in Figure 5. According to Figure 4, it describes the starting and ending moment of the charging-discharging schedule of the EVs on the whole. The charging-discharging scheduling period of this main cluster is about from 7:00 p.m. to 8:00 a.m. on the next day. Since this is an example by main cluster 3, its starting and ending scheduling moment are consistent with the final cluster results of main cluster 3, as shown in Table 4: Final cluster center of starting time of scheduling is 19.03 h, and final cluster center of ending time of scheduling is 7.60 h.
In specific analysis, charging period is mainly from the early morning to the time before starting travel, and discharging period is concentrated around 9:00 p.m. Due to the volume of residual power of each subcluster, the subcluster 1 has less residual power. So, it charges more but discharges less power. Subcluster 4, on the contrary, has the largest volume of electricity remaining and shows the opposite charging-discharging behavior. The analysis of the rest of the subclusters are similar and will not be repeated.

Results of Smart Contract between EV Agent and Power Dispatching Center
The charging-discharging volume and price reached by the agent and the power dispatching center at each moment are shown in Figure 5. As can be seen from Figure 5, the agent mainly controls charging during the trough of periods of load and electricity price. The optimized contract charging price reduces the initial electricity price as a whole. Discharging control is mainly carried out in peak hours of load and electricity price. In particular, high contract discharging price is achieved in peak hours of load to obtain optimal discharging benefits.
Based on the result of contract price, the power grid load under price DRM by dispatching the EVs through the agent is shown in Figure 6. Unordered charging refers to charging immediately after the users arrive at the charging piles at random until the expected charging volume is reached. Orderly charging means that users do not charge when the electricity price is high, and charge when the electricity price is low, until the expected charging volume is reached. Moreover, there is no discharging scheduling for orderly charging. As can be seen from Figure 6, in the case of unordered charging, users randomly charge according to their travel demands. This can lead to the phenomenon of 'peak on peak', and aggravate the burden of scheduling. In the case of orderly charging, the charging time is controlled in an orderly manner based on the electricity price. When participating in power grid interaction based on the scheduling strategy in this paper, it not only has a more obvious peak-cutting and valley-filling effect than orderly charging, but also has a certain power feedback during the peak load periods of the power grid. As a result, this can make the total load of the power grid smoother. Since the users and the agent first need to meet the driving demands in the daytime when they reach the smart contract, the effect of load peak-cutting in the daytime is not as good as that of filling in the valley at night. Especially in the afternoon, some users still carry out charging in the peak As can be seen from Figure 5, the agent mainly controls charging during the trough of periods of load and electricity price. The optimized contract charging price reduces the initial electricity price as a whole. Discharging control is mainly carried out in peak hours of load and electricity price. In particular, high contract discharging price is achieved in peak hours of load to obtain optimal discharging benefits.
Based on the result of contract price, the power grid load under price DRM by dispatching the EVs through the agent is shown in Figure 6. Unordered charging refers to charging immediately after the users arrive at the charging piles at random until the expected charging volume is reached. Orderly charging means that users do not charge when the electricity price is high, and charge when the electricity price is low, until the expected charging volume is reached. Moreover, there is no discharging scheduling for orderly charging. As can be seen from Figure 5, the agent mainly controls charging during the trough of periods of load and electricity price. The optimized contract charging price reduces the initial electricity price as a whole. Discharging control is mainly carried out in peak hours of load and electricity price. In particular, high contract discharging price is achieved in peak hours of load to obtain optimal discharging benefits.
Based on the result of contract price, the power grid load under price DRM by dispatching the EVs through the agent is shown in Figure 6. Unordered charging refers to charging immediately after the users arrive at the charging piles at random until the expected charging volume is reached. Orderly charging means that users do not charge when the electricity price is high, and charge when the electricity price is low, until the expected charging volume is reached. Moreover, there is no discharging scheduling for orderly charging. As can be seen from Figure 6, in the case of unordered charging, users randomly charge according to their travel demands. This can lead to the phenomenon of 'peak on peak', and aggravate the burden of scheduling. In the case of orderly charging, the charging time is controlled in an orderly manner based on the electricity price. When participating in power grid interaction based on the scheduling strategy in this paper, it not only has a more obvious peak-cutting and valley-filling effect than orderly charging, but also has a certain power feedback during the peak load periods of the power grid. As a result, this can make the total load of the power grid smoother. Since the users and the agent first need to meet the driving demands in the daytime when they reach the smart contract, the effect of load peak-cutting in the daytime is not as good as that of filling in the valley at night. Especially in the afternoon, some users still carry out charging in the peak As can be seen from Figure 6, in the case of unordered charging, users randomly charge according to their travel demands. This can lead to the phenomenon of 'peak on peak', and aggravate the burden of scheduling. In the case of orderly charging, the charging time is controlled in an orderly manner based on the electricity price. When participating in power grid interaction based on the scheduling strategy in this paper, it not only has a more obvious peak-cutting and valley-filling effect than orderly Energies 2020, 13, 390 14 of 17 charging, but also has a certain power feedback during the peak load periods of the power grid. As a result, this can make the total load of the power grid smoother. Since the users and the agent first need to meet the driving demands in the daytime when they reach the smart contract, the effect of load peak-cutting in the daytime is not as good as that of filling in the valley at night. Especially in the afternoon, some users still carry out charging in the peak periods of electricity price and load to meet their own electricity demand.

Analysis of Economic Benefits of Market Subjects
The optimal interests of each market subject under different scheduling strategies are shown in Table 5. As can be seen from Table 5, although the agent's participation in the charging-discharging scheduling control increases the battery loss of users, the total cost of users is reduced on the whole. It is because of the economic regulation and DRM such as discharging compensation and profit sharing. At the same time, the agent also gains certain benefits through the price difference of electricity purchase-sale. The power grid company based on dispatching plan purchases the discharging volume from EVs in peak periods, which increases the cost of electricity purchasing. However, the flexible charging-discharging resources provide additional effective dispatching means for the unit commitment. This mechanism greatly reduces the expenses of startup and shutdown, and achieves the optimal cost of economic dispatching. In conclusion, the bidding trading mechanism designed in this paper effectively achieves a win-win situation among users, agent, and the power dispatching center.

Conclusions and Future Work
This paper introduces the blockchain technology into the bidding mechanism of EVs. This paper combines the distributed transaction on the chain with the centralized dispatching off the chain. Then, a win-win bidding mechanism among EV users, agent, and power dispatching center is established: Off the chain, the EVs classification layer and unit commitment layer interact with the information through DRM; on the chain, smart contracts are reached among market subjects considering their respective demands and interests. On the premise of eliminating the risk of third-party data storage, this mechanism can fully allocate EV charging-discharging resources to participate in market bidding. The distributed ledger of the blockchain guarantees tamper-proof, transparent, and traceable data. An example analysis shows that the results of contract price and volume under bidding can be used as a way of DRM. The result of the contract charging price reduces the price excluding charging-discharging of EVs by about CNY 0.07/(kW·h). For the economic benefits, the economic dispatching cost is about CNY 36 ten thousand and CNY 84 ten thousand less than that under the orderly and disordered strategy; the cost of purchasing power for users is about CNY 5 ten thousand and CNY 49 ten thousand yuan less than that under the orderly and disordered strategy; compared with other strategies, the agent can gain an additional profit of about CNY 13 ten thousand. In all, the results not only provide flexible and effective optimal scheduling for power grid peak-cutting and valley-filling, but also achieve economic win-win for all market subjects.
In the simulation implementation of this paper, only an example is used to verify the smart contract mechanism among market subjects. The mechanism proposed in this paper is not built in the real blockchain environment. The verification of blockchain in transaction efficiency, security, applicability, and other aspects needs to be further explored. Therefore, in the future work, it is worthwhile to further study the bidding and trading mechanism including V2G in the blockchain Ethereum, so as to expand the applicability of this mechanism.
Author Contributions: B.W. and W.L. contributed to paper writing and the whole revision process. M.W. built the simulation model and analyzed the data. W.S. helped organize the article. All authors have read and agreed to the published version of the manuscript.
Funding: This research was funded by the National Natural Science Foundation of China (51777058) and 'Six talent peaks' high-level project in Jiangsu province (xny-010).

Conflicts of Interest:
The authors declare no conflict of interest.

Constants: B
capacity of the battery ∆t length of a scheduling period T ev total number of scheduling hours in a day r profit sharing proportion that the agent gives to the users λ 1 , λ 2 , λ 3 weight coefficients of each objective function respectively Variables: S need (k, i) the power demand SOC of the vehicle i in the user subgroup k S exp,min , the minimum and maximum power demand SOC expected by the users S exp,max x(k, i, t) Charging-discharging state of the vehicle i in the user subgroup k in time period t T s (k, i) the starting and ending scheduling time of the vehicle i in the user subgroup k T e (k, i) S(k, i, t) SOC of the vehicle i in the user subgroup k at the end of time period t p ch (k, i, t), charging and discharging power of the vehicle i in the user subgroup k in period t p dc (k, i, t) C AtoU buy (k) purchasing power cost from the agent for the user subgroup k W ch (t) contract charging price within time period t N k number of EVs in the user subgroup k C U loss (k) battery loss cost of the user subgroup k W loss (t) unit loss cost of the battery in time period t p dch (k, i, t) charging or discharging power of the vehicle i in the user subgroup k in period t C UtoA agent (k) cost of hiring agent for the user subgroup k W agent dispatch hire fee that the users gives the agent per vehicle R AtoG sell (k) agent's revenue by discharging power into the grid through the user subgroup k W dc (t) contract discharging price within time period t C A run (k) energy storage and operation cost of agent for the user subgroup k W run (t) unit cost of energy storage and operation of agent in time period t C AtoU comp (k) agent's discharging compensation fee for the user subgroup k W comp (t) unit compensation cost of discharging within time period t R A total (k) agent's total revenue to the user subgroup k C U total (k) total power purchase cost of the user subgroup k R AtoU bonus (k) profit sharing that the agent gives to the user subgroup k D load (k) grid load variance containing the user subgroup k P base (t) load value of the basic power grid excluding EVs in time period t P av average load value of the grid containing EVs in the total time period C E cost of the whole power economic dispatching C G unit commitment cost of the power system excluding EVs C G unit commitment cost of the power system containing EVs C AtoG buy (k) cost of grid company by purchasing discharging volume from the user subgroup k R GtoA sell (k) revenue of grid company by selling charging volume to the user subgroup k C G system total cost of the unit commitment T uc total optimization time of the unit commitment N G number of thermal power units involved in optimization F j [Y j (t)] fuel cost function of the unit j Y j (t) unit output of the unit j in the time period t a j , b j , c j fuel cost coefficient of the unit j S j startup cost of the unit j T Loff j continuous outage time before starting unit j T Moff j allowed minimum stop time of the unit j T cold j cold start time of the unit j I j (t) binary integer variable of the unit j in the on-off state during the time period t P ch (t), total charging and discharging loads of all EVs in time period t P dc (t) Y min j (t), the minimum and maximum output of unit j in the time period t Y max j (t) standby demand of the system in time period t T Aon j (t), cumulative startup and shutdown time of the unit j in time period t T Aoff single objective function of the user subgroup k after multi-objective normalization C U uc (k) purchasing cost of power when the user subgroup k is unordered charging D uc (k) grid load value when the user subgroup k is unordered charging