格式化伪代码算法

格式化伪代码算法

我需要按照 word 中的格式编写算法。我需要插入不带任何数字的启动语句,将符号格式化为粗体以表示矩阵,更改注释字体并仅在模板中更改算法字体大小。这是 latex 代码。

算法

\begin{algorithm}
\label{alg1}
\DontPrintSemicolon
\SetAlgoLined
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output} 
\Input{$e^n,e_{thr},snr_{thr},T_{tx},S_{id},l_x^n,l_y^n,l_z^n$}
\Output{Optimized Routing Path for sensor node($S^*$)}
%\Intiate{$h=1,RC\{:,0\}=0,fn=id^1$} 
\tcp*{$fn$ are the forwarding rely nodes for hop ($h$), $id^1$ is the ID of  
 source node, $RC$ is the total route cost.}
\While{ $h \geq 1$}{
\For {$ \forall  k , 1\leq  k  \leq |fn| $}
{Measure $snr^i$ between $fn^k$ and the other sensor nodes $id^i, 1 < i \leq 
|id^n|$

\tcp*{Calculate relay nodes for each hop ($h$)} 
$n_h^{fn^k}$ = $\{id^j | snr^j \geq snr_{thr}  \& \& e^j \geq e_{thr} \& \& 
l_z^j \leq l_z^{fn^k}, 1< j \leq |id^n| \}$

 \tcp*{Calculate possible relay nodes for each $fn^k$} 
  \For{$ \forall  jj , 1\leq  jj  \leq |n_h^{fn^k}| $}{
  Calculate $n_{EC}^{jj}$ between $fn^k$  and $n_h^{fn^k}(jj)$
  \tcp*{Calculate cost function (energy consumption) between $fn^k$
   and its possible relay nodes $n_h^{fn^k}$}    
  }
  Update $L\{:,h\} \leftarrow \{n_h^{fn^k}\}$ 

  \tcp*{Update $L\{:,h\}$ with $n_h^{fn^k}$ for each $fn^k$}   
  $RC\{:,h\}  \leftarrow \{n_{EC}+RC\{:,h-1\} \}$
  \tcp*{Update RC with the EC of new possible next relay nodes}  
}
 Update $fn \leftarrow L\{:,h\}$ 

 \For{$ \forall t , 1\leq  t  \leq |fn| $}
 {\tcp*{Check if reach sink node in the forwarding nodes $fn$}
   \If {$(fn^t == S_{id}$)}{
   \tcp*{Stop while loop as reach to the sink node}
   $R_{sink} \leftarrow fn^t$
    $R_{sink-rc} \leftarrow determine RC of R_{sink}$
   }
 }
 \If{$|R_{sink}|\geq 1 $}{
 Break While
 }
 $h\leftarrow h+1$    \tcp*{Increase h until reach $S_{id}$}
}
\tcp*{backtrace to select the optimized routing path with minimum RC}
$S^*\leftarrow  relay_{sink}(argmin_h R_{sink-RC}) $
\tcp*{determine the best relay node to $S_id$}
\For{$ \forall x , h-1 \leq  x  \leq 1 $}{
$S^*\leftarrow L\{:,(argmin_x RC\{:,x\}) \} $
}
Stop
\caption{Routing Path Selection Algorithm}
\end{algorithm}

这是附加乳胶代码的输出

相关内容