差分进化算法求解基于移动边缘计算 (MEC) 的无线区块链网络的联合挖矿决策和资源分配(提供MATLAB代码)

发布时间:2024年01月25日

一、优化模型介绍

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

max ? m , p , f F miner? = ∑ i ∈ N ′ F i miner? ?s.t.? C 1 : m i ∈ { 0 , 1 } , ? i ∈ N C 2 : p min ? ≤ p i ≤ p max ? , ? i ∈ N ′ C 3 : f min ? ≤ f i ≤ f max ? , ? i ∈ N ′ C 4 : ∑ i ∈ N ′ f i ≤ f total? C 5 : F M S P ≥ 0 C 6 : 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,fmax??s.t.??Fminer?=iN?Fiminer??C1:mi?{0,1},?iNC2:pminpi?pmax,?iNC3:fminfi?fmax,?iNC4:iN?fi?ftotal?C5:FMSP0C6:Tit?+Tim?+Tio?Timax?,?iN?
其中:
C1表示每个矿工可以决定是否参与挖矿;
C2 指定分配给每个参与矿机的最小和最大传输功率;
C3 表示分配给每个参与矿工的最小和最大计算资源;
C4表示分配给参与矿机的总计算资源不能超过MEC服务器的总容量;
C5保证MSP的利润不小于0;
C6 规定卸载、挖掘和传播步骤的总时间不能超过最长时间约束。
在所研究的区块链网络中,我们假设 IoTD 是同质的,并且每个 IoTD 都具有相同的传输功率范围和相同的计算资源范围。
上式中:
F i m i n e r = ( 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 + p i H i σ 2 + ∑ j ∈ N ′ \ i m j p j H j ) , ? i ∈ N ′ T i t = D i R i , ? i ∈ N ′ T i m = D i X i f i , ? i ∈ N ′ E i m = k 1 f i 3 T i m , ? i ∈ N ′ P i m = k 2 T i m , ? i ∈ N ′ F M S P = ∑ i ∈ N ′ ( c 2 f i ? c 3 E i m ) ? c 3 E 0 P i o = 1 ? e ? λ ( T i o + T i s ) = 1 ? e ? λ ( z D i + T i t ) , ? 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?(1?Pio?)?c1?Eit??c2?fi?,?iNRi?=Blog2?(1+σ2+jN\i?mj?pj?Hj?pi?Hi??),?iNTit?=Ri?Di??,?iNTim?=fi?Di?Xi??,?iNEim?=k1?fi3?Tim?,?iNPim?=Tim?k2??,?iNFMSP=iN?(c2?fi??c3?Eim?)?c3?E0?Pio??=1?e?λ(Tio?+Tis?)=1?e?λ(zDi?+Tit?),?iN?

二、差分进化算法求解

2.1部分代码

close all
clear 
clc
dbstop if all error
NP = 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.99763301712028	0.222528597636855
1.98480090600989	0.232003797981878
1.99810737020089	0.516878075461127
1.99450954175327	0.121004799048830
1.98894335292950	0.457573161395314
1.98141441375851	0.764801153373885
1.99123792611056	0.0618336115864624
1.99957268156257	0.121004799048830
1.99869990696838	0.0545812896345451
1.99958167059988	0.555322442727203
1.99842776886770	0.0425674932800246
1.99782546212753	0.556999423219330
1.99781790486039	0.196587806899822
1.99507786088204	0.115226131066544
1.99052235611421	0.245674972808444
1.99670598640193	0.0505531222716088
1.99482731112569	0.570493296084591
1.99736278961552	0.483094177861634
1.98894335292950	0.262561711571175
1.98784689496156	0.0324778719744346
1.98851683245790	0.171964220456218
1.98796386190418	0.110054645825889
1.98418972990049	0.0724358226961023
1.99516235341290	0.0341179120870288
1.99873738363101	0.489382783726158
1.99697974388302	0.0173712437086769
1.98964833679332	0.0320026913839283
1.99751719786278	0.147890074497164
1.99751719786278	0.434936315273999
1.99748331769841	0.232003797981878
1.99960825876476	0.483665232586750
1.99763301712028	0.631745087572258
1.99703599779628	0.358292746434059
1.99528222092061	0.514944354258863
1.99655084169003	0.753834027257007
1.99842776886770	0.940560567187612
1.99836116767571	0.221230559879615
1.99981576341436	0.184249732087410
1.99836116767571	0.0324778719744346
1.99654201611710	0.335915952413277
1.99237903891650	0.155001423906853
1.99760611708088	0.375017552592607
1.99978704361437	0.561786832194378
1.98578574172372	0.0236239899979008
1.99866761178096	0.0324778719744346
1.99763301712028	0.472369465588862
1.99721838438050	0.700915679954801
1.99428564716577	0.157199586550231
1.99655135483398	0.105209390328771
1.94788362094720	0.0258755419701254
1.99449453062393	0.132251896484895
1.99700992290778	0.0898397719008559
1.99965518095321	0.596537124037070
1.99278786910748	0.0256042543513514
1.99957848431148	0.894961847587823
1.99175299365895	0.0890674637434230
1.99750797157559	0.607592532504797
1.99748331769841	0.0724358226961023
1.99260527116064	0.631745087572258
1.99928439965780	0.127930497832236
1.99817708666189	0.104282160660561
1.99421206141539	0.803656147079701
1.98359960108601	0.118868109287597
1.99899700099444	0.518357001275729
1.99528222092061	0.0324778719744346
1.99877098644022	0.665529673319171
1.99763301712028	0.334090268607101
1.99860560539076	0.0866379799536027
1.99979684848517	0.377299990245342
1.99855631180132	0.389679849807951
1.99731236573268	0.434936315273999
1.99696360320736	0.570493296084591
1.99993018378939	0.391296247028955
1.99965327995029	0.287460195344814
1.99979684848517	0.450997212108626
1.99751719786278	0.287460195344814
1.99763301712028	0.155001423906853
1.99783983352391	0.103569288167448
1.99654201611710	0.127930497832236
1.98747116264687	0.0330088002325308
1.99655135483398	0.0797018166113099
1.99108222250111	0.0866379799536027
1.99718273730151	0.662248213795699
1.99869990696838	0.191058236556442
1.99652919147221	0.215505887700011
1.99459957647011	0.140056664895674
1.99806054285466	0.120547231379614
1.98593862830166	0.0916486389328984
1.97931641143295	0.462734428071515
1.99855631180132	0.101120011114003
1.99421206141539	0.258443908859530
1.99781790486039	0.543516910843497
1.99720522726900	0.0737173931186571
1.98303440848516	0.152622777636722
1.99900862513681	0.674526132004626
1.99866761178096	0.358292746434059
1.99783983352391	0.491305146804456
1.99960825876476	0.122579254402338
1.96710953562570	0.0513811784835662
1.99842776886770	0.0112006869294710

三、完整MATLAB代码

文章来源:https://blog.csdn.net/weixin_46204734/article/details/135733715
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。