1

My long algorithm exceeds one page and will not fit on the page. I am using the algorithm2e package and the IEEE Access class. How to fit this long algorithm on one page?

\documentclass{ieeeaccess}
%\usepackage{siunitx}
\usepackage{graphicx
%\usepackage{algorithmic}
\usepackage[lined,boxed,ruled,commentsnumbered]{algorithm2e}
\begin{document}

\begin{algorithm} \tiny \color{red}\caption{HGPDO Algorithm steps} \label{algo:HGPDO Algorithm} \textbf{A.} \textbf{Algorithm Inputs: } RTP, operation time duration, energy usage pattern, wind speed in (m/s), temperature, solar irradiance, efficiency, bio-gas availability, prior-scheduling pattern of appliances, BSS, CHP and EVSS initialization.\newline \textbf{B. Parameters initialization:} Number of iterations, population size, $P_m$, $P_c$, $N$, $W_i$, $C_1$, $C_2$, $dimMin$, $dimMax$, $V_{min}$, $V_{max}$, $R_t$, $n$, $g$, $a$, maximum and minimum velocity, number of swarms, global and local pulls, initial and final momentum weights, cost per hour, PAR, $T_C$, $V_C$ and emission of CO$2$.\newline \For {Time=1:24 } { For initial position\newline \For {hour=1:swarm} { \For {i=1:n} { \If {rand>0.7} { X=1 } \Else { X=0 } } } For initial velocity\newline \For {vel1=1:10} { \For {vel2=1:6} { \If {Thour=0} { H=0 } } } return $V{best1}$, return $P_{best1}$\newline For initial velocity and initial position, Calculate $Vel_{best1}$ and $Pos_{best1}$\newline Generate population for WDO\newline Assign position and velocity\newline \Begin { Based on $1^{st}$ position and velocity do evaluation of fitness function\newline Using equations (\ref{eq:EQ1}) and (\ref{eq:eq2}) update the velocity and position respectively \newline $Vel_{best2}$, $Pos_{best2}$\newline based on $2_{nd}$ best position and velocity do evaluation of fitness function\newline Using equation (\ref{eq:eq3})-(\ref{eq:eq6}) update velocity, position, check limits and boundaries, respectively \newline Evaluate the fitness for WDO \newline Check for $T_c$ and $V_c$ feasibility:\newline \If {thermal comfort and visual comfort is less than WDO scheduled comfort} { Crossover $w_{best}$ and $g_{best}$, $Crossover_{result}$ = $cr_g$\newline } \Else { Crossover $Pos_{best1}$ and $Pos_{best2}$, $Crossover_{result}$ = $cr_g$, Mutate $cr_g$, $Mutation_{result}$=$global_{best}$ } }

returned $global_{best}$\newline \textbf{C. Compute objectives: EBC, PAR, Carbon emission and UC}\newline \Begin { \textbf{ 1. Compute user comfort} \newline \For {returned $global_{best}$, to calculate UC} { \textbf{a.} Usage power schedule=$global_{best}$ \newline \textbf{b.} Compute TC using equation (\ref{eq:eq41})\newline \textbf{c.} Compute VC using equation (\ref{eq:eq39})\newline \textbf{d.} Compute delay comfort using equation (\ref{eq:eq38})\newline \textbf{e.} Compute air quality comfort by equation (\ref{eq:eq42}) } \textbf{2. Compute electricity cost} \newline \For {returned $global_{best}$, to calculate cost} { \textbf{a.} Only EG: $L_t=power$*$global_{best}$\newline \textbf{b.} EG with RES: Lt(RES)=Load-Energy from RES\newline \textbf{c. }EG with RES and BSS: Lt(RES and BSS)=Load-Energy procured from RES-BSS discharge\newline \textbf{d.} Compute EBC by Equation (\ref{eq:eq13}) for Case a, b and c } \textbf{3. Compute CO$2$ emission}\newline \For {returned global-best, to calculate CO$_2$ emission} { \textbf{ a.} Only EG: average cost excluding RES and BSS\newline \textbf{b.} EG with RES: average cost including RES\newline \textbf{ c.} EG with RES and BSS: average cost including both RES and BSS\newline \textbf{d.} Compute CO$_2$ by Equation (\ref{eq:eq37}) for Case a, b and c } \textbf{4. Compute PAR}\newline \For {Operated returned global best, to calculate PAR} { \textbf{ a.} Only EG: $L_t=Power$\times$global{best}$\newline \textbf{b.} EG and RES: Lt(RES)=Load- Procured energy by RES\newline \textbf{c.} EG, RES and BSS: Lt(RES and BSS)=Load- Procured energy from RES-BSS discharge\newline \textbf{d.} Compute PAR by Equation (\ref{eq:eq36}) for Case a, b and c } } } \end{algorithm} \end{document}

JamesT
  • 3,169
  • A quick hint: You can tell the software to pretty-print chunks of LaTeX code by highlighting the lines in question and clicking on the {} "button" in the ribbon above the edit window. (That's the treatment I just applied to your code.) – Mico May 15 '21 at 07:48
  • While the algorithm2e cannot be split, it can be broken into cropped copies. See https://tex.stackexchange.com/questions/204703/multicols-not-breaking-procedures-in-algorithm2e/204792?r=SearchResults&s=3|26.9532#204792 for example. – John Kormylo May 15 '21 at 17:48

1 Answers1

1

From the algorithm2e documentation document: "Caution: algorithms cannot be cut, so if there is not enough place to put an algorithm with H option at agiven spot, LATEX will place a blank and put the algorithm on the following page"

So I believe your best option is to embed your algorithm inside a minipage or a resizebox. See How to scale algorithm to fit in one frame and centered in the frame at same time?

  • 1
    I think the OP's main issue is that the algorithm itself is taller than \textheight. Placing the algorithm environment in a minipage doesn't fix the height issue, and it's in fact bound to fail since one can't place a LaTeX float inside a minipage. If you try it, you'll get the dreaded LaTeX Error: Not in outer par mode. error message. – Mico May 15 '21 at 09:06