1 Introduction

As our awareness about energy and the environment grows, the demand for a reliable and sustainable power grid and the need for high-quality and stable resources have led to the evolution of smart grids as novel means of electricity distribution [1, 2]. In particular, widespread blackouts in parts of the north-eastern United States and eastern Canada in 2003 attracted more attention to the development of smart grids in many countries [1]. Smart grids are the systems with complex structure and extensive stakeholders. The idea behind smart grids is to improve the efficiency of power system, from generation to end-users, which enables user participation [3]. Power supply-side management and demand-side management are the main problems in the research on smart grids. Power supply-side management refers to the management issues in traditional power systems. Demand-side management is a new research area in smart grids and aims to improve terminal power efficiency, change client electro-mode, optimize resource allocation, and realize minimum-cost power service. Demand-side management is a research focus on smart grids [4].

The deployment of communication infrastructure and intelligent devices in smart grids is associated with the concept of demand response (DR), which is a cost-effective method for reducing energy prices [5]. DR enables demand-side activities to balance the power supply and demand. In smart grids, smart meters transmit the power price and consumption information of electricity equipment to users, to better control electricity consumption and cost; the relevant information is sent to the power provider for load control and price setting [6]. Thus, DR programs are key elements in determining demand-side activities in future smart grids. These DR programs concentrate on shifting consumption from peak to off-peak periods to reduce the pressure on utility-handled equipment such as distribution transformers and power lines and valuable resources for the effective operation of smart grid structures [7, 8]. DR in demand-side management can be divided into two categories: incentive response mechanisms and price response mechanisms. Among them, the price response mechanisms refer to the load transfer or reduction behavior of the user in response to the real-time change of the electricity price. It saves electricity costs and is more feasible [9, 10]. In recent years, many scholars and researchers have studied the DR problem in smart grids and obtained considerable achievements. Parvania et al [11] presented a stochastic DR model based on two-stage stochastic mixed integer programming in the wholesale electricity market. Chai et al [12] studied the DR problem in systems with multiple utility companies and multiple residential customers, while Deng et al [13] proposed a distributed real-time DR algorithm that determines each user’s demand and each utility company’s supply. These studies are concerned with DR programs and their role in the analysis of power system operations. Haider et al [14] proposed an adaptive consumption-level DR pricing scheme, which can be used to easily implement DR. Dai et al [15] analyzed a supply–demand equilibrium model with many power providers using game theory, and Juan et al [16] examined the role and influence of voluntary real-time pricing in Spain. Asadi et al [17] proposed a method for determining real-time pricing using a welfare maximization model based on DR. The main work of the real-time pricing method based on the social welfare maximization model is to compute the shadow price (i.e., the Lagrange multiplier of an optimization problem). The demonstration proves that reasonable pricing can encourage users to actively participate in DR and is effective in shifting consumption from peak to off-peak periods and reducing the pressure on utility-handled equipment [18,19,20,21,22,23]. The government or power companies can set electricity or guidance prices based on the shadow price. In this paper, we study real-time pricing based on the social welfare maximization model.

The dual optimization method is an important method, which solves not only the decision variables of the optimization problem but also the Lagrange multiplier. Hence, the dual method is used to solve the real-time pricing problem based on the social welfare maximization model. Asadi et al [17] developed a particle swarm optimization algorithm to determine real-time pricing for smart grids, whereas Zhu et al [21] solved the real-time pricing problem using a simulated annealing algorithm. Song et al [22] applied the gradient projection method to the problem of real-time pricing, and Wang et al [23] used a distributed online algorithm to determine energy distribution in smart grids. The above techniques are based on the dual optimization method, whereby a shadow price which is Lagrange multiplier, is used to determine the basic price of electricity. The social welfare maximization model is divided into two sub-problems in the dual optimization method. One sub-problem is that users determine their intended electricity consumption based on a reference price provided by power companies. Another sub-problem is related to the electricity price and quantity of electricity produced, in which the power companies find that the quantity of electricity produced depends on the price. The price provided by power companies, is the Lagrange multipliers in the dual optimization method. Although the dual optimization method solves the price problem (i.e. Lagrange multiplier in the real-time pricing problem), the following problems still need further study.

  1. 1)

    The computation speed is slow. Real-time pricing is short-term and the algorithm needs to respond quickly. The dual optimization method is a minimax problem, which is suited to solving small-scale problems. In the social welfare maximization model, each user’s electricity consumption is a variable, and the scale of the problem is large. Hence, the dual optimization method cannot guarantee the computation speed, and it is difficult to achieve a quick response [17].

  2. 2)

    The accuracy is low. Although the Lagrange multiplier can be computed by the dual optimization method, they are obtained as a byproduct. The multiplier and the decision variable are not equal during the execution of the algorithm. The numerical accuracy of the decision variables is focused, but that of the multiplier is not high in the dual optimization method. However, the Lagrange multiplier is the electricity price we want to determine [21,22,23].

To solve these problems, we propose a complementarity method, which contains the Lagrange multiplier. First, based on the social welfare maximization model, a Karush-Kuhn-Tucker (KKT) condition is established. This system is a complementarity problem, which contains the multiplier and the decision variables. Then a Jacobian smoothing Newton method is used to solve the KKT condition and get the electricity price. The advantage of the proposed approach is that the computing speed and numerical accuracy of the associated algorithms is dramatically improved. Moreover, both the multiplier and decision variables play the same role in the algorithm. Further, convergence of Newton method has been proven, which further ensures the accuracy of the numerical results. In addition, we consider three types of users, i.e. residential users, commercial users, and industrial users. They are all important players in the electricity market, which have a great impact on the research. Residential electricity is used in household appliances for residential life, consumption is low, and prices have been low for a long time. Industrial and commercial electricity demands are large, and electrical energy requirements are higher than residential requirements. Since the price is an equilibrium price under multi-user conditions, if the electricity consumption gaps between different users are large, the equilibrium price for the user with lower power consumption is unfair. Therefore, it is more reasonable to consider the price and generation capacities separately for different types of users. In the proposed method, we consider multi-price and utility functions for different type of users, and perform simulation verification.

The remainder of this paper is organized as follows. In Section 2, we briefly describe the social welfare model. In Section 3, the real-time pricing problem is established with a KKT condition, and the Jacobian smoothing Newton method is presented. Finally, simulation results are presented and discussed in Section 4.

2 Social welfare model

Similar to [24], the intended time cycle for the operation of users is divided into \({\Gamma}\) time and \({\Gamma} =\{1, 2, ..., T\}\), is the set of all time slots. This division can be based on the behavior of all the users and their power demand pattern, peak load time slots, valley load time slots and normal load time slots. Denoting \({\mathcal{N}} = \left\{ {1,2, \cdots ,N} \right\}\) as the set of users requiring electricity, each user \(i \in {\mathcal{N}}\) requires a certain amount of electricity for his/her electrical appliances. Denoting \(x_{i}^{t}\) as the electricity consumption demand of residential user \(i\), \(y_{j}^{t}\) as the electricity consumption demand of commercial user \(j\), and \(z_{k}^{t}\) as the electricity consumption demand of industrial user \(k\) in time slot \(t\). The electricity consumption for each user and each time slot is bounded which is in \([m_{i}^{t} , M_{i}^{t}], i \in {\mathcal{N}}\). Here, the minimum electricity consumption level \(m_{i}^{t}\) represents the load from the appliances which are always required to be on during the day, and the maximum electricity consumption level \(M_{i}^{t}\) represents the total power consumption level of the appliances assuming they are all on. Denoting \(L_{t}^{x}\) as the generation capacity for residential user, \(L_{t}^{y}\) as the generation capacity for commercial user, \(L_{t}^{z}\) as the generation capacity for industrial user, and \(L_{t} = L_{t}^{x} + L_{t}^{y} + L_{t}^{z}\) as the total generation capacity in time slot \(t\). The electricity provider must provide the generation capacity to cover minimum and maximum electricity requirements of all the users, i.e., \(L_{t}^{\hbox{min} } = \sum\limits_{i = 1}^{N} {m_{i}^{t} }\) and \(L_{t}^{\hbox{max} } = \sum\limits_{i = 1}^{N} {M_{i}^{t} }\).

2.1 Utility function

Utility functions are often used in microeconomics as a measure of the requirements and desires of a customer based on their consumption or leisure activities. These functions represent the relationship between the consuming utility and the number of a commodity. They are usually increasing concave functions that satisfy:

  1. 1)

    An increasing function: \(\frac{\partial U}{\partial x} \ge 0\);

  2. 2)

    A decreasing marginal function: \(\frac{{\partial^{2} U}}{{\partial^{2} x}} \le 0\).

Where \(U( \cdot )\) is an utility function. When these two conditions are satisfied, the utility function increases with the consumption and is the maximum at the boundary. In previous studies, researchers adopted quadratic or logarithmic functions as the utility function [17,18,19,20,21,22,23]. Because the electricity requirements and desires are different for residential, industrial, and commercial users, we consider three types of utility functions.

