一、优化模型介绍

在所研究的区块链网络中,优化的变量为:挖矿决策(即 m)和资源分配(即 p 和 f),目标函数是使所有矿工的总利润最大化。问题可以表述为:

max ⁡ m , p , fF miner= ∑ i∈ N ′F i miners.t.C1: m i∈{0,1},∀i∈N C2: p min ⁡≤ p i≤ p max ⁡,∀i∈ N ′ C3: f min ⁡≤ f i≤ f max ⁡,∀i∈ N ′ C4: ∑ i∈ N ′f i≤ f total C5: F MSP ≥0 C6: T i t+ T i m+ T i o≤ T i max ⁡,∀i∈ N ′\begin{aligned} \max _{\mathbf{m}, \mathbf{p}, \mathbf{f}} & F^{\text {miner }}=\sum_{i \in \mathcal{N}^{\prime}} F_{i}^{\text {miner }} \\ \text { s.t. } & C 1: m_{i} \in\{0,1\}, \forall i \in \mathcal{N} \\ & C 2: p^{\min } \leq p_{i} \leq p^{\max }, \forall i \in \mathcal{N}^{\prime} \\ & C 3: f^{\min } \leq f_{i} \leq f^{\max }, \forall i \in \mathcal{N}^{\prime} \\ & C 4: \sum_{i \in \mathcal{N}^{\prime}} f_{i} \leq f^{\text {total }} \\ & C 5: F^{M S P} \geq 0 \\ & C 6: T_{i}^{t}+T_{i}^{m}+T_{i}^{o} \leq T_{i}^{\max }, \forall i \in \mathcal{N}^{\prime} \end{aligned} m,p,fmaxs.t.Fminer=iNFiminerC1:mi{0,1},iNC2:pminpipmax,iNC3:fminfifmax,iNC4:iNfiftotalC5:FMSP0C6:Tit+Tim+TioTimax,iN
其中:
C1表示每个矿工可以决定是否参与挖矿;
C2 指定分配给每个参与矿机的最小和最大传输功率;
C3 表示分配给每个参与矿工的最小和最大计算资源;
C4表示分配给参与矿机的总计算资源不能超过MEC服务器的总容量;
C5保证MSP的利润不小于0;
C6 规定卸载、挖掘和传播步骤的总时间不能超过最长时间约束。
在所研究的区块链网络中,我们假设 IoTD 是同质的,并且每个 IoTD 都具有相同的传输功率范围和相同的计算资源范围。
上式中:
F i miner =(w+α D i) P i m(1− P i o)− c 1 E i t− c 2 f i,∀i∈ N ′R i=B log⁡2 ( 1 +piHiσ2+ ∑ j ∈ N′\ imjpjHj ),∀i∈ N ′T i t= DiRi ,∀i∈ N ′T i m=D i X ifi ,∀i∈ N ′E i m= k 1 f i 3 T i m,∀i∈ N ′P i m= k2Tim ,∀i∈ N ′F MSP = ∑ i∈ N ′( c2fi− c3Eim)− c 3 E 0P i o = 1 − e − λ ( Tio+ Tis) = 1 − e − λ ( z Di+ Tit), ∀ i ∈ N′ F_i^{miner}=(w+\alpha D_i)P_i^m(1-P_i^o)-c_1E_i^t-c_2f_i,\forall i\in\mathcal{N’}\\R_{i}=B \log _{2}\left(1+\frac{p_{i} H_{i}}{\sigma^{2}+\sum_{j \in \mathcal{N}^{\prime} \backslash i} m_{j} p_{j} H_{j}}\right), \forall i \in \mathcal{N}^{\prime}\\T_{i}^{t}=\frac{D_{i}}{R_{i}},\forall i\in\mathcal{N}^{\prime}\\T_{i}^{m}=\frac{D_{i}X_{i}}{f_{i}},\forall i\in\mathcal{N}’\\E_i^m=k_1f_i^3T_i^m,\forall i\in\mathcal{N}’\\P_i^m=\frac{k_2}{T_i^m},\forall i\in\mathcal{N}^{\prime}\\F^{MSP}=\sum_{i\in\mathcal{N}^{\prime}}\left(c_2f_i-c_3E_i^m\right)-c_3E_0\\\begin{aligned} P_{i}^{o}& =1-e^{-\lambda(T_{i}^{o}+T_{i}^{s})} \\ &=1-e^{-\lambda(zD_{i}+T_{i}^{t})},\forall i\in\mathcal{N}^{\prime} \end{aligned} Fiminer=(w+αDi)Pim(1Pio)c1Eitc2fi,iNRi=Blog2(1+σ2+jN\imjpjHjpiHi),iNTit=RiDi,iNTim=fiDiXi,iNEim=k1fi3Tim,iNPim=Timk2,iNFMSP=iN(c2fic3Eim)c3E0Pio=1eλ(Tio+Tis)=1eλ(zDi+Tit),iN

