iterateBalance :: AlgorithmOptions
               -> Cluster.Table -- ^ the starting table
               -> [MoveJob]     -- ^ current command list
               -> [MoveJob]     -- ^ resulting commands
iterateBalance opts ini_tbl cmds =
  let Cluster.Table ini_nl ini_il _ _ = ini_tbl
      m_next_tbl = Cluster.tryBalance opts ini_tbl
  in case m_next_tbl of
    Just next_tbl@(Cluster.Table _ _ _ plc@(curplc:_)) ->
      let (idx, _, _, move, _) = curplc
          plc_len = length plc
          (_, cs) = Cluster.printSolutionLine ini_nl ini_il 1 1 curplc plc_len
          afn = Cluster.involvedNodes ini_il curplc
          cmds' = (afn, idx, move, cs):cmds
      in iterateBalance opts next_tbl cmds'
    _ -> cmds

-- | List instances evacuated in a move job, if any.
iterateBalance :: AlgorithmOptions
               -> Cluster.Table -- ^ the starting table
               -> [MoveJob]     -- ^ current command list
               -> [MoveJob]
iterateBalance opts ini_tbl cmds =
  let Cluster.Table ini_nl ini_il _ _ = ini_tbl
      m_next_tbl = Cluster.tryBalance opts ini_tbl
  in case m_next_tbl of
    Just next_tbl@(Cluster.Table _ _ _ plc@(curplc:_)) ->
      let (idx, _, _, move, _) = curplc
          plc_len = length plc
          (_, cs) = Cluster.printSolutionLine ini_nl ini_il 1 1 curplc plc_len
          afn = Cluster.involvedNodes ini_il curplc
          cmds' = (afn, idx, move, cs):cmds
      in iterateBalance opts next_tbl cmds'
    _ -> cmds

-- | List instances evacuated in a move job, if any.
iterateBalance opts ini_tbl cmds =
  let Cluster.Table ini_nl ini_il _ _ = ini_tbl
      m_next_tbl = Cluster.tryBalance opts ini_tbl
  in case m_next_tbl of
    Just next_tbl@(Cluster.Table _ _ _ plc@(curplc:_)) ->
      let (idx, _, _, move, _) = curplc
          plc_len = length plc
          (_, cs) = Cluster.printSolutionLine ini_nl ini_il 1 1 curplc plc_len
          afn = Cluster.involvedNodes ini_il curplc
          cmds' = (afn, idx, move, cs):cmds
      in iterateBalance opts next_tbl cmds'
    _ -> cmds

-- | List instances evacuated in a move job, if any.