2 do calculations for breaking problem
6 #include "linespace.hh"
11 // construct an appropriate Spacing_problem and solve it.
13 PScore::solve_line(svec<const PCol *> curline) const
16 mtor << "line of " << curline.sz() << " cols\n";
17 sp.add_column(curline[0], true, 0.0);
18 for (int i=1; i< curline.sz()-1; i++)
19 sp.add_column(curline[i]);
20 sp.add_column(curline.last(), true, linewidth);
22 // misschien moeven uit Spacing_problem?
23 for (PCursor<Idealspacing *> i(suz); i.ok(); i++) {
26 svec<Real> the_sol=sp.solve();
35 error("PScore::problem_OK(): Score does not have any columns");
36 PCursor<PCol *> start(cols);
37 PCursor<PCol *> end (cols.bottom());
39 assert(start->breakable);
40 assert(end->breakable);
43 struct Col_configuration {
44 svec<const PCol*> line;
51 void add(const PCol*c) { line.add(c);}
52 void setsol(svec<Real> sol) {
54 energy = config.last();
59 /// wordwrap type algorithm
60 /* el stupido. This should be optimised:
62 It would be nice to have a Dynamic Programming type of algorithm
68 PScore::calc_breaking()
71 PCursor<PCol *> curcol(cols);
73 svec<const PCol *> breakpoints(find_breaks());
74 assert(breakpoints.sz()>=2);
75 for (int i=0 ; i < breakpoints.sz() -1; ) {
76 Col_configuration minimum;
77 Col_configuration current;
80 current.add(breakpoints[i]->postbreak );
81 curcol++; // skip the breakable.
84 while (i < breakpoints.sz()) {
86 // add another measure.
87 while(breakpoints[i] !=curcol){
92 current.add(breakpoints[i]->prebreak );
93 current.setsol(solve_line(current.line));
94 mtor << "energy : " << current.energy << '\n';
96 if (current.energy < minimum.energy) {
102 current.line.last()=breakpoints[i];
106 mtor << "Adding line, next breakpoint " << i << '\n';
107 add_line(minimum.line, minimum.config);