二、差分进化算法求解

2.1部分代码

close allclear clcdbstop if all errorNP = 100;%矿工数量para = parametersetting(NP);para.MaxFEs =5000;%最大迭代次数Result=Compute(NP,para);figure(1)plot(Result.FitCurve,'r-','linewidth',2)xlabel('FEs')ylabel('Token')figure(2)plot(Result.ConCurve,'g-','linewidth',2)xlabel('FEs')ylabel('Con')

2.2部分结果

当矿工数量为100时:所有矿工的利润随迭代次数的变化如下图所示
算法得到的资源分配:

1.997633017120280.2225285976368551.984800906009890.2320037979818781.998107370200890.5168780754611271.994509541753270.1210047990488301.988943352929500.4575731613953141.981414413758510.7648011533738851.991237926110560.06183361158646241.999572681562570.1210047990488301.998699906968380.05458128963454511.999581670599880.5553224427272031.998427768867700.04256749328002461.997825462127530.5569994232193301.997817904860390.1965878068998221.995077860882040.1152261310665441.990522356114210.2456749728084441.996705986401930.05055312227160881.994827311125690.5704932960845911.997362789615520.4830941778616341.988943352929500.2625617115711751.987846894961560.03247787197443461.988516832457900.1719642204562181.987963861904180.1100546458258891.984189729900490.07243582269610231.995162353412900.03411791208702881.998737383631010.4893827837261581.996979743883020.01737124370867691.989648336793320.03200269138392831.997517197862780.1478900744971641.997517197862780.4349363152739991.997483317698410.2320037979818781.999608258764760.4836652325867501.997633017120280.6317450875722581.997035997796280.3582927464340591.995282220920610.5149443542588631.996550841690030.7538340272570071.998427768867700.9405605671876121.998361167675710.2212305598796151.999815763414360.1842497320874101.998361167675710.03247787197443461.996542016117100.3359159524132771.992379038916500.1550014239068531.997606117080880.3750175525926071.999787043614370.5617868321943781.985785741723720.02362398999790081.998667611780960.03247787197443461.997633017120280.4723694655888621.997218384380500.7009156799548011.994285647165770.1571995865502311.996551354833980.1052093903287711.947883620947200.02587554197012541.994494530623930.1322518964848951.997009922907780.08983977190085591.999655180953210.5965371240370701.992787869107480.02560425435135141.999578484311480.8949618475878231.991752993658950.08906746374342301.997507971575590.6075925325047971.997483317698410.07243582269610231.992605271160640.6317450875722581.999284399657800.1279304978322361.998177086661890.1042821606605611.994212061415390.8036561470797011.983599601086010.1188681092875971.998997000994440.5183570012757291.995282220920610.03247787197443461.998770986440220.6655296733191711.997633017120280.3340902686071011.998605605390760.08663797995360271.999796848485170.3772999902453421.998556311801320.3896798498079511.997312365732680.4349363152739991.996963603207360.5704932960845911.999930183789390.3912962470289551.999653279950290.2874601953448141.999796848485170.4509972121086261.997517197862780.2874601953448141.997633017120280.1550014239068531.997839833523910.1035692881674481.996542016117100.1279304978322361.987471162646870.03300880023253081.996551354833980.07970181661130991.991082222501110.08663797995360271.997182737301510.6622482137956991.998699906968380.1910582365564421.996529191472210.2155058877000111.994599576470110.1400566648956741.998060542854660.1205472313796141.985938628301660.09164863893289841.979316411432950.4627344280715151.998556311801320.1011200111140031.994212061415390.2584439088595301.997817904860390.5435169108434971.997205227269000.07371739311865711.983034408485160.1526227776367221.999008625136810.6745261320046261.998667611780960.3582927464340591.997839833523910.4913051468044561.999608258764760.1225792544023381.967109535625700.05138117848356621.998427768867700.0112006869294710

三、完整MATLAB代码