一种线性约束下的生成随机数修正方法

17 篇文章 0 订阅
16 篇文章 0 订阅

修正方法

    设需要生成一组如下所示的 N N N维随机向量 x = [ x 1 ⋯ x j ⋯ x N ] T \boldsymbol{x} = \left[ \begin{matrix} x_1 & \cdots & x_j & \cdots & x_N \end{matrix} \right]^T x=[x1xjxN]T满足如式(1)所示的 N N N个随机量上下界约束条件、 M e q M_{eq} Meq个线性方程约束和 M i e q M_{ieq} Mieq个线性不等式约束
{ x j ∈ [ x ‾ j , x ‾ j ] , j ∈ { 1 , ⋯   , N } ∑ j = 1 N a e q , i , j x j = b e q , i , i ∈ { 1 , ⋯   , M e q } ∑ j = 1 N a i e q , i , j x j ≤ b i e q , i , i ∈ { 1 , ⋯   , M i e q } \begin{equation} \begin{cases} x_j ∈ \left[ \underline{x}_j, \overline{x}_j \right], j ∈ \{ 1, \cdots, N \} \\ \displaystyle \sum_{j = 1}^{N} a_{eq, i, j} x_j = b_{eq, i}, i ∈ \{ 1, \cdots, M_{eq} \} \\ \displaystyle \sum_{j = 1}^{N} a_{ieq, i, j} x_j ≤ b_{ieq, i}, i ∈ \{ 1, \cdots, M_{ieq} \} \\ \end{cases} \end{equation} xj[xj,xj],j{1,,N}j=1Naeq,i,jxj=beq,i,i{1,,Meq}j=1Naieq,i,jxjbieq,i,i{1,,Mieq}
其中: x ‾ j \underline{x}_j xj x ‾ j \overline{x}_j xj分别是第 j j j维随机数 x j x_j xj的下界和上界; a e q , i , j a_{eq, i, j} aeq,i,j a i e q , i , j a_{ieq, i, j} aieq,i,j分别为第 i i i个线性方程约束和第 i i i个线性不等式约束中随机数 x j x_j xj的系数, a e q , i , j a_{eq, i, j} aeq,i,j a i e q , i , j a_{ieq, i, j} aieq,i,j不能全部等于 0 0 0 b e q , i b_{eq, i} beq,i b i e q , i b_{ieq, i} bieq,i分别为第 i i i个线性方程和第 i i i个线性不等式的常数项。
    若按照如式(2)所示的随机数生成方法进行生成随机数 x g e n = [ x g e n , 1 ⋯ x g e n , i ⋯ x g e n , N ] T \boldsymbol{x_{gen}} = \left[ \begin{matrix} x_{gen, 1} & \cdots & x_{gen, i} \cdots & x_{gen, N} \end{matrix} \right]^T xgen=[xgen,1xgen,ixgen,N]T作为式(1)所示问题的其中一个测试解
x g e n , j = r j ( x ‾ j − x ‾ j ) + x ‾ j , j ∈ { 1 , ⋯   , N } \begin{equation} x_{gen, j}=r_j \left(\overline{x}_j - \underline{x}_j \right) + \underline{x}_j, j ∈ \{ 1,\cdots, N \} \end{equation} xgen,j=rj(xjxj)+xj,j{1,,N}

其中: r j r_j rj [ 0 , 1 ] [0,1] [0,1]上满足特定概率分布的随机数,易得
x ‾ j ≤ x g e n , j ≤ ( x ‾ j − x ‾ j ) + x ‾ j = x ‾ j , j ∈ { 1 , ⋯   , N } \begin{equation} \underline{x}_j ≤ x_{gen, j} ≤ \left( \overline{x}_j - \underline{x}_j \right) + \underline{x}_j = \underline{x}_j, j ∈ \{ 1, \cdots, N \} \end{equation} xjxgen,j(xjxj)+xj=xj,j{1,,N}
但该随机数生成方法无法保证满足式(1)中的线性方程约束。当生成的随机向量不满足式(1)中的线性方程约束时,须通过将 x g e n \boldsymbol{x_{gen}} xgen修正为 x c o r = [ x c o r , 1 ⋯ x c o r , j ⋯ x c o r , N ] T \boldsymbol{x_{cor}} = \left[ \begin{matrix}x_{cor, 1} & \cdots & x_{cor, j} & \cdots & x_{cor, N} \end{matrix} \right]^T xcor=[xcor,1xcor,jxcor,N]T,使之既满足式(1)中的变量上下界约束,又满足式(1)中的线性方程约束。
    将式(1)中转写成矩阵形式,即有
{ x ‾ ≤ x ≤ x ‾ A e q x = b e q A i e q x ≤ b i e q \begin{equation} \begin{cases} \underline{\boldsymbol{x}} ≤ \boldsymbol{x} ≤ \overline{\boldsymbol{x}} \\ \boldsymbol{A_{eq}} \boldsymbol{x} = \boldsymbol{b_{eq}} \\ \boldsymbol{A_{ieq}} \boldsymbol{x} ≤ \boldsymbol{b_{ieq}} \\ \end{cases} \end{equation} xxxAeqx=beqAieqxbieq
其中:矩阵方程中的系数矩阵 A e q = [ a e q , 1 , 1 ⋯ a e q , 1 , j ⋯ a e q , 1 , N ⋮ ⋮ ⋮ ⋮ ⋮ a e q , i , 1 ⋯ a e q , i , j ⋯ a e q , i , N ⋮ ⋮ ⋮ ⋮ ⋮ a e q , M e q , 1 ⋯ a e q , M e q , j ⋯ a e q , M e q , N ] \boldsymbol{A_{eq}} = \left[ \begin{matrix} a_{eq, 1, 1} & \cdots & a_{eq, 1, j} & \cdots & a_{eq, 1, N} \\ \vdots & \vdots & \vdots & \vdots & \vdots \\ a_{eq, i, 1} & \cdots & a_{eq, i, j} & \cdots & a_{eq, i, N} \\ \vdots & \vdots & \vdots & \vdots & \vdots \\ a_{eq, M_{eq}, 1} & \cdots & a_{eq, M_{eq}, j} & \cdots & a_{eq, M_{eq}, N} \end{matrix} \right] Aeq= aeq,1,1aeq,i,1aeq,Meq,1aeq,1,jaeq,i,jaeq,Meq,jaeq,1,Naeq,i,Naeq,Meq,N ,常数向量 b e q = [ b e q , 1 ⋮ b e q , i ⋮ b e q , M e q ] \boldsymbol{b_{eq}} = \left[ \begin{matrix} b_{eq, 1} \\ \vdots \\ b_{eq, i} \\ \vdots \\ b_{eq, M_{eq}} \end{matrix} \right] beq= beq,1beq,ibeq,Meq ;矩阵不等式中的系数矩阵 A i e q = [ a i e q , 1 , 1 ⋯ a i e q , 1 , j ⋯ a i e q , 1 , N ⋮ ⋮ ⋮ ⋮ ⋮ a i e q , i , 1 ⋯ a i e q , i , j ⋯ a i e q , i , N ⋮ ⋮ ⋮ ⋮ ⋮ a i e q , M i e q , 1 ⋯ a i e q , M i e q , j ⋯ a i e q , M i e q , N ] \boldsymbol{A_{ieq}} = \left[ \begin{matrix} a_{ieq, 1, 1} & \cdots & a_{ieq, 1, j} & \cdots & a_{ieq, 1, N} \\ \vdots & \vdots & \vdots & \vdots & \vdots \\ a_{ieq, i, 1} & \cdots & a_{ieq, i, j} & \cdots & a_{ieq, i, N} \\ \vdots & \vdots & \vdots & \vdots & \vdots \\ a_{ieq, M_{ieq}, 1} & \cdots & a_{ieq, M_{ieq}, j} & \cdots & a_{ieq, M_{ieq}, N} \end{matrix} \right] Aieq= aieq,1,1aieq,i,1aieq,Mieq,1aieq,1,jaieq,i,jaieq,Mieq,jaieq,1,Naieq,i,Naieq,Mieq,N ,常数向量 b i e q = [ b i e q , 1 ⋮ b i e q , i ⋮ b e q , M i e q ] \boldsymbol{b_{ieq}} = \left[ \begin{matrix} b_{ieq, 1} \\ \vdots \\ b_{ieq, i} \\ \vdots \\ b_{eq, M_{ieq}} \end{matrix} \right] bieq= bieq,1bieq,ibeq,Mieq
    将矩阵方程中的系数矩阵 A e q \boldsymbol{A_{eq}} Aeq经过有限次的初等变换即转换成标准形矩阵 A e q , S T D \boldsymbol{A_{eq, STD}} Aeq,STD x \boldsymbol{x} x通过对应次序的初等列变换(实质作用为调换 x \boldsymbol{x} x中元素的顺序) x ~ \boldsymbol{\tilde{x}} x~,常数向量 b e q \boldsymbol{b_{eq}} beq通过对应次序的初等行变换转换成 b e q , S T D \boldsymbol{b_{eq, STD}} beq,STD。设 R e q ( R e q ≤ min ⁡ ( M e q , N ) ) R_{eq} \left( R_{eq} ≤ \min \left( M_{eq}, N \right) \right) Req(Reqmin(Meq,N))为矩阵 A e q \boldsymbol{A_{eq}} Aeq A e q , S T D \boldsymbol{A_{eq, STD}} Aeq,STD的秩,为简化讨论假定 x = x ~ \boldsymbol{x} = \boldsymbol{\tilde{x}} x=x~,则结合线性方程组理论和博客《一种线性方程约束下生成随机数修正的一般性方法(上)》《一种线性方程约束下生成随机数修正的一般性方法(中)》《一种线性方程约束下生成随机数修正的一般性方法(下)》中的论述可知,式(1)中线性方程的解有以下情况:

    情况1:若系数向量 b e q , S T D \boldsymbol{b_{eq, STD}} beq,STD自第 ( R e q + 1 ) \left( R_{eq} + 1 \right) (Req+1)列到第 M e q M_{eq} Meq列存在非零元素,则式(8)所示的矩阵方程无解,此时无法将 x g e n \boldsymbol{x_{gen}} xgen修正为 x c o r \boldsymbol{x_{cor}} xcor,使之满足式(1)中的线性方程约束。

    情况2:若系数向量 b e q , S T D \boldsymbol{b_{eq, STD}} beq,STD自第 ( R e q + 1 ) \left( R_{eq} + 1 \right) (Req+1)列到第 M e q M_{eq} Meq列的元素全为零,则式(8)所示的矩阵方程有解,此时可分为以下情况将 x g e n \boldsymbol{x_{gen}} xgen修正为 x c o r \boldsymbol{x_{cor}} xcor,使得修正后的 x c o r \boldsymbol{x_{cor}} xcor满足式(1)中的线性方程约束:

    情况2.1:若 R e q = 1 R_{eq} = 1 Req=1,此时可将式(4)中约简为
{ x ‾ ≤ x ≤ x ‾ A e q , 1 x = b e q , 1 A i e q x ≤ b i e q \begin{equation} \begin{cases} \underline{\boldsymbol{x}} ≤ \boldsymbol{x} ≤ \overline{\boldsymbol{x}} \\ \boldsymbol{A_{eq, 1}} \boldsymbol{x} = b_{eq, 1} \\ \boldsymbol{A_{ieq}} \boldsymbol{x} ≤ \boldsymbol{b_{ieq}} \\ \end{cases} \end{equation} xxxAeq,1x=beq,1Aieqxbieq
其中: A e q , 1 = [ a e q , 1 , 1 ⋯ a e q , 1 , j ⋯ a e q , 1 , N ] \boldsymbol{A_{eq, 1}} = \left[ \begin{matrix} a_{eq, 1, 1} & \cdots & a_{eq, 1, j} & \cdots & a_{eq, 1, N} \end{matrix} \right] Aeq,1=[aeq,1,1aeq,1,jaeq,1,N]
    将式(5)进一步转化为如式(6)所示的形式,该式仅包含变量上下界约束和线性不等式约束,然后利用博客《一种线性不等式约束下的生成随机数修正方法》所述方法即可将 x g e n \boldsymbol{x_{gen}} xgen修正为 x c o r \boldsymbol{x_{cor}} xcor
{ x ‾ ≤ x ≤ x ‾ A e q , 1 x ≤ b e q , 1 − A e q , 1 x ≤ − b e q , 1 A i e q x ≤ b i e q \begin{equation} \begin{cases} \underline{\boldsymbol{x}} ≤ \boldsymbol{x} ≤ \overline{\boldsymbol{x}} \\ \boldsymbol{A_{eq, 1}} \boldsymbol{x} ≤ b_{eq, 1} \\ -\boldsymbol{A_{eq, 1}} \boldsymbol{x} ≤ -b_{eq, 1} \\ \boldsymbol{A_{ieq}} \boldsymbol{x} ≤ \boldsymbol{b_{ieq}} \\ \end{cases} \end{equation} xxxAeq,1xbeq,1Aeq,1xbeq,1Aieqxbieq

    情况2.2:若 R e q > 1 R_{eq} > 1 Req>1,则对于式(4)中的矩阵方程部分,根据博客《一种线性方程约束下生成随机数修正的一般性方法(上)》中的论述可知, A e q , S T D \boldsymbol{A_{eq, STD}} Aeq,STD的结构如式(7)所示
A e q , S T D = [ E R e q A ~ e q R e q × ( N − R e q ) O ( M e q − R e q ) × R e q O ( M e q − R e q ) × ( N − R e q ) ] \begin{equation} \boldsymbol{A_{eq, STD}} = \left[ \begin{matrix} \boldsymbol{E}_{R_{eq}} & \boldsymbol{\tilde{A}_{eq}}_{R_{eq} \times \left( N - R_{eq} \right)} \\ \boldsymbol{O}_{\left( M_{eq} - R_{eq} \right) \times R_{eq}} & \boldsymbol{O}_{\left( M_{eq} - R_{eq} \right) \times \left( N - R_{eq} \right)} \end{matrix} \right] \end{equation} Aeq,STD=[EReqO(MeqReq)×ReqA~eqReq×(NReq)O(MeqReq)×(NReq)]
其中: E R e q \boldsymbol{E}_{R_{eq}} EReq R e q R_{eq} Req阶单位矩阵, A ~ e q R e q × ( N − R e q ) = [ a ~ e q , 1 , 1 ⋯ a ~ e q , 1 , j ⋯ a ~ e q , 1 , ( N − R e q ) ⋮ ⋮ ⋮ ⋮ ⋮ a ~ e q , i , 1 ⋯ a ~ e q , i , j ⋯ a ~ e q , i , ( N − R e q ) ⋮ ⋮ ⋮ ⋮ ⋮ a ~ e q , R e q , 1 ⋯ a ~ e q , R e q , j ⋯ a ~ e q , R e q , ( N − R e q ) ] \boldsymbol{\tilde{A}_{eq}}_{R_{eq} \times \left( N - R_{eq} \right)} = \left[ \begin{matrix} \tilde{a}_{eq, 1, 1} & \cdots & \tilde{a}_{eq, 1, j} & \cdots & \tilde{a}_{eq, 1, \left( N - R_{eq} \right)} \\ \vdots & \vdots & \vdots & \vdots & \vdots \\ \tilde{a}_{eq, i, 1} & \cdots & \tilde{a}_{eq, i, j} & \cdots & \tilde{a}_{eq, i, \left( N - R_{eq} \right)} \\ \vdots & \vdots & \vdots & \vdots & \vdots \\ \tilde{a}_{eq, R_{eq}, 1} & \cdots & \tilde{a}_{eq, R_{eq}, j} & \cdots & \tilde{a}_{eq, R_{eq}, \left( N - R_{eq} \right)} \end{matrix} \right] A~eqReq×(NReq)= a~eq,1,1a~eq,i,1a~eq,Req,1a~eq,1,ja~eq,i,ja~eq,Req,ja~eq,1,(NReq)a~eq,i,(NReq)a~eq,Req,(NReq) O ( M e q − R e q ) × R e q \boldsymbol{O}_{\left( M_{eq} - R_{eq} \right) \times R_{eq}} O(MeqReq)×Req O ( M e q − R e q ) × ( N − R e q ) \boldsymbol{O}_{\left( M_{eq} - R_{eq} \right) \times \left( N - R_{eq} \right)} O(MeqReq)×(NReq)分别为 ( M e q − R e q ) \left( M_{eq} - R_{eq} \right) (MeqReq) R e q R_{eq} Req列和 ( M e q − R e q ) \left( M_{eq} - R_{eq} \right) (MeqReq) ( N − R e q ) \left( N - R_{eq} \right) (NReq)列的零矩阵。
    进一步地,可将式(4)中的矩阵方程部分转换为如式(7)所示的矩阵不等式
{ x ‾ ≤ x ≤ x ‾ b e q , S T D − x ‾ 1 − R e q ≤ A ~ e q x 1 − R e q ≤ b e q , S T D − x ‾ 1 − R e q \begin{equation} \begin{cases} \underline{\boldsymbol{x}} ≤ \boldsymbol{x} ≤ \overline{\boldsymbol{x}} \\ \boldsymbol{b_{eq, STD}} - \boldsymbol{\overline{x}_{1 - R_{eq}}} ≤ \boldsymbol{\tilde{A}_{eq}} \boldsymbol{x_{1 - R_{eq}}} ≤ \boldsymbol{b_{eq, STD}} - \boldsymbol{\underline{x}_{1 - R_{eq}}} \\ \end{cases} \end{equation} {xxxbeq,STDx1ReqA~eqx1Reqbeq,STDx1Req
其中: x 1 − R e q = [ x 1 ⋯ x j ⋯ x R e q ] T \boldsymbol{x_{1 - R_{eq}}} = \left[ \begin{matrix} x_1 & \cdots & x_j & \cdots & x_{R_{eq}} \end{matrix} \right]^T x1Req=[x1xjxReq]T x ‾ 1 − R e q = [ x ‾ 1 ⋯ x ‾ j ⋯ x ‾ R e q ] T \boldsymbol{\underline{x}_{1 - R_{eq}}} = \left[ \begin{matrix} \underline{x}_1 & \cdots & \underline{x}_j & \cdots & \underline{x}_{R_{eq}} \end{matrix} \right]^T x1Req=[x1xjxReq]T x ‾ 1 − R e q = [ x ‾ 1 ⋯ x ‾ j ⋯ x ‾ R e q ] T \boldsymbol{\overline{x}_{1 - R_{eq}}} = \left[ \begin{matrix} \overline{x}_1 & \cdots & \overline{x}_j & \cdots & \overline{x}_{R_{eq}} \end{matrix} \right]^T x1Req=[x1xjxReq]T
    对于式(4)中的矩阵不等式部分,将其进行矩阵的分块,并在此基础上进一步转化可得如式(9)所示形式
A i e q x = [ A i e q , 1 − R e q A i e q , ( R e q + 1 ) − N ] [ x 1 − R e q x ( R e q + 1 ) − N ] = A i e q , 1 − R e q x 1 − R e q + A i e q , ( R e q + 1 ) − N x ( R e q + 1 ) − N = A i e q , 1 − R e q ( b e q , S T D − A ~ e q x ( R e q + 1 ) − N ) + A i e q , ( R e q + 1 ) − N x ( R e q + 1 ) − N = A i e q , 1 − R e q b e q , S T D + ( A i e q , ( R e q + 1 ) − N − A i e q , 1 − R e q A ~ e q ) x ( R e q + 1 ) − N ≤ b i e q \begin{equation} \begin{split} \boldsymbol{A_{ieq}} \boldsymbol{x} &= \left[ \begin{matrix} \boldsymbol{A_{ieq, 1 - R_{eq}}} & \boldsymbol{A_{ieq, \left( R_{eq} + 1 \right) - N}} \end{matrix} \right] \left[ \begin{matrix} \boldsymbol{x_{1 - R_{eq}}} \\ \boldsymbol{x_{\left( R_{eq} + 1 \right) - N}} \end{matrix} \right] \\ &= \boldsymbol{A_{ieq, 1 - R_{eq}}} \boldsymbol{x_{1 - R_{eq}}} + \boldsymbol{A_{ieq, \left( R_{eq} + 1 \right) - N}} \boldsymbol{x_{\left( R_{eq} + 1 \right) - N}} \\ &= \boldsymbol{A_{ieq, 1 - R_{eq}}} \left( \boldsymbol{b_{eq, STD}} - \boldsymbol{\tilde{A}_{eq}} \boldsymbol{x_{\left( R_{eq} + 1 \right) - N}} \right) + \boldsymbol{A_{ieq, \left( R_{eq} + 1 \right) - N}} \boldsymbol{x_{\left( R_{eq} + 1 \right) - N}} \\ &= \boldsymbol{A_{ieq, 1 - R_{eq}}} \boldsymbol{b_{eq, STD}} + \left( \boldsymbol{A_{ieq, \left( R_{eq} + 1 \right) - N}} - \boldsymbol{A_{ieq, 1 - R_{eq}}} \boldsymbol{\tilde{A}_{eq}} \right) \boldsymbol{x_{\left( R_{eq} + 1 \right) - N}} \\ &≤ \boldsymbol{b_{ieq}}\\ \end{split} \end{equation} Aieqx=[Aieq,1ReqAieq,(Req+1)N][x1Reqx(Req+1)N]=Aieq,1Reqx1Req+Aieq,(Req+1)Nx(Req+1)N=Aieq,1Req(beq,STDA~eqx(Req+1)N)+Aieq,(Req+1)Nx(Req+1)N=Aieq,1Reqbeq,STD+(Aieq,(Req+1)NAieq,1ReqA~eq)x(Req+1)Nbieq
其中: A i e q , 1 − R e q = [ a i e q , 1 , 1 ⋯ a i e q , 1 , j ⋯ a i e q , 1 , R e q ⋮ ⋮ ⋮ ⋮ ⋮ a i e q , i , 1 ⋯ a i e q , i , j ⋯ a i e q , i , R e q ⋮ ⋮ ⋮ ⋮ ⋮ a i e q , M i e q , 1 ⋯ a i e q , M i e q , j ⋯ a i e q , M i e q , R e q ] \boldsymbol{A_{ieq, 1 - R_{eq}}} = \left[ \begin{matrix} a_{ieq, 1, 1} & \cdots & a_{ieq, 1, j} & \cdots & a_{ieq, 1, R_{eq}} \\ \vdots & \vdots & \vdots & \vdots & \vdots \\ a_{ieq, i, 1} & \cdots & a_{ieq, i, j} & \cdots & a_{ieq, i, R_{eq}} \\ \vdots & \vdots & \vdots & \vdots & \vdots \\ a_{ieq, M_{ieq}, 1} & \cdots & a_{ieq, M_{ieq}, j} & \cdots & a_{ieq, M_{ieq}, R_{eq}} \end{matrix} \right] Aieq,1Req= aieq,1,1aieq,i,1aieq,Mieq,1aieq,1,jaieq,i,jaieq,Mieq,jaieq,1,Reqaieq,i,Reqaieq,Mieq,Req A i e q , ( R e q + 1 ) − N = [ a i e q , 1 , R e q + 1 ⋯ a i e q , 1 , j ⋯ a i e q , 1 , N ⋮ ⋮ ⋮ ⋮ ⋮ a i e q , i , R e q + 1 ⋯ a i e q , i , j ⋯ a i e q , i , N ⋮ ⋮ ⋮ ⋮ ⋮ a i e q , M i e q , R e q + 1 ⋯ a i e q , M i e q , j ⋯ a i e q , M i e q , N ] \boldsymbol{A_{ieq, \left( R_{eq} + 1 \right) - N}} = \left[ \begin{matrix} a_{ieq, 1, R_{eq} + 1} & \cdots & a_{ieq, 1, j} & \cdots & a_{ieq, 1, N} \\ \vdots & \vdots & \vdots & \vdots & \vdots \\ a_{ieq, i, R_{eq} + 1} & \cdots & a_{ieq, i, j} & \cdots & a_{ieq, i, N} \\ \vdots & \vdots & \vdots & \vdots & \vdots \\ a_{ieq, M_{ieq}, R_{eq} + 1} & \cdots & a_{ieq, M_{ieq}, j} & \cdots & a_{ieq, M_{ieq}, N} \end{matrix} \right] Aieq,(Req+1)N= aieq,1,Req+1aieq,i,Req+1aieq,Mieq,Req+1aieq,1,jaieq,i,jaieq,Mieq,jaieq,1,Naieq,i,Naieq,Mieq,N x ( R e q + 1 ) − N = [ x R e q + 1 ⋯ x j ⋯ x N ] T \boldsymbol{x_{\left( R_{eq} + 1 \right) - N}} = \left[ \begin{matrix} x_{R_{eq} + 1} & \cdots & x_j & \cdots & x_N \end{matrix} \right]^T x(Req+1)N=[xReq+1xjxN]T x ‾ ( R e q + 1 ) − N = [ x ‾ R e q + 1 ⋯ x ‾ j ⋯ x ‾ N ] T \boldsymbol{\underline{x}_{\left( R_{eq} + 1 \right) - N}} = \left[ \begin{matrix} \underline{x}_{R_{eq} + 1} & \cdots & \underline{x}_j & \cdots & \underline{x}_N \end{matrix} \right]^T x(Req+1)N=[xReq+1xjxN]T x ‾ ( R e q + 1 ) − N = [ x ‾ R e q + 1 ⋯ x ‾ j ⋯ x ‾ N ] T \boldsymbol{\overline{x}_{\left( R_{eq} + 1 \right) - N}} = \left[ \begin{matrix} \overline{x}_{R_{eq} + 1} & \cdots & \overline{x}_j & \cdots & \overline{x}_N \end{matrix} \right]^T x(Req+1)N=[xReq+1xjxN]T x 1 − R e q \boldsymbol{x_{1 - R_{eq}}} x1Req x ‾ ( R e q + 1 ) − N \boldsymbol{\underline{x}_{\left( R_{eq} + 1 \right) - N}} x(Req+1)N之间满足
x 1 − R e q = b e q , S T D − A ~ e q x ( R e q + 1 ) − N \begin{equation} \boldsymbol{x_{1 - R_{eq}}} = \boldsymbol{b_{eq, STD}} - \boldsymbol{\tilde{A}_{eq}} \boldsymbol{x_{\left( R_{eq} + 1 \right) - N}} \end{equation} x1Req=beq,STDA~eqx(Req+1)N
    对式(9)进行移项可得
( A i e q , ( R e q + 1 ) − N − A i e q , 1 − R e q A ~ e q ) x ( R e q + 1 ) − N ≤ b i e q − A i e q , 1 − R e q b e q , S T D \begin{equation} \left( \boldsymbol{A_{ieq, \left( R_{eq} + 1 \right) - N}} - \boldsymbol{A_{ieq, 1 - R_{eq}}} \boldsymbol{\tilde{A}_{eq}} \right) \boldsymbol{x_{\left( R_{eq} + 1 \right) - N}} ≤ \boldsymbol{b_{ieq}} - \boldsymbol{A_{ieq, 1 - R_{eq}}} \boldsymbol{b_{eq, STD}} \end{equation} (Aieq,(Req+1)NAieq,1ReqA~eq)x(Req+1)NbieqAieq,1Reqbeq,STD
将其与式(8)联立后,再进行如式(12)所示的进一步转化即可变为以 x ( R e q + 1 ) − N \boldsymbol{x_{\left( R_{eq} + 1 \right) - N}} x(Req+1)N为变量的矩阵不等式
{ x ‾ ( R e q + 1 ) − N ≤ x ( R e q + 1 ) − N ≤ x ‾ ( R e q + 1 ) − N − A ~ e q x ( R e q + 1 ) − N ≤ − ( b e q , S T D − x ‾ 1 − R e q ) A ~ e q x ( R e q + 1 ) − N ≤ b e q , S T D − x ‾ 1 − R e q ( A i e q , ( R e q + 1 ) − N − A i e q , 1 − R e q A ~ e q ) x ( R e q + 1 ) − N ≤ b i e q − A i e q , 1 − R e q b e q , S T D \begin{equation} \begin{cases} \boldsymbol{\underline{x}_{\left( R_{eq} + 1 \right) - N}} ≤ \boldsymbol{x_{\left( R_{eq} + 1 \right) - N}} ≤ \boldsymbol{\overline{x}_{\left( R_{eq} + 1 \right) - N}} \\ -\boldsymbol{\tilde{A}_{eq}} \boldsymbol{x_{\left( R_{eq} + 1 \right) - N}} ≤ -\left( \boldsymbol{b_{eq, STD}} - \boldsymbol{\overline{x}_{1 - R_{eq}}} \right) \\ \boldsymbol{\tilde{A}_{eq}} \boldsymbol{x_{\left( R_{eq} + 1 \right) - N}} ≤ \boldsymbol{b_{eq, STD}} - \boldsymbol{\underline{x}_{1 - R_{eq}}} \\ \left( \boldsymbol{A_{ieq, \left( R_{eq} + 1 \right) - N}} - \boldsymbol{A_{ieq, 1 - R_{eq}}} \boldsymbol{\tilde{A}_{eq}} \right) \boldsymbol{x_{\left( R_{eq} + 1 \right) - N}} ≤ \boldsymbol{b_{ieq}} - \boldsymbol{A_{ieq, 1 - R_{eq}}} \boldsymbol{b_{eq, STD}} \end{cases} \end{equation} x(Req+1)Nx(Req+1)Nx(Req+1)NA~eqx(Req+1)N(beq,STDx1Req)A~eqx(Req+1)Nbeq,STDx1Req(Aieq,(Req+1)NAieq,1ReqA~eq)x(Req+1)NbieqAieq,1Reqbeq,STD
随后利用博客《一种线性不等式约束下的生成随机数修正方法》所述方法将 x g e n , R e q + 1 , ⋯   , x g e n , N x_{gen, R_{eq} + 1}, \cdots, x_{gen, N} xgen,Req+1,,xgen,N修正为 x c o r , R e q + 1 , ⋯   , x c o r , N x_{cor, R_{eq} + 1}, \cdots, x_{cor, N} xcor,Req+1,,xcor,N,再根据式(10)将 x g e n , 1 , ⋯   , x g e n , R e q x_{gen, 1}, \cdots, x_{gen, R_{eq}} xgen,1,,xgen,Req修正为 x c o r , 1 , ⋯   , x c o r , R e q x_{cor, 1}, \cdots, x_{cor, R_{eq}} xcor,1,,xcor,Req,从而将 x g e n \boldsymbol{x_{gen}} xgen修正为 x c o r \boldsymbol{x_{cor}} xcor

MATLAB代码

linear_inequalities_constraints_correction函数

function [X_cor, correction_info] = linear_inequalities_constraints_correction(X_gen, lb, ub, A_ieq, b_ieq, ...
                                    W_multiplicator)
    % LINEAR_INEQUALITIES_CONSTRAINTS_CORRECTION  Correction onto generated random vector.
    %                                             A methodology of correction onto generated random vector,
    %                                             facilitating the corrected vector to range within variable
    %                                             boundaries and to meet linear constraints

    if ~exist('W_multiplicator', 'var')
        W_multiplicator = 1000;
    end
    max_runtime = ceil(W_multiplicator / size(X_gen, 2));

    M = size(A_ieq, 1);
    [N_D, N_P] = size(X_gen);
    
    b_ieq_lb = diag(A_ieq * ((A_ieq > 0)' .* lb + (A_ieq < 0)' .* ub));
    b_ieq_ub = min([diag(A_ieq * ((A_ieq > 0)' .* ub + (A_ieq < 0)' .* lb)), b_ieq], [], 2);
    
    if any(b_ieq < b_ieq_lb)
        X_cor = [];
        correction_info.is_feasible = false(1, N_P);
        correction_info.does_X_cor_exceed.by_bit = true(N_D, N_P);
        correction_info.does_X_cor_exceed.globally = true(1, N_P);
        correction_info.is_inequality_less_than_b.by_bit = false(M, N_P);
        correction_info.is_inequality_less_than_b.globally = false;

    else
        X_cor = X_gen;

        run = 0;
        while 1
            X_cor = X_gen;
            iEq_gen = A_ieq * X_gen;
            does_A_ieq_X_gen_exceed = (iEq_gen > b_ieq);
    
            for indi = 1:N_P
                if any(does_A_ieq_X_gen_exceed(:, indi))
                    flag_A_ieq_X_gen_exceed = find(does_A_ieq_X_gen_exceed(:, indi));
                    row_A_ieq_candi = flag_A_ieq_X_gen_exceed(randi(length(flag_A_ieq_X_gen_exceed)));
                    A_ieq_candi = A_ieq(row_A_ieq_candi, :);
                    Eq_candi_gen = A_ieq_candi * X_gen(:, indi);
                    b_ieq_k_lb = b_ieq_lb(row_A_ieq_candi, :);
                    b_ieq_k_ub = b_ieq_ub(row_A_ieq_candi, :);
                    delta_plus = A_ieq_candi * ((A_ieq_candi > 0)' .* (X_gen(:, indi) - lb) ...
                        + (A_ieq_candi < 0)' .* (X_gen(:, indi) - ub));
                    x_cor_base = zeros(N_D, 1);
    
                    if Eq_candi_gen > b_ieq_k_ub
                        b_eq_k_best = [b_ieq_k_lb + (delta_plus * (b_ieq_lb - A_ieq * ((A_ieq_candi > 0)' ...
                            .* lb + (A_ieq_candi < 0)' .* ub + (A_ieq_candi == 0)' .* X_gen(:, indi)))) ...
                            ./ (A_ieq * ((A_ieq_candi > 0)' .* (X_gen(:, indi) - lb) ...
                            + (A_ieq_candi < 0)' .* (X_gen(:, indi) - ub))), ...
                            b_ieq_k_lb + (delta_plus * (b_ieq_ub - A_ieq * ((A_ieq_candi > 0)' ...
                            .* lb + (A_ieq_candi < 0)' .* ub + (A_ieq_candi == 0)' .* X_gen(:, indi)))) ...
                            ./ (A_ieq * ((A_ieq_candi > 0)' .* (X_gen(:, indi) - lb) ...
                            + (A_ieq_candi < 0)' .* (X_gen(:, indi) - ub)))];
                        b_eq_k_min = max(min(b_eq_k_best, [], 2), [], 1);
                        b_eq_k_max = min(max(b_eq_k_best, [], 2), [], 1);
                        if b_eq_k_min <= b_eq_k_max
                            b_eq_k = b_eq_k_min + rand * (b_eq_k_max - b_eq_k_min);
                        else
                            b_eq_k = b_eq_k_best(row_A_ieq_candi, 1) + rand * (b_eq_k_best(row_A_ieq_candi, 2) ...
                                     - b_eq_k_best(row_A_ieq_candi, 1));
                        end
                        x_cor_base(A_ieq_candi > 0) = (((b_eq_k - b_ieq_k_lb) / delta_plus) ...
                                                      * (X_gen(A_ieq_candi > 0, indi) - lb(A_ieq_candi > 0)) ...
                                                      + lb(A_ieq_candi > 0))';
                        x_cor_base(A_ieq_candi == 0) = (X_gen(A_ieq_candi == 0))';
                        x_cor_base(A_ieq_candi < 0) = (((b_eq_k - b_ieq_k_lb) / delta_plus) ...
                                                      * (X_gen(A_ieq_candi < 0, indi) - ub(A_ieq_candi < 0)) ...
                                                      + ub(A_ieq_candi < 0))';
                    end
                    X_cor(:, indi) = x_cor_base;
                end
            end
    
            for indi = 1:N_P
                X_cor(abs(X_cor(:, indi) - lb) <= 1e-12, indi) = lb(abs(X_cor(:, indi) - lb) <= 1e-12);
                X_cor(abs(X_cor(:, indi) - ub) <= 1e-12, indi) = ub(abs(X_cor(:, indi) - ub) <= 1e-12);
            end
    
            correction_info.is_feasible = all((X_cor - lb >= -1e-12) & (X_cor - ub <= 1e-12)) ...
                                          & all((A_ieq * X_cor - b_ieq) <= 1e-12);
            correction_info.does_X_cor_exceed.by_bit = (X_cor - lb < -1e-12) | (X_cor - ub > 1e-12);
            correction_info.does_X_cor_exceed.globally = any((X_cor - lb < -1e-12) | (X_cor - ub > 1e-12));
            correction_info.is_inequality_less_than_b.by_bit = (A_ieq * X_cor - b_ieq) <= 1e-12;
            correction_info.is_inequality_less_than_b.globally = all((A_ieq * X_cor - b_ieq) <= 1e-12);

            run = run + 1;
            % Feasible, Theorem 5
            if all(correction_info.is_feasible)
                break;
            end
            % Infeasible, Theorems 4 & 5
            if ~any(correction_info.is_feasible) && run >= max_runtime
                X_cor = [];
                correction_info.is_feasible = false(1, N_P);
                correction_info.does_X_cor_exceed.by_bit = true(N_D, N_P);
                correction_info.does_X_cor_exceed.globally = true(1, N_P);
                correction_info.is_equation_equal_to_b.by_bit = false(M, N_P);
                correction_info.is_equation_equal_to_b.globally = false;
                break;
            end

            X_gen = X_cor; 
        end

    end

end

linear_constraints_correction函数

function [X_cor, correction_info] = linear_constraints_correction(X_gen, lb, ub, A_eq, b_eq, A_ieq, b_ieq, ...
                                    W_multiplicator)
    % LINEAR_PROGRAMMING_CORRECTION  Correction onto generated random vector.
    %                                A methodology of correction onto generated random vector,
    %                                facilitating the corrected vector to range within variable
    %                                boundaries and to meet linear constraints

    if ~exist('W_multiplicator', 'var')
        W_multiplicator = 1000;
    end

    Ab_eq = [A_eq, b_eq];
    
    M_eq = size(A_eq, 1);
    M_ieq = size(A_ieq, 1);
    [N_D, N_P] = size(X_gen);

    % Invoke Python for an accurate computation of the reduced row echelon form of Ab_eq
    Ab_eq_py = py.numpy.array(Ab_eq);
    Ab_eq_RREF_sym = py.sympy.Matrix(Ab_eq_py).rref();
    Ab_eq_RREF_raw = double(py.numpy.asarray(Ab_eq_RREF_sym(1), dtype = 'float'));
    if size(Ab_eq, 1) == 1
        Ab_eq_RREF = Ab_eq_RREF_raw;
    else
        Ab_eq_RREF = reshape(Ab_eq_RREF_raw, size(Ab_eq_RREF_raw, 2), size(Ab_eq_RREF_raw, 3));
    end

    R_A_eq = sum(any(Ab_eq_RREF(:, 1:end - 1), 2), 1);
    R_Ab_eq = sum(any(Ab_eq_RREF, 2), 1);

    % pivots_eq: Nonzero pivot columns in Ab_eq_RREF
    % non_pivots_eq: Other columns, except the end column, in Ab_eq_RREF
    pivots_eq = zeros(1, R_A_eq);
    for count = 1:R_A_eq
        pivots_eq(1, count) = find(Ab_eq_RREF(count, :), 1);
    end
    non_pivots_eq = find(~ismember(1:N_D, pivots_eq));
    
    A_eq_tilde = Ab_eq_RREF(:, non_pivots_eq);
    b_eq_tilde = Ab_eq_RREF(:, end);
    
    if R_A_eq < R_Ab_eq
        X_cor = [];
        correction_info.is_feasible = false(1, N_P);
        correction_info.does_X_cor_exceed.by_bit = true(N_D, N_P);
        correction_info.does_X_cor_exceed.globally = true(1, N_P);
        correction_info.is_equation_equal_to_b.by_bit = false(M_eq, N_P);
        correction_info.is_equation_equal_to_b.globally = false;
        correction_info.is_inequality_less_than_b.by_bit = false(M_ieq, N_P);
        correction_info.is_inequality_less_than_b.globally = false;
    
    else
        lb_base = lb(non_pivots_eq, :);
        ub_base = ub(non_pivots_eq, :);
        b_eq_tilde_plus = b_eq_tilde - lb(pivots_eq, end);
        b_eq_tilde_minus = b_eq_tilde - ub(pivots_eq, end);
        if isempty(A_eq)
            A_new = A_ieq;
            b_new = b_ieq;
            [X_cor, ~] = linear_inequalities_constraints_correction(X_gen, lb, ub, A_new, ...
                         b_new, W_multiplicator);

        elseif isempty(A_ieq)
            if R_A_eq == 1
                A_new = [-A_eq; A_eq];
                b_new = [-b_eq; b_eq];
                [X_cor, ~] = linear_inequalities_constraints_correction(X_gen, lb, ub, A_new, ...
                             b_new, W_multiplicator);

            else
                A_new = [-A_eq_tilde; A_eq_tilde];
                b_new = [-b_eq_tilde_minus; b_eq_tilde_plus];
                X_gen_base = X_gen(non_pivots_eq, :);
                [X_cor_base, ~] = linear_inequalities_constraints_correction(X_gen_base, lb_base, ...
                                  ub_base, A_new, b_new, W_multiplicator);
                X_cor(pivots_eq, :) = b_eq_tilde - A_eq_tilde * X_cor_base;
                X_cor(non_pivots_eq, :) = X_cor_base;

            end

        else
            if R_A_eq == 1
                A_new = [-A_eq; A_eq; A_ieq];
                b_new = [-b_eq; b_eq; b_ieq];
                [X_cor, ~] = linear_inequalities_constraints_correction(X_gen, lb, ub, A_new, ...
                             b_new, W_multiplicator);

            else
                A_new = [-A_eq_tilde; A_eq_tilde; A_ieq(:, non_pivots_eq) - A_ieq(:, pivots_eq) * A_eq_tilde];
                b_new = [-b_eq_tilde_minus; b_eq_tilde_plus; b_ieq - A_ieq(:, pivots_eq) * b_eq_tilde];
                X_gen_base = X_gen(non_pivots_eq, :);
                [X_cor_base, ~] = linear_inequalities_constraints_correction(X_gen_base, lb_base, ...
                                  ub_base, A_new, b_new, W_multiplicator);
                X_cor(pivots_eq, :) = b_eq_tilde - A_eq_tilde * X_cor_base;
                X_cor(non_pivots_eq, :) = X_cor_base;

            end
        end
        
        if isempty(A_eq)
            correction_info.is_feasible = all((X_cor - lb >= -1e-12) & (X_cor - ub <= 1e-12)) ...
                                          & all((A_ieq * X_cor - b_ieq) <= 1e-12);
            correction_info.does_X_cor_exceed.by_bit = (X_cor - lb < -1e-12) | (X_cor - ub > 1e-12);
            correction_info.does_X_cor_exceed.globally = any((X_cor - lb < -1e-12) | (X_cor - ub > 1e-12));
            correction_info.is_equation_equal_to_b.by_bit = [];
            correction_info.is_equation_equal_to_b.globally = [];
            correction_info.is_inequality_less_than_b.by_bit = (A_ieq * X_cor - b_ieq) <= 1e-12;
            correction_info.is_inequality_less_than_b.globally = all((A_ieq * X_cor - b_ieq) <= 1e-12);

        elseif isempty(A_ieq)
            correction_info.is_feasible = all((X_cor - lb >= -1e-12) & (X_cor - ub <= 1e-12)) ...
                                          & all(abs(A_eq * X_cor - b_eq) <= 1e-12);
            correction_info.does_X_cor_exceed.by_bit = (X_cor - lb < -1e-12) | (X_cor - ub > 1e-12);
            correction_info.does_X_cor_exceed.globally = any((X_cor - lb < -1e-12) | (X_cor - ub > 1e-12));
            correction_info.is_equation_equal_to_b.by_bit = abs(A_eq * X_cor - b_eq) <= 1e-12;
            correction_info.is_equation_equal_to_b.globally = all(abs(A_eq * X_cor - b_eq) <= 1e-12);
            correction_info.is_inequality_less_than_b.by_bit = [];
            correction_info.is_inequality_less_than_b.globally = [];

        else
            correction_info.is_feasible = all((X_cor - lb >= -1e-12) & (X_cor - ub <= 1e-12)) ...
                                          & all(abs(A_eq * X_cor - b_eq) <= 1e-12) & ...
                                          all((A_ieq * X_cor - b_ieq) <= 1e-12);
            correction_info.does_X_cor_exceed.by_bit = (X_cor - lb < -1e-12) | (X_cor - ub > 1e-12);
            correction_info.does_X_cor_exceed.globally = any((X_cor - lb < -1e-12) | (X_cor - ub > 1e-12));
            correction_info.is_equation_equal_to_b.by_bit = abs(A_eq * X_cor - b_eq) <= 1e-12;
            correction_info.is_equation_equal_to_b.globally = all(abs(A_eq * X_cor - b_eq) <= 1e-12);
            correction_info.is_inequality_less_than_b.by_bit = (A_ieq * X_cor - b_ieq) <= 1e-12;
            correction_info.is_inequality_less_than_b.globally = all((A_ieq * X_cor - b_ieq) <= 1e-12);

        end

    end

end

Problem 1

clear;
close all;
clc;

lb = [-3, -1, 2, -4, 0, 1, -6, -5]';
ub = [6, 4, 10, 8, 11, 3, 4, 4]';
X_gen = lb + rand(1, 100) .* (ub - lb);
A_eq = [6, -3, 1, 7, -5, 0, -3, 8];
b_eq = 12;

[X_cor, correction_info] = linear_constraints_correction(X_gen, lb, ub, [], [], A_eq, b_eq);

Problem 2

clear;
close all;
clc;

lb = [-5, -3, -6, 0]';
ub = [7, 1, -2, 6]';
X_gen = lb + rand(1, 100) .* (ub - lb);
A_eq = [1, 1, 1, 1; 0, 2, 1, 1];
b_eq = [-1, 1]';

[X_cor, correction_info] = linear_constraints_correction(X_gen, lb, ub, A_eq, b_eq, [], []);

Problem 3

clear;
close all;
clc;

lb = [-8, -15, -2, 0, -3, -10]';
ub = [9, 7, 4, 5, 8, 2]';
X_gen = lb + rand(1, 100) .* (ub - lb);
A_eq = [4, 3, 5, -7, 6, -8];
b_eq = -2;
A_ieq = [-7, -4, 8, -5, 0, 1];
b_ieq = 14;

[X_cor, correction_info] = linear_constraints_correction(X_gen, lb, ub, A_eq, b_eq, A_ieq, b_ieq);

Problem 4

clear;
close all;
clc;

lb = [-8, -15, -2, 1, -3, -10]';
ub = [9, 7, 11, 7, 8, 2]';
X_gen = lb + rand(1, 100) .* (ub - lb);
A_eq = [4, 3, 5, -7, 6, -8; -7, -4, 8, -5, 0, 8];
b_eq = [-2; 14];
A_ieq = [10, 3, -3, 6, -7, 2; 2, -3, -7, 5, -6, 3];
b_ieq = [9; -8];

[X_cor, correction_info] = linear_constraints_correction(X_gen, lb, ub, A_eq, b_eq, A_ieq, b_ieq);

研究目标

    (1) 探究满足某些非线性约束的生成随机数修正方法;
    (2) 探究随机向量为离散向量和连续-离散混合向量时的生成随机数修正方法;
    (3) 将生成随机数修正方法应用到基于启发式算法的优化问题求解中,使得启发式算法能够始终在优化问题的可行域中搜寻问题的解,从而加快启发式优化算法的收敛速度。

  • 6
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Academia1998

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值