Revision f25e5aac hbal.hs

b/hbal.hs
80 80
                                               -- commands
81 81
iterateDepth ini_tbl max_rounds disk_moves nmlen imlen
82 82
             cmd_strs oneline min_score =
83
    let Cluster.Table ini_nl ini_il ini_cv ini_plc = ini_tbl
84
        all_inst = Container.elems ini_il
85
        node_idx = map Node.idx . filter (not . Node.offline) $
86
                   Container.elems ini_nl
87
        fin_tbl = Cluster.checkMove node_idx disk_moves ini_tbl all_inst
88
        (Cluster.Table _ _ fin_cv fin_plc) = fin_tbl
89
        ini_plc_len = length ini_plc
90
        fin_plc_len = length fin_plc
91
        allowed_next = (max_rounds < 0 || length fin_plc < max_rounds)
83
    let Cluster.Table ini_nl ini_il _ _ = ini_tbl
84
        m_fin_tbl = Cluster.tryBalance ini_tbl max_rounds disk_moves min_score
92 85
    in
93
      do
94
        let
95
            (sol_line, cmds) = Cluster.printSolutionLine ini_nl ini_il
96
                               nmlen imlen (head fin_plc) fin_plc_len
97
            upd_cmd_strs = cmds:cmd_strs
98
        unless (oneline || fin_plc_len == ini_plc_len) $ do
99
          putStrLn sol_line
100
          hFlush stdout
101
        (if fin_cv < ini_cv then -- this round made success, try deeper
102
             if allowed_next && fin_cv > min_score
103
             then iterateDepth fin_tbl max_rounds disk_moves
104
                  nmlen imlen upd_cmd_strs oneline min_score
105
             -- don't go deeper, but return the better solution
106
             else return (fin_tbl, upd_cmd_strs)
107
         else
108
             return (ini_tbl, cmd_strs))
86
      case m_fin_tbl of
87
        Just fin_tbl ->
88
            do
89
              let
90
                  (Cluster.Table _ _ _ fin_plc) = fin_tbl
91
                  fin_plc_len = length fin_plc
92
                  (sol_line, cmds) = Cluster.printSolutionLine ini_nl ini_il
93
                                     nmlen imlen (head fin_plc) fin_plc_len
94
                  upd_cmd_strs = cmds:cmd_strs
95
              unless oneline $ do
96
                       putStrLn sol_line
97
                       hFlush stdout
98
              iterateDepth fin_tbl max_rounds disk_moves
99
                           nmlen imlen upd_cmd_strs oneline min_score
100
        Nothing -> return (ini_tbl, cmd_strs)
109 101

  
110 102
-- | Formats the solution for the oneline display
111 103
formatOneline :: Double -> Int -> Double -> String

Also available in: Unified diff