]> git.donarmstrong.com Git - lilypond.git/commitdiff
Don't use blank-page-force in ly:optimal-breaking.
authorJoe Neeman <joeneeman@gmail.com>
Wed, 6 Jan 2010 06:09:29 +0000 (17:09 +1100)
committerJoe Neeman <joeneeman@gmail.com>
Wed, 6 Jan 2010 08:43:40 +0000 (19:43 +1100)
Don't use an odd page penalty in space_systems_on_best_pages.
For space_systems_on_one_or_more_pages, allow the penalty to
be specified by the caller.

Also adds some -ddebug-page-breaking-scoring output for ly:optimal-breaking.

lily/include/page-breaking.hh
lily/optimal-page-breaking.cc
lily/page-breaking.cc
lily/page-turn-page-breaking.cc

index 2e5283d12fbcca5ab2f228b42a8cc1c3403699c7..002d7def29ee7e9be8409d77dbb91d9236c83b8b 100644 (file)
@@ -154,7 +154,8 @@ protected:
   Page_spacing_result space_systems_on_n_pages (vsize configuration_index,
                                                vsize n, vsize first_page_num);
   Page_spacing_result space_systems_on_n_or_one_more_pages (vsize configuration_index, vsize n,
-                                                           vsize first_page_num);
+                                                           vsize first_page_num,
+                                                           Real penalty_for_fewer_pages);
   Page_spacing_result space_systems_on_best_pages (vsize configuration_index,
                                                   vsize first_page_num);
   Page_spacing_result space_systems_with_fixed_number_per_page (vsize configuration_index,
index 0a7989df338c50a2a9ea696639b798e67817e136..94e22cb5125127751a58f727d81a54d2017b8313 100644 (file)
@@ -41,6 +41,8 @@ Optimal_page_breaking::~Optimal_page_breaking ()
 {
 }
 
+extern bool debug_page_breaking_scoring;
+
 // Solves the subproblem betwen the (END-1)th \pageBreak and the
 // ENDth \pageBreak.
 // Returns a vector of systems per page for the pages within this chunk.
@@ -98,6 +100,9 @@ Optimal_page_breaking::solve_chunk (vsize end)
       Page_spacing_result best_for_this_sys_count;
       set_current_breakpoints (end-1, end, sys_count, Line_division (), bound);
 
+      if (debug_page_breaking_scoring)
+       message (_f ("trying %d systems", (int)sys_count));
+
       for (vsize i = 0; i < current_configuration_count (); i++)
        {
          vsize min_p_count = min_page_count (i, first_page_num);
@@ -106,7 +111,7 @@ Optimal_page_breaking::solve_chunk (vsize end)
          if (min_p_count == page_count || scm_is_integer (forced_page_count))
            cur = space_systems_on_n_pages (i, page_count, first_page_num);
          else
-           cur = space_systems_on_n_or_one_more_pages (i, page_count-1, first_page_num);
+           cur = space_systems_on_n_or_one_more_pages (i, page_count-1, first_page_num, 0);
 
          if (cur.demerits_ < best_for_this_sys_count.demerits_)
            {
@@ -115,6 +120,9 @@ Optimal_page_breaking::solve_chunk (vsize end)
            }
        }
 
+      if (debug_page_breaking_scoring)
+       message (_f ("best score for this sys-count: %f", best_for_this_sys_count.demerits_));
+
       if (best_for_this_sys_count.demerits_ < best.demerits_)
        {
          best = best_for_this_sys_count;
@@ -147,6 +155,9 @@ Optimal_page_breaking::solve_chunk (vsize end)
       Real best_demerits_for_this_sys_count = infinity_f;
       set_current_breakpoints (end-1, end, sys_count, bound);
 
+      if (debug_page_breaking_scoring)
+       message (_f ("trying %d systems", (int)sys_count));
+
       for (vsize i = 0; i < current_configuration_count (); i++)
        {
          vsize min_p_count = min_page_count (i, first_page_num);
@@ -169,6 +180,10 @@ Optimal_page_breaking::solve_chunk (vsize end)
              bound = current_configuration (i);
            }
        }
+
+      if (debug_page_breaking_scoring)
+       message (_f ("best score for this sys-count: %f", best_demerits_for_this_sys_count));
+
       if (best_demerits_for_this_sys_count >= BAD_SPACING_PENALTY
        && !(best.system_count_status_ & SYSTEM_COUNT_TOO_FEW))
        break;
index e0a08c0dc5dddb7bfcfff9ea462dc6023080ae0b..a961dce545967c7494df3713e864cbf059d97fb0 100644 (file)
@@ -974,7 +974,8 @@ Page_breaking::blank_page_penalty () const
 // If systems_per_page_ is positive, we don't really try to space on N
 // or N+1 pages; see the comment to space_systems_on_n_pages.
 Page_spacing_result
-Page_breaking::space_systems_on_n_or_one_more_pages (vsize configuration, vsize n, vsize first_page_num)
+Page_breaking::space_systems_on_n_or_one_more_pages (vsize configuration, vsize n, vsize first_page_num,
+                                                    Real penalty_for_fewer_pages)
 {
   Page_spacing_result n_res;
   Page_spacing_result m_res;
@@ -1016,12 +1017,11 @@ Page_breaking::space_systems_on_n_or_one_more_pages (vsize configuration, vsize
   m_res = finalize_spacing_result (configuration, m_res);
   n_res = finalize_spacing_result (configuration, n_res);
 
-  Real penalty = blank_page_penalty ();
   Real page_spacing_weight = robust_scm2double (book_->paper_->c_variable ("page-spacing-weight"), 10);
-  n_res.demerits_ += penalty * page_spacing_weight;
+  n_res.demerits_ += penalty_for_fewer_pages * page_spacing_weight;
 
   if (n_res.force_.size ())
-    n_res.force_.back () += penalty;
+    n_res.force_.back () += penalty_for_fewer_pages;
 
   return (m_res.demerits_ < n_res.demerits_) ? m_res : n_res;
 }
@@ -1030,27 +1030,19 @@ Page_spacing_result
 Page_breaking::space_systems_on_best_pages (vsize configuration, vsize first_page_num)
 {
   vsize min_p_count = min_page_count (configuration, first_page_num);
-  Real page_spacing_weight = robust_scm2double (book_->paper_->c_variable ("page-spacing-weight"), 10);
-  Real odd_pages_penalty = blank_page_penalty () * page_spacing_weight;
 
   cache_line_details (configuration);
   Page_spacer ps (cached_line_details_, first_page_num, this);
   Page_spacing_result best = ps.solve (min_p_count);
-  best.force_.back () += (min_p_count % 2) ? odd_pages_penalty : 0;
-  best.demerits_ += (min_p_count % 2) ? odd_pages_penalty : 0;
 
   for (vsize i = min_p_count+1; i <= cached_line_details_.size (); i++)
     {
       Page_spacing_result cur = ps.solve (i);
-      cur.demerits_ += (i % 2) ? odd_pages_penalty : 0;
       if (cur.demerits_ < best.demerits_)
        best = cur;
     }
 
   Page_spacing_result ret = finalize_spacing_result (configuration, best);
-  ret.demerits_ += (ret.force_.size () % 2) ? odd_pages_penalty : 0;
-  if (ret.force_.size ())
-    ret.force_.back () += odd_pages_penalty;
   return ret;
 }
 
index c9029cf7b53e649fde6ff4455b468976b9c9117c..2641852faae7e418bfa290fc11f3209a1971f175 100644 (file)
@@ -86,14 +86,14 @@ Page_turn_page_breaking::put_systems_on_pages (vsize start,
   if (start == 0 && auto_first)
     {
       if (min_p_count % 2)
-       result = space_systems_on_n_or_one_more_pages (configuration, min_p_count, page_number);
+       result = space_systems_on_n_or_one_more_pages (configuration, min_p_count, page_number, 0);
       else
        result = space_systems_on_n_pages (configuration, min_p_count, page_number);
     }
   else if (page_number % 2 == min_p_count % 2)
     result = space_systems_on_n_pages (configuration, min_p_count, page_number);
   else
-    result = space_systems_on_n_or_one_more_pages (configuration, min_p_count, page_number);
+    result = space_systems_on_n_or_one_more_pages (configuration, min_p_count, page_number, blank_page_penalty ());
 
   Break_node ret;
   ret.prev_ = start - 1;