0

I need to write the algorithm as formatted in the word. I need to insert initiate statement without taking any numbers, format symbols bold to indicate matrix, change the comments font and change algorithm font size only in the templet. this is the latex code.

Algorithm

\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}

this is the output for attached latex code

  • 1
    What have you tried so far? Please add a MWE. – epR8GaYuh Jan 8 at 9:32
  • 5
    Welcome to TeX.SX and to the LaTeX world in general. Please note that this page is primarily to answer specific questions and not solve do-it-for-me requests. For this reason your question might get closed as it is now. To tackle your issue: there are several packages related to algorithm, e.g. algorithm2e, algorithmicx etc. It would be best if you try to solve this with one of the dedicated packages, and if you encounter problems in the process, feel free to ask specific questions with an MWE. – Skillmon Jan 8 at 9:32
  • @epR8GaYuh \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$} \BlankLine \While{While condition}{ instructions\; \eIf{condition}{ instructions1\; instructions2\; }{ instructions3\; } } – Mona Mostafa Jan 8 at 10:22
  • @MonaMostafa Welcome here. You can edit your own post, so you should add this code to your post, not to a comment. Btw, your code is not a complete and compilable MWE. – user156344 Jan 8 at 11:16
  • Adding your current code as an image makes it hard to adapt it without having to re-type everything (in fact you replaced your copyable code with an image of it in a subsequent edit) - as well as the fact that this is no full compilable document. – epR8GaYuh Jan 8 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.