For residential users:

$$U_{x} (x,\omega_{x} ) = \left\{ {\begin{array}{*{20}l} {\omega_{x} x - \frac{\alpha }{ 2}x_{{}}^{2} } \hfill & {\quad 0 \le x_{{}} < \frac{{\omega_{x} }}{\alpha }} \hfill \\ {\frac{{\omega_{x}^{2} }}{2\alpha }} \hfill & {\quad x \ge \frac{{\omega_{x} }}{\alpha }} \hfill \\ \end{array} } \right.$$
(1)

For commercial users:

$$U_{y} (y,\omega_{y} ) = \left\{ {\begin{array}{*{20}l} {\beta \log_{3} (\omega_{y} y_{\hbox{max} } + 1)} \hfill & {\quad y \ge y_{\hbox{max} }^{{}} } \hfill \\ {\beta \log_{3} (\omega_{y} y + 1)} \hfill & {\quad 0 < y < y_{\hbox{max} } } \hfill \\ 0 \hfill & {\quad y = 0} \hfill \\ \end{array} } \right.$$
(2)

For industrial users:

$$U_{z} (z,\omega_{z} ) = \left\{ {\begin{array}{*{20}l} {\gamma \log (\omega_{z} z_{\hbox{max} } + 1)} \hfill & {\quad z \ge z_{\hbox{max} } } \hfill \\ {\gamma \log (\omega_{z} z + 1)} \hfill & {\quad 0 < z < z_{\hbox{max} } } \hfill \\ 0 \hfill & {\quad z = 0} \hfill \\ \end{array} } \right.$$
(3)

where \(x\), \(y\), and \(z\) denote the electricity consumption of the three types of users; \(y_{\hbox{max} }\) and \(z_{\hbox{max} }\) are the maximum demand of commercial and industrial users, respectively; \(\alpha\), \(\beta\), and \(\gamma\) are pre-determined constants characterizing the saturation point of the utility; \(\omega_{x}\), \(\omega_{y}\) and \(\omega_{z}\) are non-negative parameters characterizing the user types; and \(U_{x} (x,\omega_{x} )\), \(U_{y} (y,\omega_{y} )\), and \(U_{z} (z,\omega_{z} )\) satisfy increasing and marginal conditions, as shown in Fig. 1.

Fig. 1
figure 1

Utility function of users

A user that consumes \(\bar{x}\) kW of electricity during a designated number of hours at a rate of p ¥/kWh is charged \(p\,\bar{x}\) ¥/h. Hence, the welfare of a user can be simply represented as:

$$W_{x} (x,\omega_{x} ) = U_{x} (x,\omega_{x} ) - p_{x} x$$
(4)
$$W_{y} (y,\omega_{y} ) = U_{y} (y,\omega_{y} ) - p_{y} y$$
(5)
$$W_{z} (z,\omega_{z} ) = U_{z} (z,\omega_{z} ) - p_{z} z$$
(6)

where \(p_{x} x\), \(p_{y} y\), and \(p_{z} z\) are the costs imposed by the electricity provider on the different types of users.

2.2 Energy cost model

The cost function \(C(L_{t} )\) is increasing and strictly convex. In smart grids, researchers often use quadratic functions as the cost function [12]. In this research, the cost function is represented as:

$$C(L_{t} ) = a_{t} L_{t}^{2} + b_{t} L_{t} + c_{t}$$
(7)

where \(a_{t}\) is a pre-determined positive constant; \(b_{t}\) and \(c_{t}\) are pre-determined non-negative constants; and \(L_{t}\) is the generation capacity in time slot \(t\).

2.3 Social welfare model

From a social equality perspective, the social welfare model of electricity aims to maximize social welfare among the users and the electricity provider. It is desirable to maximize the total utilities of the subscribers and minimize the cost imposed on the electricity provider. Thus, the objective function is the total utility of the subscribers subtracted from the cost incurred by the electricity provider [17, 21, 22]. The mathematical model can be represented as:

$$W = \sum\limits_{t = 1}^{T} {\left( {\sum\limits_{i = 1}^{{N_{1} }} {U_{x} (x_{i}^{t} ,\omega_{i}^{t} )} + \sum\limits_{j = 1}^{{N_{2} }} {U_{y}^{{}} (y_{j}^{t} ,\omega_{j}^{t} )} + \sum\limits_{k = 1}^{{N_{3} }} {U_{z} (z_{k}^{t} ,\omega_{k}^{t} )} - C(L_{t} )} \right)}$$
(8)

where \( {U_{x} (x ,\omega_{x} )} \) , \( {U_{y} (y ,\omega_{y} )} \), and \( {U_{z} (z ,\omega_{z} )} \) are described by formula (1)~(3); \( x_{i}^{t}\) is the electricity consumption demand of residential user i; \( y_{j}^{t}\) is the electricity consumption demand of commercial user j; \( z_{k}^{t}\) is the electricity consumption demand of industrial user k; \( \omega_{i}^{t}\), \( \omega_{j}^{t}\) and \( \omega_{k}^{t}\) are non-negative parameters characterizing the user types. As the total generation capacity \(L_{t}\) is the summation of all electricity production, we assume that \(L_{t}\) can be written as:

$$\left\{ {\begin{array}{*{20}l} {L_{t} = L_{t}^{x} + L_{t}^{y} + L_{t}^{z} } \hfill \\ {L_{t}^{x} = \varepsilon_{1} L_{t} } \hfill \\ {L_{t}^{y} = \varepsilon_{2} L_{t} } \hfill \\ {L_{t}^{z} = \varepsilon_{3} L_{t} } \hfill \\ \end{array} } \right.$$
(9)

where \(L_{t}^{x}\), \(L_{t}^{y}\), and \(L_{t}^{z}\) are the generation capacities of the electricity provider for the three different types of users; \(\varepsilon_{i} \in \left( {0,1} \right)\;\left( {i = 1,2,3} \right)\)is a pre-determined constants and \(\sum\limits_{i = 1}^{3} {\varepsilon_{i} } = 1\).

Bounded uncertainty has long been used to model dynamic control systems such as (8). Thus, the electricity optimization problem schedule based on the model of the users is represented as:

$$\left\{ {\begin{array}{*{20}l} {\hbox{max} \quad \sum\limits_{t = 1}^{T} {\left( {\left. {\sum\limits_{i = 1}^{{N_{1} }} {U_{x} (x_{i}^{t} ,\omega_{i}^{t} )} + \sum\limits_{j = 1}^{{N_{2} }} {U_{y} (y_{j}^{t} ,\omega_{j}^{t} )} } \right.} \right.} } \hfill \\ {\left. {\left. {\quad \quad \quad + \sum\limits_{k = 1}^{{N_{3} }} {U_{z} (z_{k}^{t} ,\omega_{k}^{t} )} } \right. - C(L_{t}^{{}} )} \right)} \hfill \\ {{\text{s}} . {\text{t}} .\quad \sum\limits_{i = 1}^{{N_{1} }} {x_{i}^{t} } \le L_{t}^{x} } \hfill \\ {\quad \quad \sum\limits_{j = 1}^{{N_{2} }} {y_{j}^{t} } \le L_{t}^{y} } \hfill \\ {\quad \quad \sum\limits_{k = 1}^{{N_{3} }} {z_{k}^{t} } \le L_{t}^{z} } \hfill \\ \end{array} } \right.$$
(10)

where \(t = 1,2, \cdots ,T\).

The objective function in (10) is the maximum sum of each social welfare model in time slot \(t\). It has the following equivalent formula:

$$\sum\limits_{t = 1}^{T}{\hbox{max}}{ \left( {\sum\limits_{i = 1}^{{N_{1} }} {U_{x} (x_{i}^{t} ,\omega_{i}^{t} ) + \sum\limits_{j = 1}^{{N_{2} }} {U_{y} (y_{j}^{t} ,\omega_{j}^{t} ) + \sum\limits_{k = 1}^{{N_{3} }} {U_{z} (z_{k}^{t} ,\omega_{k}^{t} )} } } - C(L_{t} )} \right)}$$
(11)

Obviously, (10) can be modified into a simple optimization sub-problem as follows:

$$\left\{ {\begin{array}{*{20}l} {\hbox{max} \quad \left( {\left. {\sum\limits_{i = 1}^{{N_{1} }} {U_{x} (x_{i}^{t} ,\omega_{i}^{t} )} + \sum\limits_{j = 1}^{{N_{2} }} {U_{y} (y_{j}^{t} ,\omega_{j}^{t} )} } \right.} \right.} \hfill \\ {\left. {\left. {\quad \quad \quad \quad + \sum\limits_{k = 1}^{{N_{3} }} {U_{z} (z_{k}^{t} ,\omega_{k}^{t} )} } \right. - C(L_{t}^{{}} )} \right)} \hfill \\ {{\text{s}} . {\text{t}} .\quad \sum\limits_{i = 1}^{{N_{1} }} {x_{i}^{t} } \le L_{t}^{x} } \hfill \\ {\quad \quad \sum\limits_{j = 1}^{{N_{2} }} {y_{j}^{t} } \le L_{t}^{y} } \hfill \\ {\quad \quad \sum\limits_{k = 1}^{{N_{3} }} {z_{k}^{t} } \le L_{t}^{z} } \hfill \\ \end{array} } \right.$$
(12)

where \(t = 1,2, \cdots ,T\).

For residential users, the hourly electricity load is equal to the sum of consumption of each household appliance. According to the using requirements, some household appliances such as daily lighting and refrigerators must always be on, other appliances such as geysers and washing machines are directly affected by the electricity price and require a specific amount of time to complete their work assignments. Like residential users, commercial and industrial users have reasonable electricity consumption requirements in different time slots according to order, production demand or working time. So the electricity requirements and desires of users based on electricity consumption may be different in each time slot, i.e. \(\omega_{x}\), \(\omega_{y}\), and \(\omega_{z}\) are different for each user and time slot. Hence, (12) needs to be independently solved at the beginning of each time slot.

3 Real-time pricing formulation

3.1 Model of KKT conditions

For the purposes of discussion, the objective function and constraints of (12) are expressed as follows:

$$f(\bar{\varvec{x}}) = \sum\limits_{i = 1}^{{N_{1} }} {U_{x} (x_{i}^{t} ,\omega_{i}^{t} )} + \sum\limits_{j = 1}^{{N_{2} }} {U_{y} (y_{j}^{t} ,\omega_{j}^{t} )} + \sum\limits_{k = 1}^{{N_{3} }} {U_{z} (z_{k}^{t} ,\omega_{k}^{t} )} - C(L_{t}^{{}} )$$
(13)

and

$$\varvec{g}(\bar{\varvec{x}}) = \left( {L_{t}^{x} - \sum\limits_{i = 1}^{{N_{1} }} {x_{i}^{t} } ,\;L_{t}^{y} - \sum\limits_{j = 1}^{{N_{2} }} {y_{j}^{t} } ,\;L_{t}^{z} - \sum\limits_{k = 1}^{{N_{3} }} {z_{k}^{t} } } \right)^{\text{T}}$$
(14)

where \(\overline{\varvec{x}} = \left( {x_{1}^{t} ,x_{2}^{t}, {...} ,x_{{N_{1} }}^{t} ,y_{1}^{t} ,y_{2}^{t} , {...} ,y_{{N_{2} }}^{t} ,z_{1}^{t} ,z_{2}^{t} , {...} ,z_{{N_{3} }}^{t} }, {{L}_{t}} \right)^{\text{T}}\). Then (12) is a maximum optimal problem, and can be transformed into the following equivalent minimum optimal problem:

$$\left\{ \begin{aligned} \hbox{min} \;\; - f(\bar{\varvec{x}}) \hfill \\ {\text{s}} . {\text{t}} .\;\;\varvec{g}(\bar{\varvec{x}}) \ge {\mathbf{0}} \hfill \\ \end{aligned} \right.$$
(15)

Furthermore, we obtain the following theorems.

Theorem 1

The optimization problem (15) has a unique global optimal solution.

Proof

According to (1)–(3) and (7), the utility function is concave, and the cost function is convex. The objective function \(- f(\bar{\varvec{x}})\) in (15) is the algebraic sum of quadratic functions and logarithm functions, so \(- f(\bar{\varvec{x}})\) is strictly convex. Let

$$D = \left\{ \vphantom{{\left(x_{1}^{t} ,x_{2}^{t}, {...},x_{{N_{1} }}^{t} ,y_{1}^{t} ,y_{2}^{t}, {...} ,y_{{N_{2} }}^{t} ,z_{1}^{t} ,z_{2}^{t}, {...},z_{{N_{3} }}^{t}, {L_{t}} \right)}^{\text{T}}}{\overline{\varvec{x}}\left| {\varvec{g}(\overline{\varvec{x}}) \ge {{0}},\overline{\varvec{x}} = } \right.} \right.\left. {\left(x_{1}^{t} ,x_{2}^{t}, {...},x_{{N_{1} }}^{t} ,y_{1}^{t} ,y_{2}^{t}, {...} ,y_{{N_{2} }}^{t} ,z_{1}^{t} ,z_{2}^{t}, {...},z_{{N_{3} }}^{t}, {L_{t}} \right)}^{\text{T}} \right\}$$

Set \(D\) is convex. Hence, (15) is a convex optimization problem and a solution must exist.

Suppose both \(\bar{\varvec{x}}_{1}^{ * }\) and \(\bar{\varvec{x}}_{2}^{ * }\) are global optimal solutions to (15), where \(\bar{\varvec{x}}_{1}^{ * } \ne \bar{\varvec{x}}_{2}^{ * }\). The global optimal solution must be in the feasible region, and therefore \(\bar{\varvec{x}}_{1}^{ * } ,\;\bar{\varvec{x}}_{2}^{ * } \in D\) exist. According to the definition of the strictly convex function, for any \(\mu \in (0,1)\) such that

$$\begin{aligned} - f(\mu \bar{\varvec{x}}_{1}^{ * } + (1 - \mu )\bar{\varvec{x}}_{2}^{ * } ) & < - \mu f(\bar{\varvec{x}}_{1}^{ * } ) - (1 - \mu )f(\bar{\varvec{x}}_{2}^{ * } ) \\ & \quad = - \mu f(\bar{\varvec{x}}_{1}^{ * } ) - (1 - \mu )f(\bar{\varvec{x}}_{1}^{ * } ) \\ & \quad = - f(\bar{\varvec{x}}_{1}^{ * } ) \\ \end{aligned}$$

let \(\tilde{\varvec{x}} = \mu \bar{\varvec{x}}_{1}^{ * } + (1 - \mu )\bar{\varvec{x}}_{2}^{ * }\). Feasible region \(D\) is a convex set, and therefore these must be \(\tilde{\varvec{x}} \in D\) and \(\tilde{\varvec{x}} \ne \bar{\varvec{x}}_{1}^{ * }\). Hence, \(\tilde{\varvec{x}}\) is a feasible solution. Because \(\bar{\varvec{x}}_{1}^{ * }\) is a global optimal solution, it contradicts \(- f(\tilde{\varvec{x}}) < - f(\bar{\varvec{x}}_{1}^{ * } )\). Therefore the assumption that \(\bar{\varvec{x}}_{1}^{ * }\) and \(\bar{\varvec{x}}_{2}^{ * }\) are global optimal solutions is not true. Hence the optimization problem (15) has a unique global optimal solution.

According to the extreme value theorem, if \(\bar{\varvec{x}}^{ * }\) is a local optimal solution to (15), \(\lambda \ge 0\) exists and the KKT conditions can be set up as:

$$\left\{ {\begin{array}{*{20}l} {\nabla f(\bar{\varvec{x}}^{ * } ) + \sum\limits_{k = 1}^{3} {\lambda_{k} \nabla g_{k} (\bar{\varvec{x}}^{ * } )} = 0} \hfill \\ {\varvec{\lambda}^{\text{T}} \varvec{g}(\bar{\varvec{x}}^{ * } ) = {\mathbf{0}}\quad \quad \quad \quad \quad \quad \quad \quad \quad k = 1,2,3} \hfill \\ {\lambda_{k} \ge 0,\;g_{k} (\bar{\varvec{x}}^{ * } ) \ge 0} \hfill \\ \end{array} } \right.$$
(16)

where \(f(\bar{\varvec{x}}^{ * } )\) and \(\varvec{g}(\bar{\varvec{x}}^{ * } )\) are expressed as (13)–(14). In microeconomics, \(\lambda_{i}\)\((i = 1,2,3)\) means the shadow price of electricity, which reflects the value of electricity. We adopt the shadow price as the basic electricity price of smart grids. We can prove that \(\bar{\varvec{x}}^{ * }\) is the global optimal solution to (15). There is a definition about convex function as follows [25].

Definition 1

Suppose that set \(D \subset {\text{R}}^{n}\) is convex, and \(F(\varvec{x})\) is convex in \(D\). If \(F(\varvec{x})\) is differentiable, for any \(\varvec{x},\;\;\varvec{y} \in D\), there exists a following equivalent definition:

$$F(\varvec{y}) \ge F(\varvec{x}) + \nabla F(\varvec{x})(\varvec{y} - \varvec{x})$$

Theorem 2

If \(\bar{\varvec{x}}^{ * }\) is a solution of the KKT conditions (16), then \(\bar{\varvec{x}}^{ * }\) is the global optimal solution to (15).

Proof

Since \(\bar{\varvec{x}}^{ * }\) is a solution to (16), \(\bar{\varvec{x}}^{ * }\) satisfies the condition \(\varvec{g}(\bar{\varvec{x}}^{ * } ) \ge {\mathbf{0}}\). Hence, \(\bar{\varvec{x}}^{ * } \in D\), i.e. \(\bar{\varvec{x}}^{ * }\) is a feasible solution to (15).

The objective function \(- f(\bar{\varvec{x}})\) in (15) is convex. According to Definition 1, for any feasible solution \(\varvec{y} \in D\) and \(\bar{\varvec{x}}^{ * } \in D\) which satisfies

$$- f(\varvec{y}) \ge - f(\bar{\varvec{x}}^{ * } ) + \nabla ( - f(\bar{\varvec{x}}^{ * } ))(\varvec{y} - \bar{\varvec{x}}^{ * } )$$

If \(\bar{{x}}^{ * }\) is a KKT point, it can be proved that \(\overline{{x}}^{ * }\) is a local optimal solution to (15) and satisfies \(g (\overline{{x}}^{ * }) = 0\). Hence, there does not exist a descent direction \(\varvec{p} \in {\text{R}}^{N}\) such that \(- \nabla f(\bar{\varvec{x}}^{ * } )^{\text{T}} \varvec{p} < 0\) and \(\varvec{p}^{\text{T}} \nabla g(\bar{\varvec{x}}^{ * } ) > 0\). As for any vector \(\varvec{p} \in {\text{D}}\), we have \(- \nabla f(\bar{\varvec{x}}^{ * } )^{\text{T}} \varvec{p} \ge 0\). For \(\overline{{x}}^{ * } \), we have \({(\bar{{x}}^{ * })^{T}} (- \nabla f(\bar{{x}}^{ * } ) )= {(\bar{{x}}^{ * })^{T}} {\sum\limits_{i=1}^{3}{ \lambda_{i}}\nabla {g_{i}} (\bar{{x}}^{ * })} = 0 \). Hence, for any \(\varvec{y} \in D\), there exists \(- f(\varvec{y}) \ge - f(\bar{\varvec{x}}^{ * } )\), i.e. \(\bar{\varvec{x}}^{ * }\) is the global optimal solution to (15).

Since (15) is obtained by the conversion of (12), \(\bar{\varvec{x}}^{ * }\) is also the global optimal solution to (12). Thus, we can get the optimal solution of (12) by solving the KKT conditions (16). In particular, researchers often use quadratic functions as utility functions in most simulation experiments. If only the utility function is quadratic, the optimal problem (12) is a quadratic programming problem which is a special form of convex optimization. Hence, the KKT condition can also be established for quadratic programming.

According to the extreme value theorem, each variable of the solution to (16) is optimal, that is, the electricity computation, price, and production are optimal, and the social welfare is the maximum. It is the goal to solve real-time pricing. Therefore, we can adopt the KKT condition (16) as the new real-time pricing model of smart grids based on DR.

3.2 Optimization problem formulation

In (16), \(\varvec{\lambda}^{\text{T}} \varvec{g}(\bar{\varvec{x}}) = 0,\;\lambda_{k} \ge 0,\;g_{k} (\bar{\varvec{x}}) \ge 0\) has a distinct form which requires a different method of solution.

Definition 2

Given a mapping \(\varvec{F}:{\text{R}}^{n} \to {\text{R}}^{n}\), the complementarity problem is to find a vector \(\varvec{x} \in {\text{R}}^{n}\) which satisfies

$$\left\{ \begin{aligned} &\varvec{x} \ge {\mathbf{0}} \hfill \\ &\varvec{F}(\varvec{x}) \ge {\mathbf{0}} \hfill \\ &\varvec{x}^{\text{T}} \varvec{F}(\varvec{x}) = {\mathbf{0}} \hfill \\ \end{aligned} \right.$$
(17)

Recently, the complementarity problem has undergone significant development, resulting in tremendous progress in both theory and methodology [26,27,28]. According to complementarity theory, if (17) is established, each component has the following equivalent definitions:

$$\begin{aligned} x_{i} \ge 0,F_{i} (x) \ge 0,x_{i} F_{i} (x) = 0 & \Leftrightarrow \hbox{min} \left\{ {x_{i} ,F_{i} (x)} \right\} = 0 \\ & \Leftrightarrow x_{i} - \left( {x_{i} - F_{i} (x)} \right)_{ + } = 0 \\ \end{aligned}$$
(18)

where \(x_{i} \in \varvec{x}\); \(F_{i} (\varvec{x}) \in \varvec{F}(\varvec{x})\); and \(\left( \cdot \right)_{ + } = \hbox{max} ( \cdot ,0)\).

Obviously, (16) contains a complementarity problem and can be transformed into the following system of equations:

$$\left( \begin{aligned} &\nabla f(\bar{\varvec{x}}) + \sum\limits_{k = 1}^{3} {\lambda_{k} \nabla g_{k} (\bar{\varvec{x}})} \hfill \\ &\varvec{\lambda}- \left( {\varvec{\lambda}- \varvec{g}(\bar{\varvec{x}})} \right)_{ + } \hfill \\ \end{aligned} \right) = {\mathbf{0}}$$
(19)

Define \(\varphi (\varvec{\lambda},\varvec{g}(\bar{\varvec{x}})) =\varvec{\lambda}- \left( {\varvec{\lambda}- \varvec{g}(\bar{\varvec{x}})} \right)_{ + }\). Obviously, (19) is non-smooth. Both the non-smooth and smoothing Newton methods are used to solve this system of non-smooth equations. The non-smooth Newton method solves this problem by using a Jacobian matrix, whereas the smoothing Newton method approximates the non-smooth functions by constructing a smooth function with good convergence. Previous research and numerical results show that the smoothing Newton method offers better convergence and more stable numerical results than the non-smooth method. Therefore, we propose a Jacobian smoothing Newton method to solve the system of non-smooth equations (19). The Jacobian smoothing method has global and super-linear convergence.

3.3 Smoothing method

Considering a system of non-smooth equations is:

$$\varvec{\varPhi}\left( \varvec{x} \right) = {\mathbf{0}}$$
(20)

where \(\varvec{\varPhi}\left( \cdot \right):{\text{R}}^{n} \to {\text{R}}^{n}\) is a non-smooth function. \(\varvec{\varPhi}_{{\mu_{k} }} \left( \cdot \right):{\text{R}}^{n} \to {\text{R}}^{n}\) is a sequence of smooth functions satisfying the following condition:

$$\mathop {\lim }\limits_{{\mu_{k} \to 0}}\varvec{\varPhi}_{{\mu_{k} }} \left( \varvec{x} \right) =\varvec{\varPhi}\left( \varvec{x} \right)$$
(21)

The smoothing method is to construct a smooth function \(\varvec{\varPhi}_{{\mu_{k} }} \left( \varvec{x} \right)\) to fit the non-smooth function \(\varvec{\varPhi}\left( \varvec{x} \right)\). Then the solution of the smooth equations is as follow:

$$\varvec{\varPhi}_{{\mu_{k} }} \left( \varvec{x} \right) = {\mathbf{0}}$$
(22)

is approximate to the solution of the original problem (20). The quadratic function, density and maximum entropy methods are typically used to construct the smooth function, which must satisfy the following definitions [25,26,27,28].

Definition 3

The function \(\varvec{\varPhi}\left( \varvec{x} \right):{\text{R}}^{n} \to {\text{R}}^{n}\) is non-smooth. We say that \(\varvec{\varPhi}_{\mu } \left( \varvec{x} \right):{\text{R}}^{n} \to {\text{R}}^{n}\) is a smooth function of \(\varvec{\varPhi}\left( \varvec{x} \right)\) if, for any \(\varvec{x} \in {\text{R}}^{n}\) and \(\mu > 0\), there exists a constant \(\kappa > 0\) which satisfies

$$\left\| {\varvec{\varPhi}_{\mu } \left( \varvec{x} \right) -\varvec{\varPhi}\left( \varvec{x} \right)} \right\| \le \kappa \mu$$
(23)

According to Definition 3, if function \(\varvec{\varPhi}_{\mu } \left( \varvec{x} \right)\) is a smooth function of \(\varvec{\varPhi}\left( \varvec{x} \right)\), there must exist parameter \(\mu > 0\) satisfying the curves of function \(\varvec{\varPhi}_{\mu } \left( \varvec{x} \right)\) and \(\varvec{\varPhi}\left( \varvec{x} \right)\) almost coincide. Thus, Definition 3 ensures that the solutions of (20) and (22) are similar.

Definition 4

Suppose that \(\varvec{\varPhi}\left( \varvec{x} \right):{\text{R}}^{n} \to {\text{R}}^{n}\) is locally Lipschitzian continuous. \(\varvec{\varPhi}_{\mu } \left( \varvec{x} \right):{\text{R}}^{n} \to {\text{R}}^{n}\) is a smooth function of \(\varvec{\varPhi}\left( \varvec{x} \right)\). If for any \(\varvec{x} \in {\text{R}}^{n}\), such that

$$\mathop {\lim }\limits_{\mu \to 0} {\text{dist}}\left( {\varvec{\varPhi^{\prime}}_{\mu } \left( \varvec{x} \right),\partial_{c}\varvec{\varPhi}\left( \varvec{x} \right)} \right) = 0$$
(24)

We say that the functions \(\varvec{\varPhi}_{\mu } \left( \varvec{x} \right)\) and \(\varvec{\varPhi}\left( \varvec{x} \right)\) satisfy the Jacobian consistency property, where \(\partial_{c}\varvec{\varPhi}\left( \varvec{x} \right)\) is the C-sub-differential.

Definition 4 shows the approximation of the first-order differential, i.e. the descent directions of function \(\varvec{\varPhi}_{\mu } \left( \varvec{x} \right)\) and \(\varvec{\varPhi}\left( \varvec{x} \right)\) are consistent. For real-time pricing, we will construct a new smooth function satisfying the Jacobian consistency property. First, the functions denoted by the density method are modified as follows:

$$\rho (s) = \left\{ {\begin{array}{*{20}l} {s + 1} \hfill & {\quad - {\frac{1}{2}} \le s \le \frac{1}{2}} \hfill \\\\ 0 \hfill & {\quad {\text{others}}} \hfill \\ \end{array} } \right.$$
(25)
$$\begin{aligned} P(\mu ,x) & = \int_{ - \infty }^{{{x \mathord{\left/ {\vphantom {x \mu }} \right. \kern-0pt} \mu }}} {(x - \mu s)_{ + } \rho (s){\text{d}}s} = x\int_{ - \infty }^{{{x \mathord{\left/ {\vphantom {x \mu }} \right. \kern-0pt} \mu }}} {\rho (s){\text{d}}s} - \mu \int_{ - \infty }^{{{x \mathord{\left/ {\vphantom {x \mu }} \right. \kern-0pt} \mu }}} {s\rho (s){\text{d}}s} \\ & = \left\{ {\begin{array}{*{20}l} {x - \frac{\mu }{12}} \hfill & {\quad \frac{x}{\mu } \ge \frac{1}{2}} \hfill \\ {\frac{x}{24}\left( {\frac{2x}{\mu } + 3} \right)^{2} + \frac{\mu }{12}} \hfill & {\quad - \frac{1}{2} < \frac{x}{\mu } < \frac{1}{2}} \hfill \\ 0 \hfill & {\quad \frac{x}{\mu } \le - \frac{1}{2}} \hfill \\ \end{array} } \right. \\ \end{aligned}$$
(26)
$$\varvec{\varPhi}_{\mu } (\varvec{x}) = \varvec{x} - P\left( {\mu ,\varvec{x} - \varvec{F}(\varvec{x})} \right)$$
(27)

where \(P\left( {\mu ,\varvec{x} - \varvec{F}(\varvec{x})} \right)\) is a function of (26).

$$\varvec{\varPhi}(\varvec{x}) = \varvec{x} - \left( {\varvec{x} - \varvec{F}(\varvec{x})} \right)_{ + }$$
(28)

where \(\mu \in (0,1)\) and \(\rho (s)\) are density functions. Obviously, \(\varvec{\varPhi}_{\mu } \left( \varvec{x} \right)\) is a piecewise-smooth function consisting of polynomial functions. Hence, it is easier to solve its sub-differential and the system of equations \(\varvec{\varPhi}_{\mu } (\varvec{x}) = 0\). Next, we prove that \(\varvec{\varPhi}_{\mu } \left( \varvec{x} \right)\) is a smooth function of \(\varvec{\varPhi}(\varvec{x})\) that satisfies the Jacobian consistency property.

Theorem 3

Suppose that \(\varvec{\varPhi}_{\mu } \left( \varvec{x} \right)\) and \(\varvec{\varPhi}(\varvec{x})\) are defined as (25)–(28). Then \(\varvec{\varPhi}_{\mu } \left( \varvec{x} \right)\) is a smooth function that can be used instead of \(\varvec{\varPhi}(\varvec{x})\).

Proof

Let \(\tilde{\varvec{x}} = \varvec{x} - \varvec{F}(\varvec{x})\). First, we prove that for any \(\varvec{x} \in {\text{R}}^{n}\) and \(\mu > 0\), there exists some \(\kappa > 0\) which satisfies

$$\left\| {\varvec{\varPhi}_{\mu } \left( \varvec{x} \right) -\varvec{\varPhi}\left( \varvec{x} \right)} \right\| \le \kappa \mu$$

We consider two cases: \(n = 1\) and \(n > 1\).

Case 1: \(n = 1\). We have \(x \in {\text{R}}\) and \(F:{\text{R}} \to {\text{R}}\). According to (25)–(28), if \(\tilde{x}/\mu\) is in \(\left[ {{1 \mathord{\left/ {\vphantom {1 2}} \right. \kern-0pt} 2},\;\infty } \right)\), there exists

$$\begin{aligned} \left| {\varPhi_{\mu } \left( x \right) - \varPhi \left( x \right)} \right| & = \left| {P\left( {\mu ,\tilde{x}} \right) - \left( {\tilde{x}} \right)_{ + } } \right| \\ & = \left| {\tilde{x} - \frac{1}{12}\mu - \tilde{x}} \right| = \frac{\mu }{12} < \frac{\mu }{4} \\ \end{aligned}$$

If \(\bar{x}/\mu\) is in \(\left( {0,{{\;1} \mathord{\left/ {\vphantom {{\;1} 2}} \right. \kern-0pt} 2}} \right)\), we have

$$\begin{aligned} \left| {\varPhi_{\mu } \left( x \right) - \varPhi \left( x \right)} \right| & = \left| {P\left( {\mu ,\tilde{x}} \right) - \left( {\tilde{x}} \right)_{ + } } \right| = \left| {\frac{{\tilde{x}}}{24}\left( {\frac{{2\tilde{x}}}{\mu } + 3} \right)^{2} + \frac{\mu }{12} - \tilde{x}} \right| \\ & = \left| {\frac{\mu }{24}\left( {4\left( {\frac{{\tilde{x}}}{\mu }} \right)^{3} + 12\left( {\frac{{\tilde{x}}}{\mu }} \right)^{2} - \frac{{15\tilde{x}}}{\mu } + 2} \right)} \right| \\ \end{aligned}$$

Let \(\bar{y} = \tilde{x}/\mu\) and \(Y = 4\bar{y}^{3} + 12\bar{y}^{2} - 15\bar{y} + 2\).

When \(\tilde{x}/\mu \in \left( {0,{{\;1} \mathord{\left/ {\vphantom {{\;1} 2}} \right. \kern-0pt} 2}} \right)\), \(\bar{y} \in \left( {0,{{\;1} \mathord{\left/ {\vphantom {{\;1} 2}} \right. \kern-0pt} 2}} \right)\). Obviously, \(Y\) is differentiable, and for any \(\bar{y} \in \left( {0,\;{1 \mathord{\left/ {\vphantom {1 2}} \right. \kern-0pt} 2}} \right)\), there exists

$$Y^{\prime} = 3(2\bar{y} + 5)(2\bar{y} - 1) < 0$$

According to the extreme value theorem, \(Y\) must decrease. Calculate the two end-point function values as \(Y\left| {_{{\bar{y} = 0}} } \right. = 2\) and \(Y\left| {_{{\bar{y} = {1 \mathord{\left/ {\vphantom {1 2}} \right. \kern-0pt} 2}}} } \right. = - 2\). Thus, \(Y \in \left( { - 2,2} \right)\) when \(\bar{y} \in \left( {0,\;{1 \mathord{\left/ {\vphantom {1 2}} \right. \kern-0pt} 2}} \right)\). Furthermore, for \(\tilde{x}/\mu \in \left( {0,{{\;1} \mathord{\left/ {\vphantom {{\;1} 2}} \right. \kern-0pt} 2}} \right)\), we have

$$\left| {\varPhi_{\mu } \left( x \right) - \varPhi \left( x \right)} \right| \le \frac{\mu }{12} \le \frac{\mu }{4}$$

At point \(\tilde{x}/\mu \in \left( { - {1 \mathord{\left/ {\vphantom {1 2}} \right. \kern-0pt} 2},\;0} \right]\), the proof is similar to that of \(\tilde{x}/\mu \in \left( {0,\;{1 \mathord{\left/ {\vphantom {1 2}} \right. \kern-0pt} 2}} \right)\). For \(\tilde{x}/\mu \in \left( { - {1 \mathord{\left/ {\vphantom {1 2}} \right. \kern-0pt} 2},\;0} \right]\), we can write

$$\left| {\varPhi_{\mu } \left( x \right) - \varPhi \left( x \right)} \right| = \left| {P\left( {\mu ,\tilde{x}} \right) - \left( {\tilde{x}} \right)_{ + } } \right| = \left| {\frac{{\tilde{x}}}{24}\left( {\frac{{2\tilde{x}}}{\mu } + 3} \right)^{2} + \frac{\mu }{12}} \right| \le \frac{\mu }{4}$$

If \(\tilde{x}/\mu\) is in \(\left( { - \infty ,\; - {1 \mathord{\left/ {\vphantom {1 2}} \right. \kern-0pt} 2}} \right]\),

$$\left| {\varPhi_{\mu } \left( x \right) - \varPhi \left( x \right)} \right| = \left| {P\left( {\mu ,\tilde{x}} \right) - \left( {\tilde{x}} \right)_{ + } } \right| = 0$$

If we choose \(\kappa = {1 \mathord{\left/ {\vphantom {1 4}} \right. \kern-0pt} 4}\), for any \(x \in {\text{R}}\) and \(\mu > 0\), there must exist \(\left| {\varPhi_{\mu } \left( x \right) - \varPhi \left( x \right)} \right| \le \kappa \mu\). Hence, \(\varPhi_{\mu } (x)\) is a smooth function of \(\varPhi (x)\).

Case 2: \(n > 1\). As in case 1, we choose \(\kappa = {1 \mathord{\left/ {\vphantom {1 4}} \right. \kern-0pt} 4}\). Then, for any \(\varvec{x} \in {\text{R}}^{n}\) and \(\mu > 0\), we have

$$\left\| {\varvec{\varPhi}_{\mu } (\varvec{x}) -\varvec{\varPhi}(\varvec{x})} \right\| = \sqrt {\sum\limits_{i = 1}^{n} {\left( {\varPhi_{\mu } (x_{i} ) - \varPhi (x_{i} )} \right)^{2} } } \le \sqrt n \kappa \mu$$

We choose \(\bar{\kappa } = \sqrt n \kappa\). Then, \(\left\| {\varvec{\varPhi}_{\mu } (\varvec{x}) -\varvec{\varPhi}(\varvec{x})} \right\| \le \bar{\kappa }\mu\) for any \(\varvec{x} \in {\text{R}}^{n}\) and \(\mu > 0\). Hence, according to Definition 3, \(\varvec{\varPhi}_{\mu } (\varvec{x})\) is a smooth function of \(\varvec{\varPhi}(\varvec{x})\), as shown in Fig. 2.

Fig. 2
figure 2

Numerical deviation between the non-smooth function \(y = \hbox{max} (x.0)\)and the smooth function\(y = P(\mu ,x)\) in the interval \(\left[ { - 0.08,0.08} \right]\)

Theorem 4

Suppose that \(\varvec{\varPhi}_{\mu } (\varvec{x})\) and \(\varvec{\varPhi}(\varvec{x})\) are expressed as in (25)–(28). Then, the function \(\varvec{\varPhi}_{\mu } (\varvec{x})\) and \(\varvec{\varPhi}(\varvec{x})\) satisfy the Jacobian consistency property.

Proof

As \(P(\mu ,x) = x\int_{ - \infty }^{{{x \mathord{\left/ {\vphantom {x \mu }} \right. \kern-0pt} \mu }}} {\rho (s){\text{d}}s} - \mu \int_{ - \infty }^{{{x \mathord{\left/ {\vphantom {x \mu }} \right. \kern-0pt} \mu }}} {s\rho (s){\text{d}}s}\) is differentiable, its derivative is

$$P^{\prime}(\mu ,x) = \left( {x\int_{ - \infty }^{{{x \mathord{\left/ {\vphantom {x \mu }} \right. \kern-0pt} \mu }}} {\rho (s){\text{d}}s} - \mu \int_{ - \infty }^{{{x \mathord{\left/ {\vphantom {x \mu }} \right. \kern-0pt} \mu }}} {s\rho (s){\text{d}}s} } \right)^{\prime }_{x} = \int_{ - \infty }^{{{x \mathord{\left/ {\vphantom {x \mu }} \right. \kern-0pt} \mu }}} {\rho (s){\text{d}}s}$$
(29)

\(\rho \left( s \right)\) is a density function, so \(\rho \left( s \right)\) is differentiable and satisfies

$$\rho \left( s \right) \ge 0$$
(30)
$$\int_{ - \infty }^{\infty } {\rho (s){\text{d}}s} = 1$$
(31)

Hence, \(P\left( {\mu ,x} \right)\) is continuously differentiable, and there exists \(P^{\prime}(\mu ,x) \in [0,1]\), and

$$\mathop {\lim }\limits_{{\mu \to 0^{ + } }} P^{\prime}(\mu ,x) = \left\{ {\begin{array}{*{20}c} 0 & {\quad x < 0} \\ 1 & {\quad x > 0} \\ \end{array} } \right.$$
(32)

Let \(\tilde{\varvec{x}} = \varvec{x} - \varvec{F}(\varvec{x})\), we can obtain the differential as such \(\varvec{\varPhi^{\prime}}_{\mu } \left( \varvec{x} \right) = (a_{ij} )_{n \times n}\) where

$$a_{ij} = \left\{ {\begin{array}{*{20}c} {1 - P^{\prime}(\mu ,\tilde{x}_{i} )(1 - (F_{i} (\varvec{x}))^{\prime}_{{x_{j} }} )\quad \,\,\,\,\,\,\,\,i = j} \\ {P^{\prime}(\mu ,\tilde{x}_{i} )(F^{\prime}_{i} (\varvec{x}))^{\prime}_{{x_{j} }} \quad \;\quad \;\quad \,\,\,\,\,\,\,\,\,\,\,\,i \ne j} \\ \end{array} } \right.\;\;$$
(33)

where \(i,j = 1,2, \cdots ,n\).

Denote \(\varvec{D}_{\mu } (\tilde{\varvec{x}}) = {\text{diag}}(\varvec{P^{\prime}}_{x} (\mu ,\tilde{\varvec{x}}))\), then

$$\varvec{\varPhi^{\prime}}_{\mu } \left( \varvec{x} \right) = \left( {\varvec{F^{\prime}}(\varvec{x}) - \varvec{I}} \right)\varvec{D}_{\mu } (\tilde{\varvec{x}}) + \varvec{I}$$
(34)
$$\mathop {\lim }\limits_{\mu \to 0} \left( {\varvec{D}_{\mu } (\tilde{\varvec{x}})} \right)_{ii} = \left\{ \begin{aligned} &1\,\quad \quad \quad \tilde{x}_{i} > 0 \hfill \\ &0\quad \quad \quad \tilde{x}_{i} < 0 \hfill \\ &{\in[0, 1]} \quad\! \!\tilde{{x}_{i}} = 0\end{aligned} \right.$$
(35)

Because \(\partial_{c}\varvec{\varPhi}\left( \varvec{x} \right) = \partial\varvec{\varPhi}_{1} \left( \varvec{x} \right) \times \cdots \times \partial\varvec{\varPhi}_{n} \left( \varvec{x} \right) = (a_{ij} )_{n \times n}\), where

$$a_{ij} = \left\{ {\begin{array}{*{20}l} {1 - (1 - (F_{i} (\varvec{x}))^{{\prime }}_{{x_{j} }} )} \hfill & {\quad i = j,\;\;\tilde{x}_{i} > 0} \hfill \\ 1 \hfill & {\quad i = j,\;\;\tilde{x}_{i} < 0} \hfill \\ {1 - v_{i} (1 - (F_{i} (\varvec{x}))^{{\prime }}_{{x_{j} }} )} \hfill & {\quad i = j,\;\;\tilde{x}_{i} = 0} \hfill \\ {(F_{i} (\varvec{x}))^{{\prime }}_{{x_{j} }} } \hfill & {\quad i \ne j} \hfill \\ \end{array} } \right.$$
(36)

where \(i,j = 1,2, \cdots ,n\); \(v_{i} \in \left[ {0,\;1} \right]\). Therefore, \(\partial_{c}\varvec{\varPhi}\left( \varvec{x} \right)\) can be marked as:

$$\partial_{c}\varvec{\varPhi}(\varvec{x}) = \left( {\varvec{F}^{{\prime }} (\varvec{x}) - \varvec{I}} \right)\varvec{D}(\tilde{\varvec{x}}) + \varvec{I}$$
(37)

where \(\varvec{D}(\tilde{\varvec{x}}) = {\text{diag}}(\varvec{v})\), and \(\varvec{v} \in {\text{R}}^{n}\) satisfies

$$v_{i} = \left\{ {\begin{array}{*{20}l} 1 \hfill & {\quad \tilde{x}_{i} > 0} \hfill \\ 0 \hfill & {\quad \tilde{x}_{i} < 0} \hfill \\ { \in [0,\;1]} \hfill & {\quad \tilde{x}_{i} = 0} \hfill \\ \end{array} } \right.$$
(38)

Hence, we have

$$\mathop {\lim }\limits_{\mu \to 0} {\text{dist}}\left( {\varvec{\varPhi^{\prime}}_{\mu } (\varvec{x}),\partial_{c}\varvec{\varPhi}(\varvec{x})} \right) = 0$$

According to Theorem 4 , \(\varvec{\varPhi}_{\mu } (\varvec{x})\) and \(\varvec{\varPhi}(\varvec{x})\) satisfy the Jacobian consistency property.

Definitions 3 and 4 show that if \(\mu > 0\) is small enough, the curves of function \(\varvec{\varPhi}_{\mu } (\varvec{x})\) and \(\varvec{\varPhi}(\varvec{x})\) almost coincide, and the gradient of \(\varvec{\varPhi}_{\mu } (\varvec{x})\) approximates the sub-differential of \(\varvec{\varPhi}(\varvec{x})\). The characteristic of approaching the gradient ensures that the descent directions of the smooth and non-smooth functions are consistent. Hence, we can select the function \(\varvec{\varphi }_{\mu } (\bar{\varvec{x}}) =\varvec{\lambda}- \varvec{P}\left( {\mu ,\varvec{\lambda}- \varvec{g}(\bar{\varvec{x}})} \right)\) and substitute non-smooth function \(\varvec{\varphi }(\bar{\varvec{x}}) =\varvec{\lambda}- \left( {\varvec{\lambda}- \varvec{g}(\bar{\varvec{x}})} \right)_{ + }\) in (19).

3.4 Jacobian smoothing Newton method

The Jacobian smoothing Newton method uses the Jacobian smooth function to approximate and replace the non-smooth function. Equation (19) is a partial complementarity problem, but it can be solved using the Jacobian smoothing Newton method because smooth functions satisfy Theorems 3 and 4 . Therefore, we define a system of non-smooth equations as follows:

$$\varvec{\varPhi}(\bar{\varvec{x}},\varvec{\lambda}): = \left( \begin{aligned} &\nabla f(\bar{\varvec{x}}) + \sum\limits_{k = 1}^{3} {\lambda_{k} \nabla g_{k} (\bar{\varvec{x}})} \hfill \\&\varvec{\lambda}- \left( {\varvec{\lambda}- \varvec{g}(\bar{\varvec{x}})} \right)_{ + } \hfill \\ \end{aligned} \right) = {\mathbf{0}}$$
(39)

a system of smooth equations:

$$\varvec{\varPhi}_{\mu } (\bar{\varvec{x}},\varvec{\lambda}): = \left( \begin{aligned} &\nabla f(\bar{\varvec{x}}) + \sum\limits_{k = 1}^{3} {\lambda_{k} \nabla g_{k} (\bar{\varvec{x}})} \hfill \\ &\varvec{\lambda}- \varvec{P}\left( {\mu ,\varvec{\lambda}- \varvec{g}(\bar{\varvec{x}})} \right) \hfill \\ \end{aligned} \right) = {\mathbf{0}}$$
(40)

The non-smooth (39) can be solved using the smooth version in (40). Let

$$\varvec{H}(\mu ,\bar{\varvec{x}},\varvec{\lambda}): = \left[ \begin{aligned} e^{\mu } - 1 \hfill \\\varvec{\varPhi}_{\mu } (\bar{\varvec{x}},\varvec{\lambda}) \hfill \\ \end{aligned} \right] = {\mathbf{0}}\quad \quad \mu > 0$$
(41)
$$\varvec{F}(\bar{\varvec{x}},\varvec{\lambda}): = \frac{1}{2}\left\| {\varvec{H}(\mu ,\bar{\varvec{x}},\varvec{\lambda})} \right\|^{2} = \frac{1}{2}\left( {e^{\mu } - 1} \right)^{2} +\varvec{\psi}_{\mu } (\bar{\varvec{x}},\varvec{\lambda})$$
(42)
$$\varvec{\psi}_{\mu } (\bar{\varvec{x}},\varvec{\lambda}): = \frac{1}{2}\left\| {\varvec{\varPhi}_{\mu } (\bar{\varvec{x}},\varvec{\lambda})} \right\|^{2}$$
(43)
$$\nabla\varvec{\psi}(\bar{\varvec{x}}_{k} ,\varvec{\lambda}_{k} ): = \varvec{V}^{\text{T}}\varvec{\varPhi}(\bar{\varvec{x}}_{k} ,\varvec{\lambda}_{k} )\quad \quad \varvec{V} \in \partial\varvec{\varPhi}(\bar{\varvec{x}}_{k} ,\varvec{\lambda}_{k} )$$
(44)

where \(f(\bar{\varvec{x}})\) and \(\varvec{g}(\bar{\varvec{x}})\) are expressed as (13)–(14), and \(\varvec{P}\left( {\mu ,\varvec{\lambda}- \varvec{g}(\bar{\varvec{x}})} \right)\) is expressed as (25)–(28). For the purposes of discussion, we express the variables as \(\varvec{Z} = (\mu ,\bar{\varvec{x}},\varvec{\lambda})\) and \(\varvec{X} = (\bar{\varvec{x}},\varvec{\lambda})\). The process of solving the real-time pricing based on (40) is as follows.

  1. 1)

    For electricity provider

    • Step 1: If \(t \in {\mathcal{T}}\), choose the parameters based on historical data, and then compute the electricity price and production by (40) in the beginning of pricing time; else update the information of user demand.

    • Step 2: Send the electricity price and production information to the users.

    • Step 3: Update the information of users demand. If the demand is greater than a predetermined threshold, Update the electricity generation capacity by (45)–(47) and compute the price by formula (40).

    • Step 4: Repeat the step 2 until the pricing time end or the supply and demand are in balance.

  2. 2)

    For each user

    • Step 1: Update the price and production information from provider.

    • Step 2: Determine the electricity usage based on the price and production given by provider.

    • Step 3: Send the electricity demand to the provider.

    • Step 4: Repeat the step 1 until the pricing time end or the supply and demand are in balance.

The update formula for electricity generation capacity is as follows:

$$L_{t}^{x} = L_{t}^{x} + \zeta_{1} \left( {\sum\limits_{i = 1}^{{N_{1} }} {x_{i}^{t} } - L_{t}^{x} } \right)$$
(45)
$$L_{t}^{y} = L_{t}^{y} + \zeta_{2} \left( {\sum\limits_{i = 1}^{{N_{2} }} {y_{i}^{t} } - L_{t}^{y} } \right)$$
(46)
$$L_{t}^{z} = L_{t}^{z} + \zeta_{3} \left( {\sum\limits_{i = 1}^{{N_{3} }} {z_{i}^{t} } - L_{t}^{z} } \right)$$
(47)
$$\varepsilon_{1} = \frac{{L_{t}^{x} }}{{L_{t}^{x} + L_{t}^{y} + L_{t}^{z} }}$$
(48)
$$\varepsilon_{2} = \frac{{L_{t}^{y} }}{{L_{t}^{x} + L_{t}^{y} + L_{t}^{z} }}$$
(49)
$$\varepsilon_{3} = \frac{{L_{t}^{z} }}{{L_{t}^{x} + L_{t}^{y} + L_{t}^{z} }}$$
(50)

where \(\zeta_{i} \in \left( {0,1} \right)\;\left( {i = 1,2,3} \right)\) is a step length factor. If only demands of some types exceed the threshold, the electricity generation capacities of these types are updated and the value of variables associated with other type’s users do not change.

The step of solving the equations as (40) is as follows.

  • Step 1: Choose the parameters.

  • Step 2: Determine the direction of iteration \(\Delta \varvec{z}^{k}\) and step length factor \(\rho\) by formulas as follows:

    $$\varvec{H^{\prime}(Z}^{k} )\Delta \varvec{Z}^{k} \varvec{ = - H(Z}^{k} )$$
    (51)
    $$f(\varvec{Z}^{k} + \rho \Delta \varvec{Z}^{k} ) \le (1 - 2\sigma \rho )f(\varvec{Z}^{k} )$$
    (52)

Let \(\varvec{Z}^{k + 1} = \varvec{Z}^{k} + \rho \Delta \varvec{Z}^{k}\). If (51) or (52) has no solution, determine the direction of iteration and step length factor by formulas as follows:

$$\Delta \varvec{X}^{k} = - \nabla \psi (\varvec{X}^{k} )$$
(53)
$$\psi (\varvec{X}^{k} + \rho \Delta \varvec{X}^{k} ) \le \psi (\varvec{X}^{k} ) - \sigma \rho \left\| {\Delta \varvec{X}^{k} } \right\|^{2}$$
(54)

Let \(\varvec{X}^{k + 1} = \varvec{X}^{k} + \rho \Delta \varvec{X}^{k}\) and \(\varvec{Z}^{k + 1} = (\mu^{k} ,\varvec{X}^{k} )\). Repeat the step 2 until the end condition is satisfied.

4 Numerical simulations

Numerical simulations are conducted to evaluate the performance of the proposed method. The simulation assumptions and parameters are as follows. We consider 20 residential customers, two commercial customers, and one industrial customer. The random variable \(\omega_{x}\) has the range \([0,2]\). Both \(\omega_{y}\) and \(\omega_{z}\) are also in \([0,2]\). Let \(\alpha = 0.5\), \(\beta = 10\), and \(\gamma = 25\). The cost parameters are set as \(a_{t} = 0.01\) and \(b_{t} = c_{t} = 0\).

To demonstrate the effectiveness of the proposed method, the simulation results are compared with those from a single real-time pricing model and a distributed algorithm based on the dual method.

4.1 Multi-price and single-price algorithms based on complementarity problem

In the multi-price algorithm, users are divided into residential, commercial and industrial groups, each of which is assigned a different electricity price. In the single-price algorithm, all users form a single group, and the electricity is supplied at one price.

The prices in the multi-price algorithm are lower than in the single-price algorithm as shown in Fig. 3. In the multi-price case, the industrial price is the lowest and the residential price is the highest. The low price reduces the average consumption cost, which brings more practical benefits to users. For industrial users, in particular, the cost of production can be greatly reduced. Furthermore, the multi-price algorithm considers the condition and characteristic of different user types, so it is more reasonable than the single-price algorithm.

Fig. 3
figure 3

Optimal price of multi-price algorithm and single-price algorithm based on complementarity algorithm

For residential users, the total electricity production and consumption results are shown in Fig. 4. Most of the electricity consumption is concentrated around 25–30 kWh. The greatest residential consumption occurs at 20:00, with the lowest at 00:00. There are three peaks, at 06:00, 13:00, and 20:00. The consumption increases over the period 00:00–06:00, and the price also increases. The lowest price occurs at 00:00, and the highest price occurs at 06:00. This suggests that the lowest price prevents power consumption from decreasing, while the highest price prevents electricity consumption from increasing. At higher prices, users can shift their electricity consumption from peak to off-peak periods to reduce the pressure on utility-handled equipment. This ensures that there are no “shocks” to the electricity consumption at particular times. The price and consumption patterns around the other peaks exhibit similar behavior. Obviously, this reflects the consumption is related to the price, and the model is reasonable.

Fig. 4
figure 4

Optimal electricity consumption and production for residents based on the multi-price algorithm

The results in Fig. 5 indicate that the electricity price and consumption of commercial users are stable. Electricity consumption is largely concentrated around 26–30 kWh, with the electricity price concentrated around ¥ 0.5–0.6. In Fig. 5, when the electricity consumption decreases, the price becomes lower to encourage electricity consumption. Consumption is observed to increase over the next hour, such as at 02:00, 09:00, and 20:00.

Fig. 5
figure 5

Optimal electricity consumption and production for commerce based on the multi-price algorithm

In Fig. 6, the results indicate that the electricity price and consumption of industrial users are also stable. Electricity consumption is concentrated around 24–27 kWh, with prices generally at ¥ 0.45–0.48. Stable real-time pricing is useful in ensuring the stability of electricity production because drastic changes in production can be harmful to equipment and work arrangements, potentially leading to huge losses. Thus, maintaining stable production is important for industrial users and the electricity provider.

Fig. 6
figure 6

Optimal electricity consumption and production for industries based on the multi-price algorithm

According to Figs. 4, 5 and 6, the total actual electricity consumption of the three groups of users is very similar. However, the number of users in each group is different, with twenty residential users, two commercial users, and one industrial user. This means that the individual consumption of industrial users is the highest and that of residential users is the lowest.

Figures 7 and 8 present a comparison of the multi-price and single-price algorithms. Although the prices in the multi-price algorithm are lower than the single-price, the electricity consumption and social welfare are clearly higher than those in the single-price case. Thus, the multi-price method based on the complementarity problem plays a role in enhancing satisfaction with electricity consumption. The low average cost and high welfare are beneficial to encouraging users to take part in DR programs offered by smart grids.

Fig. 7
figure 7

Optimal electricity consumption and production based on the single-price algorithm

Fig. 8
figure 8

Social welfare value of multi-price and single-price algorithm

In Fig. 9, the results indicate that the proposed multi-price method achieves good convergence and is effective. The price is close to the optimal price after 10 iterations. Thus, the proposed method is fast.

Fig. 9
figure 9

Iterations of multi-price algorithm based on the complementarity problem

4.2 Multi-price algorithm based on the complementarity problem and distributed algorithm based on the dual method

In the dual optimal method [23, 24], the social welfare maximization model is translated into sub-optimization problems as follows:

$$\left\{ {\begin{array}{*{20}l} {D(\varvec{x}) = \hbox{max} \left( {\sum\limits_{i = 1}^{N} {U(x_{i}^{t} ,\omega_{i}^{t} )} - \lambda \sum\limits_{i = 1}^{N} {x_{i}^{t} } } \right)} \hfill \\ {R(\varvec{x}) = \hbox{max} \left( {\lambda L - C(L)} \right)} \hfill \\ \end{array} } \right.$$
(55)

The iterative formula for the distributed algorithm is as follows:

$$\left\{ {\begin{array}{*{20}l} {\lambda_{k + 1}^{t} = \left[ {\lambda_{k}^{t} + r\left( {\sum\limits_{{i \in \bar{N}}}^{{}} {x_{i}^{t * } (\lambda_{k}^{t} )} - L_{t}^{ * } (\lambda_{k}^{t} )} \right)} \right]^{ + }} \\ {L_{t}^{ * } (\lambda_{k}^{t} ) = \mathop {\arg \hbox{max} }\limits_{{L_{t}^{\hbox{min} } \le L_{t} \le L_{t}^{\hbox{max} } }} \lambda_{k}^{t} L_{t} - C_{t} (L_{t} )} \\{x_{i}^{t * } (\lambda^{t} ) = \mathop {\arg \hbox{max} }\limits_{{m_{i}^{t} \le x_{i}^{t} \le M_{k}^{t} }} U(x_{i}^{t} ,\omega_{i}^{t} ) - \lambda^{t} x_{i}^{t}}\hfill \\ \end{array} } \right.$$
(56)

where the three types of users do not interact each other, and their prices are computed separately.

The price given by the distributed algorithm is shown in Fig. 10, and the electricity consumption is presented in Fig. 11.

Fig. 10
figure 10

Optimal prices based on distributed algorithm

Fig. 11
figure 11

Optimal electricity consumption based on the distributed algorithm

The price and consumption vary considerably across the different groups of users as shown in Figs. 10 and 11. The industrial price is mainly between ¥ 0.65–0.7, the commercial price is generally ¥ 0.5–0.6, and the residential price varies from ¥ 0.08–0.1. Clearly, the industrial and commercial prices are similar, and the residential price is the lowest. In response to these prices, industrial and commercial consumption is also similar at 30–35 kWh, but the residential consumption is between 45–60 kWh as shown in Fig. 11. The residential price is too low, resulting in a sharp increase in consumption. For the multi-price complementarity algorithm, the price for all three groups is between ¥ 0.4–0.6 as shown in Fig. 3, and consumption is mainly 24–30 kWh as shown in Fig. 12. This indicates that our proposed algorithm reduces the price gaps to give a balanced structure and promotes an increase in electricity consumption that prevents excessive user cost, thus balancing the consumption profile as well.

Fig. 12
figure 12

Optimal consumptions based on the multi-price complementarity algorithm

In the distributed algorithm, each user is an independent individual who does not interact with others, so the maximum social welfare is the sum of the optimal individual welfares. However, there are always certain influences between individuals in social activities. In the pricing model based on the complementarity method, every type of users interacts with each other in the process of real-time pricing, and the maximum social welfare is an integral, rather than the sum of optimal individual welfares. The numerical results show that the social welfare of the complementarity algorithm is higher than that of the distributed algorithm, as shown in Fig. 13. Obviously, the pricing model based on the complementarity algorithm is more reasonable.

Fig. 13
figure 13

Social welfare value

5 Conclusion

The complementarity model is described to solve the real-time pricing problem for smart grids. The proposed model is based on KKT conditions of the social welfare maximization problem, which computes the optimal electricity consumption for users, price and production for the electricity provider at the beginning of each time slot according to the electricity equipment information entered by users, and production and cost information provided by power companies. We consider three types of users in our model, which avoids the problem of a single utility function. Numerical results show that the proposed algorithm balances electricity supply and demand, improves social welfare, and encourages users to actively participate in the DR program. Users can use more electricity appliances during periods of low prices and turn off anything that is not required at all time during periods of high price, which is beneficial to peak cutting and valley filling. In addition, the simulations reported in this paper are on a small scale, but the advantages of peak cutting and valley filling are very significant. Hence, when the model includes larger numbers of users, the advantages will be even greater.

The method provides a new basic theory for more studies on real-time pricing. In the future, we will further study this issue from two aspects. Firstly, we will try to improve the model. Since the proposed model is simple and contains a few limitations, we will be committed to study a model with more constraints such as rewards for power consumption, energy scheduling of home appliances and the effects of weather on power distribution systems. Secondly, we will study the decentralized pricing method based on the complementarity problem.