0

I have the following problem. I have a relatively long pseudocode, and when I have text before it, either 1) there is a lot of white space, or 2) the text on the previous page is stretched out, or the line spacing is very large. Now I wanted to ask if it is possible to distribute the pseudocode dynamically on both pages, similar to equation with \allowdisplaybreak{}. This is my MWE, unfortunately I could only reproduce 1).

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{algorithm}
\usepackage[noend]{algorithmic}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}

\begin{document}

\begin{algorithm}[H]
\footnotesize
\caption{Dynamic Task Assignment}
\label{algo:task_assign}
\KwIn{$\mathcal{J}^{\text{High}}, \mathcal{J}^{\text{Low}}, \mathcal{W}, \mathcal{S}^{\text{Time}}, R_j^{\text{Start}}, R_j^{\text{Dur}}, BW, \underline{BW}, C_{ws}, \alpha^{\text{Eff}}_{type}, optimization~params$}
\KwOut{$z_{jws}^{\text{High}}, u_{js}^{\text{High}}, COST_j^{\text{High}}$}

\textbf{Step 0: Reserve resources for priority jobs}\\
\ForEach{$j \in \mathcal{J}^{\text{High}}$}{
    deadline $\leftarrow R_j^{\text{Start}}$; \\
    \If{$\exists w \in \mathcal{W}$ with $C_{ws} > 0$ on deadline}{
        Reserve one unit: $C_{ws} \leftarrow C_{ws} - 1$\;
    }
    \Else{
        \Return{Infeasible}
    }
}
\textbf{Step 1: Initialize worker load and task counts}\\
Set worker load $U_w = 0$ for all $w \in \mathcal{W}$; taskCount$_j = 0$ for all $j\in \mathcal{J}^{\text{Low}}$\;
\\
\textbf{Step 2: Assign each job}\\
\ForEach{$j \in \mathcal{J}^{\text{Low}}$}{
    Assign worker $w^*$ with minimal $U_w$ if available on $R_j^{\text{Start}}$\;
    
    Schedule first task as direct work with $w^*$, update $C_{w^*s}$, $U_{w^*}$, set $cumProg_j = 1$\;
    
    $s \leftarrow R_j^{\text{Start}} + 1$\;
    
    \While{$cumProg_j < R_j^{\text{Dur}}$}{
        \If{$s > \max\mathcal{S}^{\text{Time}}$}{break}
        
        Compute $\alpha^{\text{Eff}}_j$ based on taskCount$_j$ and $\alpha^{\text{Eff}}_{type}$ and optimization parameters\;
        
        \If{full BW-window exists}{
            \If{QoS constraint not met and $C_{w^*s} > 0$}{
                Schedule direct work with $w^*$, update $C_{w^*s}$, $U_{w^*}$, $cumProg_j += 1$\;
            }
            \Else{
                Schedule automation, taskCount$_j += 1$, $cumProg_j += \alpha^{\text{Eff}}_j$\;
            }
        }
        \Else{
            \If{$C_{w^*s} > 0$ and $R_j^{\text{Dur}} - cumProg_j \geq 1$}{
                Schedule direct work with $w^*$, update $C_{w^*s}$, $U_{w^*}$, $cumProg_j += 1$\;
            }
            \Else{
                Schedule automation, taskCount$_j += 1$, $cumProg_j += \alpha^{\text{Eff}}_j$\;
            }
        }
        $s \leftarrow s + 1$\;
    }
    \textbf{Step 3: Ensure last task is direct work}\\
    \If{last scheduled task is not direct work}{
        \If{$C_{w^*s_{last}} > 0$}{
            Replace last automation with direct work, update $cumProg_j$\;
        }
        \Else{
            \While{no direct work assigned}{
                Compute $\alpha^{\text{Eff}}_j$ for next automation session\;
                
                Schedule automation, taskCount$_j += 1$, $cumProg_j += \alpha^{\text{Eff}}_j$\;
                
                \If{$C_{w^*s_{next}} > 0$}{
                    Schedule direct work with $w^*$, update $cumProg_j$, exit loop\;
                }
            }
        }
    }
    Calculate $COST_j$\;
}
\textbf{Step 4: Return solution}\\
Return $z_{jws}^{\text{High}}, u_{js}^{\text{High}}, COST_j^{\text{High}}$ for all $j \in \mathcal{J}^{\text{Low}}$\;
\end{algorithm}

\end{document}
4
  • 1
    Your code does not compile. Commented Jul 25 at 15:19
  • 2
    Floats can not break so you would need to not use a floating environment, also if you use [H] on a float that by design produces bad white space at a page break unless you adjust the text before and after the code to move text to the correct page. Commented Jul 25 at 15:46
  • 1
    I don't think you should load both algorithmic and algorithm2e. Commented Jul 25 at 15:53
  • 2
    Related/duplicate: How to split algorithm2e over two pages; algorithm2e split over several pages Commented Jul 25 at 16:05

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.